Minor changes to the base test class

revert-70aa11f8
Rasika Perera 7 years ago
parent 030d7cd26d
commit e51e344463

@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.internal.collections.Pair;
import org.w3c.dom.Document;
@ -36,7 +35,6 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -48,7 +46,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
import org.wso2.carbon.ntask.common.TaskException;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.common.DataSourceConfig;
@ -100,7 +97,7 @@ public abstract class BasePolicyManagementDAOTest {
DeviceConfigurationManager.getInstance().initConfig();
}
protected void initializeServices() throws Exception{
protected void initializeServices() throws Exception {
initDatSource();
initSQLScript();
@ -155,7 +152,7 @@ public abstract class BasePolicyManagementDAOTest {
}
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants
.SUPER_TENANT_DOMAIN_NAME);
.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
}
@ -260,20 +257,21 @@ public abstract class BasePolicyManagementDAOTest {
}
public interface Command {
void call(Profile profile) throws Exception;
void call(Object paramObj) throws Exception;
}
protected void testThrowingException(Profile profile, Command command, String fieldName, Object mockObj,
Class<?> exceptionClass) throws Exception {
Object oldObj = changeFieldValue(profileManager, fieldName, mockObj);
protected void testThrowingException(Object targetObj, Object paramObj, Command command, String fieldName,
Object mockObj,
Class<?> exceptionClass) throws Exception {
Object oldObj = changeFieldValue(targetObj, fieldName, mockObj);
try {
command.call(profile);
command.call(paramObj);
} catch (Exception e) {
if (!(e.getCause().getClass().getName().equals(exceptionClass.getName()))) {
throw e;
}
} finally {
changeFieldValue(profileManager, fieldName, oldObj);
changeFieldValue(targetObj, fieldName, oldObj);
}
}

@ -13,14 +13,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.policy.mgt.Profile;
import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
import org.wso2.carbon.policy.mgt.core.BasePolicyManagementDAOTest;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
@ -30,9 +23,7 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
import org.wso2.carbon.policy.mgt.core.dao.impl.ProfileDAOImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mock.TypeXDeviceManagementService;
import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
import org.wso2.carbon.policy.mgt.core.util.FeatureCreator;
import org.wso2.carbon.policy.mgt.core.util.ProfileCreator;
@ -89,7 +80,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
when(profileDAO.addProfile(any(Profile.class))).thenThrow(new ProfileManagerDAOException());
//Creating profile object
Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList(), DEVICE_TYPE_C);
testThrowingException(profile, p -> profileManager.addProfile(p), "profileDAO", profileDAO,
testThrowingException(profileManager, profile, p -> profileManager.addProfile((Profile) p), "profileDAO",
profileDAO,
ProfileManagerDAOException.class);
}
@ -101,7 +93,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
new FeatureManagerDAOException());
//Creating profile object
Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList(), DEVICE_TYPE_C);
testThrowingException(profile, p -> profileManager.addProfile(p), "featureDAO", featureDAO,
testThrowingException(profileManager, profile, p -> profileManager.addProfile((Profile) p), "featureDAO",
featureDAO,
FeatureManagerDAOException.class);
}
@ -139,7 +132,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
String newProfileName = "Updated Test Profile";
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
savedProfile.setProfileName(newProfileName);
testThrowingException(savedProfile, p -> profileManager.updateProfile(p), "profileDAO", profileDAO,
testThrowingException(profileManager, savedProfile, p -> profileManager.updateProfile((Profile) p),
"profileDAO", profileDAO,
ProfileManagerDAOException.class);
}
@ -153,7 +147,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
String newProfileName = "Updated Test Profile";
Profile savedProfile = profileManager.getProfile(profile1.getProfileId());
savedProfile.setProfileName(newProfileName);
testThrowingException(savedProfile, p -> profileManager.updateProfile(p), "featureDAO", featureDAO,
testThrowingException(profileManager, savedProfile, p -> profileManager.updateProfile((Profile) p),
"featureDAO", featureDAO,
FeatureManagerDAOException.class);
}
@ -196,7 +191,9 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testGetProfileThrowingProfileManagerDAOException() throws Exception {
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
when(profileDAO.getProfile(anyInt())).thenThrow(new ProfileManagerDAOException());
testThrowingException(profile1, p -> profileManager.getProfile(p.getProfileId()), "profileDAO", profileDAO,
testThrowingException(profileManager, profile1, p -> profileManager.getProfile(((Profile) p).getProfileId()),
"profileDAO",
profileDAO,
ProfileManagerDAOException.class);
}
@ -205,7 +202,9 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testGetProfileThrowingFeatureManagerDAOException() throws Exception {
FeatureDAO featureDAO = mock(FeatureDAO.class);
when(featureDAO.getFeaturesForProfile(anyInt())).thenThrow(new FeatureManagerDAOException());
testThrowingException(profile1, p -> profileManager.getProfile(p.getProfileId()), "featureDAO", featureDAO,
testThrowingException(profileManager, profile1, p -> profileManager.getProfile(((Profile) p).getProfileId()),
"featureDAO",
featureDAO,
FeatureManagerDAOException.class);
}
@ -235,7 +234,7 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testGetAllProfilesThrowingProfileManagerDAOException() throws Exception {
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
when(profileDAO.getAllProfiles()).thenThrow(new ProfileManagerDAOException());
testThrowingException(profile1, p -> profileManager.getAllProfiles(), "profileDAO", profileDAO,
testThrowingException(profileManager, profile1, p -> profileManager.getAllProfiles(), "profileDAO", profileDAO,
ProfileManagerDAOException.class);
}
@ -244,7 +243,7 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testGetAllProfilesThrowingFeatureManagerDAOException() throws Exception {
FeatureDAO featureDAO = mock(FeatureDAO.class);
when(featureDAO.getAllProfileFeatures()).thenThrow(new FeatureManagerDAOException());
testThrowingException(profile1, p -> profileManager.getAllProfiles(), "featureDAO", featureDAO,
testThrowingException(profileManager, profile1, p -> profileManager.getAllProfiles(), "featureDAO", featureDAO,
FeatureManagerDAOException.class);
}
@ -275,7 +274,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testGetProfilesOfDeviceTypeThrowingProfileManagerDAOException() throws Exception {
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
when(profileDAO.getProfilesOfDeviceType(anyString())).thenThrow(new ProfileManagerDAOException());
testThrowingException(profile1, p -> profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C), "profileDAO",
testThrowingException(profileManager, profile1, p -> profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C),
"profileDAO",
profileDAO,
ProfileManagerDAOException.class);
}
@ -286,7 +286,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testGetProfilesOfDeviceTypeThrowingFeatureManagerDAOException() throws Exception {
FeatureDAO featureDAO = mock(FeatureDAO.class);
when(featureDAO.getAllProfileFeatures()).thenThrow(new FeatureManagerDAOException());
testThrowingException(profile1, p -> profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C), "featureDAO",
testThrowingException(profileManager, profile1, p -> profileManager.getProfilesOfDeviceType(DEVICE_TYPE_C),
"featureDAO",
featureDAO,
FeatureManagerDAOException.class);
}
@ -311,7 +312,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testDeleteProfileThrowingProfileManagerDAOException() throws Exception {
ProfileDAO profileDAO = mock(ProfileDAOImpl.class);
when(profileDAO.deleteProfile(any(Profile.class))).thenThrow(new ProfileManagerDAOException());
testThrowingException(profile1, p -> profileManager.deleteProfile(profile1), "profileDAO", profileDAO,
testThrowingException(profileManager, profile1, p -> profileManager.deleteProfile(profile1), "profileDAO",
profileDAO,
ProfileManagerDAOException.class);
}
@ -320,7 +322,8 @@ public class ProfileManagerImplTest extends BasePolicyManagementDAOTest {
public void testDeleteProfileThrowingFeatureManagerDAOException() throws Exception {
FeatureDAO featureDAO = mock(FeatureDAO.class);
when(featureDAO.deleteFeaturesOfProfile(any(Profile.class))).thenThrow(new FeatureManagerDAOException());
testThrowingException(profile1, p -> profileManager.deleteProfile(profile1), "featureDAO", featureDAO,
testThrowingException(profileManager, profile1, p -> profileManager.deleteProfile(profile1), "featureDAO",
featureDAO,
FeatureManagerDAOException.class);
}

Loading…
Cancel
Save