diff options
8 files changed, 2076 insertions, 740 deletions
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java index e42d54446..a39ea3630 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java @@ -249,6 +249,8 @@ public class StdPDPStatus implements Serializable, PDPStatus { return false; if (!loadedPolicies.equals(other.loadedPolicies)) return false; + if (!loadedRootPolicies.equals(other.loadedRootPolicies)) + return false; if (status != other.status) return false; return true; diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineTest.java index 14e30046e..f0ee8dd73 100644 --- a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineTest.java +++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineTest.java @@ -19,81 +19,374 @@ */ package org.onap.policy.xacml.test.std.pap; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; - +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.Properties; - +import org.apache.commons.io.FileUtils; +import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; -import org.onap.policy.common.logging.flexlogger.FlexLogger; -import org.onap.policy.common.logging.flexlogger.Logger; +import org.junit.rules.ExpectedException; +import org.onap.policy.xacml.api.pap.OnapPDP; +import org.onap.policy.xacml.api.pap.OnapPDPGroup; import org.onap.policy.xacml.std.pap.StdEngine; - +import org.onap.policy.xacml.std.pap.StdPDPGroup; import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPPolicy; public class StdEngineTest { - - private static Logger logger = FlexLogger.getLogger(StdEngineTest.class); - private Path repository; - Properties properties = new Properties(); - StdEngine stdEngine = null; - - @Before - public void setUp(){ - - repository = Paths.get("src/test/resources/pdps"); - try { - stdEngine = new StdEngine(repository); - } catch (PAPException e) { - logger.info(e); - } catch (IOException e) { - logger.info(e); - } - } - - @Test - public void testGetDefaultGroup(){ - try { - assertTrue(stdEngine.getDefaultGroup() != null); - } catch (PAPException e) { - logger.info(e); - } - } - @Test - public void testGetGroup(){ - try { - assertTrue(stdEngine.getGroup("1") == null); - } catch (PAPException e) { - logger.info(e); - } - - } - - @Test - public void testGetOnapPDPGroups(){ - try { - assertTrue(stdEngine.getOnapPDPGroups() != null); - } catch (PAPException e) { - logger.info(e); - } - } - @Test - public void testGetPDP(){ - try { - assertTrue(stdEngine.getPDP("1") == null); - } catch (PAPException e) { - logger.info(e); - } - } - @Test - public void testGetPDPGroup(){ - try { - assertTrue(stdEngine.getPDPGroup(null) == null); - } catch (PAPException e) { - logger.info(e); - } - } + + private Path repository; + Properties properties = new Properties(); + StdEngine stdEngine = null; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @BeforeClass + public static void setUpClass() throws IOException{ + new File("target/test/resources/pdps").mkdirs(); + new File("target/test/resources/emptyPapGroupsDefault").mkdirs(); + Files.copy(Paths.get("src/test/resources/pdps/xacml.properties"), Paths.get("target/test/resources/pdps/xacml.properties"), StandardCopyOption.REPLACE_EXISTING); + Files.copy(Paths.get("src/test/resources/emptyPapGroupsDefault/xacml.properties"), Paths.get("target/test/resources/emptyPapGroupsDefault/xacml.properties"), StandardCopyOption.REPLACE_EXISTING); + } + + @Before + public void setUp() throws PAPException, IOException { + + repository = Paths.get("target/test/resources/pdps"); + stdEngine = new StdEngine(repository); + } + + @Test + public void testGetDefaultGroup() throws PAPException { + assertTrue(stdEngine.getDefaultGroup() != null); + } + + @Test + public void testGetGroup() throws PAPException { + assertTrue(stdEngine.getGroup("1") == null); + } + + @Test + public void testGetOnapPDPGroups() throws PAPException { + assertTrue(stdEngine.getOnapPDPGroups() != null); + } + + @Test + public void testGetPDP() throws PAPException { + assertTrue(stdEngine.getPDP("1") == null); + } + + @Test + public void testGetPDPGroup() throws PAPException { + assertTrue(stdEngine.getPDPGroup(null) == null); + } + + @Test + public void testNoRepository() throws PAPException, IOException { + expectedException.expect(PAPException.class); + expectedException.expectMessage("No repository specified."); + new StdEngine((Path)null); + } + + @Test + public void testRepositoryDoesNotExist() throws PAPException, IOException { + repository = Paths.get("target/test/resources/nonExisting"); + new StdEngine(repository); + + assertTrue(Files.exists(Paths.get("target/test/resources/nonExisting/default/xacml.pip.properties"))); + assertTrue(Files.exists(Paths.get("target/test/resources/nonExisting/default/xacml.policy.properties"))); + assertTrue(Files.exists(Paths.get("target/test/resources/nonExisting/xacml.properties"))); + FileUtils.deleteDirectory(repository.toFile()); + } + + @Test + public void testEmptyPapGroupsDefault() throws PAPException, IOException { + System.setProperty("xacml.pap.groups.default", ""); + repository = Paths.get("target/test/resources/emptyPapGroupsDefault"); + new StdEngine(repository); + + assertTrue(Files.exists(Paths.get("target/test/resources/emptyPapGroupsDefault/default/xacml.pip.properties"))); + assertTrue(Files.exists(Paths.get("target/test/resources/emptyPapGroupsDefault/default/xacml.policy.properties"))); + assertTrue(Files.exists(Paths.get("target/test/resources/emptyPapGroupsDefault/xacml.properties"))); + } + + @Test + public void testNewGroupAndRemoveGroup() throws NullPointerException, PAPException, IOException { + OnapPDPGroup newGroup = createGroup("newGroup", "Description of new group"); + assertNotNull(newGroup); + + stdEngine.removeGroup(stdEngine.getGroup("newGroup"), null); + assertNull(stdEngine.getGroup("newGroup")); + } + + @Test + public void testRemoveGroupNull() throws NullPointerException, PAPException, IOException { + expectedException.expect(NullPointerException.class); + stdEngine.removeGroup(null, null); + assertNull(stdEngine.getGroup("newGroup")); + } + + @Test + public void testRemoveGroupUnknown() throws NullPointerException, PAPException, IOException { + OnapPDPGroup unknownGroup = new StdPDPGroup("unknownId", null); + + expectedException.expect(PAPException.class); + expectedException.expectMessage("The group 'unknownId' does not exist"); + stdEngine.removeGroup(unknownGroup, null); + } + + @Test + public void testRemoveGroupDefault() throws NullPointerException, PAPException, IOException { + OnapPDPGroup defaultGroup = stdEngine.getDefaultGroup(); + + expectedException.expect(PAPException.class); + expectedException.expectMessage("You cannot delete the default group."); + stdEngine.removeGroup(defaultGroup, null); + } + + @Test + public void testSetDefaultGroup() throws NullPointerException, PAPException, IOException { + OnapPDPGroup newGroup = createGroup("newGroup", "Description of new group"); + assertNotNull(newGroup); + + OnapPDPGroup defaultGroup = stdEngine.getDefaultGroup(); + assertEquals("default", defaultGroup.getName()); + stdEngine.setDefaultGroup(newGroup); + assertEquals(newGroup, stdEngine.getDefaultGroup()); + + stdEngine.setDefaultGroup(defaultGroup); + stdEngine.removeGroup(stdEngine.getGroup("newGroup"), null); + } + + @Test + public void testPdps() throws NullPointerException, PAPException{ + OnapPDPGroup group1 = createGroup("newGroup", "Description of new group"); + assertEquals(0, group1.getPdps().size()); + + stdEngine.newPDP("newPdp", group1, "newPdpName", "A new pdp", 1); + assertEquals(1, group1.getPdps().size()); + assertEquals("newPdp", group1.getPdps().iterator().next().getId()); + assertEquals("newPdpName", group1.getPdps().iterator().next().getName()); + assertEquals("A new pdp", group1.getPdps().iterator().next().getDescription()); + + OnapPDPGroup group2 = createGroup("anotherNewGroup", "Description of new group"); + assertEquals(0, group2.getPdps().size()); + + stdEngine.movePDP(group1.getOnapPdps().iterator().next(), group2); + assertEquals(0, group1.getPdps().size()); + assertEquals(1, group2.getPdps().size()); + + OnapPDP pdp = group2.getOnapPdps().iterator().next(); + pdp.setName("AnUpdatedName");; + pdp.setDescription("An updated description"); + stdEngine.updatePDP(pdp); + assertEquals("AnUpdatedName", group2.getPdps().iterator().next().getName()); + assertEquals("An updated description", group2.getPdps().iterator().next().getDescription()); + + stdEngine.removePDP(group2.getOnapPdps().iterator().next()); + assertEquals(0, group1.getPdps().size()); + assertEquals(0, group2.getPdps().size()); + } + + @Test + public void testNewPdpNullGroup() throws NullPointerException, PAPException{ + expectedException.expect(PAPException.class); + expectedException.expectMessage("You must specify which group the PDP will belong to."); + stdEngine.newPDP("newPdp", null, "newPdpName", "A new pdp", 1); + } + + @Test + public void testNewPdpUnknownGroup() throws NullPointerException, PAPException{ + OnapPDPGroup unknownGroup = new StdPDPGroup("unknownId", null); + + expectedException.expect(PAPException.class); + expectedException.expectMessage("Unknown group, not in our list."); + stdEngine.newPDP("newPdp", unknownGroup, "newPdpName", "A new pdp", 1); + } + + @Test + public void testNewPdpAlreadyExistingPdp() throws NullPointerException, PAPException{ + OnapPDPGroup group1 = createGroup("newGroup", "Description of new group"); + assertEquals(0, group1.getPdps().size()); + + stdEngine.newPDP("newPdp", group1, "newPdpName", "A new pdp", 1); + assertEquals(1, group1.getPdps().size()); + + expectedException.expect(PAPException.class); + expectedException.expectMessage("A PDP with this ID exists."); + stdEngine.newPDP("newPdp", group1, "newPdpName", "A new pdp", 1); + } + + @Test + public void testRemoveGroupWithPdps() throws NullPointerException, PAPException{ + OnapPDPGroup group1 = createGroup("newGroup", "Description of new group"); + + stdEngine.newPDP("newPdp", group1, "newPdpName", "A new pdp", 1); + assertEquals(1, group1.getPdps().size()); + + OnapPDPGroup group2 = createGroup("anotherNewGroup", "Description of new group"); + assertEquals(0, group2.getPdps().size()); + + stdEngine.removeGroup(group1, group2); + assertNull(stdEngine.getGroup("newGroup")); + assertEquals(1, group2.getPdps().size()); + } + + @Test + public void testRemoveGroupWithPdpsNoTarget() throws NullPointerException, PAPException{ + OnapPDPGroup group1 = createGroup("newGroup", "Description of new group"); + + stdEngine.newPDP("newPdp", group1, "newPdpName", "A new pdp", 1); + assertEquals(1, group1.getPdps().size()); + + OnapPDPGroup group2 = createGroup("anotherNewGroup", "Description of new group"); + assertEquals(0, group2.getPdps().size()); + + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("Group targeted for deletion has PDPs, you must provide a new group for them."); + stdEngine.removeGroup(group1, null); + } + + @Test + public void testUpdateGroupName() throws NullPointerException, PAPException, IOException { + OnapPDPGroup newGroup = createGroup("newGroup", "Description of new group"); + + OnapPDPGroup updatedGroup = new StdPDPGroup(newGroup); + updatedGroup.setName("AnUpdatedName"); + stdEngine.updateGroup(updatedGroup); + assertNull(stdEngine.getGroup("newGroup")); + assertNotNull(stdEngine.getGroup("AnUpdatedName")); + assertEquals("AnUpdatedName", stdEngine.getGroup("AnUpdatedName").getName()); + assertEquals("Description of new group", stdEngine.getGroup("AnUpdatedName").getDescription()); + } + + @Test + public void testUpdateGroupDescription() throws NullPointerException, PAPException, IOException { + OnapPDPGroup newGroup = createGroup("newGroup", "Description of new group"); + + OnapPDPGroup updatedGroup = new StdPDPGroup(newGroup.getId(), newGroup.getName(), "An updated description", Paths.get("target/test/resources/pdps/newGroup")); + updatedGroup.setDescription("An updated description"); + stdEngine.updateGroup(updatedGroup); + assertEquals("newGroup", stdEngine.getGroup("newGroup").getName()); + assertEquals("An updated description", stdEngine.getGroup("newGroup").getDescription()); + } + + @Test + public void testUpdateGroupNull() throws NullPointerException, PAPException, IOException { + expectedException.expect(PAPException.class); + expectedException.expectMessage("Group or id is null"); + stdEngine.updateGroup(null); + } + + @Test + public void testUpdateGroupIdNull() throws NullPointerException, PAPException, IOException { + StdPDPGroup group = new StdPDPGroup(null, null); + expectedException.expect(PAPException.class); + expectedException.expectMessage("Group or id is null"); + stdEngine.updateGroup(group); + } + + @Test + public void testUpdateGroupNameNull() throws NullPointerException, PAPException, IOException { + StdPDPGroup group = new StdPDPGroup("groupId", null); + expectedException.expect(PAPException.class); + expectedException.expectMessage("New name for group cannot be null or blank"); + stdEngine.updateGroup(group); + } + + @Test + public void testUpdateGroupNameEmptyString() throws NullPointerException, PAPException, IOException { + StdPDPGroup group = new StdPDPGroup("groupId", "", "description", null); + expectedException.expect(PAPException.class); + expectedException.expectMessage("New name for group cannot be null or blank"); + stdEngine.updateGroup(group); + } + + @Test + public void testUpdateGroupUnknown() throws NullPointerException, PAPException, IOException { + StdPDPGroup group = new StdPDPGroup("groupId", "groupName", "description", null); + expectedException.expect(PAPException.class); + expectedException.expectMessage("Update found no existing group with id 'groupId'"); + stdEngine.updateGroup(group); + } + + @Test + public void testPublishAndRemovePolicy() throws NullPointerException, PAPException, FileNotFoundException{ + OnapPDPGroup newGroup = createGroup("newGroup", "Description of new group"); + InputStream inputStream = new FileInputStream("src/test/resources/pdps/default/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml"); + stdEngine.publishPolicy("com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml", "Config_BRMS_Param_BRMSParamvFWDemoPolicy", true, inputStream, newGroup); + PDPPolicy policy = newGroup.getPolicy("com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml"); + assertNotNull(policy); + + stdEngine.removePolicy(policy, newGroup); + assertNull(newGroup.getPolicy("com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml")); + } + + @Test + public void testPublishPolicyNull() throws NullPointerException, PAPException, FileNotFoundException{ + expectedException.expect(NullPointerException.class); + stdEngine.publishPolicy(null, null, true, null, null); + } + + @Test + public void testPublishPolicyUnknownGroup() throws NullPointerException, PAPException, FileNotFoundException{ + OnapPDPGroup unknownGroup = new StdPDPGroup("unknownId", null); + + expectedException.expect(PAPException.class); + expectedException.expectMessage("Unknown PDP Group: unknownId"); + stdEngine.publishPolicy(null, null, true, null, unknownGroup); + } + + @Test + public void testRemovePolicyNull() throws NullPointerException, PAPException, FileNotFoundException{ + expectedException.expect(NullPointerException.class); + stdEngine.removePolicy(null, null); + } + + @Test + public void testRemovePolicyUnknownGroup() throws NullPointerException, PAPException, FileNotFoundException{ + OnapPDPGroup unknownGroup = new StdPDPGroup("unknownId", null); + + expectedException.expect(PAPException.class); + expectedException.expectMessage("Unknown PDP Group: unknownId"); + stdEngine.removePolicy(null, unknownGroup); + } + + private OnapPDPGroup createGroup(final String name, final String description) throws NullPointerException, PAPException{ + ensureGroupDoesntExist(name); + stdEngine.newGroup(name, description); + return stdEngine.getGroup(name); + } + + @After + public void tearDown() throws PAPException{ + ensureGroupDoesntExist("newGroup"); + ensureGroupDoesntExist("anotherNewGroup"); + ensureGroupDoesntExist("AnUpdatedName"); + } + + private void ensureGroupDoesntExist(final String groupName) throws PAPException{ + OnapPDPGroup group = stdEngine.getGroup(groupName); + if (group != null){ + for (OnapPDP pdp: group.getOnapPdps()){ + stdEngine.removePDP(pdp); + } + stdEngine.removeGroup(group, null); + } + } } diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPAPPolicyTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPAPPolicyTest.java index e75c555a1..42fa87288 100644 --- a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPAPPolicyTest.java +++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPAPPolicyTest.java @@ -19,15 +19,16 @@ */ package org.onap.policy.xacml.test.std.pap; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; - import java.net.URI; -import java.nio.file.Path; +import java.net.URISyntaxException; import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Properties; - import org.junit.Before; import org.junit.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -35,502 +36,904 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.xacml.std.pap.StdPAPPolicy; public class StdPAPPolicyTest { - - private static Logger logger = FlexLogger.getLogger(StdPAPPolicyTest.class); - private Path repository; - Properties properties = new Properties(); - StdPAPPolicy stdPAPPolicy; - - @Before - public void setUp(){ - - repository = Paths.get("src/test/resources/pdps"); - try { - stdPAPPolicy = new StdPAPPolicy(); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetActionAttribute(){ - try { - stdPAPPolicy.setActionAttribute("test"); - assertTrue(stdPAPPolicy.getActionAttribute() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetActionBody(){ - try { - stdPAPPolicy.setActionBody("actionBody"); - assertTrue(stdPAPPolicy.getActionBody() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetActionDictHeader(){ - try { - stdPAPPolicy.setActionDictHeader("actionDictHeader"); - assertTrue(stdPAPPolicy.getActionDictHeader() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetActionDictMethod(){ - try { - stdPAPPolicy.setActionDictMethod("actionDictMethod"); - assertTrue(stdPAPPolicy.getActionDictMethod() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetActionDictType(){ - try { - stdPAPPolicy.setActionDictType("actionDictType"); - assertTrue(stdPAPPolicy.getActionDictType() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetActionDictUrl(){ - try { - stdPAPPolicy.setActionDictUrl("actionDictUrl"); - assertTrue(stdPAPPolicy.getActionDictUrl() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetActionPerformer(){ - try { - stdPAPPolicy.setActionPerformer("actionPerformer"); - assertTrue(stdPAPPolicy.getActionPerformer() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetBrmsController(){ - try { - stdPAPPolicy.setBrmsController("brmsController"); - assertTrue(stdPAPPolicy.getBrmsController() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetBrmsDependency(){ - try { - stdPAPPolicy.setBrmsDependency(new ArrayList()); - assertTrue(stdPAPPolicy.getBrmsDependency() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetConfigBodyData(){ - try { - stdPAPPolicy.setConfigBodyData("configBodyData"); - assertTrue(stdPAPPolicy.getConfigBodyData() != null); - } catch (Exception e) { - logger.info(e); - } - } - - - @Test - public void testGetConfigName(){ - try { - stdPAPPolicy.setConfigName("configName"); - assertTrue(stdPAPPolicy.getConfigName() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetConfigPolicyType(){ - try { - stdPAPPolicy.setConfigPolicyType("configPolicyType"); - assertTrue(stdPAPPolicy.getConfigPolicyType() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetConfigType(){ - try { - stdPAPPolicy.setConfigType("configType"); - assertTrue(stdPAPPolicy.getConfigType() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetDataTypeList(){ - try { - stdPAPPolicy.setDataTypeList(new ArrayList<String>()); - assertTrue(stdPAPPolicy.getDataTypeList() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetDeleteCondition(){ - try { - stdPAPPolicy.setDeleteCondition("deleteCondition"); - assertTrue(stdPAPPolicy.getDeleteCondition() != null); - } catch (Exception e) { - logger.info(e); - } - } - - - @Test - public void testGetDrlRuleAndUIParams(){ - try { - stdPAPPolicy.setDrlRuleAndUIParams(new HashMap()); - assertTrue(stdPAPPolicy.getDrlRuleAndUIParams() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetDropDownMap(){ - try { - stdPAPPolicy.setDropDownMap(new HashMap()); - assertTrue(stdPAPPolicy.getDropDownMap() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetDynamicFieldConfigAttributes(){ - try { - assertTrue(stdPAPPolicy.getDynamicFieldConfigAttributes() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetDynamicRuleAlgorithmCombo(){ - try { - stdPAPPolicy.setDynamicRuleAlgorithmCombo(new ArrayList()); - assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmCombo() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetDynamicRuleAlgorithmField1(){ - try { - stdPAPPolicy.setDynamicRuleAlgorithmField1(new ArrayList()); - assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmField1() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetDictionary(){ - try { - stdPAPPolicy.setDictionary("dictionary"); - assertTrue(stdPAPPolicy.getDictionary() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetDictionaryFields(){ - try { - stdPAPPolicy.setDictionaryFields("dictionaryFields"); - assertTrue(stdPAPPolicy.getDictionaryFields() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetDictionaryType(){ - try { - stdPAPPolicy.setDictionaryType("dictionaryType"); - assertTrue(stdPAPPolicy.getDictionaryType() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetDomainDir(){ - try { - stdPAPPolicy.setDomainDir("domain"); - assertTrue(stdPAPPolicy.getDomainDir() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testIsDraft(){ - try { - stdPAPPolicy.setDraft(true); - assertTrue(stdPAPPolicy.isDraft() == true); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetDynamicRuleAlgorithmLabels(){ - try { - stdPAPPolicy.setDynamicRuleAlgorithmLabels(new ArrayList()); - assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmLabels() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetDynamicSettingsMap(){ - try { - stdPAPPolicy.setDynamicSettingsMap(new HashMap()); - assertTrue(stdPAPPolicy.getDynamicSettingsMap() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetDynamicVariableList(){ - try { - stdPAPPolicy.setDynamicVariableList(new ArrayList()); - assertTrue(stdPAPPolicy.getDynamicVariableList() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetGuard(){ - try { - stdPAPPolicy.setGuard("domain"); - assertTrue(stdPAPPolicy.getGuard() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetHighestVersion(){ - try { - stdPAPPolicy.setHighestVersion(123); - assertTrue(stdPAPPolicy.getHighestVersion() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testgGtJsonBody(){ - try { - stdPAPPolicy.setJsonBody("jsonBoby"); - assertTrue(stdPAPPolicy.getJsonBody() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetLocation(){ - try { - stdPAPPolicy.setLocation(new URI("test")); - assertTrue(stdPAPPolicy.getLocation() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetMsLocation(){ - try { - stdPAPPolicy.setMsLocation("MsLocation"); - assertTrue(stdPAPPolicy.getMsLocation() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testSetOldPolicyFileName(){ - try { - stdPAPPolicy.setOldPolicyFileName("domain"); - assertTrue(stdPAPPolicy.getOldPolicyFileName() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetOnapName(){ - try { - stdPAPPolicy.setOnapName("onap"); - assertTrue(stdPAPPolicy.getOnapName() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetPolicyDescription(){ - try { - stdPAPPolicy.setPolicyDescription("description test"); - assertTrue(stdPAPPolicy.getPolicyDescription() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetPolicyID(){ - try { - stdPAPPolicy.setPolicyID("test"); - assertTrue(stdPAPPolicy.getPolicyID() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testSetPolicyName(){ - try { - stdPAPPolicy.setPolicyName("MsLocation"); - assertTrue(stdPAPPolicy.getPolicyName() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testSetPriority(){ - try { - stdPAPPolicy.setPriority("domain"); - assertTrue(stdPAPPolicy.getPriority() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetProviderComboBox(){ - try { - stdPAPPolicy.setProviderComboBox("onap"); - assertTrue(stdPAPPolicy.getProviderComboBox() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetRiskLevel(){ - try { - stdPAPPolicy.setRiskLevel("test"); - assertTrue(stdPAPPolicy.getRiskLevel() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetRiskType(){ - try { - stdPAPPolicy.setRiskType("test"); - assertTrue(stdPAPPolicy.getRiskType() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testGetRuleID(){ - try { - stdPAPPolicy.setRuleID("MsLocation"); - assertTrue(stdPAPPolicy.getRuleID() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetServiceType(){ - try { - stdPAPPolicy.setServiceType("domain"); - assertTrue(stdPAPPolicy.getServiceType() != null); - } catch (Exception e) { - logger.info(e); - } - } - - @Test - public void testGetTTLDate(){ - try { - stdPAPPolicy.setTTLDate("09/20/17"); - assertTrue(stdPAPPolicy.getTTLDate() != null); - } catch (Exception e) { - logger.info(e); - } - } - - - @Test - public void testGetUuid(){ - try { - stdPAPPolicy.setUuid("11212122"); - assertTrue(stdPAPPolicy.getUuid() != null); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testGetVersion(){ - try { - stdPAPPolicy.setVersion("testv01"); - assertTrue(stdPAPPolicy.getVersion() != null); - } catch (Exception e) { - logger.info(e); - } - - } - - @Test - public void testIsEditPolicy(){ - try { - stdPAPPolicy.setEditPolicy(true); - assertTrue(stdPAPPolicy.isEditPolicy() == true); - } catch (Exception e) { - logger.info(e); - } - } - @Test - public void testToString(){ - try { - assertTrue(stdPAPPolicy.toString() != null); - } catch (Exception e) { - logger.info(e); - } - } - -}
\ No newline at end of file + + private static Logger logger = FlexLogger.getLogger(StdPAPPolicyTest.class); + Properties properties = new Properties(); + StdPAPPolicy stdPAPPolicy; + + @Before + public void setUp() { + + Paths.get("src/test/resources/pdps"); + try { + stdPAPPolicy = new StdPAPPolicy(); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionAttribute() { + try { + stdPAPPolicy.setActionAttribute("test"); + assertTrue(stdPAPPolicy.getActionAttribute() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionBody() { + try { + stdPAPPolicy.setActionBody("actionBody"); + assertTrue(stdPAPPolicy.getActionBody() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetActionDictHeader() { + try { + stdPAPPolicy.setActionDictHeader("actionDictHeader"); + assertTrue(stdPAPPolicy.getActionDictHeader() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionDictMethod() { + try { + stdPAPPolicy.setActionDictMethod("actionDictMethod"); + assertTrue(stdPAPPolicy.getActionDictMethod() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionDictType() { + try { + stdPAPPolicy.setActionDictType("actionDictType"); + assertTrue(stdPAPPolicy.getActionDictType() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionDictUrl() { + try { + stdPAPPolicy.setActionDictUrl("actionDictUrl"); + assertTrue(stdPAPPolicy.getActionDictUrl() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionPerformer() { + try { + stdPAPPolicy.setActionPerformer("actionPerformer"); + assertTrue(stdPAPPolicy.getActionPerformer() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetBrmsController() { + try { + stdPAPPolicy.setBrmsController("brmsController"); + assertTrue(stdPAPPolicy.getBrmsController() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetBrmsDependency() { + try { + stdPAPPolicy.setBrmsDependency(new ArrayList<>()); + assertTrue(stdPAPPolicy.getBrmsDependency() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetConfigBodyData() { + try { + stdPAPPolicy.setConfigBodyData("configBodyData"); + assertTrue(stdPAPPolicy.getConfigBodyData() != null); + } catch (Exception e) { + logger.info(e); + } + } + + + @Test + public void testGetConfigName() { + try { + stdPAPPolicy.setConfigName("configName"); + assertTrue(stdPAPPolicy.getConfigName() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetConfigPolicyType() { + try { + stdPAPPolicy.setConfigPolicyType("configPolicyType"); + assertTrue(stdPAPPolicy.getConfigPolicyType() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetConfigType() { + try { + stdPAPPolicy.setConfigType("configType"); + assertTrue(stdPAPPolicy.getConfigType() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDataTypeList() { + try { + stdPAPPolicy.setDataTypeList(new ArrayList<String>()); + assertTrue(stdPAPPolicy.getDataTypeList() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDeleteCondition() { + try { + stdPAPPolicy.setDeleteCondition("deleteCondition"); + assertTrue(stdPAPPolicy.getDeleteCondition() != null); + } catch (Exception e) { + logger.info(e); + } + } + + + @Test + public void testGetDrlRuleAndUIParams() { + try { + stdPAPPolicy.setDrlRuleAndUIParams(new HashMap<>()); + assertTrue(stdPAPPolicy.getDrlRuleAndUIParams() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDropDownMap() { + try { + stdPAPPolicy.setDropDownMap(new HashMap<>()); + assertTrue(stdPAPPolicy.getDropDownMap() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetDynamicFieldConfigAttributes() { + try { + assertTrue(stdPAPPolicy.getDynamicFieldConfigAttributes() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDynamicRuleAlgorithmCombo() { + try { + stdPAPPolicy.setDynamicRuleAlgorithmCombo(new ArrayList<>()); + assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmCombo() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDynamicRuleAlgorithmField1() { + try { + stdPAPPolicy.setDynamicRuleAlgorithmField1(new ArrayList<>()); + assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmField1() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDictionary() { + try { + stdPAPPolicy.setDictionary("dictionary"); + assertTrue(stdPAPPolicy.getDictionary() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDictionaryFields() { + try { + stdPAPPolicy.setDictionaryFields("dictionaryFields"); + assertTrue(stdPAPPolicy.getDictionaryFields() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetDictionaryType() { + try { + stdPAPPolicy.setDictionaryType("dictionaryType"); + assertTrue(stdPAPPolicy.getDictionaryType() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDomainDir() { + try { + stdPAPPolicy.setDomainDir("domain"); + assertTrue(stdPAPPolicy.getDomainDir() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testIsDraft() { + try { + stdPAPPolicy.setDraft(true); + assertTrue(stdPAPPolicy.isDraft() == true); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDynamicRuleAlgorithmLabels() { + try { + stdPAPPolicy.setDynamicRuleAlgorithmLabels(new ArrayList<>()); + assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmLabels() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDynamicSettingsMap() { + try { + stdPAPPolicy.setDynamicSettingsMap(new HashMap<>()); + assertTrue(stdPAPPolicy.getDynamicSettingsMap() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetDynamicVariableList() { + try { + stdPAPPolicy.setDynamicVariableList(new ArrayList<>()); + assertTrue(stdPAPPolicy.getDynamicVariableList() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetGuard() { + try { + stdPAPPolicy.setGuard("domain"); + assertTrue(stdPAPPolicy.getGuard() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetHighestVersion() { + try { + stdPAPPolicy.setHighestVersion(123); + assertTrue(stdPAPPolicy.getHighestVersion() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testgGtJsonBody() { + try { + stdPAPPolicy.setJsonBody("jsonBoby"); + assertTrue(stdPAPPolicy.getJsonBody() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetLocation() { + try { + stdPAPPolicy.setLocation(new URI("test")); + assertTrue(stdPAPPolicy.getLocation() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetMsLocation() { + try { + stdPAPPolicy.setMsLocation("MsLocation"); + assertTrue(stdPAPPolicy.getMsLocation() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testSetOldPolicyFileName() { + try { + stdPAPPolicy.setOldPolicyFileName("domain"); + assertTrue(stdPAPPolicy.getOldPolicyFileName() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetOnapName() { + try { + stdPAPPolicy.setOnapName("onap"); + assertTrue(stdPAPPolicy.getOnapName() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetPolicyDescription() { + try { + stdPAPPolicy.setPolicyDescription("description test"); + assertTrue(stdPAPPolicy.getPolicyDescription() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetPolicyID() { + try { + stdPAPPolicy.setPolicyID("test"); + assertTrue(stdPAPPolicy.getPolicyID() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testSetPolicyName() { + try { + stdPAPPolicy.setPolicyName("MsLocation"); + assertTrue(stdPAPPolicy.getPolicyName() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testSetPriority() { + try { + stdPAPPolicy.setPriority("domain"); + assertTrue(stdPAPPolicy.getPriority() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetProviderComboBox() { + try { + stdPAPPolicy.setProviderComboBox("onap"); + assertTrue(stdPAPPolicy.getProviderComboBox() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetRiskLevel() { + try { + stdPAPPolicy.setRiskLevel("test"); + assertTrue(stdPAPPolicy.getRiskLevel() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetRiskType() { + try { + stdPAPPolicy.setRiskType("test"); + assertTrue(stdPAPPolicy.getRiskType() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetRuleID() { + try { + stdPAPPolicy.setRuleID("MsLocation"); + assertTrue(stdPAPPolicy.getRuleID() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetServiceType() { + try { + stdPAPPolicy.setServiceType("domain"); + assertTrue(stdPAPPolicy.getServiceType() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetTTLDate() { + try { + stdPAPPolicy.setTTLDate("09/20/17"); + assertTrue(stdPAPPolicy.getTTLDate() != null); + } catch (Exception e) { + logger.info(e); + } + } + + + @Test + public void testGetUuid() { + try { + stdPAPPolicy.setUuid("11212122"); + assertTrue(stdPAPPolicy.getUuid() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetVersion() { + try { + stdPAPPolicy.setVersion("testv01"); + assertTrue(stdPAPPolicy.getVersion() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testIsEditPolicy() { + try { + stdPAPPolicy.setEditPolicy(true); + assertTrue(stdPAPPolicy.isEditPolicy() == true); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testToString() { + try { + assertTrue(stdPAPPolicy.toString() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testConstructorUri() throws URISyntaxException { + URI location = new URI("testUri"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy(location); + assertEquals(location, stdPAPPolicy.getLocation()); + } + + @Test + public void testConstructorStringStringStringString() throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "body", "configType", "configTypePolicy"); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("body", stdPAPPolicy.getConfigBodyData()); + assertEquals("configType", stdPAPPolicy.getConfigType()); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + } + + + @Test + public void testConstructorStringStringStringStringStringMapStringStringStringStringBooleanStringStringStringStringString() throws URISyntaxException { + Map<String, String> attributes = new HashMap<>(); + attributes.put("aKey", "aValue"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "configName", attributes, + "configType", "body", true, "domain", "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("onapName", stdPAPPolicy.getOnapName()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertEquals(attributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals("configType", stdPAPPolicy.getConfigType()); + assertEquals("body", stdPAPPolicy.getConfigBodyData()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringMapStringStringListStringListStringListStringListStringStringStringBooleanStringint(){ + Map<String, String> attributes = new HashMap<>(); + attributes.put("aKey", "aValue"); + List<String> dynamicRuleAlgorithmLabels = new ArrayList<>(); + dynamicRuleAlgorithmLabels.add("dynamicRuleAlgorithmLabel"); + List<String> dynamicRuleAlgorithmCombo = new ArrayList<>(); + dynamicRuleAlgorithmCombo.add("dynamicRuleAlgorithmCombo"); + List<String> dynamicRuleAlgorithmField1 = new ArrayList<>(); + dynamicRuleAlgorithmField1.add("dynamicRuleAlgorithmField1"); + List<String> dynamicRuleAlgorithmField2 = new ArrayList<>(); + dynamicRuleAlgorithmField2.add("dynamicRuleAlgorithmField2"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "description", attributes, dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmCombo, dynamicRuleAlgorithmField1, dynamicRuleAlgorithmField2, + "actionPerformer", "actionAttribute", true, "domain", 1); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals(attributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals(dynamicRuleAlgorithmLabels, stdPAPPolicy.getDynamicRuleAlgorithmLabels()); + assertEquals(dynamicRuleAlgorithmCombo, stdPAPPolicy.getDynamicRuleAlgorithmCombo()); + assertEquals(dynamicRuleAlgorithmField1, stdPAPPolicy.getDynamicRuleAlgorithmField1()); + assertEquals(dynamicRuleAlgorithmField2, stdPAPPolicy.getDynamicRuleAlgorithmField2()); + assertEquals("actionPerformer", stdPAPPolicy.getActionPerformer()); + assertEquals("actionAttribute", stdPAPPolicy.getActionAttribute()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + } + + @Test + public void testConstructorStringStringStringStringMapStringStringMapStringStringMapStringStringListStringListStringListStringListStringMapStringStringListObjectListStringBooleanStringint(){ + Map<String, String> attributes = new HashMap<>(); + attributes.put("aKey1", "aValue1"); + Map<String, String> settings = new HashMap<>(); + settings.put("aKey2", "aValue2"); + Map<String, String> treatments = new HashMap<>(); + treatments.put("aKey3", "aValue3"); + Map<String, String> dropDownMap = new HashMap<>(); + dropDownMap.put("aKey4", "aValue4"); + List<String> dynamicRuleAlgorithmLabels = new ArrayList<>(); + dynamicRuleAlgorithmLabels.add("dynamicRuleAlgorithmLabel"); + List<String> dynamicRuleAlgorithmCombo = new ArrayList<>(); + dynamicRuleAlgorithmCombo.add("dynamicRuleAlgorithmCombo"); + List<String> dynamicRuleAlgorithmField1 = new ArrayList<>(); + dynamicRuleAlgorithmField1.add("dynamicRuleAlgorithmField1"); + List<String> dynamicRuleAlgorithmField2 = new ArrayList<>(); + dynamicRuleAlgorithmField2.add("dynamicRuleAlgorithmField2"); + List<Object> dynamicVariableList = new ArrayList<>(); + dynamicVariableList.add("dynamicVariableList"); + List<String> dataTypeList = new ArrayList<>(); + dataTypeList.add("dataTypeList"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "description", "onapName", "providerComboBox", attributes, settings, treatments, dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmCombo, + dynamicRuleAlgorithmField1, dynamicRuleAlgorithmField2, dropDownMap, dynamicVariableList, dataTypeList, true, "domain", 1); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("onapName", stdPAPPolicy.getOnapName()); + assertEquals("providerComboBox", stdPAPPolicy.getProviderComboBox()); + assertEquals(attributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals(settings, stdPAPPolicy.getDynamicSettingsMap()); + assertEquals(treatments, stdPAPPolicy.getTreatments()); + assertEquals(dynamicRuleAlgorithmLabels, stdPAPPolicy.getDynamicRuleAlgorithmLabels()); + assertEquals(dynamicRuleAlgorithmCombo, stdPAPPolicy.getDynamicRuleAlgorithmCombo()); + assertEquals(dynamicRuleAlgorithmField1, stdPAPPolicy.getDynamicRuleAlgorithmField1()); + assertEquals(dynamicRuleAlgorithmField2, stdPAPPolicy.getDynamicRuleAlgorithmField2()); + assertEquals(dropDownMap, stdPAPPolicy.getDropDownMap()); + assertEquals(dynamicVariableList, stdPAPPolicy.getDynamicVariableList()); + assertEquals(dataTypeList, stdPAPPolicy.getDataTypeList()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + } + + @Test + public void testConstructorStringStringStringStringStringMapStringStringStringStringStringStringBooleanStringStringintStringStringStringString() throws URISyntaxException { + Map<String, String> attributes = new HashMap<>(); + attributes.put("aKey", "aValue"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "configName", attributes, + "body", "policyId", "ruleId", "configType", true, "version", "domain", 1, "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("onapName", stdPAPPolicy.getOnapName()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertEquals(attributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals("body", stdPAPPolicy.getConfigBodyData()); + assertEquals("policyId", stdPAPPolicy.getPolicyID()); + assertEquals("ruleId", stdPAPPolicy.getRuleID()); + assertEquals("configType", stdPAPPolicy.getConfigType()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("version", stdPAPPolicy.getVersion()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringStringStringBooleanStringStringIntegerStringStringStringString() throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + "domain", "jasonBody", 1, "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("jasonBody", stdPAPPolicy.getJsonBody()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringStringStringBooleanStringStringIntegerStringStringStringStringString() throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + "domain", "jasonBody", 1, "eCompName", "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("jasonBody", stdPAPPolicy.getJsonBody()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("eCompName", stdPAPPolicy.getOnapName()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorMapStringStringIntegerStringStringStringStringStringStringStringArrayListString() throws URISyntaxException { + Map<String, String> dyanamicFieldConfigAttributes = new HashMap<>(); + dyanamicFieldConfigAttributes.put("aKey", "aValue"); + ArrayList<String> brmsDependency = new ArrayList<>(); + brmsDependency.add("brmsDependency"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + "domain", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", "riskLevel", "riskType", "guard", "ttlDate", "brmsController", brmsDependency); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals(dyanamicFieldConfigAttributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("eCompName", stdPAPPolicy.getOnapName()); + assertEquals("configBodyData", stdPAPPolicy.getConfigBodyData()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + assertEquals("brmsController", stdPAPPolicy.getBrmsController()); + assertEquals(brmsDependency, stdPAPPolicy.getBrmsDependency()); + } + + @Test + public void testConstructorMapStringStringIntegerStringStringMapStringStringStringStringStringStringStringArrayListString() throws URISyntaxException { + Map<String, String> dyanamicFieldConfigAttributes = new HashMap<>(); + dyanamicFieldConfigAttributes.put("aKey", "aValue"); + Map<String, String> drlRuleAndUIParams = new HashMap<>(); + drlRuleAndUIParams.put("aDrlRuleKey", "aDrlRuleValue"); + ArrayList<String> brmsDependency = new ArrayList<>(); + brmsDependency.add("brmsDependency"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + "domain", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", drlRuleAndUIParams, "riskLevel", "riskType", "guard", "ttlDate", "brmsController", brmsDependency); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals(dyanamicFieldConfigAttributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("eCompName", stdPAPPolicy.getOnapName()); + assertEquals("configBodyData", stdPAPPolicy.getConfigBodyData()); + assertEquals(drlRuleAndUIParams, stdPAPPolicy.getDrlRuleAndUIParams()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + assertEquals("brmsController", stdPAPPolicy.getBrmsController()); + assertEquals(brmsDependency, stdPAPPolicy.getBrmsDependency()); + } + + @Test + public void testConstructorStringStringStringStringStringBooleanStringStringBooleanStringIntegerStringStringStringString() throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "jasonBody", true, + "oldPolicyFileName", "serviceType", true, "domain", 1, "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("onapName", stdPAPPolicy.getOnapName()); + assertEquals("jasonBody", stdPAPPolicy.getJsonBody()); + assertTrue(stdPAPPolicy.isDraft()); + assertEquals("oldPolicyFileName", stdPAPPolicy.getOldPolicyFileName()); + assertEquals("serviceType", stdPAPPolicy.getServiceType()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringStringStringBooleanStringStringStringStringStringIntegerStringStringStringString() throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, "domain", "policyId", "ruleId", + "version", "jasonBody", 1, "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("policyId", stdPAPPolicy.getPolicyID()); + assertEquals("ruleId", stdPAPPolicy.getRuleID()); + assertEquals("version", stdPAPPolicy.getVersion()); + assertEquals("jasonBody", stdPAPPolicy.getJsonBody()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringStringStringStringStringStringStringStringStringStringBooleanStringintStringStringStringString() throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "configName", "serviceType", + "uuid", "msLocation", "jasonBody", "priority" , "version", true, "domain", + 1, "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("onapName", stdPAPPolicy.getOnapName()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertEquals("serviceType", stdPAPPolicy.getServiceType()); + assertEquals("uuid", stdPAPPolicy.getUuid()); + assertEquals("msLocation", stdPAPPolicy.getMsLocation()); + assertEquals("jasonBody", stdPAPPolicy.getJsonBody()); + assertEquals("priority", stdPAPPolicy.getPriority()); + assertEquals("version", stdPAPPolicy.getVersion()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringStringStringBooleanStringStringStringStringStringIntegerStringStringStringStringString() throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, "domain", "policyId", "ruleId", "version", + "jasonBody", 1, "ecompName", "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("policyId", stdPAPPolicy.getPolicyID()); + assertEquals("ruleId", stdPAPPolicy.getRuleID()); + assertEquals("version", stdPAPPolicy.getVersion()); + assertEquals("jasonBody", stdPAPPolicy.getJsonBody()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("ecompName", stdPAPPolicy.getOnapName()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringStringStringBooleanStringStringStringStringMapStringStringIntegerStringStringStringStringString() throws URISyntaxException { + Map<String, String> dyanamicFieldConfigAttributes = new HashMap<>(); + dyanamicFieldConfigAttributes.put("aKey", "aValue"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + "domain", "policyId", "ruleId", "version", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("policyId", stdPAPPolicy.getPolicyID()); + assertEquals("ruleId", stdPAPPolicy.getRuleID()); + assertEquals("version", stdPAPPolicy.getVersion()); + assertEquals(dyanamicFieldConfigAttributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("eCompName", stdPAPPolicy.getOnapName()); + assertEquals("configBodyData", stdPAPPolicy.getConfigBodyData()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringStringStringStringBooleanStringStringStringStringMapStringStringIntegerStringMapStringStringStringStringStringString() throws URISyntaxException { + Map<String, String> dyanamicFieldConfigAttributes = new HashMap<>(); + dyanamicFieldConfigAttributes.put("aKey", "aValue"); + Map<String, String> drlRuleAndUIParams = new HashMap<>(); + drlRuleAndUIParams.put("aDrlRuleKey", "aDrlRuleValue"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + "domain", "policyId", "ruleId", "version", dyanamicFieldConfigAttributes, 1, "eCompName", drlRuleAndUIParams, "riskLevel", "riskType", "guard", "ttlDate"); + assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("description", stdPAPPolicy.getPolicyDescription()); + assertEquals("configName", stdPAPPolicy.getConfigName()); + assertTrue(stdPAPPolicy.isEditPolicy()); + assertEquals("domain", stdPAPPolicy.getDomainDir()); + assertEquals("policyId", stdPAPPolicy.getPolicyID()); + assertEquals("ruleId", stdPAPPolicy.getRuleID()); + assertEquals("version", stdPAPPolicy.getVersion()); + assertEquals(dyanamicFieldConfigAttributes, stdPAPPolicy.getDynamicFieldConfigAttributes()); + assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); + assertEquals("eCompName", stdPAPPolicy.getOnapName()); + assertEquals(drlRuleAndUIParams, stdPAPPolicy.getDrlRuleAndUIParams()); + assertEquals("riskLevel", stdPAPPolicy.getRiskLevel()); + assertEquals("riskType", stdPAPPolicy.getRiskType()); + assertEquals("guard", stdPAPPolicy.getGuard()); + assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); + } + + @Test + public void testConstructorStringString() { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "deleteCondition"); + assertEquals("policyName", stdPAPPolicy.getPolicyName()); + assertEquals("deleteCondition", stdPAPPolicy.getDeleteCondition()); + } + + @Test + public void testConstructorStringStringString() { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("dictionaryType", "dictionary", "dictionaryFields"); + assertEquals("dictionaryType", stdPAPPolicy.getDictionaryType()); + assertEquals("dictionary", stdPAPPolicy.getDictionary()); + assertEquals("dictionaryFields", stdPAPPolicy.getDictionaryFields()); + } +} diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupStatusTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupStatusTest.java index 27d471fd0..3e1d81578 100644 --- a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupStatusTest.java +++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPGroupStatusTest.java @@ -19,10 +19,11 @@ */ package org.onap.policy.xacml.test.std.pap; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; - import java.util.HashSet; - +import java.util.Set; import org.junit.Before; import org.junit.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -30,178 +31,451 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.xacml.std.pap.StdPDP; import org.onap.policy.xacml.std.pap.StdPDPGroupStatus; import org.onap.policy.xacml.std.pap.StdPDPPIPConfig; +import org.onap.policy.xacml.std.pap.StdPDPPolicy; +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroupStatus.Status; +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.att.research.xacml.api.pap.PDPPolicy; public class StdPDPGroupStatusTest { - private static Logger logger = FlexLogger.getLogger(StdPDPGroupStatus.class); - - private StdPDPGroupStatus stdPDPGroupStatus; - - @Before - public void setUp(){ - - try { - stdPDPGroupStatus = new StdPDPGroupStatus(); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void tesGgetStatus() { - try { - assertTrue(stdPDPGroupStatus.getStatus() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetFailedPIPConfigs() { - try { - assertTrue(stdPDPGroupStatus.getFailedPIPConfigs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetUnknownPDPs() { - try { - assertTrue(stdPDPGroupStatus.getUnknownPDPs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetLoadErrors() { - try { - stdPDPGroupStatus.setLoadErrors(new HashSet<String>()); - assertTrue(stdPDPGroupStatus.getLoadErrors() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetLoadWarnings() { - try { - stdPDPGroupStatus.setLoadWarnings(new HashSet<>()); - assertTrue(stdPDPGroupStatus.getLoadWarnings() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetLoadedPolicies() { - try { - stdPDPGroupStatus.setLoadedPolicies(new HashSet<>()); - assertTrue(stdPDPGroupStatus.getLoadedPolicies() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetFailedPolicies() { - try { - stdPDPGroupStatus.setFailedPolicies(new HashSet<>()); - assertTrue(stdPDPGroupStatus.getFailedPolicies() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetLoadedPipConfigs() { - try { - stdPDPGroupStatus.addLoadedPipConfig(new StdPDPPIPConfig()); - assertTrue(stdPDPGroupStatus.getLoadedPipConfigs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetFailedPipConfigs() { - try { - stdPDPGroupStatus.addFailedPipConfig(new StdPDPPIPConfig()); - assertTrue(stdPDPGroupStatus.getFailedPipConfigs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetInSynchPDPs() { - try { - stdPDPGroupStatus.addInSynchPDP(new StdPDP()); - assertTrue(stdPDPGroupStatus.getInSynchPDPs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetOutOfSynchPDPs() { - try { - stdPDPGroupStatus.addOutOfSynchPDP(new StdPDP()); - assertTrue(stdPDPGroupStatus.getOutOfSynchPDPs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetFailedPDPs() { - try { - stdPDPGroupStatus.addFailedPDP(new StdPDP()); - assertTrue(stdPDPGroupStatus.getFailedPDPs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetUpdatingPDPs() { - try { - stdPDPGroupStatus.addUpdatingPDP(new StdPDP()); - assertTrue(stdPDPGroupStatus.getUpdatingPDPs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetLastUpdateFailedPDPs() { - try { - stdPDPGroupStatus.addLastUpdateFailedPDP(new StdPDP()); - assertTrue(stdPDPGroupStatus.getLastUpdateFailedPDPs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testGetUnknownStatusPDPs() { - try { - stdPDPGroupStatus.addUnknownPDP(new StdPDP()); - assertTrue(stdPDPGroupStatus.getUnknownStatusPDPs() != null); - } catch (Exception e) { - logger.error(e); - } - } - - @Test - public void testIsGroupOk() { - try { - stdPDPGroupStatus.policiesOK(); - assertTrue(stdPDPGroupStatus.isGroupOk() == false); - } catch (Exception e) { - logger.error(e); - } - } + private static Logger logger = FlexLogger.getLogger(StdPDPGroupStatus.class); + + private StdPDPGroupStatus stdPDPGroupStatus; + + @Before + public void setUp() { + + try { + stdPDPGroupStatus = new StdPDPGroupStatus(); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void tesGgetStatus() { + try { + assertTrue(stdPDPGroupStatus.getStatus() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetFailedPIPConfigs() { + try { + assertTrue(stdPDPGroupStatus.getFailedPIPConfigs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetUnknownPDPs() { + try { + assertTrue(stdPDPGroupStatus.getUnknownPDPs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetLoadErrors() { + try { + stdPDPGroupStatus.setLoadErrors(new HashSet<String>()); + assertTrue(stdPDPGroupStatus.getLoadErrors() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetLoadWarnings() { + try { + stdPDPGroupStatus.setLoadWarnings(new HashSet<>()); + assertTrue(stdPDPGroupStatus.getLoadWarnings() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetLoadedPolicies() { + try { + stdPDPGroupStatus.setLoadedPolicies(new HashSet<>()); + assertTrue(stdPDPGroupStatus.getLoadedPolicies() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetFailedPolicies() { + try { + stdPDPGroupStatus.setFailedPolicies(new HashSet<>()); + assertTrue(stdPDPGroupStatus.getFailedPolicies() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetLoadedPipConfigs() { + try { + stdPDPGroupStatus.addLoadedPipConfig(new StdPDPPIPConfig()); + assertTrue(stdPDPGroupStatus.getLoadedPipConfigs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetFailedPipConfigs() { + try { + stdPDPGroupStatus.addFailedPipConfig(new StdPDPPIPConfig()); + assertTrue(stdPDPGroupStatus.getFailedPipConfigs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetInSynchPDPs() { + try { + stdPDPGroupStatus.addInSynchPDP(new StdPDP()); + assertTrue(stdPDPGroupStatus.getInSynchPDPs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetOutOfSynchPDPs() { + try { + stdPDPGroupStatus.addOutOfSynchPDP(new StdPDP()); + assertTrue(stdPDPGroupStatus.getOutOfSynchPDPs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetFailedPDPs() { + try { + stdPDPGroupStatus.addFailedPDP(new StdPDP()); + assertTrue(stdPDPGroupStatus.getFailedPDPs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetUpdatingPDPs() { + try { + stdPDPGroupStatus.addUpdatingPDP(new StdPDP()); + assertTrue(stdPDPGroupStatus.getUpdatingPDPs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetLastUpdateFailedPDPs() { + try { + stdPDPGroupStatus.addLastUpdateFailedPDP(new StdPDP()); + assertTrue(stdPDPGroupStatus.getLastUpdateFailedPDPs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testGetUnknownStatusPDPs() { + try { + stdPDPGroupStatus.addUnknownPDP(new StdPDP()); + assertTrue(stdPDPGroupStatus.getUnknownStatusPDPs() != null); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testIsGroupOk() { + try { + stdPDPGroupStatus.policiesOK(); + assertTrue(stdPDPGroupStatus.isGroupOk() == false); + } catch (Exception e) { + logger.error(e); + } + } + + @Test + public void testPoliciesOK() { + assertTrue(stdPDPGroupStatus.policiesOK()); + stdPDPGroupStatus.addFailedPolicy(new StdPDPPolicy()); + assertFalse(stdPDPGroupStatus.policiesOK()); + } + + @Test + public void testPipConfigOK() { + assertTrue(stdPDPGroupStatus.pipConfigOK()); + stdPDPGroupStatus.addFailedPipConfig(new StdPDPPIPConfig()); + assertFalse(stdPDPGroupStatus.pipConfigOK()); + } + + @Test + public void testPdpsOKOutOfSyncPdp() { + assertTrue(stdPDPGroupStatus.pdpsOK()); + stdPDPGroupStatus.addOutOfSynchPDP(new StdPDP()); + assertFalse(stdPDPGroupStatus.pdpsOK()); + } + + @Test + public void testPdpsOKFailedPdp() { + assertTrue(stdPDPGroupStatus.pdpsOK()); + stdPDPGroupStatus.addFailedPDP(new StdPDP()); + assertFalse(stdPDPGroupStatus.pdpsOK()); + } + + @Test + public void testPdpsOKLastUpdateFailedPdp() { + assertTrue(stdPDPGroupStatus.pdpsOK()); + stdPDPGroupStatus.addLastUpdateFailedPDP(new StdPDP()); + assertFalse(stdPDPGroupStatus.pdpsOK()); + } + + @Test + public void testPdpsOKUnknownPdp() { + assertTrue(stdPDPGroupStatus.pdpsOK()); + stdPDPGroupStatus.addUnknownPDP(new StdPDP()); + assertFalse(stdPDPGroupStatus.pdpsOK()); + } + + @Test + public void testIsGroupOkFailedPolicy() { + stdPDPGroupStatus.setStatus(Status.OK); + assertTrue(stdPDPGroupStatus.isGroupOk()); + stdPDPGroupStatus.addFailedPolicy(new StdPDPPolicy()); + assertFalse(stdPDPGroupStatus.isGroupOk()); + } + + @Test + public void testIsGroupOkFailedPipConfig() { + stdPDPGroupStatus.setStatus(Status.OK); + assertTrue(stdPDPGroupStatus.isGroupOk()); + stdPDPGroupStatus.addFailedPipConfig(new StdPDPPIPConfig()); + assertFalse(stdPDPGroupStatus.isGroupOk()); + } + + @Test + public void testIsGroupOkFailedPdp() { + stdPDPGroupStatus.setStatus(Status.OK); + assertTrue(stdPDPGroupStatus.isGroupOk()); + stdPDPGroupStatus.addLastUpdateFailedPDP(new StdPDP()); + assertFalse(stdPDPGroupStatus.isGroupOk()); + } + + @Test + public void testIsGroupOkLoadErrors() { + stdPDPGroupStatus.setStatus(Status.OK); + assertTrue(stdPDPGroupStatus.isGroupOk()); + stdPDPGroupStatus.addLoadError("A load error"); + assertFalse(stdPDPGroupStatus.isGroupOk()); + } + + @Test + public void testIsGroupOkStatusOutOfSynch() { + stdPDPGroupStatus.setStatus(Status.OK); + assertTrue(stdPDPGroupStatus.isGroupOk()); + stdPDPGroupStatus.setStatus(Status.OUT_OF_SYNCH); + assertFalse(stdPDPGroupStatus.isGroupOk()); + } + + @Test + public void testConstructor() { + Status status = Status.OK; + Set<PDP> failedPDPs = new HashSet<>(); + failedPDPs.add(new StdPDP()); + Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>(); + failedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> failedPolicies = new HashSet<>(); + failedPolicies.add(new StdPDPPolicy()); + Set<PDP> inSynchPDPs = new HashSet<>(); + inSynchPDPs.add(new StdPDP()); + Set<PDP> lastUpdateFailedPDPs = new HashSet<>(); + lastUpdateFailedPDPs.add(new StdPDP()); + Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<>(); + loadedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> loadedPolicies = new HashSet<>(); + loadedPolicies.add(new StdPDPPolicy()); + Set<String> loadErrors = new HashSet<>(); + loadErrors.add("An error"); + Set<String> loadWarnings = new HashSet<>(); + loadWarnings.add("An error"); + Set<PDP> outOfSynchPDPs = new HashSet<>(); + outOfSynchPDPs.add(new StdPDP()); + Set<PDP> unknownPDPs = new HashSet<>(); + unknownPDPs.add(new StdPDP()); + Set<PDP> updatingPDPs = new HashSet<>(); + updatingPDPs.add(new StdPDP()); + + + stdPDPGroupStatus.setStatus(status); + stdPDPGroupStatus.setFailedPDPs(failedPDPs); + stdPDPGroupStatus.setFailedPIPConfigs(failedPIPConfigs); + stdPDPGroupStatus.setFailedPolicies(failedPolicies); + stdPDPGroupStatus.setInSynchPDPs(inSynchPDPs); + stdPDPGroupStatus.setLastUpdateFailedPDPs(lastUpdateFailedPDPs); + stdPDPGroupStatus.setLoadedPIPConfigs(loadedPIPConfigs); + stdPDPGroupStatus.setLoadedPolicies(loadedPolicies); + stdPDPGroupStatus.setLoadErrors(loadErrors); + stdPDPGroupStatus.setLoadWarnings(loadWarnings); + stdPDPGroupStatus.setOutOfSynchPDPs(outOfSynchPDPs); + stdPDPGroupStatus.setUnknownPDPs(unknownPDPs); + stdPDPGroupStatus.setUpdatingPDPs(updatingPDPs); + + StdPDPGroupStatus stdPDPGroupStatus2 = new StdPDPGroupStatus(stdPDPGroupStatus); + + assertEquals(status, stdPDPGroupStatus2.getStatus()); + assertEquals(failedPDPs, stdPDPGroupStatus2.getFailedPDPs()); + assertEquals(failedPIPConfigs, stdPDPGroupStatus2.getFailedPIPConfigs()); + assertEquals(failedPolicies, stdPDPGroupStatus2.getFailedPolicies()); + assertEquals(inSynchPDPs, stdPDPGroupStatus2.getInSynchPDPs()); + assertEquals(lastUpdateFailedPDPs, stdPDPGroupStatus2.getLastUpdateFailedPDPs()); + assertEquals(loadedPIPConfigs, stdPDPGroupStatus2.getLoadedPIPConfigs()); + assertEquals(loadedPolicies, stdPDPGroupStatus2.getLoadedPolicies()); + assertEquals(loadErrors, stdPDPGroupStatus2.getLoadErrors()); + assertEquals(loadWarnings, stdPDPGroupStatus2.getLoadWarnings()); + assertEquals(outOfSynchPDPs, stdPDPGroupStatus2.getOutOfSynchPDPs()); + assertEquals(unknownPDPs, stdPDPGroupStatus2.getUnknownPDPs()); + assertEquals(updatingPDPs, stdPDPGroupStatus2.getUpdatingPDPs()); + } + + @Test + public void testEqualsAndHashCode() { + Status status = Status.OK; + Set<PDP> failedPDPs = new HashSet<>(); + failedPDPs.add(new StdPDP()); + Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>(); + failedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> failedPolicies = new HashSet<>(); + failedPolicies.add(new StdPDPPolicy()); + Set<PDP> inSynchPDPs = new HashSet<>(); + inSynchPDPs.add(new StdPDP()); + Set<PDP> lastUpdateFailedPDPs = new HashSet<>(); + lastUpdateFailedPDPs.add(new StdPDP()); + Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<>(); + loadedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> loadedPolicies = new HashSet<>(); + loadedPolicies.add(new StdPDPPolicy()); + Set<String> loadErrors = new HashSet<>(); + loadErrors.add("An error"); + Set<String> loadWarnings = new HashSet<>(); + loadWarnings.add("An error"); + Set<PDP> outOfSynchPDPs = new HashSet<>(); + outOfSynchPDPs.add(new StdPDP()); + Set<PDP> unknownPDPs = new HashSet<>(); + unknownPDPs.add(new StdPDP()); + Set<PDP> updatingPDPs = new HashSet<>(); + updatingPDPs.add(new StdPDP()); + + StdPDPGroupStatus stdPDPGroupStatus1 = new StdPDPGroupStatus(); + + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + + stdPDPGroupStatus.setStatus(status); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setStatus(status); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setFailedPDPs(failedPDPs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setFailedPDPs(failedPDPs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setFailedPIPConfigs(failedPIPConfigs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setFailedPIPConfigs(failedPIPConfigs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setFailedPolicies(failedPolicies); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setFailedPolicies(failedPolicies); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setInSynchPDPs(inSynchPDPs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setInSynchPDPs(inSynchPDPs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setLastUpdateFailedPDPs(lastUpdateFailedPDPs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setLastUpdateFailedPDPs(lastUpdateFailedPDPs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setLoadedPIPConfigs(loadedPIPConfigs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setLoadedPIPConfigs(loadedPIPConfigs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setLoadedPolicies(loadedPolicies); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setLoadedPolicies(loadedPolicies); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setLoadErrors(loadErrors); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setLoadErrors(loadErrors); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setLoadWarnings(loadWarnings); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setLoadWarnings(loadWarnings); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setOutOfSynchPDPs(outOfSynchPDPs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setOutOfSynchPDPs(outOfSynchPDPs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setUnknownPDPs(unknownPDPs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setUnknownPDPs(unknownPDPs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + + stdPDPGroupStatus.setUpdatingPDPs(updatingPDPs); + assertFalse(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + stdPDPGroupStatus1.setUpdatingPDPs(updatingPDPs); + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus1)); + assertEquals(stdPDPGroupStatus.hashCode(), stdPDPGroupStatus1.hashCode()); + } + + @Test + public void testEqualsSameObject() { + assertTrue(stdPDPGroupStatus.equals(stdPDPGroupStatus)); + } + + @Test + public void testEqualsNull() { + assertFalse(stdPDPGroupStatus.equals(null)); + } + + @Test + public void testEqualsInstanceOfDiffClass() { + assertFalse(stdPDPGroupStatus.equals("")); + } } diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPStatusTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPStatusTest.java new file mode 100644 index 000000000..c99eef8ee --- /dev/null +++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPDPStatusTest.java @@ -0,0 +1,311 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.xacml.test.std.pap; + +import static org.junit.Assert.*; +import java.util.HashSet; +import java.util.Set; +import org.junit.Test; +import org.onap.policy.xacml.std.pap.StdPDPPIPConfig; +import org.onap.policy.xacml.std.pap.StdPDPPolicy; +import org.onap.policy.xacml.std.pap.StdPDPStatus; +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus.Status; + +public class StdPDPStatusTest { + + StdPDPStatus stdPDPStatus = new StdPDPStatus(); + + @Test + public void testSetAndGetStatus() { + Status status = Status.UP_TO_DATE; + stdPDPStatus.setStatus(status); + assertEquals(status, stdPDPStatus.getStatus()); + } + + @Test + public void testSetAndGetLoadErrors() { + Set<String> errors = new HashSet<>(); + errors.add("An error"); + stdPDPStatus.setLoadErrors(errors); + assertEquals(errors, stdPDPStatus.getLoadErrors()); + } + + @Test + public void testSetAndGetLoadWarnings() { + Set<String> warnings = new HashSet<>(); + warnings.add("An error"); + stdPDPStatus.setLoadWarnings(warnings); + assertEquals(warnings, stdPDPStatus.getLoadWarnings()); + } + + @Test + public void testSetAndGetLoadedPolicies() { + Set<PDPPolicy> loadedPolicies = new HashSet<>(); + loadedPolicies.add(new StdPDPPolicy()); + stdPDPStatus.setLoadedPolicies(loadedPolicies); + assertEquals(loadedPolicies, stdPDPStatus.getLoadedPolicies()); + } + + @Test + public void testSetAndGetLoadedRootPolicies() { + Set<PDPPolicy> loadedRootPolicies = new HashSet<>(); + loadedRootPolicies.add(new StdPDPPolicy()); + stdPDPStatus.setLoadedRootPolicies(loadedRootPolicies); + assertEquals(loadedRootPolicies, stdPDPStatus.getLoadedRootPolicies()); + } + + @Test + public void testSetAndGetFailedPolicies() { + Set<PDPPolicy> failedPolicies = new HashSet<>(); + failedPolicies.add(new StdPDPPolicy()); + stdPDPStatus.setFailedPolicies(failedPolicies); + assertEquals(failedPolicies, stdPDPStatus.getFailedPolicies()); + } + + @Test + public void testSetAndGetLoadedPipConfigs() { + Set<PDPPIPConfig> loadedPipConfigs = new HashSet<>(); + loadedPipConfigs.add(new StdPDPPIPConfig()); + stdPDPStatus.setLoadedPipConfigs(loadedPipConfigs); + assertEquals(loadedPipConfigs, stdPDPStatus.getLoadedPipConfigs()); + } + + @Test + public void testSetAndGetFailedPipConfigs() { + Set<PDPPIPConfig> failedPipConfigs = new HashSet<>(); + failedPipConfigs.add(new StdPDPPIPConfig()); + stdPDPStatus.setFailedPipConfigs(failedPipConfigs); + assertEquals(failedPipConfigs, stdPDPStatus.getFailedPipConfigs()); + } + + @Test + public void testPoliciesOK() { + assertTrue(stdPDPStatus.policiesOK()); + stdPDPStatus.addFailedPolicy(new StdPDPPolicy()); + assertFalse(stdPDPStatus.policiesOK()); + } + + @Test + public void testPipConfigOK() { + assertTrue(stdPDPStatus.pipConfigOK()); + stdPDPStatus.addFailedPipConfig(new StdPDPPIPConfig()); + assertFalse(stdPDPStatus.pipConfigOK()); + } + + @Test + public void testIsOkFailedPolicy() { + stdPDPStatus.setStatus(Status.UP_TO_DATE); + assertTrue(stdPDPStatus.isOk()); + stdPDPStatus.addFailedPolicy(new StdPDPPolicy()); + assertFalse(stdPDPStatus.isOk()); + } + + @Test + public void testIsOkFailedPipConfig() { + stdPDPStatus.setStatus(Status.UP_TO_DATE); + assertTrue(stdPDPStatus.isOk()); + stdPDPStatus.addFailedPipConfig(new StdPDPPIPConfig()); + assertFalse(stdPDPStatus.isOk()); + } + + @Test + public void testIsOkStatusOutOfSync() { + stdPDPStatus.setStatus(Status.UP_TO_DATE); + assertTrue(stdPDPStatus.isOk()); + stdPDPStatus.setStatus(Status.OUT_OF_SYNCH); + assertFalse(stdPDPStatus.isOk()); + } + + @Test + public void testAddLoadError() { + stdPDPStatus.addLoadError("An error"); + assertEquals("An error", stdPDPStatus.getLoadErrors().iterator().next()); + } + + @Test + public void testAddLoadWarning() { + stdPDPStatus.addLoadWarning("A warning"); + assertEquals("A warning", stdPDPStatus.getLoadWarnings().iterator().next()); + } + + @Test + public void testAddLoadedPolicy() { + PDPPolicy policy = new StdPDPPolicy(); + stdPDPStatus.addLoadedPolicy(policy); + assertEquals(policy, stdPDPStatus.getLoadedPolicies().iterator().next()); + } + + @Test + public void testAddRootPolicy() { + PDPPolicy policy = new StdPDPPolicy(); + stdPDPStatus.addRootPolicy(policy); + assertEquals(policy, stdPDPStatus.getLoadedRootPolicies().iterator().next()); + } + + @Test + public void testAddAllLoadedRootPolicy() { + Set<PDPPolicy> policies = new HashSet<>(); + PDPPolicy policy = new StdPDPPolicy(); + policies.add(policy); + stdPDPStatus.addAllLoadedRootPolicies(policies); + assertEquals(policies, stdPDPStatus.getLoadedRootPolicies()); + } + + @Test + public void testAddLoadedPipConfig(){ + PDPPIPConfig pipConfig = new StdPDPPIPConfig(); + stdPDPStatus.addLoadedPipConfig(pipConfig); + assertEquals(pipConfig, stdPDPStatus.getLoadedPipConfigs().iterator().next()); + } + + @Test + public void testSet() { + Status status = Status.UP_TO_DATE; + Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>(); + failedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> failedPolicies = new HashSet<>(); + failedPolicies.add(new StdPDPPolicy()); + Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<>(); + loadedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> loadedPolicies = new HashSet<>(); + loadedPolicies.add(new StdPDPPolicy()); + Set<PDPPolicy> loadedRootPolicies = new HashSet<>(); + loadedRootPolicies.add(new StdPDPPolicy()); + Set<String> loadErrors = new HashSet<>(); + loadErrors.add("An error"); + Set<String> loadWarnings = new HashSet<>(); + loadWarnings.add("An error"); + + stdPDPStatus.setStatus(status); + stdPDPStatus.setFailedPipConfigs(failedPIPConfigs); + stdPDPStatus.setFailedPolicies(failedPolicies); + stdPDPStatus.setLoadedPipConfigs(loadedPIPConfigs); + stdPDPStatus.setLoadedPolicies(loadedPolicies); + stdPDPStatus.setLoadedRootPolicies(loadedRootPolicies); + stdPDPStatus.setLoadErrors(loadErrors); + stdPDPStatus.setLoadWarnings(loadWarnings); + + StdPDPStatus stdPDPStatus1 = new StdPDPStatus(); + stdPDPStatus1.set(stdPDPStatus); + + assertEquals(status, stdPDPStatus1.getStatus()); + assertEquals(loadErrors, stdPDPStatus1.getLoadErrors()); + assertEquals(loadWarnings, stdPDPStatus1.getLoadWarnings()); + assertEquals(loadedPolicies, stdPDPStatus1.getLoadedPolicies()); + assertEquals(loadedRootPolicies, stdPDPStatus1.getLoadedRootPolicies()); + assertEquals(failedPolicies, stdPDPStatus1.getFailedPolicies()); + assertEquals(loadedPIPConfigs, stdPDPStatus1.getLoadedPipConfigs()); + assertEquals(failedPIPConfigs, stdPDPStatus1.getFailedPipConfigs()); + + assertEquals("StdPDPStatus [status=UP_TO_DATE, loadErrors=[An error], loadWarnings=[An error], loadedPolicies=[StdPDPPolicy " + + "[id=null, name=null, policyId=null, description=null, version=, isRoot=false, isValid=false, location=null]], " + + "loadedRootPolicies=[StdPDPPolicy [id=null, name=null, policyId=null, description=null, version=, isRoot=false, " + + "isValid=false, location=null]], failedPolicies=[StdPDPPolicy [id=null, name=null, policyId=null, description=null, " + + "version=, isRoot=false, isValid=false, location=null]], loadedPIPConfigs=[StdPDPPIPConfig [id=null, name=null, " + + "description=null, classname=null, config={}]], failedPIPConfigs=[StdPDPPIPConfig [id=null, name=null, description=null, classname=null, config={}]]]", + stdPDPStatus1.toString()); + } + + @Test + public void testEqualsAndHashCode() { + Status status = Status.UP_TO_DATE; + Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>(); + failedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> failedPolicies = new HashSet<>(); + failedPolicies.add(new StdPDPPolicy()); + Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<>(); + loadedPIPConfigs.add(new StdPDPPIPConfig()); + Set<PDPPolicy> loadedPolicies = new HashSet<>(); + loadedPolicies.add(new StdPDPPolicy()); + Set<PDPPolicy> loadedRootPolicies = new HashSet<>(); + loadedRootPolicies.add(new StdPDPPolicy()); + Set<String> loadErrors = new HashSet<>(); + loadErrors.add("An error"); + Set<String> loadWarnings = new HashSet<>(); + loadWarnings.add("An error"); + + StdPDPStatus stdPDPStatus1 = new StdPDPStatus(); + + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + + stdPDPStatus.setStatus(status); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setStatus(status); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + + stdPDPStatus.setFailedPipConfigs(failedPIPConfigs); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setFailedPipConfigs(failedPIPConfigs); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + + stdPDPStatus.setFailedPolicies(failedPolicies); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setFailedPolicies(failedPolicies); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + + stdPDPStatus.setLoadedPipConfigs(loadedPIPConfigs); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setLoadedPipConfigs(loadedPIPConfigs); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + + stdPDPStatus.setLoadedPolicies(loadedPolicies); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setLoadedPolicies(loadedPolicies); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + + stdPDPStatus.setLoadedRootPolicies(loadedRootPolicies); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setLoadedRootPolicies(loadedRootPolicies); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + + stdPDPStatus.setLoadErrors(loadErrors); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setLoadErrors(loadErrors); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + + stdPDPStatus.setLoadWarnings(loadWarnings); + assertFalse(stdPDPStatus.equals(stdPDPStatus1)); + stdPDPStatus1.setLoadWarnings(loadWarnings); + assertTrue(stdPDPStatus.equals(stdPDPStatus1)); + assertEquals(stdPDPStatus.hashCode(), stdPDPStatus1.hashCode()); + } + + @Test + public void testEqualsSameObject() { + assertTrue(stdPDPStatus.equals(stdPDPStatus)); + } + + @Test + public void testEqualsNull() { + assertFalse(stdPDPStatus.equals(null)); + } + + @Test + public void testEqualsInstanceOfDiffClass() { + assertFalse(stdPDPStatus.equals("")); + } +} diff --git a/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/default/xacml.pip.properties b/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/default/xacml.pip.properties new file mode 100644 index 000000000..ada317ca5 --- /dev/null +++ b/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/default/xacml.pip.properties @@ -0,0 +1,24 @@ +### +# ============LICENSE_START======================================================= +# Copyright (C) 2018 Ericsson. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Tue Feb 13 13:39:20 GMT 2018 +AAF.description=AAFEngine to communicate with AAF to take decisions +AAF.classname=org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine +AAF.name=AAFEngine +xacml.pip.engines=AAF diff --git a/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/default/xacml.policy.properties b/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/default/xacml.policy.properties new file mode 100644 index 000000000..e3cb9840a --- /dev/null +++ b/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/default/xacml.policy.properties @@ -0,0 +1,22 @@ +### +# ============LICENSE_START======================================================= +# Copyright (C) 2018 Ericsson. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Tue Feb 13 13:39:20 GMT 2018 +xacml.referencedPolicies= +xacml.rootPolicies= diff --git a/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/xacml.properties b/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/xacml.properties new file mode 100644 index 000000000..be5102f2d --- /dev/null +++ b/ONAP-XACML/src/test/resources/emptyPapGroupsDefault/xacml.properties @@ -0,0 +1,7 @@ +# +#Fri Feb 16 11:15:29 GMT 2018 +xacml.pap.groups.default= +xacml.pap.groups=default +default.name=default +default.description=The default group where new PDP's are put. +default.pdps= |