|
|
@ -37,6 +37,7 @@ package org.wso2.carbon.device.mgt.core.service;
|
|
|
|
|
|
|
|
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.Assert;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
import org.testng.annotations.BeforeClass;
|
|
|
|
|
|
|
|
import org.testng.annotations.DataProvider;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
@ -101,91 +102,91 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
|
|
|
|
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
|
|
|
groupManagementProviderService.createGroup(TestUtils.createDeviceGroup4(), DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void updateGroup() throws GroupManagementException, GroupNotExistException {
|
|
|
|
public void updateGroup() throws GroupManagementException, GroupNotExistException {
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName(), false);
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName(), false);
|
|
|
|
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
|
|
|
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
|
|
|
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
|
|
|
|
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
|
|
|
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
|
|
|
|
public void getGroupNull() throws GroupManagementException, GroupNotExistException {
|
|
|
|
public void getGroupNull() throws GroupManagementException, GroupNotExistException {
|
|
|
|
groupManagementProviderService.getGroup(null, false);
|
|
|
|
groupManagementProviderService.getGroup(null, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Rename again to use in different place.
|
|
|
|
// Rename again to use in different place.
|
|
|
|
@Test(dependsOnMethods = ("updateGroup"))
|
|
|
|
@Test(dependsOnMethods = "updateGroup")
|
|
|
|
public void updateGroupSecondTime() throws GroupManagementException, GroupNotExistException {
|
|
|
|
public void updateGroupSecondTime() throws GroupManagementException, GroupNotExistException {
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName() + "_UPDATED", true);
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup1().getName() + "_UPDATED", true);
|
|
|
|
deviceGroup.setName(TestUtils.createDeviceGroup1().getName());
|
|
|
|
deviceGroup.setName(TestUtils.createDeviceGroup1().getName());
|
|
|
|
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
|
|
|
|
groupManagementProviderService.updateGroup(deviceGroup, deviceGroup.getGroupId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
|
|
|
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
|
|
|
public void updateGroupError() throws GroupManagementException, GroupNotExistException {
|
|
|
|
public void updateGroupError() throws GroupManagementException, GroupNotExistException {
|
|
|
|
groupManagementProviderService.updateGroup(null, 1);
|
|
|
|
groupManagementProviderService.updateGroup(null, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
|
|
|
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class, GroupNotExistException.class})
|
|
|
|
public void updateGroupErrorNotExist() throws GroupManagementException, GroupNotExistException {
|
|
|
|
public void updateGroupErrorNotExist() throws GroupManagementException, GroupNotExistException {
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup2().getName(), false);
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup2().getName(), false);
|
|
|
|
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
|
|
|
deviceGroup.setName(deviceGroup.getName() + "_UPDATED");
|
|
|
|
groupManagementProviderService.updateGroup(deviceGroup, 6);
|
|
|
|
groupManagementProviderService.updateGroup(deviceGroup, 6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void deleteGroup() throws GroupManagementException {
|
|
|
|
public void deleteGroup() throws GroupManagementException {
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup4().getName(), false);
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup4().getName(), false);
|
|
|
|
Assert.assertTrue(groupManagementProviderService.deleteGroup(deviceGroup.getGroupId(), false));
|
|
|
|
Assert.assertTrue(groupManagementProviderService.deleteGroup(deviceGroup.getGroupId(), false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void deleteGroupNotExists() throws GroupManagementException {
|
|
|
|
public void deleteGroupNotExists() throws GroupManagementException {
|
|
|
|
groupManagementProviderService.deleteGroup(8, false);
|
|
|
|
groupManagementProviderService.deleteGroup(8, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroup() throws GroupManagementException {
|
|
|
|
public void getGroup() throws GroupManagementException {
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName(), false);
|
|
|
|
DeviceGroup deviceGroup = groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName(), false);
|
|
|
|
Assert.assertNotNull(groupManagementProviderService.getGroup(deviceGroup.getGroupId(), false));
|
|
|
|
Assert.assertNotNull(groupManagementProviderService.getGroup(deviceGroup.getGroupId(), false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroupByName() throws GroupManagementException {
|
|
|
|
public void getGroupByName() throws GroupManagementException {
|
|
|
|
Assert.assertNotNull(groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName(), false));
|
|
|
|
Assert.assertNotNull(groupManagementProviderService.getGroup(TestUtils.createDeviceGroup3().getName(), false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroups() throws GroupManagementException {
|
|
|
|
public void getGroups() throws GroupManagementException {
|
|
|
|
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups(true);
|
|
|
|
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups(true);
|
|
|
|
Assert.assertNotNull(deviceGroups);
|
|
|
|
Assert.assertNotNull(deviceGroups);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroupsByUsername() throws GroupManagementException {
|
|
|
|
public void getGroupsByUsername() throws GroupManagementException {
|
|
|
|
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups("admin", true);
|
|
|
|
List<DeviceGroup> deviceGroups = groupManagementProviderService.getGroups("admin", true);
|
|
|
|
Assert.assertNotNull(deviceGroups);
|
|
|
|
Assert.assertNotNull(deviceGroups);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
|
|
|
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
|
|
|
|
public void getGroupsByUsernameError() throws GroupManagementException {
|
|
|
|
public void getGroupsByUsernameError() throws GroupManagementException {
|
|
|
|
groupManagementProviderService.getGroups((String) null, false);
|
|
|
|
groupManagementProviderService.getGroups((String) null, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroupsByPagination() throws GroupManagementException {
|
|
|
|
public void getGroupsByPagination() throws GroupManagementException {
|
|
|
|
PaginationResult result = groupManagementProviderService.getGroups(TestUtils.createPaginationRequest(), true);
|
|
|
|
PaginationResult result = groupManagementProviderService.getGroups(TestUtils.createPaginationRequest(), true);
|
|
|
|
Assert.assertNotNull(result);
|
|
|
|
Assert.assertNotNull(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
|
|
|
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
|
|
|
|
public void getGroupsByPaginationError() throws GroupManagementException {
|
|
|
|
public void getGroupsByPaginationError() throws GroupManagementException {
|
|
|
|
groupManagementProviderService.getGroups((GroupPaginationRequest) null, true);
|
|
|
|
groupManagementProviderService.getGroups((GroupPaginationRequest) null, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroupsByUsernameAndPagination()
|
|
|
|
public void getGroupsByUsernameAndPagination()
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
PaginationResult result = groupManagementProviderService.getGroups("admin", TestUtils.createPaginationRequest(), false);
|
|
|
|
PaginationResult result = groupManagementProviderService.getGroups("admin", TestUtils.createPaginationRequest(), false);
|
|
|
@ -193,25 +194,30 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"), expectedExceptions = {GroupManagementException.class})
|
|
|
|
@Test(dependsOnMethods = "createGroup", expectedExceptions = {GroupManagementException.class})
|
|
|
|
public void getGroupsByUsernameAndPaginationError()
|
|
|
|
public void getGroupsByUsernameAndPaginationError()
|
|
|
|
throws GroupManagementException {
|
|
|
|
throws GroupManagementException {
|
|
|
|
groupManagementProviderService.getGroups(null, TestUtils.createPaginationRequest(), true);
|
|
|
|
groupManagementProviderService.getGroups(null, TestUtils.createPaginationRequest(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroupCount() throws GroupManagementException {
|
|
|
|
public void getGroupCount() throws GroupManagementException {
|
|
|
|
int x = groupManagementProviderService.getGroupCount();
|
|
|
|
int x = groupManagementProviderService.getGroupCount();
|
|
|
|
Assert.assertNotNull(x);
|
|
|
|
Assert.assertNotNull(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@DataProvider(name = "getGroupCountByUsernameProvider")
|
|
|
|
|
|
|
|
public static Object[][] userName() {
|
|
|
|
|
|
|
|
return new Object[][] {{"admin"}};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = "createGroup", dataProvider = "getGroupCountByUsernameProvider")
|
|
|
|
public void getGroupCountByUsername(String username) throws GroupManagementException {
|
|
|
|
public void getGroupCountByUsername(String username) throws GroupManagementException {
|
|
|
|
int x = groupManagementProviderService.getGroupCount(username, null);
|
|
|
|
int x = groupManagementProviderService.getGroupCount(username, null);
|
|
|
|
Assert.assertNotNull(x);
|
|
|
|
Assert.assertNotEquals(x, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("updateGroupSecondTime"))
|
|
|
|
@Test(dependsOnMethods = "updateGroupSecondTime")
|
|
|
|
public void manageGroupSharing() throws GroupManagementException, RoleDoesNotExistException, UserStoreException {
|
|
|
|
public void manageGroupSharing() throws GroupManagementException, RoleDoesNotExistException, UserStoreException {
|
|
|
|
groupManagementProviderService.manageGroupSharing(0, null);
|
|
|
|
groupManagementProviderService.manageGroupSharing(0, null);
|
|
|
|
List<String> newRoles = new ArrayList<>();
|
|
|
|
List<String> newRoles = new ArrayList<>();
|
|
|
@ -234,25 +240,25 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
|
|
|
|
TestUtils.createDeviceGroup1().getName(), false).getGroupId(), newRoles);
|
|
|
|
TestUtils.createDeviceGroup1().getName(), false).getGroupId(), newRoles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getRoles() throws GroupManagementException {
|
|
|
|
public void getRoles() throws GroupManagementException {
|
|
|
|
List<String> roles = groupManagementProviderService.getRoles(1);
|
|
|
|
List<String> roles = groupManagementProviderService.getRoles(1);
|
|
|
|
Assert.assertNotNull(roles);
|
|
|
|
Assert.assertNotNull(roles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getDevices() throws GroupManagementException {
|
|
|
|
public void getDevices() throws GroupManagementException {
|
|
|
|
List<Device> devices = groupManagementProviderService.getDevices(1, 1, 50, false);
|
|
|
|
List<Device> devices = groupManagementProviderService.getDevices(1, 1, 50, false);
|
|
|
|
Assert.assertNotNull(devices);
|
|
|
|
Assert.assertNotNull(devices);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getDeviceCount() throws GroupManagementException {
|
|
|
|
public void getDeviceCount() throws GroupManagementException {
|
|
|
|
int x = groupManagementProviderService.getDeviceCount(1);
|
|
|
|
int x = groupManagementProviderService.getDeviceCount(1);
|
|
|
|
Assert.assertEquals(0, x);
|
|
|
|
Assert.assertEquals(0, x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void addDevices() throws GroupManagementException, DeviceNotFoundException {
|
|
|
|
public void addDevices() throws GroupManagementException, DeviceNotFoundException {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceCacheConfiguration configuration = new DeviceCacheConfiguration();
|
|
|
|
DeviceCacheConfiguration configuration = new DeviceCacheConfiguration();
|
|
|
@ -268,7 +274,7 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
|
|
|
|
TestUtils.createDeviceGroup3().getName(), false).getGroupId(), list);
|
|
|
|
TestUtils.createDeviceGroup3().getName(), false).getGroupId(), list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("addDevices"))
|
|
|
|
@Test(dependsOnMethods = "addDevices")
|
|
|
|
public void removeDevice() throws GroupManagementException, DeviceNotFoundException {
|
|
|
|
public void removeDevice() throws GroupManagementException, DeviceNotFoundException {
|
|
|
|
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
|
|
|
|
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
|
|
|
|
groupManagementProviderService.removeDevice(groupManagementProviderService.getGroup(
|
|
|
|
groupManagementProviderService.removeDevice(groupManagementProviderService.getGroup(
|
|
|
@ -277,13 +283,13 @@ public class GroupManagementProviderServiceTest extends BaseDeviceManagementTest
|
|
|
|
TestUtils.createDeviceGroup3().getName(), false).getGroupId(), list);
|
|
|
|
TestUtils.createDeviceGroup3().getName(), false).getGroupId(), list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("createGroup"))
|
|
|
|
@Test(dependsOnMethods = "createGroup")
|
|
|
|
public void getGroupsByUsernameAndPermissions() throws GroupManagementException {
|
|
|
|
public void getGroupsByUsernameAndPermissions() throws GroupManagementException {
|
|
|
|
List<DeviceGroup> groups = groupManagementProviderService.getGroups("admin", "/permission/device-mgt/admin/groups", true);
|
|
|
|
List<DeviceGroup> groups = groupManagementProviderService.getGroups("admin", "/permission/device-mgt/admin/groups", true);
|
|
|
|
Assert.assertNotNull(groups);
|
|
|
|
Assert.assertNotNull(groups);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(dependsOnMethods = ("addDevices"))
|
|
|
|
@Test(dependsOnMethods = "addDevices")
|
|
|
|
public void getGroupsByDeviceIdentifier() throws GroupManagementException {
|
|
|
|
public void getGroupsByDeviceIdentifier() throws GroupManagementException {
|
|
|
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
|
|
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
|
|
|
identifier.setId("12345");
|
|
|
|
identifier.setId("12345");
|
|
|
|