mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding negative test cases for GroupProviderServiceImpl
This commit is contained in:
parent
b6c40cfa69
commit
b392f93aab
@ -445,11 +445,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException {
|
private int getGroupCount(GroupPaginationRequest request) throws GroupManagementException {
|
||||||
if (request == null) {
|
|
||||||
String msg = "Received empty request for getGroupCount";
|
|
||||||
log.error(msg);
|
|
||||||
throw new GroupManagementException(msg);
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Get groups count, pagination request " + request.toString());
|
log.debug("Get groups count, pagination request " + request.toString());
|
||||||
}
|
}
|
||||||
@ -522,7 +517,14 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
userStoreManager =
|
userStoreManager =
|
||||||
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
|
DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(
|
||||||
tenantId).getUserStoreManager();
|
tenantId).getUserStoreManager();
|
||||||
List<String> currentUserRoles = getRoles(groupId);
|
} catch (UserStoreException e) {
|
||||||
|
String msg = "User store error in updating sharing roles.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new GroupManagementException(msg, e);
|
||||||
|
}
|
||||||
|
List<String> currentUserRoles = getRoles(groupId);
|
||||||
|
try {
|
||||||
|
|
||||||
GroupManagementDAOFactory.beginTransaction();
|
GroupManagementDAOFactory.beginTransaction();
|
||||||
if (newRoles != null) {
|
if (newRoles != null) {
|
||||||
for (String role : newRoles) {
|
for (String role : newRoles) {
|
||||||
@ -546,10 +548,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
|
|||||||
GroupManagementDAOFactory.rollbackTransaction();
|
GroupManagementDAOFactory.rollbackTransaction();
|
||||||
log.error(e);
|
log.error(e);
|
||||||
throw new GroupManagementException(e);
|
throw new GroupManagementException(e);
|
||||||
} catch (UserStoreException e) {
|
|
||||||
String msg = "User store error in updating sharing roles.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new GroupManagementException(msg, e);
|
|
||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
throw new GroupManagementException(e);
|
throw new GroupManagementException(e);
|
||||||
|
|||||||
@ -0,0 +1,136 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.core.service;
|
||||||
|
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.TestUtils;
|
||||||
|
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GroupManagementProviderServiceNegativeTest extends BaseDeviceManagementTest {
|
||||||
|
private GroupManagementProviderService groupManagementProviderService;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
DataSource datasource = this.getDataSource(this.
|
||||||
|
readDataSourceConfig("src/test/resources/config/datasource/no-table-data-source-config.xml"));
|
||||||
|
GroupManagementDAOFactory.init(datasource);
|
||||||
|
groupManagementProviderService = new GroupManagementProviderServiceImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the addDevices method under negative scenarios",
|
||||||
|
expectedExceptions = {GroupManagementException.class},
|
||||||
|
expectedExceptionsMessageRegExp = "Error occurred while adding device to group.*")
|
||||||
|
public void testAddDevicesScenario1() throws GroupManagementException, DeviceNotFoundException {
|
||||||
|
List<DeviceIdentifier> list = TestUtils.getDeviceIdentifiersList();
|
||||||
|
groupManagementProviderService.addDevices(1, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the addDevices method under negative circumstances", expectedExceptions =
|
||||||
|
{GroupManagementException.class}, expectedExceptionsMessageRegExp = "Error occurred in addDevices for.*")
|
||||||
|
public void testAddDevicesScenario2() throws GroupManagementException, DeviceNotFoundException {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier("test", "test");
|
||||||
|
List<DeviceIdentifier> list = new ArrayList<>();
|
||||||
|
list.add(deviceIdentifier);
|
||||||
|
groupManagementProviderService.addDevices(1, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroup method of the GroupManagementProviderService under "
|
||||||
|
+ "negative conditions", expectedExceptions = {GroupManagementException.class},
|
||||||
|
expectedExceptionsMessageRegExp = "Error occurred while obtaining group.*")
|
||||||
|
public void testGetGroup() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroup(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroup method of the GroupManagementProviderService under "
|
||||||
|
+ "negative conditions", expectedExceptions = {GroupManagementException.class},
|
||||||
|
expectedExceptionsMessageRegExp = "Error occurred while obtaining group with name.*")
|
||||||
|
public void testGetGroupWithName() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroup("1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroups method of the GroupManagementProviderService under negative "
|
||||||
|
+ "conditions", expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp =
|
||||||
|
"Error occurred while retrieving all groups in tenant.*")
|
||||||
|
public void testGetGroups() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroups method of the GroupManagementProviderService under negative "
|
||||||
|
+ "conditions", expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp =
|
||||||
|
"Error occurred while retrieving all groups accessible to user.*")
|
||||||
|
public void testGetGroupsWithUserName() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroups("test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroupCount method under negative circumstances", expectedExceptions
|
||||||
|
= {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Error occurred while retrieving all "
|
||||||
|
+ "groups in tenant")
|
||||||
|
public void testGetGroupCount() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroupCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroupCount method with username under negative circumstances",
|
||||||
|
expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Error occurred "
|
||||||
|
+ "while retrieving group count of user.*")
|
||||||
|
public void testGetGroupCountWithUserName() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroupCount("test");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroups method with pagination request under negative "
|
||||||
|
+ "circumstances", expectedExceptions = {GroupManagementException.class},
|
||||||
|
expectedExceptionsMessageRegExp = "Error occurred while retrieving all groups in tenant")
|
||||||
|
public void testGetGroupsWithPaginationRequest() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroups(TestUtils.createPaginationRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroups method with pagination request and username under negative "
|
||||||
|
+ "circumstances", expectedExceptions = {GroupManagementException.class},
|
||||||
|
expectedExceptionsMessageRegExp = "Error occurred while retrieving all groups accessible to user.")
|
||||||
|
public void testGetGroupsWithPaginationRequestAndUserName() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroups("test", TestUtils.createPaginationRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the get roles method under negative circumstances",
|
||||||
|
expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Error occurred "
|
||||||
|
+ "while retrieving all groups in tenant.*")
|
||||||
|
public void testManageGroupSharing() throws GroupManagementException, RoleDoesNotExistException {
|
||||||
|
groupManagementProviderService.getRoles(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getDeviceCount under negative circumstances.", expectedExceptions =
|
||||||
|
{GroupManagementException.class}, expectedExceptionsMessageRegExp = "Error occurred while retrieving all "
|
||||||
|
+ "groups in tenant.*")
|
||||||
|
public void testGetDeviceCount() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getDeviceCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getDevices method under negative circumstances", expectedExceptions =
|
||||||
|
{GroupManagementException.class})
|
||||||
|
public void testGetDevicesWithPagination() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getDevices(1, 0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests the getGroupCount with username when the user name is given as null",
|
||||||
|
expectedExceptions = {GroupManagementException.class}, expectedExceptionsMessageRegExp = "Received empty "
|
||||||
|
+ "user name for getGroupCount.*")
|
||||||
|
public void testGetGroupCountWithUserName2() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroupCount(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "This method tests getGroups method under negative circumstances",
|
||||||
|
expectedExceptionsMessageRegExp = "Received empty device identifier for getGroups",
|
||||||
|
expectedExceptions = {GroupManagementException.class})
|
||||||
|
public void testGetGroupsWithDeviceIdentifier() throws GroupManagementException {
|
||||||
|
groupManagementProviderService.getGroups((DeviceIdentifier) null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -54,6 +54,7 @@
|
|||||||
<class name="org.wso2.carbon.device.mgt.core.search.ProcessorImplTest"/>
|
<class name="org.wso2.carbon.device.mgt.core.search.ProcessorImplTest"/>
|
||||||
<class name="org.wso2.carbon.device.mgt.core.search.SearchMgtUtilTest"/>
|
<class name="org.wso2.carbon.device.mgt.core.search.SearchMgtUtilTest"/>
|
||||||
<class name="org.wso2.carbon.device.mgt.core.cache.DeviceCacheManagerImplTest"/>
|
<class name="org.wso2.carbon.device.mgt.core.cache.DeviceCacheManagerImplTest"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceNegativeTest"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user