diff options
Diffstat (limited to 'models-pdp/src/test/java')
8 files changed, 119 insertions, 88 deletions
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java index 89ee5b90d..808bfe7d4 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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. @@ -42,6 +43,20 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi * @author Liam Fallon (liam.fallon@est.tech) */ public class PdpGroupFilterTest { + private static final String POLICY_TYPE3 = "policy.type.3"; + private static final String POLICY_TYPE2 = "policy.type.2"; + private static final String POLICY_TYPE1 = "policy.type.1"; + private static final String POLICY_TYPE0 = "policy.type.0"; + private static final String POLICY3 = "Policy3"; + private static final String POLICY2 = "Policy2"; + private static final String POLICY1 = "Policy1"; + private static final String POLICY0 = "Policy0"; + private static final String NON_EXISTANT = "Nonexistant"; + private static final String VERSION9 = "9.9.9"; + private static final String VERSION7 = "7.8.9"; + private static final String VERSION4 = "4.5.6"; + private static final String VERSION1 = "1.2.3"; + private static final String VERSION0 = "0.1.2"; private List<PdpGroup> pdpGroupList; /** @@ -161,43 +176,43 @@ public class PdpGroupFilterTest { public void testFilterPolicyType() { List<ToscaPolicyTypeIdentifier> identifierList = new ArrayList<>(); - identifierList.add(new ToscaPolicyTypeIdentifier("Nonexistant", "1.2.3")); + identifierList.add(new ToscaPolicyTypeIdentifier(NON_EXISTANT, VERSION1)); PdpGroupFilter filter = PdpGroupFilter.builder().policyTypeList(identifierList).build(); List<PdpGroup> filteredList = filter.filter(pdpGroupList); assertEquals(0, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE0, VERSION1)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(4, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE1, VERSION4)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(4, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.2", "7.8.9")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE2, VERSION7)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(2, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE3, VERSION0)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(2, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("Nonexistant", "1.2.3")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "9.9.9")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.2", "7.8.9")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2")); + identifierList.add(new ToscaPolicyTypeIdentifier(NON_EXISTANT, VERSION1)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE0, VERSION9)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE0, VERSION1)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE1, VERSION4)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE2, VERSION7)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE3, VERSION0)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(5, filteredList.size()); @@ -207,30 +222,30 @@ public class PdpGroupFilterTest { assertEquals(0, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE0, VERSION1)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(2, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.2", "7.8.9")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE0, VERSION1)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE1, VERSION4)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE2, VERSION7)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE0, VERSION1)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE1, VERSION4)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE3, VERSION0)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6")); - identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2")); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE1, VERSION4)); + identifierList.add(new ToscaPolicyTypeIdentifier(POLICY_TYPE3, VERSION0)); filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); @@ -240,49 +255,49 @@ public class PdpGroupFilterTest { public void testFilterPolicy() { List<ToscaPolicyIdentifier> identifierList = new ArrayList<>(); - identifierList.add(new ToscaPolicyIdentifier("Nonexistant", "1.2.3")); + identifierList.add(new ToscaPolicyIdentifier(NON_EXISTANT, VERSION1)); PdpGroupFilter filter = PdpGroupFilter.builder().policyList(identifierList).build(); List<PdpGroup> filteredList = filter.filter(pdpGroupList); assertEquals(0, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy0", "9.9.9")); + identifierList.add(new ToscaPolicyIdentifier(POLICY0, VERSION9)); filter = PdpGroupFilter.builder().policyList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(0, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6")); + identifierList.add(new ToscaPolicyIdentifier(POLICY0, VERSION4)); filter = PdpGroupFilter.builder().policyList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(4, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy1", "4.5.6")); + identifierList.add(new ToscaPolicyIdentifier(POLICY1, VERSION4)); filter = PdpGroupFilter.builder().policyList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6")); + identifierList.add(new ToscaPolicyIdentifier(POLICY2, VERSION4)); filter = PdpGroupFilter.builder().policyList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(2, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy3", "1.2.3")); + identifierList.add(new ToscaPolicyIdentifier(POLICY3, VERSION1)); filter = PdpGroupFilter.builder().policyList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Nonexistant", "1.2.3")); - identifierList.add(new ToscaPolicyIdentifier("Policy0", "9.9.9")); - identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6")); - identifierList.add(new ToscaPolicyIdentifier("Policy1", "4.5.6")); - identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6")); - identifierList.add(new ToscaPolicyIdentifier("Policy3", "1.2.3")); + identifierList.add(new ToscaPolicyIdentifier(NON_EXISTANT, VERSION1)); + identifierList.add(new ToscaPolicyIdentifier(POLICY0, VERSION9)); + identifierList.add(new ToscaPolicyIdentifier(POLICY0, VERSION4)); + identifierList.add(new ToscaPolicyIdentifier(POLICY1, VERSION4)); + identifierList.add(new ToscaPolicyIdentifier(POLICY2, VERSION4)); + identifierList.add(new ToscaPolicyIdentifier(POLICY3, VERSION1)); filter = PdpGroupFilter.builder().policyList(identifierList).build(); filteredList = filter.filter(pdpGroupList); assertEquals(5, filteredList.size()); @@ -292,27 +307,27 @@ public class PdpGroupFilterTest { assertEquals(0, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6")); + identifierList.add(new ToscaPolicyIdentifier(POLICY0, VERSION4)); filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(3, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6")); - identifierList.add(new ToscaPolicyIdentifier("Policy1", "4.5.6")); + identifierList.add(new ToscaPolicyIdentifier(POLICY0, VERSION4)); + identifierList.add(new ToscaPolicyIdentifier(POLICY1, VERSION4)); filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6")); + identifierList.add(new ToscaPolicyIdentifier(POLICY2, VERSION4)); filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); identifierList.clear(); - identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6")); - identifierList.add(new ToscaPolicyIdentifier("Policy3", "1.2.3")); + identifierList.add(new ToscaPolicyIdentifier(POLICY2, VERSION4)); + identifierList.add(new ToscaPolicyIdentifier(POLICY3, VERSION1)); filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build(); filteredList = filter.filter(pdpGroupList); assertEquals(1, filteredList.size()); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java index a717dc2d8..a282b7dba 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java @@ -43,6 +43,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi * Test methods not tested by {@link ModelsTest}. */ public class PdpGroupTest { + private static final String VERSION = "1.2.3"; private static final String NAME = "my-name"; private static final String PDP_TYPE1 = "type-1"; private static final String PDP_TYPE2 = "type-2"; @@ -61,7 +62,7 @@ public class PdpGroupTest { // verify with all values orig.setDescription("my-descript"); orig.setName(NAME); - orig.setVersion("1.2.3"); + orig.setVersion(VERSION); orig.setDescription("my-description"); orig.setPdpGroupState(PdpState.SAFE); @@ -100,11 +101,11 @@ public class PdpGroupTest { public void testCompareTo() { PdpGroup pdpGroup0 = new PdpGroup(); pdpGroup0.setName("Name0"); - pdpGroup0.setVersion("1.2.3"); + pdpGroup0.setVersion(VERSION); PdpGroup pdpGroup1 = new PdpGroup(); pdpGroup1.setName("Name0"); - pdpGroup1.setVersion("1.2.3"); + pdpGroup1.setVersion(VERSION); assertEquals(0, pdpGroup0.compareTo(pdpGroup1)); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java index 10f31312c..9047a7ae1 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java @@ -30,6 +30,7 @@ import org.junit.Test; import org.onap.policy.models.pdp.enums.PdpMessageType; public class PdpMessageTest { + private static final String PDP_GROUP_STRING = " pdp group "; private static final String PDP_NAME = "pdpA"; private static final String PDP_GROUP = "groupA"; private static final String PDP_SUBGROUP = "subgroupA"; @@ -67,7 +68,7 @@ public class PdpMessageTest { for (String pdpGroup : new String[] {null, PDP_GROUP, DIFFERENT}) { for (String pdpSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) { - assertTrue("name msg " + message + " pdp group " + pdpGroup + "/" + pdpSubgroup, + assertTrue("name msg " + message + PDP_GROUP_STRING + pdpGroup + "/" + pdpSubgroup, message.appliesTo(PDP_NAME, pdpGroup, pdpSubgroup)); } } @@ -83,7 +84,7 @@ public class PdpMessageTest { for (String pdpGroup : new String[] {null, PDP_GROUP, DIFFERENT}) { for (String pdpSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) { - assertFalse("name msg " + message + " pdp group " + pdpGroup + "/" + pdpSubgroup, + assertFalse("name msg " + message + PDP_GROUP_STRING + pdpGroup + "/" + pdpSubgroup, message.appliesTo(DIFFERENT, pdpGroup, pdpSubgroup)); } } @@ -110,7 +111,7 @@ public class PdpMessageTest { message = makeMessage(null, msgGroup, msgSubgroup); for (String pdpGroup : new String[] {null, DIFFERENT}) { - assertFalse("group msg " + message + " pdp group " + pdpGroup, + assertFalse("group msg " + message + PDP_GROUP_STRING + pdpGroup, message.appliesTo(PDP_NAME, pdpGroup, PDP_SUBGROUP)); } } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java index ee7e15b6a..a308ab036 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageUtils.java @@ -25,6 +25,10 @@ package org.onap.policy.models.pdp.concepts; */ public class PdpMessageUtils { + private PdpMessageUtils() { + + } + public static String removeVariableFields(String text) { return text.replaceAll("requestId=[^,]*", "requestId=xxx").replaceAll("timestampMs=[^,]*", "timestampMs=nnn"); } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java index c0545fa36..a2f502bcc 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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. @@ -47,6 +48,10 @@ import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild; */ public class JpaPdpGroupTest { + private static final String NULL_KEY_ERROR = "key is marked @NonNull but is null"; + private static final String PDP_GROUP0 = "PDPGroup0"; + private static final String VERSION = "1.0.0"; + @Test public void testJpaPdpGroup() { assertThatThrownBy(() -> { @@ -55,7 +60,7 @@ public class JpaPdpGroupTest { assertThatThrownBy(() -> { new JpaPdpGroup((PfConceptKey) null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpGroup((PdpGroup) null); @@ -67,7 +72,7 @@ public class JpaPdpGroupTest { assertThatThrownBy(() -> { new JpaPdpGroup(null, null, null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpGroup(new PfConceptKey(), null, null); @@ -79,31 +84,31 @@ public class JpaPdpGroupTest { assertThatThrownBy(() -> { new JpaPdpGroup(null, PdpState.PASSIVE, null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpGroup(null, PdpState.PASSIVE, new ArrayList<>()); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpGroup(null, null, new ArrayList<>()); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertNotNull(new JpaPdpGroup((new PfConceptKey()))); assertNotNull(new JpaPdpGroup((new JpaPdpGroup()))); PdpGroup testPdpGroup = new PdpGroup(); - testPdpGroup.setName("PDPGroup0"); + testPdpGroup.setName(PDP_GROUP0); testPdpGroup.setPdpSubgroups(new ArrayList<>()); JpaPdpGroup testJpaPdpGroup = new JpaPdpGroup(); testJpaPdpGroup.setKey(null); testJpaPdpGroup.setKey(new PfConceptKey()); - testPdpGroup.setVersion("1.0.0"); + testPdpGroup.setVersion(VERSION); testJpaPdpGroup.fromAuthorative(testPdpGroup); - assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName()); + assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName()); testJpaPdpGroup.setKey(PfConceptKey.getNullKey()); testJpaPdpGroup.fromAuthorative(testPdpGroup); @@ -111,19 +116,19 @@ public class JpaPdpGroupTest { testJpaPdpGroup.fromAuthorative(null); }).hasMessage("pdpGroup is marked @NonNull but is null"); - testJpaPdpGroup.setKey(new PfConceptKey("PDPGroup0", "1.0.0")); + testJpaPdpGroup.setKey(new PfConceptKey(PDP_GROUP0, VERSION)); testJpaPdpGroup.fromAuthorative(testPdpGroup); assertThatThrownBy(() -> { testJpaPdpGroup.copyTo(null); }).hasMessage("target is marked @NonNull but is null"); - assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName()); - assertEquals("PDPGroup0", new JpaPdpGroup(testPdpGroup).getKey().getName()); - assertEquals("PDPGroup0", ((PfConceptKey) new JpaPdpGroup(testPdpGroup).getKeys().get(0)).getName()); + assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName()); + assertEquals(PDP_GROUP0, new JpaPdpGroup(testPdpGroup).getKey().getName()); + assertEquals(PDP_GROUP0, ((PfConceptKey) new JpaPdpGroup(testPdpGroup).getKeys().get(0)).getName()); testJpaPdpGroup.clean(); - assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName()); + assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName()); assertThatThrownBy(() -> { testJpaPdpGroup.validate(null); @@ -135,7 +140,7 @@ public class JpaPdpGroupTest { testJpaPdpGroup.setKey(PfConceptKey.getNullKey()); assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk()); - testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", "1.0.0")); + testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", VERSION)); assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk()); testJpaPdpGroup.setDescription(" "); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java index d066d9be7..981f40f06 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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. @@ -46,6 +47,9 @@ import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild; */ public class JpaPdpSubGroupTest { + private static final String NULL_KEY_ERROR = "key is marked @NonNull but is null"; + private static final String PDP_A = "PDP-A"; + @Test public void testJpaPdpSubGroup() { assertThatThrownBy(() -> { @@ -54,7 +58,7 @@ public class JpaPdpSubGroupTest { assertThatThrownBy(() -> { new JpaPdpSubGroup((PfReferenceKey) null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup((PdpSubGroup) null); @@ -62,7 +66,7 @@ public class JpaPdpSubGroupTest { assertThatThrownBy(() -> { new JpaPdpSubGroup(null, null, null, null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup(new PfReferenceKey(), null, null, null); @@ -74,19 +78,19 @@ public class JpaPdpSubGroupTest { assertThatThrownBy(() -> { new JpaPdpSubGroup(null, new ArrayList<>(), null, null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup(null, new ArrayList<>(), new ArrayList<>(), null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup(null, null, new ArrayList<>(), null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup(null, null, null, new ArrayList<>()); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup(new PfReferenceKey(), null, null, new ArrayList<>()); @@ -98,24 +102,24 @@ public class JpaPdpSubGroupTest { assertThatThrownBy(() -> { new JpaPdpSubGroup(null, new ArrayList<>(), null, new ArrayList<>()); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup(null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdpSubGroup(null, null, new ArrayList<>(), null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertNotNull(new JpaPdpSubGroup((new PfReferenceKey()))); PdpSubGroup testPdpSubgroup = new PdpSubGroup(); - testPdpSubgroup.setPdpType("PDP-A"); + testPdpSubgroup.setPdpType(PDP_A); JpaPdpSubGroup testJpaPdpSubGroup = new JpaPdpSubGroup(); testJpaPdpSubGroup.setKey(null); testJpaPdpSubGroup.fromAuthorative(testPdpSubgroup); - assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName()); + assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName()); testJpaPdpSubGroup.setKey(PfReferenceKey.getNullKey()); testJpaPdpSubGroup.fromAuthorative(testPdpSubgroup); @@ -127,12 +131,12 @@ public class JpaPdpSubGroupTest { testJpaPdpSubGroup.copyTo(null); }).hasMessage("target is marked @NonNull but is null"); - assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName()); - assertEquals("PDP-A", new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName()); - assertEquals("PDP-A", ((PfReferenceKey) new JpaPdpSubGroup(testPdpSubgroup).getKeys().get(0)).getLocalName()); + assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName()); + assertEquals(PDP_A, new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName()); + assertEquals(PDP_A, ((PfReferenceKey) new JpaPdpSubGroup(testPdpSubgroup).getKeys().get(0)).getLocalName()); testJpaPdpSubGroup.clean(); - assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName()); + assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName()); assertThatThrownBy(() -> { testJpaPdpSubGroup.validate(null); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java index ebdf31c2f..5ffba10b9 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. 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. @@ -33,7 +34,6 @@ import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpState; -import org.onap.policy.models.pdp.persistence.concepts.JpaPdp; import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpChild; /** @@ -43,6 +43,9 @@ import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpChild; */ public class JpaPdpTest { + private static final String NULL_KEY_ERROR = "key is marked @NonNull but is null"; + private static final String PDP1 = "ThePDP"; + @Test public void testJpaPdp() { assertThatThrownBy(() -> { @@ -51,11 +54,11 @@ public class JpaPdpTest { assertThatThrownBy(() -> { new JpaPdp((PfReferenceKey) null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdp(null, null, null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdp(new PfReferenceKey(), null, null); @@ -67,15 +70,15 @@ public class JpaPdpTest { assertThatThrownBy(() -> { new JpaPdp(null, PdpState.ACTIVE, null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdp(null, PdpState.ACTIVE, PdpHealthStatus.UNKNOWN); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdp(null, null, PdpHealthStatus.UNKNOWN); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessage(NULL_KEY_ERROR); assertThatThrownBy(() -> { new JpaPdp((Pdp) null); @@ -84,11 +87,11 @@ public class JpaPdpTest { assertNotNull(new JpaPdp((new PfReferenceKey()))); Pdp testPdp = new Pdp(); - testPdp.setInstanceId("ThePDP"); + testPdp.setInstanceId(PDP1); JpaPdp testJpaPdp = new JpaPdp(); testJpaPdp.setKey(null); testJpaPdp.fromAuthorative(testPdp); - assertEquals("ThePDP", testJpaPdp.getKey().getLocalName()); + assertEquals(PDP1, testJpaPdp.getKey().getLocalName()); testJpaPdp.setKey(PfReferenceKey.getNullKey()); testJpaPdp.fromAuthorative(testPdp); @@ -100,12 +103,12 @@ public class JpaPdpTest { testJpaPdp.copyTo(null); }).hasMessage("target is marked @NonNull but is null"); - assertEquals("ThePDP", testJpaPdp.getKey().getLocalName()); - assertEquals("ThePDP", new JpaPdp(testPdp).getKey().getLocalName()); - assertEquals("ThePDP", ((PfReferenceKey) new JpaPdp(testPdp).getKeys().get(0)).getLocalName()); + assertEquals(PDP1, testJpaPdp.getKey().getLocalName()); + assertEquals(PDP1, new JpaPdp(testPdp).getKey().getLocalName()); + assertEquals(PDP1, ((PfReferenceKey) new JpaPdp(testPdp).getKeys().get(0)).getLocalName()); testJpaPdp.clean(); - assertEquals("ThePDP", testJpaPdp.getKey().getLocalName()); + assertEquals(PDP1, testJpaPdp.getKey().getLocalName()); testJpaPdp.setMessage(" A Message "); testJpaPdp.clean(); diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java index f0af69ea4..4314b81c1 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; import java.util.Properties; - import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; @@ -49,7 +48,6 @@ import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpState; -import org.onap.policy.models.pdp.persistence.provider.PdpProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; @@ -99,7 +97,7 @@ public class PdpProviderTest { } @After - public void teardown() throws Exception { + public void teardown() { pfDao.close(); } |