summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-06-18 12:22:21 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-18 12:22:21 +0000
commit26e7f16c6e3f224d38e09441be30c1d4fa795c2a (patch)
treed784ca790e8865577d6e2b0b44ee869af4eab45e
parent92bd3a4d89a3f7740094e0c5dac278722fc3f27c (diff)
parent77df45928640808633af05908c680955848e4cd2 (diff)
Merge "Fix simple sonar issues in models: errors to sim-pdp"
-rw-r--r--models-errors/src/test/java/org/onap/policy/models/errors/concepts/ErrorResponseUtilsTest.java14
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java27
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java8
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java172
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java51
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java491
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java40
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java133
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java2
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java2
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java2
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java2
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java20
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java7
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java3
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java6
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java15
-rw-r--r--models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java11
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java26
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java12
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java7
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java48
-rw-r--r--models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java5
23 files changed, 533 insertions, 571 deletions
diff --git a/models-errors/src/test/java/org/onap/policy/models/errors/concepts/ErrorResponseUtilsTest.java b/models-errors/src/test/java/org/onap/policy/models/errors/concepts/ErrorResponseUtilsTest.java
index 4f4ef395a..261e58a8d 100644
--- a/models-errors/src/test/java/org/onap/policy/models/errors/concepts/ErrorResponseUtilsTest.java
+++ b/models-errors/src/test/java/org/onap/policy/models/errors/concepts/ErrorResponseUtilsTest.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.
@@ -32,21 +33,18 @@ import org.junit.Test;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class ErrorResponseUtilsTest {
+ private static final String EXCEPTION1 = "Exception 1";
+
@Test
public void testErrorResponseUtils() {
try {
- try {
- throw new NumberFormatException("Exception 0");
- }
- catch (Exception nfe) {
- throw new IOException("Exception 1", nfe);
- }
+ throw new IOException(EXCEPTION1, new NumberFormatException("Exception 0"));
} catch (Exception ioe) {
ErrorResponse errorResponse = new ErrorResponse();
ErrorResponseUtils.getExceptionMessages(errorResponse, ioe);
- assertEquals("Exception 1", errorResponse.getErrorMessage());
- assertEquals("Exception 1", errorResponse.getErrorDetails().get(0));
+ assertEquals(EXCEPTION1, errorResponse.getErrorMessage());
+ assertEquals(EXCEPTION1, errorResponse.getErrorDetails().get(0));
assertEquals("Exception 0", errorResponse.getErrorDetails().get(1));
}
}
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 9047a7ae1..dc6726846 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,7 +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_GROUP_MSG = " pdp group ";
private static final String PDP_NAME = "pdpA";
private static final String PDP_GROUP = "groupA";
private static final String PDP_SUBGROUP = "subgroupA";
@@ -65,13 +65,7 @@ public class PdpMessageTest {
for (String msgGroup : new String[] {null, PDP_GROUP, DIFFERENT}) {
for (String msgSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) {
message = makeMessage(PDP_NAME, msgGroup, msgSubgroup);
-
- for (String pdpGroup : new String[] {null, PDP_GROUP, DIFFERENT}) {
- for (String pdpSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) {
- assertTrue("name msg " + message + PDP_GROUP_STRING + pdpGroup + "/" + pdpSubgroup,
- message.appliesTo(PDP_NAME, pdpGroup, pdpSubgroup));
- }
- }
+ testName(PDP_NAME, true);
}
}
@@ -81,13 +75,16 @@ public class PdpMessageTest {
for (String msgGroup : new String[] {null, PDP_GROUP, DIFFERENT}) {
for (String msgSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) {
message = makeMessage(PDP_NAME, msgGroup, msgSubgroup);
+ testName(DIFFERENT, false);
+ }
+ }
+ }
- for (String pdpGroup : new String[] {null, PDP_GROUP, DIFFERENT}) {
- for (String pdpSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) {
- assertFalse("name msg " + message + PDP_GROUP_STRING + pdpGroup + "/" + pdpSubgroup,
- message.appliesTo(DIFFERENT, pdpGroup, pdpSubgroup));
- }
- }
+ private void testName(String pdpName, boolean expectMatch) {
+ for (String pdpGroup : new String[] {null, PDP_GROUP, DIFFERENT}) {
+ for (String pdpSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) {
+ assertEquals("name msg " + message + PDP_GROUP_MSG + pdpGroup + "/" + pdpSubgroup, expectMatch,
+ message.appliesTo(pdpName, pdpGroup, pdpSubgroup));
}
}
}
@@ -111,7 +108,7 @@ public class PdpMessageTest {
message = makeMessage(null, msgGroup, msgSubgroup);
for (String pdpGroup : new String[] {null, DIFFERENT}) {
- assertFalse("group msg " + message + PDP_GROUP_STRING + pdpGroup,
+ assertFalse("group msg " + message + PDP_GROUP_MSG + pdpGroup,
message.appliesTo(PDP_NAME, pdpGroup, PDP_SUBGROUP));
}
}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java
index 7a7babecc..e24e8e2d6 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java
@@ -44,6 +44,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi
* Test methods not tested by {@link ModelsTest}.
*/
public class PdpSubGroupTest {
+ private static final String VERSION_300 = "3.0.0";
private static final Coder coder = new StandardCoder();
@Test
@@ -95,7 +96,8 @@ public class PdpSubGroupTest {
subgrp.setDesiredInstanceCount(1);
subgrp.setPdpType("pdp-type");
- subgrp.setSupportedPolicyTypes(Arrays.asList(makeIdent("type-X", "3.0.0", ToscaPolicyTypeIdentifier.class)));
+ subgrp.setSupportedPolicyTypes(
+ Arrays.asList(makeIdent("type-X", VERSION_300, ToscaPolicyTypeIdentifier.class)));
subgrp.setPolicies(Arrays.asList(makeIdent("policy-X", "4.0.0", ToscaPolicyIdentifier.class)));
// valid
@@ -136,7 +138,7 @@ public class PdpSubGroupTest {
// invalid policy type item
sub2 = new PdpSubGroup(subgrp);
- sub2.getSupportedPolicyTypes().set(0, makeIdent(null, "3.0.0", ToscaPolicyTypeIdentifier.class));
+ sub2.getSupportedPolicyTypes().set(0, makeIdent(null, VERSION_300, ToscaPolicyTypeIdentifier.class));
assertInvalid(sub2);
// null policies
@@ -151,7 +153,7 @@ public class PdpSubGroupTest {
// invalid policy item
sub2 = new PdpSubGroup(subgrp);
- sub2.getPolicies().set(0, makeIdent(null, "3.0.0", ToscaPolicyIdentifier.class));
+ sub2.getPolicies().set(0, makeIdent(null, VERSION_300, ToscaPolicyIdentifier.class));
assertInvalid(sub2);
}
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 4314b81c1..5cbbaaa8f 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
@@ -58,6 +58,12 @@ import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class PdpProviderTest {
+ private static final String PDP_GROUPS0_JSON = "testdata/PdpGroups0.json";
+ private static final String PDP_TYPE_IS_NULL = "pdpType is marked @NonNull but is null";
+ private static final String SUBGROUP_IS_NULL = "pdpSubGroup is marked @NonNull but is null";
+ private static final String GROUP_IS_NULL = "pdpGroupName is marked @NonNull but is null";
+ private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String PDP_GROUP0 = "PdpGroup0";
private PfDao pfDao;
private StandardCoder standardCoder;
@@ -105,13 +111,13 @@ public class PdpProviderTest {
public void testGroupsGet() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().getPdpGroups(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().getPdpGroups(null, "name");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
- String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ String originalJson = ResourceUtils.getResourceAsString(PDP_GROUPS0_JSON);
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
@@ -120,7 +126,7 @@ public class PdpProviderTest {
assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
PdpGroups gotPdpGroups0 = new PdpGroups();
- gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0));
String gotJson = standardCoder.encode(gotPdpGroups0);
@@ -131,11 +137,11 @@ public class PdpProviderTest {
public void testFilteredPdpGroupGet() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().getFilteredPdpGroups(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().getFilteredPdpGroups(null, PdpGroupFilter.builder().build());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().getFilteredPdpGroups(pfDao, null);
@@ -155,7 +161,7 @@ public class PdpProviderTest {
// @formatter:off
final PdpGroupFilter filter = PdpGroupFilter.builder()
.groupState(PdpState.PASSIVE)
- .name("PdpGroup0")
+ .name(PDP_GROUP0)
.matchPoliciesExactly(false)
.matchPolicyTypesExactly(false)
.pdpState(PdpState.PASSIVE)
@@ -171,17 +177,17 @@ public class PdpProviderTest {
public void testGroupsCreate() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().createPdpGroups(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().createPdpGroups(null, new ArrayList<>());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().createPdpGroups(pfDao, null);
}).hasMessage("pdpGroups is marked @NonNull but is null");
- String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ String originalJson = ResourceUtils.getResourceAsString(PDP_GROUPS0_JSON);
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
@@ -190,7 +196,7 @@ public class PdpProviderTest {
assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
PdpGroups gotPdpGroups0 = new PdpGroups();
- gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0));
String gotJson = standardCoder.encode(gotPdpGroups0);
assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
@@ -226,17 +232,17 @@ public class PdpProviderTest {
public void testGroupsUpdate() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().updatePdpGroups(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpGroups(null, new ArrayList<>());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpGroups(pfDao, null);
}).hasMessage("pdpGroups is marked @NonNull but is null");
- String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ String originalJson = ResourceUtils.getResourceAsString(PDP_GROUPS0_JSON);
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
@@ -245,7 +251,7 @@ public class PdpProviderTest {
assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
PdpGroups gotPdpGroups0 = new PdpGroups();
- gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0));
String gotJson = standardCoder.encode(gotPdpGroups0);
assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
@@ -270,11 +276,11 @@ public class PdpProviderTest {
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().deletePdpGroup(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().deletePdpGroup(null, "name");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().deletePdpGroup(pfDao, null);
@@ -284,7 +290,7 @@ public class PdpProviderTest {
new PdpProvider().deletePdpGroup(pfDao, "name");
}).hasMessage("delete of PDP group \"name:0.0.0\" failed, PDP group does not exist");
- String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ String originalJson = ResourceUtils.getResourceAsString(PDP_GROUPS0_JSON);
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
@@ -293,19 +299,19 @@ public class PdpProviderTest {
assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
PdpGroups gotPdpGroups0 = new PdpGroups();
- gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0));
String gotJson = standardCoder.encode(gotPdpGroups0);
assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
- PdpGroup deletedPdpGroup = new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0");
+ PdpGroup deletedPdpGroup = new PdpProvider().deletePdpGroup(pfDao, PDP_GROUP0);
assertEquals(createdPdpGroups0.getGroups().get(0), deletedPdpGroup);
- assertEquals(0, new PdpProvider().getPdpGroups(pfDao, "PdpGroup0").size());
+ assertEquals(0, new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0).size());
assertThatThrownBy(() -> {
- new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0");
+ new PdpProvider().deletePdpGroup(pfDao, PDP_GROUP0);
}).hasMessage("delete of PDP group \"PdpGroup0:0.0.0\" failed, PDP group does not exist");
}
@@ -313,37 +319,37 @@ public class PdpProviderTest {
public void testPdpSubgroupUpdate() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(null, null, new PdpSubGroup());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(null, "name", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(null, "name", new PdpSubGroup());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(pfDao, null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(pfDao, null, new PdpSubGroup());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(pfDao, "name", null);
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ }).hasMessage(SUBGROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpSubGroup(pfDao, "name", new PdpSubGroup());
}).hasMessage("parameter \"localName\" is null");
- String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ String originalJson = ResourceUtils.getResourceAsString(PDP_GROUPS0_JSON);
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
@@ -352,7 +358,7 @@ public class PdpProviderTest {
assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
PdpGroups gotPdpGroups0 = new PdpGroups();
- gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0));
String gotJson = standardCoder.encode(gotPdpGroups0);
assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
@@ -360,15 +366,15 @@ public class PdpProviderTest {
PdpSubGroup existingSubGroup = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0);
existingSubGroup.setCurrentInstanceCount(10);
existingSubGroup.setDesiredInstanceCount(10);
- new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", existingSubGroup);
+ new PdpProvider().updatePdpSubGroup(pfDao, PDP_GROUP0, existingSubGroup);
- List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0");
+ List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0);
assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getCurrentInstanceCount());
assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
existingSubGroup.setDesiredInstanceCount(-1);
assertThatThrownBy(() -> {
- new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", existingSubGroup);
+ new PdpProvider().updatePdpSubGroup(pfDao, PDP_GROUP0, existingSubGroup);
}).hasMessageContaining("INVALID:the desired instance count of a PDP sub group may not be negative");
existingSubGroup.setDesiredInstanceCount(10);
}
@@ -377,59 +383,59 @@ public class PdpProviderTest {
public void testPdpUpdate() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, null, null, new Pdp());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, null, "TYPE", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, null, "TYPE", new Pdp());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, "name", null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, "name", null, new Pdp());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, "name", "TYPE", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(null, "name", "TYPE", new Pdp());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, null, null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, null, null, new Pdp());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, null, "TYPE", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, null, "TYPE", new Pdp());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, "name", null, null);
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ }).hasMessage(SUBGROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, "name", null, new Pdp());
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ }).hasMessage(SUBGROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdp(pfDao, "name", "TYPE", null);
@@ -439,7 +445,7 @@ public class PdpProviderTest {
new PdpProvider().updatePdp(pfDao, "name", "TYPE", new Pdp());
}).hasMessage("parameter \"localName\" is null");
- String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ String originalJson = ResourceUtils.getResourceAsString(PDP_GROUPS0_JSON);
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
@@ -448,7 +454,7 @@ public class PdpProviderTest {
assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
PdpGroups gotPdpGroups0 = new PdpGroups();
- gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0));
String gotJson = standardCoder.encode(gotPdpGroups0);
assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
@@ -456,9 +462,9 @@ public class PdpProviderTest {
Pdp existingPdp = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances().get(0);
existingPdp.setPdpState(PdpState.TEST);
existingPdp.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS);
- new PdpProvider().updatePdp(pfDao, "PdpGroup0", "APEX", existingPdp);
+ new PdpProvider().updatePdp(pfDao, PDP_GROUP0, "APEX", existingPdp);
- List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0");
+ List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, PDP_GROUP0);
assertEquals(PdpState.TEST,
afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).getPdpState());
assertEquals(PdpHealthStatus.TEST_IN_PROGRESS,
@@ -466,7 +472,7 @@ public class PdpProviderTest {
existingPdp.setMessage("");
assertThatThrownBy(() -> {
- new PdpProvider().updatePdp(pfDao, "PdpGroup0", "APEX", existingPdp);
+ new PdpProvider().updatePdp(pfDao, PDP_GROUP0, "APEX", existingPdp);
}).hasMessageContaining("INVALID:message may not be blank");
existingPdp.setMessage("A Message");
}
@@ -475,11 +481,11 @@ public class PdpProviderTest {
public void testGetPdpStatistics() throws PfModelException {
assertThatThrownBy(() -> {
new PdpProvider().getPdpStatistics(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().getPdpStatistics(null, "name");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertEquals(0, new PdpProvider().getPdpStatistics(pfDao, "name").size());
}
@@ -488,115 +494,115 @@ public class PdpProviderTest {
public void testUpdatePdpStatistics() throws PfModelException {
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, null, null, new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, null, "inst", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, null, "inst", new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, "TYPE", null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, "TYPE", null, new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, "TYPE", "inst", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, null, "TYPE", "inst", new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", null, null, new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", null, "inst", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", null, "inst", new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", "TYPE", null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", "TYPE", null, new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", "TYPE", "inst", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(null, "name", "TYPE", "inst", new PdpStatistics());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, null, null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, null, null, new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, null, "inst", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, null, "inst", new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", null, new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", "inst", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", "inst", new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ }).hasMessage(GROUP_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, null);
- }).hasMessage("pdpType is marked @NonNull but is null");
+ }).hasMessage(PDP_TYPE_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, new PdpStatistics());
- }).hasMessage("pdpType is marked @NonNull but is null");
+ }).hasMessage(PDP_TYPE_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, "name", null, "inst", null);
- }).hasMessage("pdpType is marked @NonNull but is null");
+ }).hasMessage(PDP_TYPE_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, "name", null, "inst", new PdpStatistics());
- }).hasMessage("pdpType is marked @NonNull but is null");
+ }).hasMessage(PDP_TYPE_IS_NULL);
assertThatThrownBy(() -> {
new PdpProvider().updatePdpStatistics(pfDao, "name", "TYPE", null, null);
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java
index 628d9fc53..5e87f808d 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.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.
@@ -20,11 +21,9 @@
package org.onap.policy.models.provider;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import lombok.ToString;
-
import org.junit.Test;
/**
@@ -39,52 +38,38 @@ public class PolicyModelsProviderFactoryTest {
public void testFactory() {
PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory();
- try {
+ assertThatThrownBy(() -> {
factory.createPolicyModelsProvider(null);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("parameters is marked @NonNull but is null", exc.getMessage());
- }
+ }).hasMessage("parameters is marked @NonNull but is null");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation(null);
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"",
- exc.getMessage());
- }
+ }).hasMessage("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("com.acmecorp.RoadRunner");
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("could not find implementation of the \"PolicyModelsProvider\" "
- + "interface \"com.acmecorp.RoadRunner\"", exc.getMessage());
- }
+ })
+ .hasMessage("could not find implementation of the \"PolicyModelsProvider\" "
+ + "interface \"com.acmecorp.RoadRunner\"");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("java.lang.String");
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals(
- "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface",
- exc.getMessage());
- }
+ })
+ .hasMessage(
+ "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("org.onap.policy.models.provider.impl.DummyBadProviderImpl");
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("could not create an instance of PolicyModelsProvider "
- + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"", exc.getMessage());
- }
+ })
+ .hasMessage("could not create an instance of PolicyModelsProvider "
+ + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"");
}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index c188560e5..d5c03a2cd 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.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.
@@ -57,6 +58,30 @@ import org.slf4j.LoggerFactory;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class DatabasePolicyModelsProviderTest {
+ private static final String NAME = "name";
+
+ private static final String TEMPLATE_IS_NULL = "serviceTemplate is marked @NonNull but is null";
+
+ private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null";
+
+ private static final String PDP_TYPE_IS_NULL = "pdpType is marked @NonNull but is null";
+
+ private static final String SUBGROUP_IS_NULL = "pdpSubGroup is marked @NonNull but is null";
+
+ private static final String GROUP_IS_NULL = "pdpGroupName is marked @NonNull but is null";
+
+ private static final String NAME_IS_NULL = "name is marked @NonNull but is null";
+
+ private static final String FILTER_IS_NULL = "filter is marked @NonNull but is null";
+
+ private static final String INSTANCE = "Instance";
+
+ private static final String POLICY_ID = "policy_id";
+
+ private static final String GROUP = "group";
+
+ private static final String VERSION_100 = "1.0.0";
+
private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderTest.class);
PolicyModelsProviderParameters parameters;
@@ -85,302 +110,284 @@ public class DatabasePolicyModelsProviderTest {
parameters.setDatabaseUrl("jdbc://www.acmecorp.nonexist");
- try {
- databaseProvider.close();
- databaseProvider.init();
- } catch (Exception pfme) {
- fail("test shold not throw an exception here");
- }
+ databaseProvider.close();
+ databaseProvider.init();
+
databaseProvider.close();
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
parameters.setPersistenceUnit("WileECoyote");
- assertThatThrownBy(() -> {
- databaseProvider.init();
- }).hasMessageContaining("could not create Data Access Object (DAO)");
+ assertThatThrownBy(databaseProvider::init).hasMessageContaining("could not create Data Access Object (DAO)");
parameters.setPersistenceUnit("ToscaConceptTest");
- try {
- databaseProvider.init();
- databaseProvider.close();
- } catch (Exception pfme) {
- pfme.printStackTrace();
- fail("test shold not throw an exception here");
- }
+ databaseProvider.init();
+ databaseProvider.close();
assertThatThrownBy(() -> {
databaseProvider.init();
databaseProvider.init();
}).hasMessage("provider is already initialized");
- try {
- databaseProvider.close();
- } catch (Exception pfme) {
- fail("test shold not throw an exception here");
- }
+ databaseProvider.close();
- try {
- databaseProvider.close();
- } catch (Exception pfme) {
- fail("test shold not throw an exception here");
- }
+ databaseProvider.close();
}
@Test
public void testProviderMethodsNull() throws Exception {
- PolicyModelsProvider databaseProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicyTypes(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ try (PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicyTypeList(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicyTypes(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createPolicyTypes(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicyTypeList(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePolicyTypes(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createPolicyTypes(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicyType(null, null);
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePolicyTypes(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicyType("aaa", null);
- }).hasMessage("version is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyType(null, null);
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicyType(null, "aaa");
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyType("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicies(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyType(null, "aaa");
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicyList(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicies(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createPolicies(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicyList(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePolicies(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createPolicies(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicy(null, null);
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePolicies(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicy(null, "aaa");
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicy(null, null);
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicy("aaa", null);
- }).hasMessage("version is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicy(null, "aaa");
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicy("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("", null);
- }).hasMessage("no policy found for policy: :null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createOperationalPolicy(null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy("", null);
+ }).hasMessage("no policy found for policy: :null");
- assertThatThrownBy(() -> {
- databaseProvider.updateOperationalPolicy(null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createOperationalPolicy(null);
+ }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updateOperationalPolicy(null);
+ }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy("", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy("", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("", null);
- }).hasMessage("no policy found for policy: :null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createGuardPolicy(null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy("", null);
+ }).hasMessage("no policy found for policy: :null");
- assertThatThrownBy(() -> {
- databaseProvider.updateGuardPolicy(null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createGuardPolicy(null);
+ }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updateGuardPolicy(null);
+ }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy("", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPdpGroups(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy("", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.createPdpGroups(null);
- }).hasMessage("pdpGroups is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPdpGroups(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpGroups(null);
- }).hasMessage("pdpGroups is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createPdpGroups(null);
+ }).hasMessage("pdpGroups is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup(null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpGroups(null);
+ }).hasMessage("pdpGroups is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup(null, new PdpSubGroup());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup("name", null);
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(null, new PdpSubGroup());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup("name", new PdpSubGroup());
- }).hasMessage("parameter \"localName\" is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(NAME, null);
+ }).hasMessage(SUBGROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(NAME, new PdpSubGroup());
+ }).hasMessage("parameter \"localName\" is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, null, new Pdp());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, "sub", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, null, new Pdp());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, "sub", new Pdp());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, "sub", null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", null, null);
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, "sub", new Pdp());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", null, new Pdp());
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, null, null);
+ }).hasMessage(SUBGROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", "sub", null);
- }).hasMessage("pdp is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, null, new Pdp());
+ }).hasMessage(SUBGROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", "sub", new Pdp());
- }).hasMessage("parameter \"localName\" is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, "sub", null);
+ }).hasMessage("pdp is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deletePdpGroup(null);
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, "sub", new Pdp());
+ }).hasMessage("parameter \"localName\" is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePdpGroup(null);
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, null, new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, "Instance", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, null, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, "Instance", new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, INSTANCE, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, INSTANCE, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", null, new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", "Instance", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", null, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", "Instance", new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", INSTANCE, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, null, null);
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", INSTANCE, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, null, new PdpStatistics());
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, null, null);
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, "Instance", null);
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, null, new PdpStatistics());
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, "Instance", new PdpStatistics());
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, INSTANCE, null);
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", "type", null, null);
- }).hasMessage("pdpInstanceId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, INSTANCE, new PdpStatistics());
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", "type", null, new PdpStatistics());
- }).hasMessage("pdpInstanceId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, "type", null, null);
+ }).hasMessage("pdpInstanceId is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", "type", "Instance", null);
- }).hasMessage("pdpStatistics is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, "type", null, new PdpStatistics());
+ }).hasMessage("pdpInstanceId is marked @NonNull but is null");
- databaseProvider.updatePdpStatistics("name", "type", "Instance", new PdpStatistics());
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, "type", INSTANCE, null);
+ }).hasMessage("pdpStatistics is marked @NonNull but is null");
- databaseProvider.close();
+ databaseProvider.updatePdpStatistics(NAME, "type", INSTANCE, new PdpStatistics());
+ }
}
@Test
@@ -391,7 +398,7 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.close();
assertThatThrownBy(() -> {
- databaseProvider.getPolicyTypes("name", "version");
+ databaseProvider.getPolicyTypes(NAME, "version");
}).hasMessage("policy models provider is not initilaized");
}
@@ -400,8 +407,8 @@ public class DatabasePolicyModelsProviderTest {
try (PolicyModelsProvider databaseProvider =
new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
- assertTrue(databaseProvider.getPolicyTypes("name", "1.0.0").getPolicyTypes().isEmpty());
- assertEquals(0, databaseProvider.getPolicyTypeList("name", "1.0.0").size());
+ assertTrue(databaseProvider.getPolicyTypes(NAME, VERSION_100).getPolicyTypes().isEmpty());
+ assertTrue(databaseProvider.getPolicyTypeList(NAME, VERSION_100).isEmpty());
assertEquals(0, databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())
.getPolicyTypes().size());
assertEquals(0, databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).size());
@@ -414,13 +421,13 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
}).hasMessage("no policy types specified on service template");
- assertTrue(databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().isEmpty());
+ assertTrue(databaseProvider.deletePolicyType(NAME, VERSION_100).getPolicyTypes().isEmpty());
- assertTrue(databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().isEmpty());
+ assertTrue(databaseProvider.deletePolicyType(NAME, VERSION_100).getPolicyTypes().isEmpty());
assertTrue(
- databaseProvider.getPolicies("name", "1.0.0").getToscaTopologyTemplate().getPolicies().isEmpty());
- assertEquals(0, databaseProvider.getPolicyList("name", "1.0.0").size());
+ databaseProvider.getPolicies(NAME, VERSION_100).getToscaTopologyTemplate().getPolicies().isEmpty());
+ assertTrue(databaseProvider.getPolicyList(NAME, VERSION_100).isEmpty());
assertEquals(0, databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build())
.getToscaTopologyTemplate().getPolicies().size());
assertEquals(0, databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).size());
@@ -437,31 +444,31 @@ public class DatabasePolicyModelsProviderTest {
.isEmpty());
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("policy_id", null);
+ databaseProvider.getOperationalPolicy(POLICY_ID, null);
}).hasMessage("no policy found for policy: policy_id:null");
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("policy_id", "10");
+ databaseProvider.getOperationalPolicy(POLICY_ID, "10");
}).hasMessage("no policy found for policy: policy_id:10");
assertThatThrownBy(() -> {
databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessage(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessage(NAME_IS_NULL);
assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy("policy_id", "55");
+ databaseProvider.deleteOperationalPolicy(POLICY_ID, "55");
}).hasMessage("no policy found for policy: policy_id:55");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("policy_id", null);
+ databaseProvider.getGuardPolicy(POLICY_ID, null);
}).hasMessage("no policy found for policy: policy_id:null");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("policy_id", "6");
+ databaseProvider.getGuardPolicy(POLICY_ID, "6");
}).hasMessage("no policy found for policy: policy_id:6");
assertThatThrownBy(() -> {
@@ -473,17 +480,17 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("policy type for guard policy \"null\" unknown");
assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy("policy_id", "33");
+ databaseProvider.deleteGuardPolicy(POLICY_ID, "33");
}).hasMessage("no policy found for policy: policy_id:33");
- assertEquals(0, databaseProvider.getPdpGroups("name").size());
+ assertEquals(0, databaseProvider.getPdpGroups(NAME).size());
assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>()));
assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>()));
PdpGroup pdpGroup = new PdpGroup();
- pdpGroup.setName("group");
+ pdpGroup.setName(GROUP);
pdpGroup.setVersion("1.2.3");
pdpGroup.setPdpGroupState(PdpState.ACTIVE);
pdpGroup.setPdpSubgroups(new ArrayList<>());
@@ -507,29 +514,29 @@ public class DatabasePolicyModelsProviderTest {
assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
.getDesiredInstanceCount());
- assertEquals(1, databaseProvider.getPdpGroups("group").size());
+ assertEquals(1, databaseProvider.getPdpGroups(GROUP).size());
pdpSubGroup.setDesiredInstanceCount(234);
- databaseProvider.updatePdpSubGroup("group", pdpSubGroup);
- assertEquals(234,
- databaseProvider.getPdpGroups("group").get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
+ databaseProvider.updatePdpSubGroup(GROUP, pdpSubGroup);
+ assertEquals(234, databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
+ .get(0).getDesiredInstanceCount());
- assertEquals("Hello", databaseProvider.getPdpGroups("group").get(0).getPdpSubgroups().get(0)
- .getPdpInstances().get(0).getMessage());
+ assertEquals("Hello", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
+ .get(0).getPdpInstances().get(0).getMessage());
pdp.setMessage("Howdy");
- databaseProvider.updatePdp("group", "type", pdp);
- assertEquals("Howdy", databaseProvider.getPdpGroups("group").get(0).getPdpSubgroups().get(0)
- .getPdpInstances().get(0).getMessage());
+ databaseProvider.updatePdp(GROUP, "type", pdp);
+ assertEquals("Howdy", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
+ .get(0).getPdpInstances().get(0).getMessage());
assertThatThrownBy(() -> {
- databaseProvider.deletePdpGroup("name");
+ databaseProvider.deletePdpGroup(NAME);
}).hasMessage("delete of PDP group \"name:0.0.0\" failed, PDP group does not exist");
- assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup("group").getName());
+ assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName());
assertEquals(0, databaseProvider.getPdpStatistics(null).size());
- databaseProvider.updatePdpStatistics("group", "type", "type-0", new PdpStatistics());
+ databaseProvider.updatePdpStatistics(GROUP, "type", "type-0", new PdpStatistics());
} catch (Exception exc) {
LOGGER.warn("test should not throw an exception", exc);
fail("test should not throw an exception");
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
index 07f4ed72d..21d13fd83 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.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.
@@ -20,6 +21,7 @@
package org.onap.policy.models.provider.impl;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -55,10 +57,14 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public void close() throws PfModelException {}
+ public void close() throws PfModelException {
+ // do nothing
+ }
@Override
- public void init() throws PfModelException {}
+ public void init() throws PfModelException {
+ // do nothing
+ }
@Override
public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
@@ -152,22 +158,24 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<PdpGroup> getPdpGroups(String name) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<PdpGroup> createPdpGroups(@NonNull List<PdpGroup> pdpGroups) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<PdpGroup> updatePdpGroups(@NonNull List<PdpGroup> pdpGroups) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpSubGroup, @NonNull Pdp pdp)
- throws PfModelException {}
+ throws PfModelException {
+ // do nothing
+ }
@Override
public PdpGroup deletePdpGroup(@NonNull String name) throws PfModelException {
@@ -176,7 +184,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<ToscaPolicyType> getPolicyTypeList(String name, String version) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
@@ -187,12 +195,12 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter)
throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<ToscaPolicy> getPolicyList(String name, String version) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
@@ -202,24 +210,28 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public void updatePdpSubGroup(@NonNull String pdpGroupName, @NonNull PdpSubGroup pdpSubGroup)
- throws PfModelException {}
+ throws PfModelException {
+ // do nothing
+ }
@Override
public List<PdpStatistics> getPdpStatistics(String name) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpType,
- @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {}
+ @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {
+ // do nothing
+ }
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
index 93cb89165..e05c1067e 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.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.
@@ -20,14 +21,13 @@
package org.onap.policy.models.provider.impl;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
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 static org.junit.Assert.fail;
import java.util.ArrayList;
-
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
@@ -49,6 +49,9 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
*/
public class DummyPolicyModelsProviderTest {
+ private static final String POLICY_ID = "policy_id";
+ private static final String VERSION = "version";
+
@Test
public void testProvider() throws Exception {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
@@ -56,16 +59,16 @@ public class DummyPolicyModelsProviderTest {
parameters.setDatabaseUrl("jdbc:dummy");
parameters.setPersistenceUnit("dummy");
- PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
-
- dummyProvider.init();
+ try (PolicyModelsProvider dummyProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
- ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies("onap.vcpe.tca", "1.0.0");
- assertNotNull(serviceTemplate);
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app",
- serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("onap.vcpe.tca").getType());
+ dummyProvider.init();
- dummyProvider.close();
+ ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies("onap.vcpe.tca", "1.0.0");
+ assertNotNull(serviceTemplate);
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app",
+ serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("onap.vcpe.tca").getType());
+ }
}
@Test
@@ -75,75 +78,59 @@ public class DummyPolicyModelsProviderTest {
parameters.setDatabaseUrl("jdbc:dummy");
parameters.setPersistenceUnit("dummy");
- PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
- dummyProvider.init();
-
- assertNotNull(dummyProvider.getPolicyTypes("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()));
- assertNotNull(dummyProvider.getPolicyTypeList("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()));
- assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.deletePolicyType("name", "version"));
-
- assertNotNull(dummyProvider.getPolicies("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()));
- assertNotNull(dummyProvider.getPolicyList("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()));
- assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.deletePolicy("name", "version"));
-
- assertNotNull(dummyProvider.getOperationalPolicy("policy_id", "1"));
- assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
- assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
- assertNotNull(dummyProvider.deleteOperationalPolicy("policy_id", "1"));
-
- assertNotNull(dummyProvider.getGuardPolicy("policy_id", "1"));
- assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput()));
- assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
- assertNotNull(dummyProvider.deleteGuardPolicy("policy_id", "1"));
-
- assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
- assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
- assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
- assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
- assertNull(dummyProvider.deletePdpGroup("name"));
-
- dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
- dummyProvider.updatePdp("name", "type", new Pdp());
- dummyProvider.updatePdpStatistics("name", "type", "type-0", new PdpStatistics());
- assertTrue(dummyProvider.getPdpStatistics("name").isEmpty());
-
- dummyProvider.close();
+ try (PolicyModelsProvider dummyProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
+ dummyProvider.init();
+
+ assertNotNull(dummyProvider.getPolicyTypes("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()));
+ assertNotNull(dummyProvider.getPolicyTypeList("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()));
+ assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.deletePolicyType("name", VERSION));
+
+ assertNotNull(dummyProvider.getPolicies("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()));
+ assertNotNull(dummyProvider.getPolicyList("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()));
+ assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.deletePolicy("name", VERSION));
+
+ assertNotNull(dummyProvider.getOperationalPolicy(POLICY_ID, "1"));
+ assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
+ assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
+ assertNotNull(dummyProvider.deleteOperationalPolicy(POLICY_ID, "1"));
+
+ assertNotNull(dummyProvider.getGuardPolicy(POLICY_ID, "1"));
+ assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput()));
+ assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
+ assertNotNull(dummyProvider.deleteGuardPolicy(POLICY_ID, "1"));
+
+ assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
+ assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
+ assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
+ assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
+ assertNull(dummyProvider.deletePdpGroup("name"));
+
+ dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
+ dummyProvider.updatePdp("name", "type", new Pdp());
+ dummyProvider.updatePdpStatistics("name", "type", "type-0", new PdpStatistics());
+ assertTrue(dummyProvider.getPdpStatistics("name").isEmpty());
+ }
}
@Test
public void testDummyResponse() {
- DummyPolicyModelsProviderSubImpl resp = null;
-
- try {
- resp = new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters());
- resp.getBadDummyResponse1();
- fail("test should throw an exception");
- } catch (Exception npe) {
- assertEquals("error serializing object", npe.getMessage());
- } finally {
- if (resp != null) {
- resp.close();
- }
+ try (DummyPolicyModelsProviderSubImpl resp =
+ new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
+ assertThatThrownBy(resp::getBadDummyResponse1).hasMessage("error serializing object");
}
- try {
- resp = new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters());
- resp.getBadDummyResponse2();
- fail("test should throw an exception");
- } catch (Exception npe) {
- assertEquals("error serializing object", npe.getMessage());
- } finally {
- if (resp != null) {
- resp.close();
- }
+ try (DummyPolicyModelsProviderSubImpl resp =
+ new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
+ assertThatThrownBy(resp::getBadDummyResponse2).hasMessage("error serializing object");
}
}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
index fbbbaed9a..ef83ea669 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
@@ -78,7 +78,7 @@ public class PolicyLegacyGuardPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
// H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
index 77a0cac9c..e6ecf5ade 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
@@ -78,7 +78,7 @@ public class PolicyLegacyOperationalPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
// H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
index a08ad6669..1f577ae21 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
@@ -86,7 +86,7 @@ public class PolicyPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
// H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
index 140194276..9012d84b1 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
@@ -83,7 +83,7 @@ public class PolicyToscaPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
parameters.setDatabaseDriver("org.h2.Driver");
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java
index be396de05..502dec7b3 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorActivator.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.
@@ -22,11 +23,9 @@ package org.onap.policy.models.sim.pdp;
import java.util.List;
import java.util.Properties;
-
+import java.util.Random;
import lombok.Getter;
import lombok.Setter;
-
-
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
@@ -57,6 +56,7 @@ public class PdpSimulatorActivator {
private List<TopicSink> topicSinks;// topics to which pdp sends pdp status
private List<TopicSource> topicSources; // topics to which pdp listens to for messages from pap.
private static final String[] MSG_TYPE_NAMES = { "messageName" };
+ private static final Random RANDOM = new Random();
/**
* Listens for messages on the topic, decodes them into a message, and then dispatches them.
@@ -85,9 +85,9 @@ public class PdpSimulatorActivator {
topicSinks = TopicEndpoint.manager.addTopicSinks(topicProperties);
topicSources = TopicEndpoint.manager.addTopicSources(topicProperties);
- final int random = (int) (Math.random() * 1000);
+ final int random = RANDOM.nextInt();
final String instanceId = "pdp_" + random;
- LOGGER.debug("PdpSimulatorActivator initializing with instance id:" + instanceId);
+ LOGGER.debug("PdpSimulatorActivator initializing with instance id: {}", instanceId);
try {
this.pdpSimulatorParameterGroup = pdpSimulatorParameterGroup;
this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
@@ -100,8 +100,8 @@ public class PdpSimulatorActivator {
// @formatter:off
this.manager = new ServiceManager()
.addAction("topics",
- () -> TopicEndpoint.manager.start(),
- () -> TopicEndpoint.manager.shutdown())
+ TopicEndpoint.manager::start,
+ TopicEndpoint.manager::shutdown)
.addAction("set alive",
() -> setAlive(true),
() -> setAlive(false))
@@ -117,7 +117,7 @@ public class PdpSimulatorActivator {
() -> Registry.register(PdpSimulatorConstants.REG_PDP_STATUS_PUBLISHER,
new PdpStatusPublisher(topicSinks,
pdpSimulatorParameterGroup.getPdpStatusParameters().getTimeIntervalMs())),
- () -> stopAndRemovePdpStatusPublisher())
+ this::stopAndRemovePdpStatusPublisher)
.addAction("Register pdp update listener",
() -> msgDispatcher.register(PdpMessageType.PDP_UPDATE.name(), pdpUpdateListener),
() -> msgDispatcher.unregister(PdpMessageType.PDP_UPDATE.name()))
@@ -125,8 +125,8 @@ public class PdpSimulatorActivator {
() -> msgDispatcher.register(PdpMessageType.PDP_STATE_CHANGE.name(), pdpStateChangeListener),
() -> msgDispatcher.unregister(PdpMessageType.PDP_STATE_CHANGE.name()))
.addAction("Message Dispatcher",
- () -> registerMsgDispatcher(),
- () -> unregisterMsgDispatcher());
+ this::registerMsgDispatcher,
+ this::unregisterMsgDispatcher);
// @formatter:on
}
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java
index f5892d5c8..78330135a 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/PdpSimulatorMain.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.
@@ -23,8 +24,6 @@ package org.onap.policy.models.sim.pdp;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Properties;
-
-
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
@@ -52,7 +51,9 @@ public class PdpSimulatorMain {
* @param args the command line arguments
*/
public PdpSimulatorMain(final String[] args) {
- LOGGER.info("In PdpSimulator with parameters ", Arrays.toString(args));
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("In PdpSimulator with parameters {}", Arrays.toString(args));
+ }
// Check the arguments
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java
index d4296c6df..7b8f29c4b 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpMessageHandler.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.
@@ -22,8 +23,6 @@ package org.onap.policy.models.sim.pdp.handler;
import java.util.ArrayList;
import java.util.List;
-
-
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStatus;
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java
index ec1fa25a3..9df1aa103 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpStateChangeMessageHandler.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.
@@ -21,7 +22,6 @@
package org.onap.policy.models.sim.pdp.handler;
import java.util.List;
-
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
@@ -31,8 +31,6 @@ import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This class supports the handling of pdp state change messages.
@@ -41,8 +39,6 @@ import org.slf4j.LoggerFactory;
*/
public class PdpStateChangeMessageHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpStateChangeMessageHandler.class);
-
/**
* Method which handles a pdp state change event from PAP.
*
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java
index 94499f43d..4f33d079f 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/handler/PdpUpdateMessageHandler.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.
@@ -21,8 +22,6 @@
package org.onap.policy.models.sim.pdp.handler;
import java.util.List;
-
-
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
@@ -32,8 +31,6 @@ import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This class supports the handling of pdp update messages.
@@ -42,8 +39,6 @@ import org.slf4j.LoggerFactory;
*/
public class PdpUpdateMessageHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpUpdateMessageHandler.class);
-
/**
* Method which handles a pdp update event from PAP.
*
@@ -68,11 +63,9 @@ public class PdpUpdateMessageHandler {
pdpStatusContext.setPdpSubgroup(pdpUpdateMsg.getPdpSubgroup());
pdpStatusContext
.setPolicies(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
- if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
- if (!pdpUpdateMsg.getPolicies().isEmpty()) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
- PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running.");
- }
+ if (pdpStatusContext.getState().equals(PdpState.ACTIVE) && !pdpUpdateMsg.getPolicies().isEmpty()) {
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running.");
}
Registry.registerOrReplace(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST, pdpUpdateMsg.getPolicies());
if (null == pdpResponseDetails) {
diff --git a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java
index 2c5ccebf9..84ae53908 100644
--- a/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/main/java/org/onap/policy/models/sim/pdp/parameters/PdpSimulatorParameterHandler.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.
@@ -21,8 +22,6 @@
package org.onap.policy.models.sim.pdp.parameters;
import java.io.File;
-
-
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -39,7 +38,7 @@ import org.slf4j.LoggerFactory;
*/
public class PdpSimulatorParameterHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpSimulatorParameterHandler.class);
+ private static final Logger logger = LoggerFactory.getLogger(PdpSimulatorParameterHandler.class);
private static final Coder CODER = new StandardCoder();
/**
@@ -61,14 +60,14 @@ public class PdpSimulatorParameterHandler {
} catch (final CoderException e) {
final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
+ "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
- LOGGER.error(errorMessage, e);
+ logger.error(errorMessage);
throw new PdpSimulatorException(errorMessage, e);
}
// The JSON processing returns null if there is an empty file
if (pdpSimulatorParameterGroup == null) {
final String errorMessage = "no parameters found in \"" + arguments.getConfigurationFilePath() + "\"";
- LOGGER.error(errorMessage);
+ logger.error(errorMessage);
throw new PdpSimulatorException(errorMessage);
}
@@ -79,7 +78,7 @@ public class PdpSimulatorParameterHandler {
"validation error(s) on parameters from \"" + arguments.getConfigurationFilePath() + "\"\n";
returnMessage += validationResult.getResult();
- LOGGER.error(returnMessage);
+ logger.error(returnMessage);
throw new PdpSimulatorException(returnMessage);
}
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
index 8e3582e21..324edd7c5 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpStateChangeListener.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.
@@ -23,7 +24,6 @@ package org.onap.policy.models.sim.pdp.comm;
import static org.junit.Assert.assertEquals;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -33,7 +33,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +45,6 @@ import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorActivator;
import org.onap.policy.models.sim.pdp.PdpSimulatorCommandLineArguments;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
-import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterHandler;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -57,6 +55,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
public class TestPdpStateChangeListener {
+ private static final String PDP_SUBGROUP = "pdpSubgroup";
+ private static final String PDP_GROUP = "pdpGroup";
private PdpUpdateListener pdpUpdateMessageListener;
private PdpStateChangeListener pdpStateChangeListener;
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
@@ -66,12 +66,10 @@ public class TestPdpStateChangeListener {
/**
* Method for setup before each test.
*
- * @throws PdpSimulatorException if some error occurs while starting up the pdp simulator
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
+ * @throws Exception if an error occurs
*/
@Before
- public void setUp() throws PdpSimulatorException, FileNotFoundException, IOException {
+ public void setUp() throws Exception {
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.newRegistry();
@@ -125,8 +123,8 @@ public class TestPdpStateChangeListener {
private PdpUpdate performPdpUpdate(final String instance) {
final PdpUpdate pdpUpdateMsg = new PdpUpdate();
pdpUpdateMsg.setDescription("dummy pdp status for test");
- pdpUpdateMsg.setPdpGroup("pdpGroup");
- pdpUpdateMsg.setPdpSubgroup("pdpSubgroup");
+ pdpUpdateMsg.setPdpGroup(PDP_GROUP);
+ pdpUpdateMsg.setPdpSubgroup(PDP_SUBGROUP);
pdpUpdateMsg.setName(instance);
final ToscaPolicy toscaPolicy = new ToscaPolicy();
toscaPolicy.setType("apexpolicytype");
@@ -142,7 +140,7 @@ public class TestPdpStateChangeListener {
propertiesMap.put("content", "");
}
toscaPolicy.setProperties(propertiesMap);
- final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
+ final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
pdpUpdateMsg.setPolicies(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
@@ -155,8 +153,8 @@ public class TestPdpStateChangeListener {
performPdpUpdate(pdpStatus.getName());
final PdpStateChange pdpStateChangeMsg = new PdpStateChange();
pdpStateChangeMsg.setState(PdpState.PASSIVE);
- pdpStateChangeMsg.setPdpGroup("pdpGroup");
- pdpStateChangeMsg.setPdpSubgroup("pdpSubgroup");
+ pdpStateChangeMsg.setPdpGroup(PDP_GROUP);
+ pdpStateChangeMsg.setPdpSubgroup(PDP_SUBGROUP);
pdpStateChangeMsg.setName(pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -170,8 +168,8 @@ public class TestPdpStateChangeListener {
pdpStatus.setState(PdpState.ACTIVE);
final PdpStateChange pdpStateChangeMsg = new PdpStateChange();
pdpStateChangeMsg.setState(PdpState.ACTIVE);
- pdpStateChangeMsg.setPdpGroup("pdpGroup");
- pdpStateChangeMsg.setPdpSubgroup("pdpSubgroup");
+ pdpStateChangeMsg.setPdpGroup(PDP_GROUP);
+ pdpStateChangeMsg.setPdpSubgroup(PDP_SUBGROUP);
pdpStateChangeMsg.setName(pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
index f3885f42d..e5eebf066 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/comm/TestPdpUpdateListener.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.
@@ -23,7 +24,6 @@ package org.onap.policy.models.sim.pdp.comm;
import static org.junit.Assert.assertEquals;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -33,7 +33,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -44,7 +43,6 @@ import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.sim.pdp.PdpSimulatorActivator;
import org.onap.policy.models.sim.pdp.PdpSimulatorCommandLineArguments;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
-import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
import org.onap.policy.models.sim.pdp.handler.PdpMessageHandler;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterHandler;
@@ -64,12 +62,10 @@ public class TestPdpUpdateListener {
/**
* Method for setup before each test.
*
- * @throws PdpSimulatorException if some error occurs while starting up the pdp simulator
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
+ * @throws Exception if an error occurs
*/
@Before
- public void setUp() throws PdpSimulatorException, FileNotFoundException, IOException {
+ public void setUp() throws Exception {
Registry.newRegistry();
final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json",
"-p", "src/test/resources/topic.properties" };
@@ -136,7 +132,7 @@ public class TestPdpUpdateListener {
propertiesMap.put("content", "");
}
toscaPolicy.setProperties(propertiesMap);
- final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
+ final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
pdpUpdateMsg.setPolicies(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java
index 4351645b8..e0da3d805 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/CommonTestData.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.
@@ -45,9 +46,9 @@ public class CommonTestData {
public static final String DESCRIPTION = "Pdp status for HealthCheck";
public static final String POLICY_NAME = "onap.controllloop.operational.apex.BBS";
public static final String POLICY_VERSION = "0.0.1";
- public static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
+ protected static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
- private static final String REST_SERVER_PASSWORD = "zb!XztG34";
+ private static final String REST_SERVER_PASS = "zb!XztG34";
private static final String REST_SERVER_USER = "healthcheck";
private static final int REST_SERVER_PORT = 6969;
private static final String REST_SERVER_HOST = "0.0.0.0";
@@ -116,7 +117,7 @@ public class CommonTestData {
map.put("host", REST_SERVER_HOST);
map.put("port", REST_SERVER_PORT);
map.put("userName", REST_SERVER_USER);
- map.put("password", REST_SERVER_PASSWORD);
+ map.put("password", REST_SERVER_PASS);
}
return map;
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java
index e8e1f9036..337092f2f 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpSimulatorParameterHandler.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.
@@ -20,6 +21,7 @@
package org.onap.policy.models.sim.pdp.parameters;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -61,12 +63,8 @@ public class TestPdpSimulatorParameterHandler {
final PdpSimulatorCommandLineArguments noArguments = new PdpSimulatorCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new PdpSimulatorParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("no parameters found"));
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("no parameters found");
}
@Test
@@ -76,13 +74,9 @@ public class TestPdpSimulatorParameterHandler {
final PdpSimulatorCommandLineArguments invalidArguments = new PdpSimulatorCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
- try {
- new PdpSimulatorParameterHandler().getParameters(invalidArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("error reading parameters from"));
- assertTrue(e.getCause() instanceof CoderException);
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(invalidArguments))
+ .hasMessageStartingWith("error reading parameters from")
+ .hasCauseInstanceOf(CoderException.class);
}
@Test
@@ -92,11 +86,8 @@ public class TestPdpSimulatorParameterHandler {
final PdpSimulatorCommandLineArguments noArguments = new PdpSimulatorCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new PdpSimulatorParameterHandler().getParameters(noArguments);
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("is null"));
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("is null");
}
@Test
@@ -113,19 +104,14 @@ public class TestPdpSimulatorParameterHandler {
@Test
public void testPdpSimulatorParameterGroup_InvalidName() throws PdpSimulatorException {
- final String[] pdpSimulatorConfigParameters = {"-c",
+ final String[] pdpSimulatorConfigParameters = {"-c",
"src/test/resources/PdpSimulatorConfigParameters_InvalidName.json"};
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
arguments.parse(pdpSimulatorConfigParameters);
- try {
- new PdpSimulatorParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains(
- "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
- }
+ assertThatThrownBy(() -> new PdpSimulatorParameterHandler().getParameters(arguments)).hasMessageContaining(
+ "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string");
}
@Test
@@ -145,13 +131,11 @@ public class TestPdpSimulatorParameterHandler {
}
@Test
- public void testPdpSimulatorInvalidOption() throws PdpSimulatorException {
+ public void testPdpSimulatorInvalidOption() {
final String[] pdpSimulatorConfigParameters = { "-d" };
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
- try {
- arguments.parse(pdpSimulatorConfigParameters);
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
- }
+
+ assertThatThrownBy(() -> arguments.parse(pdpSimulatorConfigParameters))
+ .hasMessageStartingWith("invalid command line arguments specified");
}
}
diff --git a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java
index a48082901..49ec29bb7 100644
--- a/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.java
+++ b/models-sim/policy-models-sim-pdp/src/test/java/org/onap/policy/models/sim/pdp/parameters/TestPdpStatusParameters.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.
@@ -36,7 +37,7 @@ public class TestPdpStatusParameters {
private static CommonTestData testData = new CommonTestData();
@Test
- public void test() throws Exception {
+ public void test() {
final PdpStatusParameters pdpStatusParameters =
testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final GroupValidationResult validationResult = pdpStatusParameters.validate();
@@ -48,7 +49,7 @@ public class TestPdpStatusParameters {
}
@Test
- public void testValidate() throws Exception {
+ public void testValidate() {
final PdpStatusParameters pdpStatusParameters =
testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final GroupValidationResult result = pdpStatusParameters.validate();