summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-10 08:25:22 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-15 13:42:21 +0100
commitb8e3df6f43e46159c210ac7d1ec6983871d52ea5 (patch)
tree4992a599861db084882ad6d881ed011dd9569aaa /model
parent592e04f6301dd38ae48d38501cc251fc3d5ad2fb (diff)
Replaced try/catch blocks with assertj - apex-pdp
Removed try/catch blocks in apex-pdp with assertj assertions Part IV Issue-ID: POLICY-2451 Change-Id: I4b6accb9f944195db9ccf8a5de165b169301ac7f Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'model')
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java251
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java39
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java39
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java75
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java18
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java83
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java41
7 files changed, 197 insertions, 349 deletions
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java
index 28121fce6..084623f6f 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java
@@ -1,32 +1,32 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.model.policymodel.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Map;
import java.util.TreeMap;
@@ -54,7 +54,7 @@ public class PoliciesTest {
assertNotNull(new AxPolicy(new AxArtifactKey()));
assertNotNull(new AxPolicy(new AxArtifactKey(), "PolicyTemplate", stateMapEmpty, "FirstState"));
- AxPolicy policy = new AxPolicy();
+ final AxPolicy policy = new AxPolicy();
final AxArtifactKey policyKey = new AxArtifactKey("PolicyName", "0.0.1");
@@ -65,199 +65,180 @@ public class PoliciesTest {
badState.getStateOutputs().put(badStateOutput.getKey().getLocalName(), badStateOutput);
stateMap.put(firstState.getKey().getLocalName(), firstState);
- try {
- policy.setKey(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("key may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> policy.setKey(null))
+ .hasMessage("key may not be null");
policy.setKey(policyKey);
assertEquals("PolicyName:0.0.1", policy.getKey().getId());
assertEquals("PolicyName:0.0.1", policy.getKeys().get(0).getId());
- try {
- policy.setTemplate(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("template may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> policy.setTemplate(null))
+ .hasMessage("template may not be null");
policy.setTemplate("PolicyTemplate");
assertEquals("PolicyTemplate", policy.getTemplate());
- try {
- policy.setStateMap(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("stateMap may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> policy.setStateMap(null))
+ .hasMessage("stateMap may not be null");
policy.setStateMap(stateMap);
assertEquals(stateMap, policy.getStateMap());
- try {
- policy.setFirstState(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("firstState may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> policy.setFirstState(null))
+ .hasMessage("firstState may not be null");
policy.setFirstState("FirstState");
assertEquals("FirstState", policy.getFirstState());
assertEquals("PolicyName:0.0.1", policy.getKeys().get(0).getId());
- policy = new SupportApexPolicyModelCreator().getModel().getPolicies().get("policy");
+ final AxPolicy policyPN = new SupportApexPolicyModelCreator().getModel().getPolicies().get("policy");
AxValidationResult result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- final AxArtifactKey savedPolicyKey = policy.getKey();
- policy.setKey(AxArtifactKey.getNullKey());
+ final AxArtifactKey savedPolicyKey = policyPN.getKey();
+ policyPN.setKey(AxArtifactKey.getNullKey());
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
- policy.setKey(savedPolicyKey);
+ policyPN.setKey(savedPolicyKey);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- final String savedTemplate = policy.getTemplate();
- policy.setTemplate("");
+ final String savedTemplate = policyPN.getTemplate();
+ policyPN.setTemplate("");
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
- policy.setTemplate(savedTemplate);
+ policyPN.setTemplate(savedTemplate);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- final Map<String, AxState> savedStateMap = policy.getStateMap();
+ final Map<String, AxState> savedStateMap = policyPN.getStateMap();
- policy.setStateMap(stateMapEmpty);
+ policyPN.setStateMap(stateMapEmpty);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
- policy.setStateMap(savedStateMap);
+ policyPN.setStateMap(savedStateMap);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
savedStateMap.put(AxKey.NULL_KEY_NAME, firstState);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
savedStateMap.remove(AxKey.NULL_KEY_NAME);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
savedStateMap.put("NullState", null);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
savedStateMap.remove("NullState");
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
savedStateMap.put("BadStateKey", firstState);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
savedStateMap.remove("BadStateKey");
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
savedStateMap.put(badState.getKey().getLocalName(), badState);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
savedStateMap.remove(badState.getKey().getLocalName());
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- final String savedFirstState = policy.getFirstState();
+ final String savedFirstState = policyPN.getFirstState();
- policy.setFirstState("");
+ policyPN.setFirstState("");
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
- policy.setFirstState(savedFirstState);
+ policyPN.setFirstState(savedFirstState);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- policy.setFirstState("NonExistantFirstState");
+ policyPN.setFirstState("NonExistantFirstState");
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
- policy.setFirstState(savedFirstState);
+ policyPN.setFirstState(savedFirstState);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- final AxState clonedState = new AxState(policy.getStateMap().get("state"));
+ final AxState clonedState = new AxState(policyPN.getStateMap().get("state"));
clonedState.getKey().setLocalName("ClonedState");
clonedState.afterUnmarshal(null, null);
savedStateMap.put(clonedState.getKey().getLocalName(), clonedState);
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.WARNING, result.getValidationResult());
savedStateMap.remove(clonedState.getKey().getLocalName());
result = new AxValidationResult();
- result = policy.validate(result);
+ result = policyPN.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- policy.clean();
+ policyPN.clean();
- final AxPolicy clonedPolicy = new AxPolicy(policy);
+ final AxPolicy clonedPolicy = new AxPolicy(policyPN);
assertEquals("AxPolicy:(key=AxArtifactKey:(name=policy,version=0.0.1),template=FREEFORM,sta",
clonedPolicy.toString().substring(0, 77));
- assertFalse(policy.hashCode() == 0);
+ assertFalse(policyPN.hashCode() == 0);
- assertTrue(policy.equals(policy));
- assertTrue(policy.equals(clonedPolicy));
- assertFalse(policy.equals(null));
- assertFalse(policy.equals((Object) "Hello"));
- assertFalse(policy.equals(
+ assertTrue(policyPN.equals(policyPN));
+ assertTrue(policyPN.equals(clonedPolicy));
+ assertFalse(policyPN.equals(null));
+ assertFalse(policyPN.equals((Object) "Hello"));
+ assertFalse(policyPN.equals(
new AxPolicy(AxArtifactKey.getNullKey(), savedTemplate, savedStateMap, savedFirstState)));
- assertFalse(policy.equals(new AxPolicy(savedPolicyKey, "SomeTemplate", savedStateMap, savedFirstState)));
- assertFalse(policy.equals(new AxPolicy(savedPolicyKey, savedTemplate, stateMapEmpty, savedFirstState)));
- assertFalse(policy.equals(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, "SomeFirstState")));
- assertTrue(policy.equals(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, savedFirstState)));
-
- assertEquals(0, policy.compareTo(policy));
- assertEquals(0, policy.compareTo(clonedPolicy));
- assertNotEquals(0, policy.compareTo(new AxArtifactKey()));
- assertNotEquals(0, policy.compareTo(null));
- assertNotEquals(0, policy.compareTo(
+ assertFalse(policyPN.equals(new AxPolicy(savedPolicyKey, "SomeTemplate", savedStateMap, savedFirstState)));
+ assertFalse(policyPN.equals(new AxPolicy(savedPolicyKey, savedTemplate, stateMapEmpty, savedFirstState)));
+ assertFalse(policyPN.equals(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, "SomeFirstState")));
+ assertTrue(policyPN.equals(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, savedFirstState)));
+
+ assertEquals(0, policyPN.compareTo(policyPN));
+ assertEquals(0, policyPN.compareTo(clonedPolicy));
+ assertNotEquals(0, policyPN.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, policyPN.compareTo(null));
+ assertNotEquals(0, policyPN.compareTo(
new AxPolicy(AxArtifactKey.getNullKey(), savedTemplate, savedStateMap, savedFirstState)));
- assertNotEquals(0,
- policy.compareTo(new AxPolicy(savedPolicyKey, "SomeTemplate", savedStateMap, savedFirstState)));
- assertNotEquals(0,
- policy.compareTo(new AxPolicy(savedPolicyKey, savedTemplate, stateMapEmpty, savedFirstState)));
- assertNotEquals(0,
- policy.compareTo(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, "SomeFirstState")));
- assertEquals(0, policy.compareTo(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, savedFirstState)));
+ assertNotEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey,
+ "SomeTemplate", savedStateMap, savedFirstState)));
+ assertNotEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey, savedTemplate,
+ stateMapEmpty, savedFirstState)));
+ assertNotEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey, savedTemplate,
+ savedStateMap, "SomeFirstState")));
+ assertEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey, savedTemplate,
+ savedStateMap, savedFirstState)));
- assertNotNull(policy.getKeys());
+ assertNotNull(policyPN.getKeys());
final AxPolicies policies = new AxPolicies();
result = new AxValidationResult();
@@ -272,7 +253,7 @@ public class PoliciesTest {
result = policies.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
- policies.getPolicyMap().put(savedPolicyKey, policy);
+ policies.getPolicyMap().put(savedPolicyKey, policyPN);
result = new AxValidationResult();
result = policies.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
@@ -297,7 +278,7 @@ public class PoliciesTest {
result = policies.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- policies.getPolicyMap().put(new AxArtifactKey("BadEventKey", "0.0.1"), policy);
+ policies.getPolicyMap().put(new AxArtifactKey("BadEventKey", "0.0.1"), policyPN);
result = new AxValidationResult();
result = policies.validate(result);
assertEquals(ValidationResult.INVALID, result.getValidationResult());
@@ -343,78 +324,64 @@ public class PoliciesTest {
assertNotNull(stateTree.getReferencedStateList());
assertNotNull(stateTree.getReferencedStateSet());
- final AxState secondState = new AxState(policy.getStateMap().get("state"));
+ final AxState secondState = new AxState(policyPN.getStateMap().get("state"));
secondState.getKey().setLocalName("SecondState");
secondState.afterUnmarshal(null, null);
- policy.getStateMap().put("SecondState", secondState);
- policy.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+ policyPN.getStateMap().put("SecondState", secondState);
+ policyPN.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
- stateTree = policy.getStateTree();
+ stateTree = policyPN.getStateTree();
assertNotNull(stateTree);
assertNotNull(stateTree.getReferencedStateList());
assertNotNull(stateTree.getReferencedStateSet());
assertNotNull(stateTree.getNextStates());
- policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
- .setNextState(policy.getStateMap().get("state").getKey());
- try {
- policy.getStateTree();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("loop detected in state tree for policy policy:0.0.1 state SecondState, "
- + "next state state referenced more than once", e.getMessage());
- }
-
- policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ .setNextState(policyPN.getStateMap().get("state").getKey());
+ assertThatThrownBy(() -> policyPN.getStateTree())
+ .hasMessageContaining("loop detected in state tree for policy policy:0.0.1 state SecondState, "
+ + "next state state referenced more than once");
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
.setNextState(AxReferenceKey.getNullKey());
- final AxState thirdState = new AxState(policy.getStateMap().get("state"));
+ final AxState thirdState = new AxState(policyPN.getStateMap().get("state"));
thirdState.getKey().setLocalName("ThirdState");
thirdState.afterUnmarshal(null, null);
- policy.getStateMap().put("ThirdState", thirdState);
- policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0").setNextState(thirdState.getKey());
- policy.getStateMap().get("ThirdState").getStateOutputs().get("stateOutput0")
+ policyPN.getStateMap().put("ThirdState", thirdState);
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ .setNextState(thirdState.getKey());
+ policyPN.getStateMap().get("ThirdState").getStateOutputs().get("stateOutput0")
.setNextState(AxReferenceKey.getNullKey());
- stateTree = policy.getStateTree();
+ stateTree = policyPN.getStateTree();
final AxStateOutput ssS0Clone = new AxStateOutput(
- policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0"));
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0"));
ssS0Clone.getKey().setLocalName("ssS0Clone");
- policy.getStateMap().get("SecondState").getStateOutputs().put("ssS0Clone", ssS0Clone);
-
- try {
- policy.getStateTree();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("loop detected in state tree for policy policy:0.0.1 state SecondState, "
- + "next state ThirdState referenced more than once", e.getMessage());
- }
+ policyPN.getStateMap().get("SecondState").getStateOutputs().put("ssS0Clone", ssS0Clone);
- policy.getStateMap().get("SecondState").getStateOutputs().remove("ssS0Clone");
+ assertThatThrownBy(() -> policyPN.getStateTree())
+ .hasMessageContaining("loop detected in state tree for policy policy:0.0.1 state SecondState, "
+ + "next state ThirdState referenced more than once");
+ policyPN.getStateMap().get("SecondState").getStateOutputs().remove("ssS0Clone");
- policy.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+ policyPN.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
secondState.getStateOutputs().get("stateOutput0").setNextState(thirdState.getKey());
thirdState.getStateOutputs().get("stateOutput0").setNextState(AxReferenceKey.getNullKey());
- stateTree = policy.getStateTree();
+ stateTree = policyPN.getStateTree();
assertNotNull(stateTree.getState());
thirdState.getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
- try {
- policy.getStateTree();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("loop detected in state tree for policy policy:0.0.1 state ThirdState, "
- + "next state SecondState referenced more than once", e.getMessage());
- }
-
+ assertThatThrownBy(() -> policyPN.getStateTree())
+ .hasMessageContaining("loop detected in state tree for policy policy:0.0.1 state ThirdState, "
+ + "next state SecondState referenced more than once");
thirdState.getStateOutputs().get("stateOutput0").setNextState(AxReferenceKey.getNullKey());
- stateTree = policy.getStateTree();
+ stateTree = policyPN.getStateTree();
- final AxStateTree otherStateTree = policy.getStateTree();
+ final AxStateTree otherStateTree = policyPN.getStateTree();
assertEquals(0, stateTree.compareTo(otherStateTree));
for (final AxStateTree childStateTree : stateTree.getNextStates()) {
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java
index 307a746e5..77ce93d4c 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java
@@ -1,32 +1,32 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.model.policymodel.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -36,7 +36,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.Validat
/**
* Test state outputs.
- *
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class StateOutputTest {
@@ -54,34 +54,19 @@ public class StateOutputTest {
final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
- try {
- so.setKey(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("key may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> so.setKey(null))
+ .hasMessage("key may not be null");
so.setKey(soKey);
assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
- try {
- so.setNextState(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("nextState may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> so.setNextState(null))
+ .hasMessage("nextState may not be null");
so.setNextState(nsKey);
assertEquals(nsKey, so.getNextState());
- try {
- so.setOutgoingEvent(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("outgoingEvent may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> so.setOutgoingEvent(null))
+ .hasMessage("outgoingEvent may not be null");
so.setOutgoingEvent(eKey);
assertEquals(eKey, so.getOutgingEvent());
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java
index 87e896155..aa5dd6109 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java
@@ -1,32 +1,32 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.model.policymodel.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -36,7 +36,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.Validat
/**
* Test state task references.
- *
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class StateTaskReferenceTest {
@@ -54,24 +54,14 @@ public class StateTaskReferenceTest {
AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
- try {
- stRef.setKey(null);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("key may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> stRef.setKey(null))
+ .hasMessage("key may not be null");
stRef.setKey(stRefKey);
assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKey().getId());
assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKeys().get(0).getId());
- try {
- stRef.setStateTaskOutputType(null);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("outputType may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> stRef.setStateTaskOutputType(null))
+ .hasMessage("outputType may not be null");
stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
assertEquals(AxStateTaskOutputType.UNDEFINED, stRef.getStateTaskOutputType());
stRef.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
@@ -79,13 +69,8 @@ public class StateTaskReferenceTest {
stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
assertEquals(AxStateTaskOutputType.LOGIC, stRef.getStateTaskOutputType());
- try {
- stRef.setOutput(null);
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals("output may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> stRef.setOutput(null))
+ .hasMessage("output may not be null");
AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
stRef.setOutput(soKey);
assertEquals(soKey, stRef.getOutput());
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java
index adcc040b7..ef015e798 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +21,12 @@
package org.onap.policy.apex.model.policymodel.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Set;
import java.util.TreeMap;
@@ -75,13 +76,8 @@ public class StateTest {
final AxArtifactKey taskKey2 = new AxArtifactKey("Task2", "0.0.1");
final AxArtifactKey taskKeyBad = new AxArtifactKey("TaskBad", "0.0.1");
- try {
- state.setKey(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("key may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setKey(null))
+ .hasMessage("key may not be null");
state.setKey(stateKey);
assertEquals("PolicyName:0.0.1:NULL:StateName", state.getKey().getId());
assertEquals("PolicyName:0.0.1:NULL:StateName", state.getKeys().get(0).getId());
@@ -116,75 +112,40 @@ public class StateTest {
trMap.put(taskKey1.getKey(), str1);
trMap.put(taskKey2.getKey(), str2);
- try {
- state.setTrigger(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("trigger may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setTrigger(null))
+ .hasMessage("trigger may not be null");
state.setTrigger(triggerKey);
assertEquals(triggerKey, state.getTrigger());
- try {
- state.setStateOutputs(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("stateOutputs may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setStateOutputs(null))
+ .hasMessage("stateOutputs may not be null");
state.setStateOutputs(soMap);
assertEquals(soMap, state.getStateOutputs());
- try {
- state.setContextAlbumReferences(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("contextAlbumReferenceSet may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setContextAlbumReferences(null))
+ .hasMessage("contextAlbumReferenceSet may not be null");
state.setContextAlbumReferences(ctxtSet);
assertEquals(ctxtSet, state.getContextAlbumReferences());
- try {
- state.setTaskSelectionLogic(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("taskSelectionLogic may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setTaskSelectionLogic(null))
+ .hasMessage("taskSelectionLogic may not be null");
assertEquals(false, state.checkSetTaskSelectionLogic());
state.setTaskSelectionLogic(tsl);
assertEquals(tsl, state.getTaskSelectionLogic());
assertEquals(true, state.checkSetTaskSelectionLogic());
- try {
- state.setStateFinalizerLogicMap(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("stateFinalizerLogic may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setStateFinalizerLogicMap(null))
+ .hasMessage("stateFinalizerLogic may not be null");
state.setStateFinalizerLogicMap(sflMap);
assertEquals(sflMap, state.getStateFinalizerLogicMap());
- try {
- state.setDefaultTask(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("defaultTask may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setDefaultTask(null))
+ .hasMessage("defaultTask may not be null");
state.setDefaultTask(defTaskKey);
assertEquals(defTaskKey, state.getDefaultTask());
- try {
- state.setTaskReferences(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("taskReferenceMap may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> state.setTaskReferences(null))
+ .hasMessage("taskReferenceMap may not be null");
state.setTaskReferences(trMap);
assertEquals(trMap, state.getTaskReferences());
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java
index 0fc08d436..3dcc5e8d7 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java
@@ -1,26 +1,27 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.model.policymodel.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -71,13 +72,8 @@ public class TaskParameterTest {
result = par.validate(result);
assertEquals(ValidationResult.VALID, result.getValidationResult());
- try {
- par.setDefaultValue(null);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("defaultValue may not be null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> par.setDefaultValue(null))
+ .hasMessage("defaultValue may not be null");
par.setDefaultValue("");
result = new AxValidationResult();
result = par.validate(result);
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java
index ebb6d9765..a2cbe7415 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java
@@ -1,28 +1,29 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.model.policymodel.handling;
+import static org.assertj.core.api.Assertions.assertThat;
+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;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
@@ -31,7 +32,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxLogic;
/**
* Logic reader for policy tests.
- *
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class PolicyLogicReaderTest {
@@ -48,66 +49,36 @@ public class PolicyLogicReaderTest {
plReader.setDefaultLogic("FunkyDefaultLogic");
assertEquals("FunkyDefaultLogic", plReader.getDefaultLogic());
- try {
- new AxLogic(logicKey, "FunkyLogic", plReader);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("logic not found for logic "
- + "\"somewhere/over/the/rainbow/funkylogic/FunkyDefaultLogic.funkylogic\"", e.getMessage());
- }
-
+ assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
+ .hasMessage("logic not found for logic "
+ + "\"somewhere/over/the/rainbow/funkylogic/FunkyDefaultLogic.funkylogic\"");
plReader.setDefaultLogic(null);
- try {
- new AxLogic(logicKey, "FunkyLogic", plReader);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("logic not found for logic "
- + "\"somewhere/over/the/rainbow/funkylogic/LogicParentLogicInstanceName.funkylogic\"",
- e.getMessage());
- }
-
+ assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
+ .hasMessage("logic not found for logic "
+ + "\"somewhere/over/the/rainbow/funkylogic/LogicParentLogicInstanceName.funkylogic\"");
logicKey.setParentLocalName("LogicParentLocalName");
- try {
- new AxLogic(logicKey, "FunkyLogic", plReader);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("logic not found for logic " + "\"somewhere/over/the/rainbow/funkylogic/"
- + "LogicParentLogicParentLocalNameLogicInstanceName.funkylogic\"", e.getMessage());
- }
-
+ assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
+ .hasMessage("logic not found for logic " + "\"somewhere/over/the/rainbow/funkylogic/"
+ + "LogicParentLogicParentLocalNameLogicInstanceName.funkylogic\"");
plReader.setLogicPackage("path.to.apex.logic");
- try {
- final AxLogic logic = new AxLogic(logicKey, "FunkyLogic", plReader);
- assertTrue(logic.getLogic().endsWith("Way out man, this is funky logic!"));
- } catch (final Exception e) {
- fail("test should not throw an exception");
- }
+
+ AxLogic logic = new AxLogic(logicKey, "FunkyLogic", plReader);
+ assertThat(logic.getLogic()).endsWith("Way out man, this is funky logic!");
plReader.setLogicPackage("somewhere.over.the.rainbow");
plReader.setDefaultLogic("JavaLogic");
- try {
- final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
- assertEquals("somewhere.over.the.rainbow.java.JavaLogic", logic.getLogic());
- } catch (final Exception e) {
- fail("test should not throw an exception");
- }
+ logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.JavaLogic", logic.getLogic());
plReader.setDefaultLogic(null);
- try {
- final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
- assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicParentLocalNameLogicInstanceName",
- logic.getLogic());
- } catch (final Exception e) {
- fail("test should not throw an exception");
- }
+
+ logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicParentLocalNameLogicInstanceName",
+ logic.getLogic());
logicKey.setParentLocalName(AxKey.NULL_KEY_NAME);
- try {
- final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
- assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicInstanceName", logic.getLogic());
- } catch (final Exception e) {
- fail("test should not throw an exception");
- }
+ logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicInstanceName", logic.getLogic());
}
}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java
index 5dbdc0fab..f8fc99dd8 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java
@@ -1,29 +1,29 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.model.policymodel.handling;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Set;
import java.util.TreeSet;
@@ -34,7 +34,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
public class PolicyModelSplitterTest {
@Test
- public void test() {
+ public void test() throws ApexModelException {
final AxPolicyModel apexModel = new SupportApexPolicyModelCreator().getModel();
final Set<AxArtifactKey> requiredPolicySet = new TreeSet<AxArtifactKey>();
@@ -43,11 +43,7 @@ public class PolicyModelSplitterTest {
// There's only one policy so a split of this model on that policy should return the same
// model
AxPolicyModel splitApexModel = null;
- try {
- splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
- } catch (final ApexModelException e) {
- fail(e.getMessage());
- }
+ splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
// The only difference between the models should be that the unused event outEvent1 should
// not be in the split model
@@ -59,19 +55,11 @@ public class PolicyModelSplitterTest {
requiredPolicySet.add(new AxArtifactKey("MissingPolicy", "0.0.1"));
AxPolicyModel missingSplitApexModel = null;
- try {
- missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
- } catch (final ApexModelException e) {
- fail(e.getMessage());
- }
+ missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
assertNotNull(missingSplitApexModel);
splitApexModel = null;
- try {
- splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
- } catch (final ApexModelException e) {
- fail(e.getMessage());
- }
+ splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
// The only difference between the models should be that the unused event outEvent1 should
// not be in the split model
@@ -81,13 +69,8 @@ public class PolicyModelSplitterTest {
// There's only one policy so a split of this model on that policy should return the same
// model
- try {
- apexModel.getKey().setName("InvalidPolicyModelName");
- PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("source model is invalid: \n***validation of model f", e.getMessage().substring(0, 50));
- }
-
+ apexModel.getKey().setName("InvalidPolicyModelName");
+ assertThatThrownBy(() -> PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet))
+ .hasMessageContaining("source model is invalid: \n***validation of model f");
}
}