Adding couple of missing testcase in policy service

revert-70aa11f8
Jasintha 7 years ago
parent 23983303a1
commit 3a298be073

@ -149,8 +149,14 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
deviceIdentifier.getId() + " - " + deviceIdentifier.getType());
}
} catch (PolicyEvaluationException e) {
String msg = "Error occurred while getting the effective features from the PEP service " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
String msg;
if(deviceIdentifier != null) {
msg = "Error occurred while getting the effective features from the PEP service " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
}else {
msg = "Null deviceIdentifier object is passed to the method";
}
log.error(msg, e);
throw new FeatureManagementException(msg, e);
}

@ -19,6 +19,7 @@ package org.wso2.carbon.policy.mgt.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mockito.Spy;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -51,6 +52,8 @@ 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.policy.mgt.common.FeatureManagementException;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask;
@ -212,6 +215,7 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
policy1.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
policy1 = policyManagerService.addPolicy(policy1);
int policyCount = policyManagerService.getPolicyCount();
Assert.assertEquals(policyCount, 1, "Policy count should be 1");
@ -232,6 +236,8 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
policyManagerService.getPAP().activatePolicy(policy1.getId());
Policy effectivePolicy = policyManagerService.getEffectivePolicy(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
Assert.assertEquals(effectivePolicy.getPolicyName(), POLICY1, POLICY1 + " was not activated for " + DEVICE1);
}
@Test(dependsOnMethods = "activatePolicy")
@ -326,9 +332,32 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
}
@Test(dependsOnMethods = "updatePolicy")
public void deletePolicy() throws PolicyManagementException {
public void deletePolicyById() throws PolicyManagementException {
policyManagerService.deletePolicy(policy1.getId());
Policy tempPolicy = policyManagerService.getPAP().getPolicy(policy1.getId());
Assert.assertNull(tempPolicy, "Policy was not deleted successfully");
}
}
@Test(dependsOnMethods = "updatePolicy")
public void deletePolicyByPolicy() throws PolicyManagementException {
policyManagerService.deletePolicy(policy1);
Policy tempPolicy = policyManagerService.getPAP().getPolicy(policy1.getId());
Assert.assertNull(tempPolicy, "Policy was not deleted successfully");
}
@Test(dependsOnMethods = "applyPolicy")
public void getEffectiveFeatures( ) throws Exception {
List<ProfileFeature> effectiveFeatures = policyManagerService.
getEffectiveFeatures(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
Assert.assertNotNull(effectiveFeatures);
Assert.assertEquals(POLICY1_FEATURE1_CODE,effectiveFeatures.get(0).getFeatureCode());
try{
policyManagerService.getEffectiveFeatures(null);
}catch(FeatureManagementException e){
Assert.assertTrue(e.getCause()instanceof PolicyEvaluationException);
}
}
}

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.ProfileFeature;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import java.util.Collections;
import java.util.List;
@ -76,7 +77,11 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint {
@Override
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
return null;
if(deviceIdentifier!=null) {
return getEffectivePolicy(deviceIdentifier).getProfile().getProfileFeaturesList();
}else {
throw new PolicyEvaluationException();
}
}
@Override

Loading…
Cancel
Save