diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 484d22def90..13f87ad01fd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -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); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java index 4ee74076b4a..1a216461506 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestUtils.java @@ -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 getDeviceIdentifiersList(){ + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setId("12345"); + identifier.setType("Test"); + + List list = new ArrayList<>(); + list.add(identifier); + + return list; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java new file mode 100644 index 00000000000..6a13e27b705 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceTest.java @@ -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 deviceGroups = groupManagementProviderService.getGroups(); + Assert.assertNotNull(deviceGroups); + } + + @Test(dependsOnMethods = ("createGroup")) + public void getGroupsByUsername() throws GroupManagementException { + List 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 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 roles = groupManagementProviderService.getRoles(1); + Assert.assertNotNull(roles); + } + + @Test(dependsOnMethods = ("createGroup")) + public void getDevices() throws GroupManagementException { + List 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 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 list = TestUtils.getDeviceIdentifiersList(); +// groupManagementProviderService.removeDevice(2, list); +// groupManagementProviderService.removeDevice(3, list); +// } + + @Test(dependsOnMethods = ("createGroup")) + public void getGroupsByUsernameAndPermissions() throws GroupManagementException { + List 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 groups = groupManagementProviderService.getGroups(identifier); +// Assert.assertNull(groups); +// } + + @Test + public void createDefaultGroup() throws GroupManagementException { + groupManagementProviderService.createDefaultGroup("BYOD"); + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 068c97664c1..686d0a6b3b9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -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, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml index e562ed1740b..3315b7109a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml @@ -40,6 +40,7 @@ + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml index ebc6ed4cfc0..d7468d13c72 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml @@ -19,12 +19,12 @@ true - admin - - admin - admin - - everyone + admin + + admin + admin + + everyone false 500 jdbc:h2:target/databasetest/CARBON_TEST @@ -33,34 +33,54 @@ 60000 5 - - org.wso2.carbon.user.core.tenant.JDBCTenantManager - false - 100 - false - default + + [\S]{5,30}$ + [\\S]{5,30} + SELECT * FROM UM_USER WHERE UM_USER_NAME=? AND UM_TENANT_ID=? + + + + + + + + + + + + + + + SHA-256 true - true - true false - ^[\S]{5,30}$ - Password length should be between 5 to 30 characters - - ^[\S]{5,30}$ - [a-zA-Z0-9._-|//]{3,30}$ - ^[\S]{3,30}$ - ^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$ - ^[\S]{3,30}$ - true - 100 + false + wso2.com + true 100 - false - false - true - , - true - + + + INSERT INTO UM_ROLE (UM_ROLE_NAME, UM_TENANT_ID) VALUES (?, ?) + + + + + + + + + + + + + + + + + org.wso2.carbon.user.core.tenant.JDBCTenantManager + true @@ -78,3 +98,4 @@ delegate-identity +