mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #982 from charithag/master
Add test cases for grouping
This commit is contained in:
commit
3e9f62824e
@ -345,17 +345,18 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
for (DeviceGroup deviceGroup : deviceGroups) {
|
||||
groups.put(deviceGroup.getGroupId(), deviceGroup);
|
||||
}
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while getting user store manager.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
// } catch (UserStoreException e) {
|
||||
// String msg = "Error occurred while getting user store manager.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while retrieving all groups accessible to user.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (UserStoreException | SQLException | GroupManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving all groups accessible to user.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
log.error(e);
|
||||
throw new GroupManagementException(e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getGroups for " + username;
|
||||
log.error(msg, e);
|
||||
@ -385,17 +386,18 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
deviceGroupIds = this.groupDAO.getOwnGroupIds(username, tenantId);
|
||||
deviceGroupIds.addAll(this.groupDAO.getGroupIds(roleList, tenantId));
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while getting user store manager.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
// } catch (UserStoreException e) {
|
||||
// String msg = "Error occurred while getting user store manager.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while retrieving all groups accessible to user.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (UserStoreException | SQLException | GroupManagementDAOException e) {
|
||||
String msg = "Error occurred while retrieving all groups accessible to user.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
log.error(e);
|
||||
throw new GroupManagementException(e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getGroups for username '" + username + "'";
|
||||
log.error(msg, e);
|
||||
@ -424,14 +426,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
allMatchingGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
} catch (GroupManagementDAOException | SQLException e) {
|
||||
String msg = "Error occurred while retrieving all groups in tenant";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening a connection to the data source.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getGroups";
|
||||
log.error(msg, e);
|
||||
@ -454,14 +456,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return groupDAO.getGroupCount(tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
} catch (GroupManagementDAOException | SQLException e) {
|
||||
String msg = "Error occurred while retrieving all groups in tenant";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening a connection to the data source.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred";
|
||||
log.error(msg, e);
|
||||
@ -484,14 +486,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return groupDAO.getGroupCount(request, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
} catch (GroupManagementDAOException | SQLException e) {
|
||||
String msg = "Error occurred while retrieving all groups in tenant";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening a connection to the data source.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getGroupCount";
|
||||
log.error(msg, e);
|
||||
@ -525,18 +527,18 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
count = groupDAO.getOwnGroupsCount(username, tenantId);
|
||||
count += groupDAO.getGroupsCount(roleList, tenantId);
|
||||
return count;
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while getting user store manager.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
// } catch (UserStoreException e) {
|
||||
// String msg = "Error occurred while getting user store manager.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (UserStoreException | GroupManagementDAOException | SQLException e) {
|
||||
String msg = "Error occurred while retrieving group count of user '" + username + "'";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening a connection to the data source.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getGroupCount for username '" + username + "'";
|
||||
log.error(msg, e);
|
||||
@ -613,14 +615,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return groupDAO.getRoles(groupId, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
} catch (GroupManagementDAOException | SQLException e) {
|
||||
String msg = "Error occurred while retrieving all groups in tenant";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening a connection to the data source.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getRoles for groupId: " + groupId;
|
||||
log.error(msg, e);
|
||||
@ -645,18 +647,18 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
rowCount = DeviceManagerUtil.validateDeviceListPageSize(rowCount);
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
devices = this.groupDAO.getDevices(groupId, startIndex, rowCount, tenantId);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
} catch (GroupManagementDAOException | SQLException | DeviceManagementException e) {
|
||||
String msg = "Error occurred while getting devices in group.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while validating the limit of the devices to be returned";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening a connection to the data source.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
// } catch (DeviceManagementException e) {
|
||||
// String msg = "Error occurred while validating the limit of the devices to be returned";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getDevices for groupId: " + groupId;
|
||||
log.error(msg, e);
|
||||
@ -678,14 +680,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
try {
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return groupDAO.getDeviceCount(groupId, CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
} catch (GroupManagementDAOException e) {
|
||||
} catch (GroupManagementDAOException | SQLException e) {
|
||||
String msg = "Error occurred while retrieving all groups in tenant";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening a connection to the data source.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening a connection to the data source.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getDeviceCount for groupId: " + groupId;
|
||||
log.error(msg, e);
|
||||
@ -836,18 +838,18 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
||||
GroupManagementDAOFactory.openConnection();
|
||||
return groupDAO.getGroups(device.getId(),
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while retrieving the device details.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (GroupManagementDAOException e) {
|
||||
// } catch (DeviceManagementException e) {
|
||||
// String msg = "Error occurred while retrieving the device details.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (DeviceManagementException | GroupManagementDAOException | SQLException e) {
|
||||
String msg = "Error occurred while retrieving device groups.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening database connection.";
|
||||
log.error(msg, e);
|
||||
throw new GroupManagementException(msg, e);
|
||||
// } catch (SQLException e) {
|
||||
// String msg = "Error occurred while opening database connection.";
|
||||
// log.error(msg, e);
|
||||
// throw new GroupManagementException(msg, e);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error occurred in getGroups";
|
||||
log.error(msg, e);
|
||||
|
||||
@ -19,11 +19,16 @@ package org.wso2.carbon.device.mgt.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
@ -53,4 +58,54 @@ public class TestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static DeviceGroup createDeviceGroup1(){
|
||||
DeviceGroup group = new DeviceGroup();
|
||||
group.setName("TEST_GROUP_01");
|
||||
group.setDescription("TEST_GROUP_01 - Description");
|
||||
group.setOwner("admin");
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
public static DeviceGroup createDeviceGroup2(){
|
||||
DeviceGroup group = new DeviceGroup();
|
||||
group.setName("TEST_GROUP_02");
|
||||
group.setDescription("TEST_GROUP_02 - Description");
|
||||
group.setOwner("admin");
|
||||
return group;
|
||||
}
|
||||
|
||||
public static DeviceGroup createDeviceGroup3(){
|
||||
DeviceGroup group = new DeviceGroup();
|
||||
group.setName("TEST_GROUP_03");
|
||||
group.setDescription("TEST_GROUP_03 - Description");
|
||||
group.setOwner("admin");
|
||||
return group;
|
||||
}
|
||||
|
||||
public static DeviceGroup createDeviceGroup4(){
|
||||
DeviceGroup group = new DeviceGroup();
|
||||
group.setName("TEST_GROUP_04");
|
||||
group.setDescription("TEST_GROUP_04 - Description");
|
||||
group.setOwner("admin");
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
public static GroupPaginationRequest createPaginationRequest(){
|
||||
GroupPaginationRequest request = new GroupPaginationRequest(0, 5);
|
||||
return request;
|
||||
}
|
||||
|
||||
public static List<DeviceIdentifier> getDeviceIdentifiersList(){
|
||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||
identifier.setId("12345");
|
||||
identifier.setType("Test");
|
||||
|
||||
List<DeviceIdentifier> list = new ArrayList<>();
|
||||
list.add(identifier);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.service;
|
||||
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.*;
|
||||
import org.wso2.carbon.device.mgt.core.TestUtils;
|
||||
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService;
|
||||
import org.wso2.carbon.user.api.Permission;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.api.UserStoreManager;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest {
|
||||
|
||||
GroupManagementProviderService groupManagementProviderService;
|
||||
private static final String DEFAULT_ADMIN_ROLE = "admin";
|
||||
private static final String[] DEFAULT_ADMIN_PERMISSIONS = {"/permission/device-mgt/admin/groups",
|
||||
"/permission/device-mgt/user/groups"};
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
groupManagementProviderService = new GroupManagementProviderServiceImpl();
|
||||
RealmService realmService = new InMemoryRealmService();
|
||||
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
||||
realmService.getTenantManager().getSuperTenantDomain();
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = {GroupManagementException.class, GroupAlreadyExistException.class})
|
||||
public void createGroupNull() throws GroupManagementException, GroupAlreadyExistException {
|
||||
groupManagementProviderService.createGroup(null, null, null);
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = {GroupManagementException.class, GroupAlreadyExistException.class, TransactionManagementException.class})
|
||||
public void createGroupError() throws GroupManagementException, GroupAlreadyExistException, TransactionManagementException {
|
||||
GroupManagementDAOFactory.beginTransaction();
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void createGroup() throws GroupManagementException, GroupAlreadyExistException {
|
||||
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup1(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup2(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup3(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
|
||||
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void updateGroup() throws GroupManagementException, GroupNotExistException {
|
||||
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName());
|
||||
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
||||
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
||||
public void updateGroupError() throws GroupManagementException, GroupNotExistException {
|
||||
groupManagementProviderService.updateGroup(null, 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
||||
public void updateGroupErrorNotExist() throws GroupManagementException, GroupNotExistException {
|
||||
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup2().getName());
|
||||
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
||||
groupManagementProviderService.updateGroup(deviceGroup, 6);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void deleteGroup() throws GroupManagementException {
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup4().getName());
|
||||
Assert.assertTrue(groupManagementProviderService.deleteGroup(deviceGroup.getGroupId()));
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void deleteGroupNotExists() throws GroupManagementException {
|
||||
groupManagementProviderService.deleteGroup(8);
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroup() throws GroupManagementException {
|
||||
|
||||
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName());
|
||||
Assert.assertNotNull(groupManagementProviderService.getGroup(deviceGroup.getGroupId()));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupByName() throws GroupManagementException {
|
||||
Assert.assertNotNull(groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName()));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroups() throws GroupManagementException {
|
||||
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups();
|
||||
Assert.assertNotNull(deviceGroups);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByUsername() throws GroupManagementException {
|
||||
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups("admin");
|
||||
Assert.assertNotNull(deviceGroups);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
||||
public void getGroupsByUsernameError() throws GroupManagementException {
|
||||
String username = null;
|
||||
groupManagementProviderService.getGroups(username);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByPagination() throws GroupManagementException {
|
||||
PaginationResult result = groupManagementProviderService.getGroups(TestUtils.createPaginationRequest());
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
||||
public void getGroupsByPaginationError() throws GroupManagementException {
|
||||
GroupPaginationRequest request = null;
|
||||
groupManagementProviderService.getGroups(request);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByUsernameAndPagination(String username, GroupPaginationRequest paginationRequest)
|
||||
throws GroupManagementException {
|
||||
PaginationResult result = groupManagementProviderService.getGroups(username, paginationRequest);
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupCount() throws GroupManagementException {
|
||||
int x = groupManagementProviderService.getGroupCount();
|
||||
Assert.assertNotNull(x);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupCountByUsername(String username) throws GroupManagementException {
|
||||
int x = groupManagementProviderService.getGroupCount(username);
|
||||
Assert.assertNotNull(x);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void manageGroupSharing() throws GroupManagementException, RoleDoesNotExistException, UserStoreException {
|
||||
// groupManagementProviderService.manageGroupSharing(0, null);
|
||||
// List<String> newRoles = new ArrayList<>();
|
||||
// newRoles.add("TEST_ROLE_1");
|
||||
// newRoles.add("TEST_ROLE_2");
|
||||
// newRoles.add("TEST_ROLE_3");
|
||||
//
|
||||
// UserStoreManager userStoreManager =
|
||||
// DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
|
||||
// -1234).getUserStoreManager();
|
||||
// Permission[] permissions = new Permission[1];
|
||||
// Permission perm = new Permission("/admin/test/perm", "add");
|
||||
//// perm.setAction("execute.ui");
|
||||
//// perm.setResourceId("/admin/test/perm");
|
||||
// permissions[0] = perm;
|
||||
//
|
||||
// userStoreManager.addRole("TEST_ROLE_1", null, permissions);
|
||||
//
|
||||
// groupManagementProviderService.manageGroupSharing(1, newRoles);
|
||||
// }
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getRoles() throws GroupManagementException {
|
||||
List<String> roles = groupManagementProviderService.getRoles(1);
|
||||
Assert.assertNotNull(roles);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getDevices() throws GroupManagementException {
|
||||
List<Device> devices = groupManagementProviderService.getDevices(1, 1, 50);
|
||||
Assert.assertNotNull(devices);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getDeviceCount() throws GroupManagementException {
|
||||
int x = groupManagementProviderService.getDeviceCount(1);
|
||||
Assert.assertEquals(0, x);
|
||||
}
|
||||
|
||||
// @Test(dependsOnMethods = ("createGroup"))
|
||||
// public void addDevices() throws GroupManagementException, DeviceNotFoundException {
|
||||
//
|
||||
// DeviceCacheConfiguration configuration = new DeviceCacheConfiguration();
|
||||
// configuration.setEnabled(false);
|
||||
//
|
||||
// DeviceConfigurationManager.getInstance().getDeviceManagementConfig().setDeviceCacheConfiguration(configuration);
|
||||
//
|
||||
// List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
|
||||
// groupManagementProviderService.addDevices(1, list);
|
||||
// groupManagementProviderService.addDevices(2, list);
|
||||
// groupManagementProviderService.addDevices(3, list);
|
||||
// }
|
||||
//
|
||||
// @Test(dependsOnMethods = ("addDevices"))
|
||||
// public void removeDevice() throws GroupManagementException, DeviceNotFoundException {
|
||||
// List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
|
||||
// groupManagementProviderService.removeDevice(2, list);
|
||||
// groupManagementProviderService.removeDevice(3, list);
|
||||
// }
|
||||
|
||||
@Test(dependsOnMethods = ("createGroup"))
|
||||
public void getGroupsByUsernameAndPermissions() throws GroupManagementException {
|
||||
List<DeviceGroup> groups = groupManagementProviderService.getGroups("admin", "/permission/device-mgt/admin/groups");
|
||||
Assert.assertNotNull(groups);
|
||||
}
|
||||
|
||||
// @Test(dependsOnMethods = ("addDevices"))
|
||||
// public void getGroupsByDeviceIdentifier() throws GroupManagementException {
|
||||
// DeviceIdentifier identifier = new DeviceIdentifier();
|
||||
// identifier.setId("12345");
|
||||
// identifier.setType("Test");
|
||||
// List<DeviceGroup> groups = groupManagementProviderService.getGroups(identifier);
|
||||
// Assert.assertNull(groups);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void createDefaultGroup() throws GroupManagementException {
|
||||
groupManagementProviderService.createDefaultGroup("BYOD");
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
||||
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
||||
TENANT_ID VARCHAR(100) DEFAULT NULL,
|
||||
TENANT_ID VARCHAR(100),
|
||||
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, TENANT_ID)
|
||||
);
|
||||
|
||||
@ -438,7 +438,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
||||
INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
|
||||
EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
|
||||
EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
|
||||
CONNECTION_TYPE VARCHAR(10) NULL,
|
||||
CONNECTION_TYPE VARCHAR(50) NULL,
|
||||
SSID VARCHAR(45) NULL,
|
||||
CPU_USAGE DECIMAL(5) NULL,
|
||||
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
|
||||
|
||||
@ -40,6 +40,7 @@
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServiceTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.operation.OperationManagementTests"/>
|
||||
</classes>
|
||||
</test>
|
||||
|
||||
@ -19,12 +19,12 @@
|
||||
<Realm>
|
||||
<Configuration>
|
||||
<AddAdmin>true</AddAdmin>
|
||||
<AdminRole>admin</AdminRole>
|
||||
<AdminUser>
|
||||
<UserName>admin</UserName>
|
||||
<Password>admin</Password>
|
||||
</AdminUser>
|
||||
<EveryOneRoleName>everyone</EveryOneRoleName>
|
||||
<AdminRole>admin</AdminRole>
|
||||
<AdminUser>
|
||||
<UserName>admin</UserName>
|
||||
<Password>admin</Password>
|
||||
</AdminUser>
|
||||
<EveryOneRoleName>everyone</EveryOneRoleName>
|
||||
<ReadOnly>false</ReadOnly>
|
||||
<MaxUserNameListLength>500</MaxUserNameListLength>
|
||||
<Property name="url">jdbc:h2:target/databasetest/CARBON_TEST</Property>
|
||||
@ -33,34 +33,54 @@
|
||||
<Property name="maxWait">60000</Property>
|
||||
<Property name="minIdle">5</Property>
|
||||
</Configuration>
|
||||
<UserStoreManager class="org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager">
|
||||
<Property name="TenantManager">org.wso2.carbon.user.core.tenant.JDBCTenantManager</Property>
|
||||
<Property name="ReadOnly">false</Property>
|
||||
<Property name="MaxUserNameListLength">100</Property>
|
||||
<Property name="IsEmailUserName">false</Property>
|
||||
<Property name="DomainCalculation">default</Property>
|
||||
<UserStoreManager
|
||||
class="org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager">
|
||||
<Property name="PasswordJavaRegEx">[\S]{5,30}$</Property>
|
||||
<Property name="PasswordJavaScriptRegEx">[\\S]{5,30}</Property>
|
||||
<Property name="SelectUserSQL">SELECT * FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>
|
||||
<!--<Property name="GetRoleListSQL">SELECT UM_ROLE_NAME FROM UM_ROLE WHERE UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="UserFilterSQL">SELECT UM_USER_NAME FROM UM_USER WHERE UM_USER_NAME LIKE ? AND UM_TENANT_ID=? ORDER BY UM_USER_NAME</Property>-->
|
||||
<!--<Property name="UserRoleSQL">SELECT UM_ROLE_NAME FROM UM_USER_ROLE, UM_ROLE, UM_USER WHERE UM_USER.UM_USER_NAME=? AND UM_USER.UM_ID=UM_USER_ROLE.UM_USER_ID AND UM_ROLE.UM_ID=UM_USER_ROLE.UM_ROLE_ID AND UM_USER_ROLE.UM_TENANT_ID=? AND UM_ROLE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="IsRoleExistingSQL">SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="IsUserExistingSQL">SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserListOfRoleSQL">SELECT UM_USER_NAME FROM UM_USER_ROLE, UM_ROLE, UM_USER WHERE UM_ROLE.UM_ROLE_NAME=? AND UM_USER.UM_ID=UM_USER_ROLE.UM_USER_ID AND UM_ROLE.UM_ID=UM_USER_ROLE.UM_ROLE_ID AND UM_USER_ROLE.UM_TENANT_ID=? AND UM_ROLE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserPropertyForProfileSQL">SELECT UM_ATTR_VALUE FROM UM_USER_ATTRIBUTE, UM_USER WHERE UM_USER.UM_ID = UM_USER_ATTRIBUTE.UM_USER_ID AND UM_USER.UM_USER_NAME=? AND UM_ATTR_NAME=? AND UM_PROFILE_ID=? AND UM_USER_ATTRIBUTE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserPropertiesForProfileSQL">SELECT UM_ATTR_NAME, UM_ATTR_VALUE FROM UM_USER_ATTRIBUTE, UM_USER WHERE UM_USER.UM_ID = UM_USER_ATTRIBUTE.UM_USER_ID AND UM_USER.UM_USER_NAME=? AND UM_PROFILE_ID=? AND UM_USER_ATTRIBUTE.UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetProfileNamesSQL">SELECT DISTINCT UM_PROFILE_ID FROM UM_USER_ATTRIBUTE WHERE UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserProfileNamesSQL">SELECT DISTINCT UM_PROFILE_ID FROM UM_USER_ATTRIBUTE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUsersWithDefaultPasswordsSQL">SELECT UM_USER_NAME FROM UM_USER WHERE WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="UserNameUniqueAcrossTenantsSQL">SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=?</Property>-->
|
||||
<!--<Property name="GetUserIDFromUserNameSQL">SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetUserNameFromTenantIDSQL">SELECT UM_USER_NAME FROM UM_USER WHERE UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="GetTenantIDFromUserNameSQL">SELECT UM_TENANT_ID FROM UM_USER WHERE UM_USER_NAME=?</Property>-->
|
||||
<Property name="PasswordDigest">SHA-256</Property>
|
||||
<Property name="StoreSaltedPassword">true</Property>
|
||||
<Property name="ReadGroups">true</Property>
|
||||
<Property name="WriteGroups">true</Property>
|
||||
<Property name="UserNameUniqueAcrossTenants">false</Property>
|
||||
<Property name="PasswordJavaRegEx">^[\S]{5,30}$</Property>
|
||||
<Property name="PasswordJavaRegExViolationErrorMsg">Password length should be between 5 to 30 characters
|
||||
</Property>
|
||||
<Property name="PasswordJavaScriptRegEx">^[\S]{5,30}$</Property>
|
||||
<Property name="UsernameJavaRegEx">[a-zA-Z0-9._-|//]{3,30}$</Property>
|
||||
<Property name="UsernameJavaScriptRegEx">^[\S]{3,30}$</Property>
|
||||
<Property name="RolenameJavaRegEx">^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$</Property>
|
||||
<Property name="RolenameJavaScriptRegEx">^[\S]{3,30}$</Property>
|
||||
<Property name="UserRolesCacheEnabled">true</Property>
|
||||
<Property name="MaxRoleNameListLength">100</Property>
|
||||
<Property name="IsEmailUserName">false</Property>
|
||||
<Property name="SuperDomain">wso2.com</Property>
|
||||
<Property name="IsUsersOfRoleListing">true</Property>
|
||||
<Property name="MaxUserNameListLength">100</Property>
|
||||
<Property name="SharedGroupEnabled">false</Property>
|
||||
<Property name="SCIMEnabled">false</Property>
|
||||
<Property name="CaseSensitiveUsername">true</Property>
|
||||
<Property name="MultiAttributeSeparator">,</Property>
|
||||
<Property name="BulkImportSupported">true</Property>
|
||||
</UserStoreManager>
|
||||
<!-- writing sqls follow-->
|
||||
<!--<Property name="AddUserSQL">INSERT INTO UM_USER (UM_USER_NAME, UM_USER_PASSWORD, UM_SALT_VALUE, UM_REQUIRE_CHANGE, UM_CHANGED_TIME, UM_TENANT_ID) VALUES (?, ?, ?, ?, ?, ?)</Property>-->
|
||||
<Property name="AddRoleSQL">INSERT INTO UM_ROLE (UM_ROLE_NAME, UM_TENANT_ID) VALUES (?, ?)</Property>
|
||||
<!--<Property name="AddUserToRoleSQL">INSERT INTO UM_USER_ROLE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID) VALUES ((SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?), ?)</Property>-->
|
||||
<!--<Property name="AddUserToRoleSQL-mssql">INSERT INTO UM_USER_ROLE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID) SELECT (SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?),(?)</Property>-->
|
||||
<!--<Property name="RemoveUserFromRoleSQL">DELETE FROM UM_USER_ROLE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_ROLE_ID=(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="AddRoleToUserSQL">INSERT INTO UM_USER_ROLE (UM_ROLE_ID, UM_USER_ID, UM_TENANT_ID) VALUES ((SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), ?)</Property>-->
|
||||
<!--<Property name="AddRoleToUserSQL-mssql">INSERT INTO UM_USER_ROLE (UM_ROLE_ID, UM_USER_ID, UM_TENANT_ID) SELECT (SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?),(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), (?)</Property>-->
|
||||
<!--<Property name="RemoveRoleFromUserSQL">DELETE FROM UM_USER_ROLE WHERE UM_ROLE_ID=(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="DeleteRoleSQL">DELETE FROM UM_ROLE WHERE UM_ROLE_NAME = ? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="OnDeleteRoleRemoveUserRoleMappingSQL">DELETE FROM UM_USER_ROLE WHERE UM_ROLE_ID=(SELECT UM_ID FROM UM_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="OnDeleteUserRemoveUserRoleMappingSQL">DELETE FROM UM_USER_ROLE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="OnDeleteUserRemoveUserAttributeSQL">DELETE FROM UM_USER_ATTRIBUTE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="DeleteUserSQL">DELETE FROM UM_USER WHERE UM_USER_NAME = ? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="UpdateUserPasswordSQL">UPDATE UM_USER SET UM_USER_PASSWORD= ?, UM_SALT_VALUE=?, UM_REQUIRE_CHANGE=?, UM_CHANGED_TIME=? WHERE UM_USER_NAME= ? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="AddUserPropertySQL">INSERT INTO UM_USER_ATTRIBUTE (UM_USER_ID, UM_ATTR_NAME, UM_ATTR_VALUE, UM_PROFILE_ID, UM_TENANT_ID) VALUES ((SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), ?, ?, ?, ?)</Property>-->
|
||||
<!--<Property name="AddUserPropertySQL-mssql">INSERT INTO UM_USER_ATTRIBUTE (UM_USER_ID, UM_ATTR_NAME, UM_ATTR_VALUE, UM_PROFILE_ID, UM_TENANT_ID) SELECT (SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?), (?), (?), (?), (?)</Property>-->
|
||||
<!--<Property name="UpdateUserPropertySQL">UPDATE UM_USER_ATTRIBUTE SET UM_ATTR_VALUE=? WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_ATTR_NAME=? AND UM_PROFILE_ID=? AND UM_TENANT_ID=?</Property>-->
|
||||
<!--<Property name="DeleteUserPropertySQL">DELETE FROM UM_USER_ATTRIBUTE WHERE UM_USER_ID=(SELECT UM_ID FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=?) AND UM_ATTR_NAME=? AND UM_PROFILE_ID=? AND UM_TENANT_ID=?</Property>-->
|
||||
<Property name="TenantManager">org.wso2.carbon.user.core.tenant.JDBCTenantManager</Property>
|
||||
</UserStoreManager>
|
||||
<AuthorizationManager
|
||||
class="org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager">
|
||||
<Property name="AuthorizationCacheEnabled">true</Property>
|
||||
@ -78,3 +98,4 @@
|
||||
<Permission>delegate-identity</Permission>
|
||||
</SystemPermission>
|
||||
</UserManager>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user