From 6f79ae79e2899f992b963caa41492b86776d9d13 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Tue, 9 Dec 2014 12:13:03 +0530 Subject: [PATCH] Changing the policy test cases --- .../mgt/common/impl/PolicyManagement.java | 10 +++++++ .../mgt/common/spi/PolicyManagerService.java | 18 ++++++++++-- .../mgt/common/PolicyManagementTestCase.java | 28 ++++++++----------- .../mgt/common/utils/PolicyCreator.java | 11 ++------ 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java index 5fc857ab4e..db14d8e1fc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java @@ -24,6 +24,11 @@ import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.spi.PolicyManagerService; public class PolicyManagement implements PolicyManagerService { + @Override + public int addPolicy(Policy policy) { + return 0; + } + @Override public int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException { return 0; @@ -39,6 +44,11 @@ public class PolicyManagement implements PolicyManagerService { return 0; } + @Override + public Policy getPolicy() { + return null; + } + @Override public Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException { return null; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java index 2ee94d8da4..941647a09a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyManagerService.java @@ -28,13 +28,20 @@ import org.wso2.carbon.policy.mgt.common.PolicyManagementException; public interface PolicyManagerService { - // void addPolicy(Policy policy); + /** + * This method adds a policy to the platform + * @param policy + * @return + */ + + int addPolicy(Policy policy); /** * This method adds a policy per device which should be implemented by the related plugins. * @param deviceId * @param deviceType * @param policy + * @return */ int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException; @@ -43,6 +50,7 @@ public interface PolicyManagerService { * This method adds a policy to device type by the related device type plugins. * @param deviceType * @param policy + * @return */ int addPolicyToDeviceType(String deviceType,Policy policy) throws FeatureManagementException, PolicyManagementException; @@ -51,10 +59,16 @@ public interface PolicyManagerService { * This method adds the policy to specific role. * @param roleName * @param policy + * @return */ int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException; - // Policy getPolicy(); + /** + * This method returns the policy of whole platform + * @return + */ + + Policy getPolicy(); /** * This method gives the device specific policy. diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java index a9198b7b3c..5e28b2154c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/PolicyManagementTestCase.java @@ -32,28 +32,24 @@ public class PolicyManagementTestCase { private static final Log log = LogFactory.getLog(PolicyManagementTestCase.class); - PolicyCreator creator = new PolicyCreator(); - Policy policy = creator.getPolicy(); + Policy policy = PolicyCreator.createPolicy(); private PolicyManagement policyManagement = new PolicyManagement(); - @Test(groups = "policy.mgt.test", description = "Testing the first test case with testng.") - public void testPolicy() { - Assert.assertEquals("A", "A"); + + @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device") + public void testAddPolicy() throws FeatureManagementException, PolicyManagementException { + Assert.assertEquals(policyManagement.addPolicyToDevice("1212-ESDD-12ER-7890", "MD", policy), 0); } + @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device type") + public void testAddPolicyToDeviceType() throws FeatureManagementException, PolicyManagementException { + Assert.assertEquals(policyManagement.addPolicyToDeviceType("MD", policy), 0); + } - @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device") - public void testAddPolicy() { - try { - Assert.assertEquals(policyManagement.addPolicyToDevice("1212-ESDD-12ER-7890", "MD", policy), 0); - } catch (FeatureManagementException e) { - log.error("Feature management exception happened.", e); - Assert.fail(); - } catch (PolicyManagementException e) { - log.error("Policy management exception happened.", e); - Assert.fail(); - } + @Test(groups = "policy.mgt.test", description = "Testing the adding policy to a user Role") + public void testAddPolicyToRole() throws FeatureManagementException, PolicyManagementException { + Assert.assertEquals(policyManagement.addPolicyToRole("Admin", policy), 0); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java index 5b8da71dba..4807334e96 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/test/java/org/wos2/carbon/policy/mgt/common/utils/PolicyCreator.java @@ -26,13 +26,9 @@ import java.util.List; public class PolicyCreator { - private Policy policy = new Policy(); + private static Policy policy = new Policy(); - public PolicyCreator() { - createPolicy(); - } - - private void createPolicy() { + public static Policy createPolicy() { Feature feature = new Feature(); feature.setName("Camera"); @@ -45,9 +41,6 @@ public class PolicyCreator { policy.setFeaturesList(featureList); policy.setPolicyName("Camera_related_policy"); - } - - public Policy getPolicy() { return policy; }