aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroupTest.java59
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroupTest.java39
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpTest.java38
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java5
4 files changed, 127 insertions, 14 deletions
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 a4bf25209..060f650fb 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -95,21 +95,17 @@ public class JpaPdpGroupTest {
assertNotNull(new JpaPdpGroup((new PfConceptKey())));
assertNotNull(new JpaPdpGroup((new JpaPdpGroup())));
+ }
+ @Test
+ public void testPdpGroupSet() {
PdpGroup testPdpGroup = new PdpGroup();
testPdpGroup.setName(PDP_GROUP0);
testPdpGroup.setPdpSubgroups(new ArrayList<>());
- JpaPdpGroup testJpaPdpGroup = new JpaPdpGroup();
- testJpaPdpGroup.setKey(null);
- testJpaPdpGroup.setKey(new PfConceptKey());
-
- testPdpGroup.setVersion(VERSION);
- testJpaPdpGroup.fromAuthorative(testPdpGroup);
+ JpaPdpGroup testJpaPdpGroup = setUpSmallJpaPdpGroup();
assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
- testJpaPdpGroup.setKey(PfConceptKey.getNullKey());
- testJpaPdpGroup.fromAuthorative(testPdpGroup);
assertThatThrownBy(() -> {
testJpaPdpGroup.fromAuthorative(null);
@@ -126,6 +122,11 @@ public class JpaPdpGroupTest {
testJpaPdpGroup.clean();
assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
+ }
+
+ @Test
+ public void testPdpGroupValidation() {
+ JpaPdpGroup testJpaPdpGroup = setUpSmallJpaPdpGroup();
assertThatThrownBy(() -> {
testJpaPdpGroup.validate(null);
@@ -158,6 +159,11 @@ public class JpaPdpGroupTest {
assertFalse(testJpaPdpGroup.validate("").isValid());
testJpaPdpGroup.getProperties().remove("NullKey");
assertTrue(testJpaPdpGroup.validate("").isValid());
+ }
+
+ @Test
+ public void testPdpSubgroups() {
+ JpaPdpGroup testJpaPdpGroup = setUpJpaPdpGroup();
List<JpaPdpSubGroup> jpaPdpSubgroups = testJpaPdpGroup.getPdpSubGroups();
assertNotNull(jpaPdpSubgroups);
@@ -212,8 +218,12 @@ public class JpaPdpGroupTest {
psg = testJpaPdpGroup.toAuthorative();
assertNull(psg.getProperties());
testJpaPdpGroup.setProperties(new LinkedHashMap<>());
+ }
+
+ @Test
+ public void testPdpGroupsProperties() {
+ JpaPdpGroup testJpaPdpGroup = setUpJpaPdpGroup();
- testJpaPdpGroup.clean();
testJpaPdpGroup.getProperties().put(" PropKey ", " Prop Value ");
testJpaPdpGroup.clean();
assertEquals("PropKey", testJpaPdpGroup.getProperties().keySet().iterator().next());
@@ -222,6 +232,9 @@ public class JpaPdpGroupTest {
testJpaPdpGroup.clean();
assertEquals("A Description", testJpaPdpGroup.getDescription());
+ JpaPdpSubGroup anotherPdpSubgroup =
+ new JpaPdpSubGroup(new PfReferenceKey(testJpaPdpGroup.getKey(), "AnotherPdpSubgroup"));
+
assertEquals(1, testJpaPdpGroup.getKeys().size());
testJpaPdpGroup.getPdpSubGroups().add(anotherPdpSubgroup);
assertEquals(2, testJpaPdpGroup.getKeys().size());
@@ -230,4 +243,30 @@ public class JpaPdpGroupTest {
assertEquals(testJpaPdpGroup, new JpaPdpGroup(testJpaPdpGroup));
}
+
+ private JpaPdpGroup setUpSmallJpaPdpGroup() {
+ PdpGroup testPdpGroup = new PdpGroup();
+ testPdpGroup.setName(PDP_GROUP0);
+ testPdpGroup.setPdpSubgroups(new ArrayList<>());
+ testPdpGroup.setVersion(VERSION);
+
+ JpaPdpGroup testJpaPdpGroup = new JpaPdpGroup();
+ testJpaPdpGroup.setKey(new PfConceptKey(PDP_GROUP0, VERSION));
+ testJpaPdpGroup.fromAuthorative(testPdpGroup);
+ testJpaPdpGroup.clean();
+
+ return testJpaPdpGroup;
+ }
+
+ private JpaPdpGroup setUpJpaPdpGroup() {
+ JpaPdpGroup testJpaPdpGroup = setUpSmallJpaPdpGroup();
+
+ testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", VERSION));
+ testJpaPdpGroup.setDescription(null);
+ testJpaPdpGroup.setPdpGroupState(PdpState.PASSIVE);
+ testJpaPdpGroup.setProperties(new LinkedHashMap<>());
+ testJpaPdpGroup.clean();
+
+ return testJpaPdpGroup;
+ }
}
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 969b59c6d..566de0d98 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,7 +52,7 @@ public class JpaPdpSubGroupTest {
private static final String PDP_A = "PDP-A";
@Test
- public void testJpaPdpSubGroup() {
+ public void testJpaPdpSubGroupErrors() {
assertThatThrownBy(() -> {
new JpaPdpSubGroup((JpaPdpSubGroup) null);
}).hasMessageMatching("copyConcept is marked .*ull but is null");
@@ -114,7 +114,10 @@ public class JpaPdpSubGroupTest {
}).hasMessageMatching(NULL_KEY_ERROR);
assertNotNull(new JpaPdpSubGroup((new PfReferenceKey())));
+ }
+ @Test
+ public void testJpaPdpSubGroup() {
PdpSubGroup testPdpSubgroup = new PdpSubGroup();
testPdpSubgroup.setPdpType(PDP_A);
JpaPdpSubGroup testJpaPdpSubGroup = new JpaPdpSubGroup();
@@ -154,6 +157,11 @@ public class JpaPdpSubGroupTest {
testJpaPdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
testJpaPdpSubGroup.getSupportedPolicyTypes().add(new PfSearchableKey("APolicyType:1.0.0"));
assertTrue(testJpaPdpSubGroup.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaPdpSubGroupSavedKey() {
+ JpaPdpSubGroup testJpaPdpSubGroup = setUpJpaPdpSubGroup();
PfReferenceKey savedKey = testJpaPdpSubGroup.getKey();
testJpaPdpSubGroup.setKey(PfReferenceKey.getNullKey());
@@ -185,6 +193,11 @@ public class JpaPdpSubGroupTest {
assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setProperties(null);
assertTrue(testJpaPdpSubGroup.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaPdpSubGroupPolicyTypes() {
+ JpaPdpSubGroup testJpaPdpSubGroup = setUpJpaPdpSubGroup();
List<PfSearchableKey> supportedPolicyTypes = testJpaPdpSubGroup.getSupportedPolicyTypes();
assertNotNull(supportedPolicyTypes);
@@ -212,6 +225,11 @@ public class JpaPdpSubGroupTest {
assertTrue(testJpaPdpSubGroup.validate("").isValid());
testJpaPdpSubGroup.setPdpInstances(pdpInstances);
assertTrue(testJpaPdpSubGroup.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaPdpSubGroupKeys() {
+ JpaPdpSubGroup testJpaPdpSubGroup = setUpJpaPdpSubGroup();
JpaPdpSubGroup otherJpaPdpSubGroup = new JpaPdpSubGroup(testJpaPdpSubGroup);
assertEquals(0, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
@@ -278,4 +296,21 @@ public class JpaPdpSubGroupTest {
assertEquals(testJpaPdpSubGroup, new JpaPdpSubGroup(testJpaPdpSubGroup));
}
+
+ private JpaPdpSubGroup setUpJpaPdpSubGroup() {
+ PdpSubGroup testPdpSubgroup = new PdpSubGroup();
+ testPdpSubgroup.setPdpType(PDP_A);
+ JpaPdpSubGroup testJpaPdpSubGroup = new JpaPdpSubGroup();
+ testJpaPdpSubGroup.setKey(PfReferenceKey.getNullKey());
+ testJpaPdpSubGroup.fromAuthorative(testPdpSubgroup);
+ testJpaPdpSubGroup.getKey().setParentConceptKey(new PfConceptKey("Parent:1.0.0"));
+ testJpaPdpSubGroup.setProperties(new LinkedHashMap<>());
+ testJpaPdpSubGroup.setDesiredInstanceCount(0);
+ testJpaPdpSubGroup.setCurrentInstanceCount(0);
+ testJpaPdpSubGroup.setProperties(null);
+ testJpaPdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
+ testJpaPdpSubGroup.getSupportedPolicyTypes().add(new PfSearchableKey("APolicyType:1.0.0"));
+ testJpaPdpSubGroup.clean();
+ return testJpaPdpSubGroup;
+ }
}
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 3102c5098..b5b29d30b 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -87,7 +87,10 @@ public class JpaPdpTest {
}).hasMessageMatching("authorativeConcept is marked .*ull but is null");
assertNotNull(new JpaPdp((new PfReferenceKey())));
+ }
+ @Test
+ public void testJpaPdpInstace() {
Pdp testPdp = new Pdp();
testPdp.setInstanceId(PDP1);
JpaPdp testJpaPdp = new JpaPdp();
@@ -113,6 +116,15 @@ public class JpaPdpTest {
testJpaPdp.setMessage(" A Message ");
testJpaPdp.clean();
assertEquals("A Message", testJpaPdp.getMessage());
+ }
+
+ @Test
+ public void testJpaPdpValidation() {
+ Pdp testPdp = new Pdp();
+ testPdp.setInstanceId(PDP1);
+ JpaPdp testJpaPdp = new JpaPdp();
+ testJpaPdp.setKey(PfReferenceKey.getNullKey());
+ testJpaPdp.fromAuthorative(testPdp);
assertThatThrownBy(() -> {
testJpaPdp.validate(null);
@@ -142,6 +154,11 @@ public class JpaPdpTest {
testJpaPdp.setHealthy(PdpHealthStatus.HEALTHY);
assertTrue(testJpaPdp.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaPdpValidationSwapKey() {
+ JpaPdp testJpaPdp = setUpJpaPdp();
PfReferenceKey savedKey = testJpaPdp.getKey();
testJpaPdp.setKey(PfReferenceKey.getNullKey());
@@ -155,6 +172,11 @@ public class JpaPdpTest {
assertFalse(testJpaPdp.validate("").isValid());
testJpaPdp.setMessage("Valid Message");
assertTrue(testJpaPdp.validate("").isValid());
+ }
+
+ @Test
+ public void testJpaPdpCompare() {
+ JpaPdp testJpaPdp = setUpJpaPdp();
JpaPdp otherJpaPdp = new JpaPdp(testJpaPdp);
assertEquals(0, testJpaPdp.compareTo(otherJpaPdp));
@@ -184,4 +206,18 @@ public class JpaPdpTest {
assertEquals(testJpaPdp, new JpaPdp(testJpaPdp));
}
+
+ private JpaPdp setUpJpaPdp() {
+ Pdp testPdp = new Pdp();
+ testPdp.setInstanceId(PDP1);
+ JpaPdp testJpaPdp = new JpaPdp();
+ testJpaPdp.setKey(PfReferenceKey.getNullKey());
+ testJpaPdp.fromAuthorative(testPdp);
+ testJpaPdp.getKey().setParentConceptKey(new PfConceptKey("Parent:1.0.0"));
+ testJpaPdp.getKey().setParentLocalName("ParentLocal");
+ testJpaPdp.setPdpState(PdpState.ACTIVE);
+ testJpaPdp.setHealthy(PdpHealthStatus.HEALTHY);
+ testJpaPdp.setMessage("Valid Message");
+ return testJpaPdp;
+ }
}
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 aadaf3500..2e911c525 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
@@ -519,7 +519,7 @@ public class PdpProviderTest {
}
@Test
- public void testUpdatePdpStatistics() throws PfModelException {
+ public void testUpdatePdpStatisticsDao() throws PfModelException {
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, null, null, null);
}).hasMessageMatching(DAO_IS_NULL);
@@ -583,7 +583,10 @@ public class PdpProviderTest {
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", "TYPE", "inst", new PdpStatistics());
}).hasMessageMatching(DAO_IS_NULL);
+ }
+ @Test
+ public void testUpdatePdpStatisticsGroup() throws PfModelException {
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, null, null, null);
}).hasMessageMatching(GROUP_IS_NULL);