summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rwxr-xr-xpackages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat10
-rwxr-xr-xpackages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh2
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java43
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java55
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java69
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java121
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java229
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java12
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java52
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java50
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java33
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java11
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java122
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java89
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java78
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java78
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java63
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java73
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java56
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java97
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java77
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java79
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java76
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java90
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java41
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java300
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java201
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java41
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java275
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java156
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java337
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java306
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java603
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java55
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java61
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java58
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java64
-rw-r--r--tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java20
45 files changed, 1714 insertions, 3015 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");
}
}
diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat
index b5a92fd5a..00cec4a0f 100755
--- a/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat
+++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.bat
@@ -32,12 +32,12 @@
@echo off
setlocal enableDelayedExpansion
-if not defined KEYSTORE_PASSWD (
- set KEYSTORE_PASSWD=Pol1cy_0nap
+if not defined KEYSTORE_PASSWORD (
+ set KEYSTORE_PASSWORD=Pol1cy_0nap
)
-if not defined TRUSTSTORE_PASSWD (
- set TRUSTSTORE_PASSWD=Pol1cy_0nap
+if not defined TRUSTSTORE_PASSWORD (
+ set TRUSTSTORE_PASSWORD=Pol1cy_0nap
)
if defined APEX_HOME (
@@ -63,7 +63,7 @@ set KEYSTORE=%APEX_HOME%/etc/ssl/policy-keystore"
set TRUSTSTORE=%APEX_HOME%/etc/ssl/policy-truststore"
:: HTTPS parameters
-set HTTPS_PARAMETERS=-Djavax.net.ssl.keyStore=%KEYSTORE% -Djavax.net.ssl.keyStorePassword=%KEYSTORE_PASSWD% -Djavax.net.ssl.trustStore=%TRUSTSTORE% -Djavax.net.ssl.trustStorePassword=%TRUSTSTORE_PASSWD%
+set HTTPS_PARAMETERS=-Djavax.net.ssl.keyStore=%KEYSTORE% -Djavax.net.ssl.keyStorePassword=%KEYSTORE_PASSWORD% -Djavax.net.ssl.trustStore=%TRUSTSTORE% -Djavax.net.ssl.trustStorePassword=%TRUSTSTORE_PASSWORD%
:: script name for output
set MOD_SCRIPT_NAME=apexApps
diff --git a/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh
index 8f966369d..de8f2b59b 100755
--- a/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh
+++ b/packages/apex-pdp-package-full/src/main/package/scripts/apexApps.sh
@@ -52,7 +52,7 @@ KEYSTORE="${APEX_HOME}/etc/ssl/policy-keystore"
TRUSTSTORE="${APEX_HOME}/etc/ssl/policy-truststore"
## HTTPS parameters
-HTTPS_PARAMETERS="-Djavax.net.ssl.keyStore=${KEYSTORE} -Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWD:-Pol1cy_0nap} -Djavax.net.ssl.trustStore=$TRUSTSTORE -Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWD:-Pol1cy_0nap}"
+HTTPS_PARAMETERS="-Djavax.net.ssl.keyStore=${KEYSTORE} -Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWORD:-Pol1cy_0nap} -Djavax.net.ssl.trustStore=$TRUSTSTORE -Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD:-Pol1cy_0nap}"
## script name for output
MOD_SCRIPT_NAME=`basename $0`
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java
index 51ac21209..e4a336676 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java
@@ -21,8 +21,8 @@
package org.onap.policy.apex.plugins.context.schema.avro;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.IOException;
import org.apache.avro.generic.GenericData.EnumSymbol;
@@ -120,35 +120,18 @@ public class AvroSchemaEnumTest {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleHearts.json");
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL",
- e.getMessage());
- }
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL",
- e.getMessage());
- }
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad0.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed: Unknown symbol in enum TWEED",
- e.getMessage());
- }
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad1.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals(
- "AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed: Unknown symbol in enum Hearts",
- e.getMessage());
- }
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
+ + "Got VALUE_NULL");
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json"))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
+ + "Got VALUE_NULL");
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad0.json"))
+ .hasMessage("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed: Unknown symbol "
+ + "in enum TWEED");
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad1.json"))
+ .hasMessage("AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed: Unknown symbol "
+ + "in enum Hearts");
}
/**
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java
index 19f0761a1..368619ee8 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.plugins.context.schema.avro;
+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 java.io.IOException;
import org.apache.avro.generic.GenericData.Fixed;
@@ -98,15 +98,10 @@ public class AvroSchemaFixedTest {
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
- try {
- schemaHelper.createNewInstance();
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance "
+ assertThatThrownBy(() -> schemaHelper.createNewInstance())
+ .hasMessage("AvroTest:0.0.1: could not create an instance "
+ "of class \"org.apache.avro.generic.GenericData$Fixed\" "
- + "using the default constructor \"Fixed()\"", e.getMessage());
- }
-
+ + "using the default constructor \"Fixed()\"");
final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/FixedExampleGood.json");
final Fixed newFixedFull = (Fixed) schemaHelper.createNewInstance(inString);
assertTrue(newFixedFull.toString().startsWith("[48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65"));
@@ -128,35 +123,19 @@ public class AvroSchemaFixedTest {
testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleGood.json");
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL",
- e.getMessage());
- }
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. Got VALUE_NULL",
- e.getMessage());
- }
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad0.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"\"BADBAD\"\" "
- + "Avro unmarshalling failed: Expected fixed length 64, but got6", e.getMessage());
- }
- try {
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad1.json");
- fail("This test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object "
- + "\"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" "
- + "Avro unmarshalling failed: Expected fixed length 64, but got65", e.getMessage());
- }
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
+ + "Got VALUE_NULL");
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json"))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. "
+ + "Got VALUE_NULL");
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad0.json"))
+ .hasMessage("AvroTest:0.0.1: object \"\"BADBAD\"\" "
+ + "Avro unmarshalling failed: Expected fixed length 64, but got6");
+ assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad1.json"))
+ .hasMessage("AvroTest:0.0.1: object "
+ + "\"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" "
+ + "Avro unmarshalling failed: Expected fixed length 64, but got65");
}
/**
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java
index 0eae99bfc..5bbaf97fa 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java
@@ -1,27 +1,27 @@
/*-
* ============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.plugins.context.schema.avro;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.After;
import org.junit.Before;
@@ -83,71 +83,36 @@ public class AvroSchemaHelperBadSchemasTest {
final AxContextSchema avroBadSchema0 = new AxContextSchema(new AxArtifactKey("AvroBad0", "0.0.1"), "AVRO", "}");
schemas.getSchemasMap().put(avroBadSchema0.getKey(), avroBadSchema0);
- try {
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema0.getKey());
- fail("This test should throw an exception");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad0:0.0.1\" schema is invalid"));
- }
-
+ assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema0.getKey()))
+ .hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad0:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema1 = new AxContextSchema(new AxArtifactKey("AvroBad1", "0.0.1"), "AVRO", "");
schemas.getSchemasMap().put(avroBadSchema1.getKey(), avroBadSchema1);
- try {
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema1.getKey());
- fail("This test should throw an exception");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad1:0.0.1\" schema is invalid"));
- }
-
+ assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema1.getKey()))
+ .hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad1:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema2 =
new AxContextSchema(new AxArtifactKey("AvroBad2", "0.0.1"), "AVRO", "{}");
schemas.getSchemasMap().put(avroBadSchema2.getKey(), avroBadSchema2);
- try {
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema2.getKey());
- fail("This test should throw an exception");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad2:0.0.1\" schema is invalid"));
- }
-
+ assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema2.getKey()))
+ .hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad2:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema3 =
new AxContextSchema(new AxArtifactKey("AvroBad3", "0.0.1"), "AVRO", "{zooby}");
schemas.getSchemasMap().put(avroBadSchema3.getKey(), avroBadSchema3);
- try {
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema3.getKey());
- fail("This test should throw an exception");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad3:0.0.1\" schema is invalid"));
- }
-
+ assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema3.getKey()))
+ .hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad3:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema4 =
new AxContextSchema(new AxArtifactKey("AvroBad4", "0.0.1"), "AVRO", "{\"zooby\"}");
schemas.getSchemasMap().put(avroBadSchema4.getKey(), avroBadSchema4);
- try {
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema4.getKey());
- fail("This test should throw an exception");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad4:0.0.1\" schema is invalid"));
- }
-
+ assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema4.getKey()))
+ .hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad4:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema5 =
new AxContextSchema(new AxArtifactKey("AvroBad5", "0.0.1"), "AVRO", "{\"type\": \"zooby\"}");
schemas.getSchemasMap().put(avroBadSchema5.getKey(), avroBadSchema5);
- try {
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema5.getKey());
- fail("This test should throw an exception");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad5:0.0.1\" schema is invalid"));
- }
+ assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema5.getKey()))
+ .hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad5:0.0.1\" schema is invalid");
}
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java
index 004521c6c..d84481da8 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java
@@ -21,9 +21,8 @@
package org.onap.policy.apex.plugins.context.schema.avro;
+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.After;
import org.junit.Before;
@@ -109,24 +108,14 @@ public class AvroSchemaHelperMarshalTest {
assertEquals("true", schemaHelper1.marshal2String(true));
assertEquals("false", schemaHelper1.marshal2String(false));
- try {
- schemaHelper1.marshal2String(0);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- e.printStackTrace();
- assertEquals("AvroTest:0.0.1: object \"0\" Avro marshalling failed: "
+ assertThatThrownBy(() -> schemaHelper1.marshal2String(0))
+ .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed: "
+ "class java.lang.Integer cannot be cast to class java.lang.Boolean (java.lang.Integer and "
- + "java.lang.Boolean are in module java.base of loader 'bootstrap')", e.getMessage());
- }
- try {
- schemaHelper1.marshal2String("0");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- e.printStackTrace();
- assertEquals("AvroTest:0.0.1: object \"0\" Avro marshalling failed: class java.lang.String cannot be cast "
- + "to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of "
- + "loader 'bootstrap')", e.getMessage());
- }
+ + "java.lang.Boolean are in module java.base of loader 'bootstrap')");
+ assertThatThrownBy(() -> schemaHelper1.marshal2String("0"))
+ .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed: class java.lang.String "
+ + "cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module"
+ + " java.base of loader 'bootstrap')");
}
/**
@@ -148,20 +137,11 @@ public class AvroSchemaHelperMarshalTest {
assertEquals("-1", schemaHelper2.marshal2String(-1.23));
assertEquals("2147483647", schemaHelper2.marshal2String(2147483647));
assertEquals("-2147483648", schemaHelper2.marshal2String(-2147483648));
- try {
- schemaHelper2.marshal2String("Hello");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Number"));
- }
- try {
- schemaHelper2.marshal2String(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\""));
- }
+ assertThatThrownBy(() -> schemaHelper2.marshal2String("Hello"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "class java.lang.String cannot be cast to class java.lang.Number");
+ assertThatThrownBy(() -> schemaHelper2.marshal2String(null))
+ .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\"");
}
/**
@@ -181,20 +161,11 @@ public class AvroSchemaHelperMarshalTest {
assertEquals("-1", schemaHelper3.marshal2String(-1L));
assertEquals("9223372036854775807", schemaHelper3.marshal2String(9223372036854775807L));
assertEquals("-9223372036854775808", schemaHelper3.marshal2String(-9223372036854775808L));
- try {
- schemaHelper3.marshal2String("Hello");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Long"));
- }
- try {
- schemaHelper3.marshal2String(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\""));
- }
+ assertThatThrownBy(() -> schemaHelper3.marshal2String("Hello"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "class java.lang.String cannot be cast to class java.lang.Long");
+ assertThatThrownBy(() -> schemaHelper3.marshal2String(null))
+ .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\"");
}
/**
@@ -218,20 +189,11 @@ public class AvroSchemaHelperMarshalTest {
assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F));
assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F));
assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F));
- try {
- schemaHelper4.marshal2String("Hello");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Float"));
- }
- try {
- schemaHelper4.marshal2String(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\""));
- }
+ assertThatThrownBy(() -> schemaHelper4.marshal2String("Hello"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "class java.lang.String cannot be cast to class java.lang.Float");
+ assertThatThrownBy(() -> schemaHelper4.marshal2String(null))
+ .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\"");
}
/**
@@ -255,20 +217,11 @@ public class AvroSchemaHelperMarshalTest {
assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18));
assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18));
assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18));
- try {
- schemaHelper5.marshal2String("Hello");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
- + "class java.lang.String cannot be cast to class java.lang.Double"));
- }
- try {
- schemaHelper5.marshal2String(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\""));
- }
+ assertThatThrownBy(() -> schemaHelper5.marshal2String("Hello"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: "
+ + "class java.lang.String cannot be cast to class java.lang.Double");
+ assertThatThrownBy(() -> schemaHelper5.marshal2String(null))
+ .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\"");
}
/**
@@ -293,13 +246,8 @@ public class AvroSchemaHelperMarshalTest {
assertEquals("\"9223372036854775808\"", schemaHelper7.marshal2String("9223372036854775808"));
assertEquals("\"-9223372036854775809\"", schemaHelper7.marshal2String("-9223372036854775809"));
assertEquals("\"Hello\"", schemaHelper7.marshal2String("Hello"));
- try {
- schemaHelper7.marshal2String(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\""));
- }
+ assertThatThrownBy(() -> schemaHelper7.marshal2String(null))
+ .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\"");
}
/**
@@ -317,12 +265,7 @@ public class AvroSchemaHelperMarshalTest {
final String helloOut = schemaHelper.marshal2String(helloBytes);
assertEquals("\"hello\"", helloOut);
- try {
- schemaHelper.marshal2String(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"[Ljava.lang.Byte;\""));
- }
+ assertThatThrownBy(() -> schemaHelper.marshal2String(null))
+ .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"[Ljava.lang.Byte;\"");
}
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java
index fee21ae2a..2b6050acc 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java
@@ -1,7 +1,7 @@
/*-
* ============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.
@@ -21,9 +21,8 @@
package org.onap.policy.apex.plugins.context.schema.avro;
+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.apache.avro.util.Utf8;
import org.junit.After;
@@ -91,23 +90,13 @@ public class AvroSchemaHelperUnmarshalTest {
final SchemaHelper schemaHelper0 = new SchemaHelperFactory().createSchemaHelper(testKey,
avroNullSchema.getKey());
- try {
- schemaHelper0.createNewInstance();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance, schema class for the schema is null",
- e.getMessage());
- }
-
+ assertThatThrownBy(schemaHelper0::createNewInstance)
+ .hasMessage("AvroTest:0.0.1: could not create an instance, schema class for the schema is null");
assertEquals(null, schemaHelper0.unmarshal("null"));
- try {
- schemaHelper0.unmarshal("123");
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: "
- + "Expected null. Got VALUE_NUMBER_INT", e.getMessage());
- }
+ assertThatThrownBy(() -> schemaHelper0.unmarshal("123"))
+ .hasMessage("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: "
+ + "Expected null. Got VALUE_NUMBER_INT");
}
/**
@@ -122,25 +111,17 @@ public class AvroSchemaHelperUnmarshalTest {
final SchemaHelper schemaHelper1 = new SchemaHelperFactory().createSchemaHelper(testKey,
avroBooleanSchema.getKey());
- try {
- schemaHelper1.createNewInstance();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Boolean\" "
- + "using the default constructor \"Boolean()\"", e.getMessage());
- }
+ assertThatThrownBy(schemaHelper1::createNewInstance)
+ .hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Boolean\" "
+ + "using the default constructor \"Boolean()\"");
assertEquals(true, schemaHelper1.createNewInstance("true"));
assertEquals(true, schemaHelper1.unmarshal("true"));
assertEquals(false, schemaHelper1.unmarshal("false"));
- try {
- schemaHelper1.unmarshal(0);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: object \"0\" of type \"java.lang.Integer\" must be assignable to "
- + "\"java.lang.Boolean\" or be a Json string representation of it for "
- + "Avro unmarshalling", e.getMessage());
- }
+ assertThatThrownBy(() -> schemaHelper1.unmarshal(0))
+ .hasMessage("AvroTest:0.0.1: object \"0\" of type \"java.lang.Integer\" must be assignable to "
+ + "\"java.lang.Boolean\" or be a Json string representation of it for "
+ + "Avro unmarshalling");
}
/**
@@ -155,13 +136,9 @@ public class AvroSchemaHelperUnmarshalTest {
final SchemaHelper schemaHelper2 = new SchemaHelperFactory().createSchemaHelper(testKey,
avroIntSchema.getKey());
- try {
- schemaHelper2.createNewInstance();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Integer\" "
- + "using the default constructor \"Integer()\"", e.getMessage());
- }
+ assertThatThrownBy(schemaHelper2::createNewInstance)
+ .hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Integer\" "
+ + "using the default constructor \"Integer()\"");
assertEquals(123, schemaHelper2.createNewInstance("123"));
assertEquals(0, schemaHelper2.unmarshal("0"));
@@ -171,27 +148,15 @@ public class AvroSchemaHelperUnmarshalTest {
assertEquals(-1, schemaHelper2.unmarshal("-1.23"));
assertEquals(2147483647, schemaHelper2.unmarshal("2147483647"));
assertEquals(-2147483648, schemaHelper2.unmarshal("-2147483648"));
- try {
- schemaHelper2.unmarshal("2147483648");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: "
- + "Numeric value (2147483648) out of range of int"));
- }
- try {
- schemaHelper2.unmarshal("-2147483649");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: "
- + "Numeric value (-2147483649) out of range of int"));
- }
- try {
- schemaHelper2.unmarshal(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!"));
- }
+ assertThatThrownBy(() -> schemaHelper2.unmarshal("2147483648"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: "
+ + "Numeric value (2147483648) out of range of int");
+ assertThatThrownBy(() -> schemaHelper2.unmarshal("-2147483649"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: "
+ + "Numeric value (-2147483649) out of range of int");
+ assertThatThrownBy(() -> schemaHelper2.unmarshal(null))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!");
}
/**
@@ -206,13 +171,9 @@ public class AvroSchemaHelperUnmarshalTest {
final SchemaHelper schemaHelper3 = new SchemaHelperFactory().createSchemaHelper(testKey,
avroLongSchema.getKey());
- try {
- schemaHelper3.createNewInstance();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Long\" "
- + "using the default constructor \"Long()\"", e.getMessage());
- }
+ assertThatThrownBy(schemaHelper3::createNewInstance)
+ .hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Long\" "
+ + "using the default constructor \"Long()\"");
assertEquals(123456789L, schemaHelper3.createNewInstance("123456789"));
assertEquals(0L, schemaHelper3.unmarshal("0"));
@@ -222,36 +183,18 @@ public class AvroSchemaHelperUnmarshalTest {
assertEquals(-1L, schemaHelper3.unmarshal("-1.23"));
assertEquals(9223372036854775807L, schemaHelper3.unmarshal("9223372036854775807"));
assertEquals(-9223372036854775808L, schemaHelper3.unmarshal("-9223372036854775808"));
- try {
- schemaHelper3.unmarshal("9223372036854775808");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: "
- + "Numeric value (9223372036854775808) out of range of long"));
- }
- try {
- schemaHelper3.unmarshal("-9223372036854775809");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .startsWith("AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: "
- + "Numeric value (-9223372036854775809) out of range of long"));
- }
- try {
- schemaHelper3.unmarshal("\"Hello\"");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
- + "Expected long. Got VALUE_STRING"));
- }
- try {
- schemaHelper3.unmarshal(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!"));
- }
+ assertThatThrownBy(() -> schemaHelper3.unmarshal("9223372036854775808"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: "
+ + "Numeric value (9223372036854775808) out of range of long");
+ assertThatThrownBy(() -> schemaHelper3.unmarshal("-9223372036854775809"))
+ .hasMessageStartingWith("AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: "
+ + "Numeric value (-9223372036854775809) out of range of long");
+ assertThatThrownBy(() -> schemaHelper3.unmarshal("\"Hello\""))
+ .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
+ + "Expected long. Got VALUE_STRING");
+ assertThatThrownBy(() -> schemaHelper3.unmarshal(null))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!");
}
/**
@@ -266,13 +209,9 @@ public class AvroSchemaHelperUnmarshalTest {
final SchemaHelper schemaHelper4 = new SchemaHelperFactory().createSchemaHelper(testKey,
avroFloatSchema.getKey());
- try {
- schemaHelper4.createNewInstance();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Float\" "
- + "using the default constructor \"Float()\"", e.getMessage());
- }
+ assertThatThrownBy(schemaHelper4::createNewInstance)
+ .hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Float\" "
+ + "using the default constructor \"Float()\"");
assertEquals(1.2345F, schemaHelper4.createNewInstance("1.2345"));
assertEquals(0.0F, schemaHelper4.unmarshal("0"));
@@ -284,20 +223,12 @@ public class AvroSchemaHelperUnmarshalTest {
assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775808"));
assertEquals(9.223372E18F, schemaHelper4.unmarshal("9223372036854775808"));
assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775809"));
- try {
- schemaHelper4.unmarshal("\"Hello\"");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
- + "Expected float. Got VALUE_STRING"));
- }
- try {
- schemaHelper4.unmarshal(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!"));
- }
+ assertThatThrownBy(() -> schemaHelper4.unmarshal("\"Hello\""))
+ .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
+ + "Expected float. Got VALUE_STRING");
+ assertThatThrownBy(() -> schemaHelper4.unmarshal(null))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!");
}
/**
@@ -312,13 +243,9 @@ public class AvroSchemaHelperUnmarshalTest {
final SchemaHelper schemaHelper5 = new SchemaHelperFactory().createSchemaHelper(testKey,
avroDoubleSchema.getKey());
- try {
- schemaHelper5.createNewInstance();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"java.lang.Double\" "
- + "using the default constructor \"Double()\"", e.getMessage());
- }
+ assertThatThrownBy(schemaHelper5::createNewInstance)
+ .hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Double\" "
+ + "using the default constructor \"Double()\"");
assertEquals(1.2345E06, schemaHelper5.createNewInstance("1.2345E06"));
assertEquals(0.0, schemaHelper5.unmarshal("0"));
@@ -330,20 +257,12 @@ public class AvroSchemaHelperUnmarshalTest {
assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775808"));
assertEquals(9.223372036854776E18, schemaHelper5.unmarshal("9223372036854775808"));
assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775809"));
- try {
- schemaHelper5.unmarshal("\"Hello\"");
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
- + "Expected double. Got VALUE_STRING"));
- }
- try {
- schemaHelper5.unmarshal(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!"));
- }
+ assertThatThrownBy(() -> schemaHelper5.unmarshal("\"Hello\""))
+ .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: "
+ + "Expected double. Got VALUE_STRING");
+ assertThatThrownBy(() -> schemaHelper5.unmarshal(null))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!");
}
/**
@@ -372,13 +291,9 @@ public class AvroSchemaHelperUnmarshalTest {
assertEquals("-9223372036854775809", schemaHelper7.unmarshal("-9223372036854775809"));
assertEquals("Hello", schemaHelper7.unmarshal("Hello"));
assertEquals("Hello", schemaHelper7.unmarshal(new Utf8("Hello")));
- try {
- schemaHelper7.unmarshal(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!"));
- }
+ assertThatThrownBy(() -> schemaHelper7.unmarshal(null))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!");
}
/**
@@ -392,13 +307,9 @@ public class AvroSchemaHelperUnmarshalTest {
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
- try {
- schemaHelper.createNewInstance();
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("AvroTest:0.0.1: could not create an instance of class \"[Ljava.lang.Byte;\" "
- + "using the default constructor \"Byte[]()\"", e.getMessage());
- }
+ assertThatThrownBy(schemaHelper::createNewInstance)
+ .hasMessage("AvroTest:0.0.1: could not create an instance of class \"[Ljava.lang.Byte;\" "
+ + "using the default constructor \"Byte[]()\"");
final byte[] newBytes = (byte[]) schemaHelper.createNewInstance("\"hello\"");
assertEquals(5, newBytes.length);
assertEquals(104, newBytes[0]);
@@ -407,12 +318,8 @@ public class AvroSchemaHelperUnmarshalTest {
assertEquals(108, newBytes[3]);
assertEquals(111, newBytes[4]);
- try {
- schemaHelper.unmarshal(null);
- fail("Test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().equals("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
- + "String to read from cannot be null!"));
- }
+ assertThatThrownBy(() -> schemaHelper.unmarshal(null))
+ .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: "
+ + "String to read from cannot be null!");
}
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java
index ca1ac6561..8d85f4ecb 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java
@@ -21,15 +21,14 @@
package org.onap.policy.apex.plugins.context.schema.avro;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.IOException;
import org.apache.avro.generic.GenericRecord;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.apex.context.ContextRuntimeException;
import org.onap.policy.apex.context.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -149,13 +148,8 @@ public class AvroSchemaRecordTest {
subRecord = (GenericRecord) schemaHelper.createNewSubInstance("EmailAddress");
assertEquals(null, subRecord.get("address"));
- try {
- subRecord = (GenericRecord) schemaHelper.createNewSubInstance("IDontExist");
- fail("test should throw an exception here");
- } catch (ContextRuntimeException cre) {
- assertEquals("AvroTest:0.0.1: the schema \"User\" does not have a subtype of type \"IDontExist\"",
- cre.getMessage());
- }
+ assertThatThrownBy(() -> schemaHelper.createNewSubInstance("IDontExist"))
+ .hasMessage("AvroTest:0.0.1: the schema \"User\" does not have a subtype of type \"IDontExist\"");
}
/**
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
index ea5e80161..e506513a8 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -76,27 +77,19 @@ public class ApexRestClientConusmerTest {
EventHandlerParameters consumerParameters = new EventHandlerParameters();
SupportApexEventReceiver incomingEventReceiver = new SupportApexEventReceiver();
- try {
- arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals(
- "specified consumer properties are not applicable to REST client consumer (RestClientConsumer)",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver))
+ .hasMessageContaining("specified consumer properties are not applicable to REST client"
+ + " consumer (RestClientConsumer)");
RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(rcctp);
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.DELETE);
- try {
+ assertThatThrownBy(() -> {
arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
- assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals("specified HTTP method of \"DELETE\" is invalid, only HTTP method \"GET\" is supported "
- + "for event reception on REST client consumer (RestClientConsumer)", e.getMessage());
- }
+ }).hasMessageContaining("specified HTTP method of \"DELETE\" is invalid, only HTTP method \"GET\" is "
+ + "supported for event reception on REST client consumer (RestClientConsumer)");
+ assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.DELETE, rcctp.getHttpMethod());
rcctp.setHttpMethod(null);
rcctp.setHttpCodeFilter("zzz");
@@ -174,7 +167,7 @@ public class ApexRestClientConusmerTest {
}
@Test
- public void testApexRestClientConsumerJsonError() {
+ public void testApexRestClientConsumerJsonError() throws ApexEventException {
MockitoAnnotations.initMocks(this);
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
@@ -186,18 +179,13 @@ public class ApexRestClientConusmerTest {
consumerParameters.setCarrierTechnologyParameters(rcctp);
rcctp.setHttpCodeFilter("[1-5][0][0-5]");
- try {
- arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
- assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
-
- assertEquals("RestClientConsumer", arcc.getName());
+ arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver);
+ assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
+ assertEquals("RestClientConsumer", arcc.getName());
- arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
+ arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (ApexEventException e) {
- fail("test should not throw an exception");
- }
+ assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
@@ -341,14 +329,8 @@ public class ApexRestClientConusmerTest {
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
- try {
- // We have not set the URL, this test should not receive any events
- arcc.start();
- await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
- arcc.stop();
- } catch (Exception e) {
- // test invalid status code
- assertEquals("received an invalid status code \"200\"", e.getMessage());
- }
+ arcc.start();
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
+ arcc.stop();
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
index 0ee8fe6ad..a4ef6e38e 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
+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.fail;
import java.util.Properties;
import javax.ws.rs.client.Client;
@@ -64,29 +64,18 @@ public class ApexRestClientProducerTest {
assertNotNull(arcp);
EventHandlerParameters producerParameters = new EventHandlerParameters();
- try {
- arcp.init("RestClientProducer", producerParameters);
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals(
- "specified producer properties are not applicable to REST client producer (RestClientProducer)",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcp.init("RestClientProducer", producerParameters))
+ .hasMessage("specified producer properties are not applicable to REST client producer"
+ + " (RestClientProducer)");
RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters();
producerParameters.setCarrierTechnologyParameters(rcctp);
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.DELETE);
- try {
- arcp.init("RestClientConsumer", producerParameters);
- assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
- fail("test should throw an exception here");
- } catch (ApexEventException e) {
- assertEquals(
- "specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\" and \"PUT\" "
- + "are supported for event sending on REST client producer (RestClientConsumer)",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcp.init("RestClientConsumer", producerParameters))
+ .hasMessage("specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\""
+ + " and \"PUT\" are supported for event sending on REST client producer (RestClientConsumer)");
+ assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.DELETE, rcctp.getHttpMethod());
rcctp.setHttpMethod(null);
arcp.init("RestClientConsumer", producerParameters);
assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod());
@@ -168,15 +157,12 @@ public class ApexRestClientProducerTest {
rcctp.setUrl("http://some.place2.that.{key}.not/{tag}and.again.{tag}");
Properties properties = new Properties();
properties.put("tag", "exist");
- try {
+ assertThatThrownBy(() -> {
arcp.sendEvent(123, properties, "EventName", "This is an Event");
arcp.stop();
- fail("test should throw an exception");
- } catch (Exception e) {
- assertEquals("key \"key\" specified on url "
- + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\" not found "
- + "in execution properties passed by the current policy", e.getMessage());
- }
+ }).hasMessageContaining("key \"key\" specified on url "
+ + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\" not found "
+ + "in execution properties passed by the current policy");
}
@Test
@@ -303,14 +289,8 @@ public class ApexRestClientProducerTest {
Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl());
arcp.setClient(httpClientMock);
- try {
- arcp.sendEvent(123, null, "EventName", "This is an Event");
- fail("test should throw an exception here");
- } catch (Exception e) {
- assertEquals(
- "send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
- + "failed with status code 400 and message \"null\", event:\n" + "This is an Event",
- e.getMessage());
- }
+ assertThatThrownBy(() -> arcp.sendEvent(123, null, "EventName", "This is an Event"))
+ .hasMessageContaining("send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
+ + "failed with status code 400 and message \"null\", event:\n" + "This is an Event");
}
} \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
index 42a9c0f73..f704ad3ec 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
@@ -22,10 +22,10 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
import static org.assertj.core.api.Assertions.assertThatCode;
+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.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Set;
import org.junit.Test;
@@ -45,13 +45,8 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderBadList.json");
arguments.setRelativeFileRoot(".");
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (ParameterException pe) {
- assertTrue(pe.getMessage().contains("HTTP header array entry is null\n parameter"));
- assertTrue(pe.getMessage().trim().endsWith("HTTP header array entry is null"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("HTTP header array entry is null\n parameter");
}
@Test
@@ -60,15 +55,9 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNotKvPairs.json");
arguments.setRelativeFileRoot(".");
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (ParameterException pe) {
- assertTrue(pe.getMessage()
- .contains("HTTP header array entries must have one key and one value: [aaa, bbb, ccc]"));
- assertTrue(pe.getMessage().trim()
- .endsWith("HTTP header array entries must have one key and one value: [aaa]"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("HTTP header array entries must have one key and one value: [aaa, bbb, ccc]")
+ .hasMessageEndingWith("HTTP header array entries must have one key and one value: [aaa]\n");
}
@Test
@@ -77,13 +66,9 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNulls.json");
arguments.setRelativeFileRoot(".");
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (ParameterException pe) {
- assertTrue(pe.getMessage().contains("HTTP header key is null or blank: [null, bbb]"));
- assertTrue(pe.getMessage().trim().endsWith("HTTP header value is null or blank: [ccc, null]"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("HTTP header key is null or blank: [null, bbb]")
+ .hasMessageEndingWith("HTTP header value is null or blank: [ccc, null]\n");
}
@Test
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
index 3d620ebf4..2fbae65e4 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
@@ -21,8 +21,8 @@
package org.onap.policy.apex.plugins.event.protocol.yaml;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
@@ -215,13 +215,8 @@ public class YamlEventProtocolTest {
*/
@Test
public void testYamlProcessing() throws ApexEventException, IOException {
- try {
- testYamlDecodeEncode("TestEvent0", 1, 0, "Empty0");
- fail("test should fail here");
- } catch (ApexEventException e) {
- assertEquals("event processing failed, event is null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> testYamlDecodeEncode("TestEvent0", 1, 0, "Empty0"))
+ .hasMessage("event processing failed, event is null");
testYamlDecodeEncode("TestEvent0", 1, 0, "Empty1");
testYamlDecodeEncode("TestEvent1", 1, 1, "Collection0");
testYamlDecodeEncode("TestEvent2", 1, 3, "Collection1");
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
index 6f82c7dfd..398bddb16 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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,9 +21,9 @@
package org.onap.policy.apex.plugins.event.protocol.yaml;
+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 java.io.IOException;
import java.util.List;
@@ -41,7 +42,6 @@ import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
import org.onap.policy.apex.model.eventmodel.concepts.AxField;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
-import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
import org.onap.policy.common.parameters.ParameterService;
/**
@@ -112,52 +112,22 @@ public class YamlPluginStabilityTest {
public void testStability() throws ApexEventException {
Apex2YamlEventConverter converter = new Apex2YamlEventConverter();
- try {
- converter.init(null);
- fail("this test should throw an exception");
- } catch (ApexEventRuntimeException e) {
- assertEquals("specified consumer properties are not applicable to the YAML event protocol", e.getMessage());
- }
-
+ assertThatThrownBy(() -> converter.init(null))
+ .hasMessage("specified consumer properties are not applicable to the YAML event protocol");
YamlEventProtocolParameters pars = new YamlEventProtocolParameters();
converter.init(pars);
- try {
- converter.toApexEvent("NonExistantEvent", "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: an event definition for an event named \"NonExistantEvent\"",
- e.getMessage().substring(0, 89));
- }
-
- try {
- converter.toApexEvent("TestEvent", null);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("event processing failed, event is null", e.getMessage());
- }
-
- try {
- converter.toApexEvent("TestEvent", 1);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("error converting event \"1\" to a string", e.getMessage());
- }
-
- try {
- converter.toApexEvent("TestEvent", "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertTrue(e.getMessage().contains("Field \"doubleValue\" is missing"));
- }
-
- try {
- converter.fromApexEvent(null);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("event processing failed, Apex event is null", e.getMessage());
- }
-
+ assertThatThrownBy(() -> converter.toApexEvent("NonExistantEvent", ""))
+ .hasMessageContaining("Failed to unmarshal YAML event: an event definition for an event named "
+ + "\"NonExistantEvent\"");
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", null))
+ .hasMessage("event processing failed, event is null");
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", 1))
+ .hasMessage("error converting event \"1\" to a string");
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", ""))
+ .hasMessageContaining("Field \"doubleValue\" is missing");
+ assertThatThrownBy(() -> converter.fromApexEvent(null))
+ .hasMessage("event processing failed, Apex event is null");
ApexEvent apexEvent = new ApexEvent(testEvent.getKey().getName(), testEvent.getKey().getVersion(),
testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget());
apexEvent.put("doubleValue", 123.45);
@@ -169,31 +139,15 @@ public class YamlPluginStabilityTest {
assertTrue(yamlString.contains("my wonderful exception message"));
apexEvent.remove("intValue");
- try {
- yamlString = (String) converter.fromApexEvent(apexEvent);
- fail("this test should throw an exception");
- } catch (ApexEventRuntimeException e) {
- assertEquals("error parsing TestEvent:0.0.1 event to Json. Field \"intValue\" is missing",
- e.getMessage().substring(0, 72));
- }
-
- try {
- converter.toApexEvent(null, "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: event received without mandatory parameter \"name\"",
- e.getMessage().substring(0, 81));
- }
-
+ assertThatThrownBy(() -> converter.fromApexEvent(apexEvent))
+ .hasMessageContaining("error parsing TestEvent:0.0.1 event to Json. Field \"intValue\" is missing");
+ assertThatThrownBy(() -> converter.toApexEvent(null, ""))
+ .hasMessageContaining("Failed to unmarshal YAML event: event received without mandatory parameter"
+ + " \"name\"");
pars.setNameAlias("TheNameField");
- try {
- converter.toApexEvent(null, "");
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: event received without mandatory parameter \"name\"",
- e.getMessage().substring(0, 81));
- }
-
+ assertThatThrownBy(() -> converter.toApexEvent(null, ""))
+ .hasMessageContaining("Failed to unmarshal YAML event: event received without mandatory parameter"
+ + " \"name\"");
apexEvent.put("intValue", 123);
apexEvent.remove("stringValue");
@@ -228,14 +182,9 @@ public class YamlPluginStabilityTest {
yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: org.some.other.namespace";
pars.setVersionAlias(null);
pars.setNameSpaceAlias("stringValue");
- try {
- converter.toApexEvent("TestEvent", yamlInputString);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: namespace \"org.some.other.namespace\" on event",
- e.getMessage().substring(0, 77));
- }
-
+ final String yamlInputStringCopy = yamlInputString;
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy))
+ .hasMessageContaining("Failed to unmarshal YAML event: namespace \"org.some.other.namespace\" on event");
yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n"
+ "stringValue: org.onap.policy.apex.plugins.event.protocol.yaml";
eventList = converter.toApexEvent("TestEvent", yamlInputString);
@@ -257,21 +206,12 @@ public class YamlPluginStabilityTest {
yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyString";
pars.setSourceAlias(null);
pars.setTargetAlias("intValue");
- try {
- converter.toApexEvent("TestEvent", yamlInputString);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertEquals("Failed to unmarshal YAML event: field \"target\" with type \"java.lang.Integer\"",
- e.getMessage().substring(0, 76));
- }
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy))
+ .hasMessageContaining("Failed to unmarshal YAML event: field \"target\" with type \"java.lang.Integer\"");
pars.setTargetAlias(null);
- yamlInputString = "doubleValue: 123.45\n" + "intValue: ~\n" + "stringValue: MyString";
- try {
- converter.toApexEvent("TestEvent", yamlInputString);
- fail("this test should throw an exception");
- } catch (ApexEventException e) {
- assertTrue(e.getMessage().contains("mandatory field \"intValue\" is missing"));
- }
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", "doubleValue: 123.45\n" + "intValue: ~\n"
+ + "stringValue: MyString"))
+ .hasMessageContaining("mandatory field \"intValue\" is missing");
}
}
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
index 106467ac4..a1c296436 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.java;
+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.fail;
import java.util.Properties;
import org.junit.After;
@@ -75,88 +76,48 @@ public class JavaStateFinalizerExecutorTest {
}
@Test
- public void testJavaStateFinalizerExecutor() {
+ public void testJavaStateFinalizerExecutor() throws StateMachineException, ContextException {
JavaStateFinalizerExecutor jsfe = new JavaStateFinalizerExecutor();
assertNotNull(jsfe);
- try {
- jsfe.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals(java.lang.NullPointerException.class, jtseException.getClass());
- }
-
+ assertThatThrownBy(jsfe::prepare).isInstanceOf(java.lang.NullPointerException.class);
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+
+ internalContext = new ApexInternalContext(new AxPolicyModel());
StateExecutor parentStateExcutor = null;
- try {
- parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
- } catch (StateMachineException e) {
- fail("test should not throw an exception here");
- }
+
+ parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
AxState state = new AxState();
parentStateExcutor.setContext(null, state, internalContext);
AxStateFinalizerLogic stateFinalizerLogic = new AxStateFinalizerLogic();
jsfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext);
- try {
- jsfe.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("instantiation error on Java class \"\"", jtseException.getMessage());
- }
-
+ assertThatThrownBy(jsfe::prepare)
+ .hasMessage("instantiation error on Java class \"\"");
stateFinalizerLogic.setLogic("java.lang.String");
- try {
- jsfe.prepare();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
-
- try {
- jsfe.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"",
- jtseException.getMessage());
- }
+ jsfe.prepare();
+ assertThatThrownBy(() -> jsfe.execute(-1, new Properties(), null))
+ .hasMessage("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"");
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- try {
- jsfe.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"",
- jtseException.getMessage());
- }
-
+ assertThatThrownBy(() -> jsfe.execute(-1, new Properties(), event))
+ .hasMessage("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"");
stateFinalizerLogic.setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaStateFinalizerLogic");
- try {
- jsfe.prepare();
+ jsfe.prepare();
+ assertThatThrownBy(() -> {
jsfe.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:NULL:NULL\" "
- + "on finalizer logic NULL:0.0.0:NULL:NULL", jtseException.getMessage());
- }
-
+ }).hasMessage("execute-post: state finalizer logic execution failure on state "
+ + "\"NULL:0.0.0:NULL:NULL\" on finalizer logic NULL:0.0.0:NULL:NULL");
state.getStateOutputs().put("SelectedOutputIsMe", null);
- try {
- jsfe.prepare();
- String stateOutput = jsfe.execute(0, new Properties(), event);
- assertEquals("SelectedOutputIsMe", stateOutput);
- jsfe.cleanUp();
- } catch (Exception jtseException) {
- jtseException.printStackTrace();
- fail("test should not throw an exception here");
- }
+
+ jsfe.prepare();
+ String stateOutput = jsfe.execute(0, new Properties(), event);
+ assertEquals("SelectedOutputIsMe", stateOutput);
+ jsfe.cleanUp();
+
}
}
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java
index 8d7cca3aa..7f263245c 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.java;
+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.fail;
import java.util.HashMap;
import java.util.Map;
@@ -36,6 +37,7 @@ import org.onap.policy.apex.context.parameters.DistributorParameters;
import org.onap.policy.apex.context.parameters.LockManagerParameters;
import org.onap.policy.apex.context.parameters.PersistorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.model.policymodel.concepts.AxTask;
import org.onap.policy.common.parameters.ParameterService;
@@ -66,73 +68,37 @@ public class JavaTaskExecutorTest {
}
@Test
- public void testJavaTaskExecutor() {
+ public void testJavaTaskExecutor() throws ContextException, StateMachineException {
JavaTaskExecutor jte = new JavaTaskExecutor();
assertNotNull(jte);
- try {
- jte.prepare();
- fail("test should throw an exception here");
- } catch (Exception jteException) {
- assertEquals(java.lang.NullPointerException.class, jteException.getClass());
- }
-
+ assertThatThrownBy(jte::prepare)
+ .isInstanceOf(java.lang.NullPointerException.class);
AxTask task = new AxTask();
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
- jte.setContext(null, task, internalContext);
+ internalContext = new ApexInternalContext(new AxPolicyModel());
- try {
- jte.prepare();
- fail("test should throw an exception here");
- } catch (Exception jteException) {
- assertEquals("instantiation error on Java class \"\"", jteException.getMessage());
- }
+ jte.setContext(null, task, internalContext);
+ assertThatThrownBy(jte::prepare)
+ .hasMessage("instantiation error on Java class \"\"");
task.getTaskLogic().setLogic("java.lang.String");
- try {
- jte.prepare();
- } catch (Exception jteException) {
- fail("test should not throw an exception here");
- }
-
- try {
- jte.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception jteException) {
- assertEquals(java.lang.NullPointerException.class, jteException.getClass());
- }
+ jte.prepare();
+ assertThatThrownBy(() -> jte.execute(-1, new Properties(), null))
+ .isInstanceOf(java.lang.NullPointerException.class);
Map<String, Object> incomingParameters = new HashMap<>();
- try {
- jte.execute(-1, new Properties(), incomingParameters);
- fail("test should throw an exception here");
- } catch (Exception jteException) {
- assertEquals("task logic failed to run for task \"NULL:0.0.0\"", jteException.getMessage());
- }
-
+ assertThatThrownBy(() -> jte.execute(-1, new Properties(), incomingParameters))
+ .hasMessage("task logic failed to run for task \"NULL:0.0.0\"");
task.getTaskLogic().setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaTaskLogic");
- try {
- jte.prepare();
- jte.execute(-1, new Properties(), incomingParameters);
- fail("test should throw an exception here");
- } catch (Exception jteException) {
- assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0",
- jteException.getMessage());
- }
+ jte.prepare();
+ assertThatThrownBy(() -> jte.execute(-1, new Properties(), incomingParameters))
+ .hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0");
+ jte.prepare();
+ Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);
+ assertEquals(0, returnMap.size());
+ jte.cleanUp();
- try {
- jte.prepare();
- Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);
- assertEquals(0, returnMap.size());
- jte.cleanUp();
- } catch (Exception jteException) {
- fail("test should not throw an exception here");
- }
}
}
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java
index 38792c409..61acecd9b 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.java;
+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.fail;
import java.util.Properties;
import org.junit.After;
@@ -35,6 +36,7 @@ import org.onap.policy.apex.context.parameters.LockManagerParameters;
import org.onap.policy.apex.context.parameters.PersistorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@@ -67,76 +69,40 @@ public class JavaTaskSelectExecutorTest {
}
@Test
- public void testJavaTaskSelectExecutor() {
+ public void testJavaTaskSelectExecutor() throws StateMachineException, ContextException {
JavaTaskSelectExecutor jtse = new JavaTaskSelectExecutor();
assertNotNull(jtse);
- try {
- jtse.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals(java.lang.NullPointerException.class, jtseException.getClass());
- }
-
+ assertThatThrownBy(jtse::prepare)
+ .isInstanceOf(java.lang.NullPointerException.class);
AxState state = new AxState();
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+ internalContext = new ApexInternalContext(new AxPolicyModel());
jtse.setContext(null, state, internalContext);
- try {
- jtse.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("instantiation error on Java class \"\"", jtseException.getMessage());
- }
-
+ assertThatThrownBy(jtse::prepare)
+ .hasMessage("instantiation error on Java class \"\"");
state.getTaskSelectionLogic().setLogic("java.lang.String");
- try {
- jtse.prepare();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
-
- try {
- jtse.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals(java.lang.NullPointerException.class, jtseException.getClass());
- }
+ jtse.prepare();
+ assertThatThrownBy(() -> jtse.execute(-1, new Properties(), null))
+ .isInstanceOf(java.lang.NullPointerException.class);
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- try {
- jtse.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("task selection logic failed to run for state \"NULL:0.0.0:NULL:NULL\"",
- jtseException.getMessage());
- }
-
+ assertThatThrownBy(() -> jtse.execute(-1, new Properties(), event))
+ .hasMessage("task selection logic failed to run for state \"NULL:0.0.0:NULL:NULL\"");
state.getTaskSelectionLogic()
.setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaTaskSelectionLogic");
- try {
- jtse.prepare();
+
+ jtse.prepare();
+ assertThatThrownBy(() -> {
jtse.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"",
- jtseException.getMessage());
- }
+ }).hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"");
- try {
- jtse.prepare();
- AxArtifactKey taskKey = jtse.execute(0, new Properties(), event);
- assertEquals("NULL:0.0.0", taskKey.getId());
- jtse.cleanUp();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
+ jtse.prepare();
+ AxArtifactKey taskKey = jtse.execute(0, new Properties(), event);
+ assertEquals("NULL:0.0.0", taskKey.getId());
+ jtse.cleanUp();
}
}
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java
index fd6f24474..eca9a45cd 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.jruby;
+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.fail;
import java.lang.reflect.Field;
import java.util.Properties;
@@ -76,68 +77,44 @@ public class JrubyStateFinalizerExecutorTest {
}
@Test
- public void testJrubyStateFinalizerExecutor() {
+ public void testJrubyStateFinalizerExecutor() throws StateMachineException, ContextException,
+ NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
JrubyStateFinalizerExecutor jsfe = new JrubyStateFinalizerExecutor();
assertNotNull(jsfe);
- try {
- Field fieldContainer = JrubyStateFinalizerExecutor.class.getDeclaredField("container");
- fieldContainer.setAccessible(true);
- fieldContainer.set(jsfe, null);
- jsfe.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals(java.lang.NullPointerException.class, jtseException.getClass());
- }
+ Field fieldContainer = JrubyStateFinalizerExecutor.class.getDeclaredField("container");
+ fieldContainer.setAccessible(true);
+ fieldContainer.set(jsfe, null);
+ assertThatThrownBy(jsfe::prepare).isInstanceOf(java.lang.NullPointerException.class);
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+
+ internalContext = new ApexInternalContext(new AxPolicyModel());
StateExecutor parentStateExcutor = null;
- try {
- parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
- } catch (StateMachineException e) {
- fail("test should not throw an exception here");
- }
+ parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
AxState state = new AxState();
parentStateExcutor.setContext(null, state, internalContext);
AxStateFinalizerLogic stateFinalizerLogic = new AxStateFinalizerLogic();
jsfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext);
- try {
- jsfe.prepare();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
- try {
- jsfe.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:NULL:NULL\" on "
- + "finalizer logic NULL:0.0.0:NULL:NULL", jtseException.getMessage());
- }
+ jsfe.prepare();
+ assertThatThrownBy(() -> jsfe.execute(-1, new Properties(), null))
+ .hasMessage("execute-post: state finalizer logic execution failure on state \""
+ + "NULL:0.0.0:NULL:NULL\" on finalizer logic NULL:0.0.0:NULL:NULL");
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
- EnEvent event = new EnEvent(axEvent);
final String jrubyLogic = "if executor.executionId == -1" + "\n return false" + "\n else "
+ "\n executor.setSelectedStateOutputName(\"SelectedOutputIsMe\")" + "\n return true" + "\n end";
stateFinalizerLogic.setLogic(jrubyLogic);
+ EnEvent event = new EnEvent(axEvent);
state.getStateOutputs().put("SelectedOutputIsMe", null);
- try {
- jsfe.prepare();
- String stateOutput = jsfe.execute(0, new Properties(), event);
- assertEquals("SelectedOutputIsMe", stateOutput);
- jsfe.cleanUp();
- } catch (Exception jtseException) {
- jtseException.printStackTrace();
- fail("test should not throw an exception here");
- }
+ jsfe.prepare();
+ String stateOutput = jsfe.execute(0, new Properties(), event);
+ assertEquals("SelectedOutputIsMe", stateOutput);
+ jsfe.cleanUp();
}
}
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
index eb4707c5b..e2785d816 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * 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.
@@ -21,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.jruby;
+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.fail;
import java.lang.reflect.Field;
import java.util.HashMap;
@@ -38,6 +38,7 @@ import org.onap.policy.apex.context.parameters.DistributorParameters;
import org.onap.policy.apex.context.parameters.LockManagerParameters;
import org.onap.policy.apex.context.parameters.PersistorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.model.policymodel.concepts.AxTask;
import org.onap.policy.common.parameters.ParameterService;
@@ -68,7 +69,8 @@ public class JrubyTaskExecutorTest {
}
@Test
- public void testJrubyTaskExecutor() {
+ public void testJrubyTaskExecutor() throws StateMachineException, ContextException,
+ IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
// Run test twice to check for incorrect shutdown activity
jrubyExecutorTest();
jrubyExecutorTest();
@@ -77,63 +79,38 @@ public class JrubyTaskExecutorTest {
/**
* Test the JRuby executor.
*/
- private void jrubyExecutorTest() {
+ private void jrubyExecutorTest() throws StateMachineException, ContextException,
+ IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
JrubyTaskExecutor jte = new JrubyTaskExecutor();
assertNotNull(jte);
- try {
- Field fieldContainer = JrubyTaskExecutor.class.getDeclaredField("container");
- fieldContainer.setAccessible(true);
- fieldContainer.set(jte, null);
- jte.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals(java.lang.NullPointerException.class, jtseException.getClass());
- }
-
+ Field fieldContainer = JrubyTaskExecutor.class.getDeclaredField("container");
+ fieldContainer.setAccessible(true);
+ fieldContainer.set(jte, null);
+ assertThatThrownBy(jte::prepare).isInstanceOf(java.lang.NullPointerException.class);
AxTask task = new AxTask();
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+ internalContext = new ApexInternalContext(new AxPolicyModel());
+
jte.setContext(null, task, internalContext);
- try {
- jte.prepare();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
- Map<String, Object> incomingParameters = new HashMap<>();
- try {
- jte.execute(-1, new Properties(), incomingParameters);
- fail("test should throw an exception here");
- } catch (Exception jteException) {
- assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0",
- jteException.getMessage());
- }
+ jte.prepare();
+ Map<String, Object> incomingParameters = new HashMap<>();
+ assertThatThrownBy(() -> jte.execute(-1, new Properties(), incomingParameters))
+ .hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0");
final String jrubyLogic = "if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true"
+ "\n end";
task.getTaskLogic().setLogic(jrubyLogic);
- try {
- jte.prepare();
- Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);
- assertEquals(0, returnMap.size());
- jte.cleanUp();
- } catch (Exception jteException) {
- fail("test should not throw an exception here");
- }
+ jte.prepare();
+ Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);
+ assertEquals(0, returnMap.size());
+ jte.cleanUp();
- try {
- jte.prepare();
- Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters);
- assertEquals(0, returnMap.size());
- jte.cleanUp();
- } catch (Exception jteException) {
- fail("test should not throw an exception here");
- }
+ jte.prepare();
+ Map<String, Object> returnMap1 = jte.execute(0, new Properties(), incomingParameters);
+ assertEquals(0, returnMap1.size());
+ jte.cleanUp();
}
}
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java
index 617db8d8c..59d1be4b4 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.jruby;
+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.fail;
import java.lang.reflect.Field;
import java.util.Properties;
@@ -36,6 +37,7 @@ import org.onap.policy.apex.context.parameters.LockManagerParameters;
import org.onap.policy.apex.context.parameters.PersistorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@@ -68,56 +70,36 @@ public class JrubyTaskSelectExecutorTest {
}
@Test
- public void testJrubyTaskSelectExecutor() {
+ public void testJrubyTaskSelectExecutor() throws StateMachineException, ContextException,
+ NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
JrubyTaskSelectExecutor jtse = new JrubyTaskSelectExecutor();
assertNotNull(jtse);
assertNotNull(jtse.getOutputEventSet());
- try {
- Field fieldContainer = JrubyTaskSelectExecutor.class.getDeclaredField("container");
- fieldContainer.setAccessible(true);
- fieldContainer.set(jtse, null);
- jtse.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals(java.lang.NullPointerException.class, jtseException.getClass());
- }
+ Field fieldContainer = JrubyTaskSelectExecutor.class.getDeclaredField("container");
+ fieldContainer.setAccessible(true);
+ fieldContainer.set(jtse, null);
+
+ assertThatThrownBy(jtse::prepare).isInstanceOf(java.lang.NullPointerException.class);
AxState state = new AxState();
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+ internalContext = new ApexInternalContext(new AxPolicyModel());
+
jtse.setContext(null, state, internalContext);
- try {
- jtse.prepare();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
+ jtse.prepare();
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- try {
- jtse.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"",
- jtseException.getMessage());
- }
-
+ assertThatThrownBy(() -> jtse.execute(-1, new Properties(), event))
+ .hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"");
final String jrubyLogic =
"if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true" + "\n end";
state.getTaskSelectionLogic().setLogic(jrubyLogic);
- try {
- jtse.prepare();
- AxArtifactKey taskKey = jtse.execute(0, new Properties(), event);
- assertEquals("NULL:0.0.0", taskKey.getId());
- jtse.cleanUp();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
+ jtse.prepare();
+ AxArtifactKey taskKey = jtse.execute(0, new Properties(), event);
+ assertEquals("NULL:0.0.0", taskKey.getId());
+ jtse.cleanUp();
}
}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java
index 54ab78e61..2cd19c6f6 100644
--- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.mvel;
+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.fail;
import java.util.Properties;
import org.junit.After;
@@ -80,30 +81,18 @@ public class MvelStateFinalizerExecutorTest {
}
@Test
- public void testJavaStateFinalizerExecutor() {
+ public void testJavaStateFinalizerExecutor() throws StateMachineException, ContextException {
MvelStateFinalizerExecutor msfe = new MvelStateFinalizerExecutor();
assertNotNull(msfe);
- try {
- msfe.prepare();
- fail("test should throw an exception here");
- } catch (Exception msfeException) {
- assertEquals(java.lang.NullPointerException.class, msfeException.getClass());
- }
-
+ assertThatThrownBy(msfe::prepare)
+ .isInstanceOf(java.lang.NullPointerException.class);
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+ internalContext = new ApexInternalContext(new AxPolicyModel());
StateExecutor parentStateExcutor = null;
- try {
- parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
- } catch (StateMachineException e) {
- fail("test should not throw an exception here");
- }
+
+ parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
AxState state = new AxState();
parentStateExcutor.setContext(null, state, internalContext);
@@ -111,69 +100,31 @@ public class MvelStateFinalizerExecutorTest {
msfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext);
stateFinalizerLogic.setLogic("x > 1 2 ()");
- try {
- msfe.prepare();
- fail("test should throw an exception here");
- } catch (Exception msfeException) {
- assertEquals("failed to compile MVEL code for state NULL:0.0.0:NULL:NULL", msfeException.getMessage());
- }
-
+ assertThatThrownBy(msfe::prepare)
+ .hasMessage("failed to compile MVEL code for state NULL:0.0.0:NULL:NULL");
stateFinalizerLogic.setLogic("java.lang.String");
- try {
- msfe.prepare();
- } catch (Exception msfeException) {
- fail("test should not throw an exception here");
- }
-
- try {
- msfe.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception msfeException) {
- assertEquals("failed to execute MVEL code for state NULL:0.0.0:NULL:NULL",
- msfeException.getMessage());
- }
+ msfe.prepare();
+ assertThatThrownBy(() -> msfe.execute(-1, new Properties(), null))
+ .hasMessage("failed to execute MVEL code for state NULL:0.0.0:NULL:NULL");
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- try {
- msfe.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception msfeException) {
- assertEquals("failed to execute MVEL code for state NULL:0.0.0:NULL:NULL",
- msfeException.getMessage());
- }
-
+ assertThatThrownBy(() -> msfe.execute(-1, new Properties(), event))
+ .hasMessage("failed to execute MVEL code for state NULL:0.0.0:NULL:NULL");
stateFinalizerLogic.setLogic("executionId !=-1");
- try {
- msfe.prepare();
- msfe.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception msfeException) {
- assertEquals(
- "execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:NULL:NULL\" "
- + "on finalizer logic NULL:0.0.0:NULL:NULL",
- msfeException.getMessage());
- }
-
+ msfe.prepare();
+ assertThatThrownBy(() -> msfe.execute(-1, new Properties(), event))
+ .hasMessage("execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:"
+ + "NULL:NULL\" on finalizer logic NULL:0.0.0:NULL:NULL");
stateFinalizerLogic.setLogic(
"if (executionId == -1) {return false;}setSelectedStateOutputName(\"SelectedOutputIsMe\");"
+ "return true;");
state.getStateOutputs().put("SelectedOutputIsMe", null);
- try {
- msfe.prepare();
- String stateOutput = msfe.execute(0, new Properties(), event);
- assertEquals("SelectedOutputIsMe", stateOutput);
- } catch (Exception msfeException) {
- LOGGER.warn("Unexpected exception happened here.", msfeException);
- fail("test should not throw an exception here");
- } finally {
- try {
- msfe.cleanUp();
- } catch (StateMachineException msfeException) {
- LOGGER.warn("Unexpected exception happened here.", msfeException);
- fail("test should not throw an exception here");
- }
- }
+
+ msfe.prepare();
+ String stateOutput = msfe.execute(0, new Properties(), event);
+ assertEquals("SelectedOutputIsMe", stateOutput);
+ msfe.cleanUp();
}
}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java
index e4169274a..a4d2cbf2b 100644
--- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.mvel;
+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.fail;
import java.util.HashMap;
import java.util.Map;
@@ -36,6 +37,7 @@ import org.onap.policy.apex.context.parameters.DistributorParameters;
import org.onap.policy.apex.context.parameters.LockManagerParameters;
import org.onap.policy.apex.context.parameters.PersistorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.model.policymodel.concepts.AxTask;
import org.onap.policy.common.parameters.ParameterService;
@@ -66,74 +68,37 @@ public class MvelTaskExecutorTest {
}
@Test
- public void testMvelTaskExecutor() {
+ public void testMvelTaskExecutor() throws StateMachineException, ContextException {
MvelTaskExecutor mte = new MvelTaskExecutor();
assertNotNull(mte);
- try {
- mte.prepare();
- fail("test should throw an exception here");
- } catch (Exception mteException) {
- assertEquals(java.lang.NullPointerException.class, mteException.getClass());
- }
-
+ assertThatThrownBy(mte::prepare)
+ .isInstanceOf(java.lang.NullPointerException.class);
AxTask task = new AxTask();
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+ internalContext = new ApexInternalContext(new AxPolicyModel());
mte.setContext(null, task, internalContext);
task.getTaskLogic().setLogic("x > 1 2 ()");
- try {
- mte.prepare();
- fail("test should throw an exception here");
- } catch (Exception mteException) {
- assertEquals("failed to compile MVEL code for task NULL:0.0.0", mteException.getMessage());
- }
-
+ assertThatThrownBy(mte::prepare)
+ .hasMessage("failed to compile MVEL code for task NULL:0.0.0");
task.getTaskLogic().setLogic("x");
- try {
- mte.prepare();
- } catch (Exception mteException) {
- fail("test should not throw an exception here");
- }
-
- try {
- mte.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception mteException) {
- assertEquals(java.lang.NullPointerException.class, mteException.getClass());
- }
+ mte.prepare();
+ assertThatThrownBy(() -> mte.execute(-1, new Properties(), null))
+ .isInstanceOf(java.lang.NullPointerException.class);
Map<String, Object> incomingParameters = new HashMap<>();
- try {
- mte.execute(-1, new Properties(), incomingParameters);
- fail("test should throw an exception here");
- } catch (Exception mteException) {
- assertEquals("failed to execute MVEL code for task NULL:0.0.0", mteException.getMessage());
- }
-
+ assertThatThrownBy(() -> mte.execute(-1, new Properties(), incomingParameters))
+ .hasMessage("failed to execute MVEL code for task NULL:0.0.0");
task.getTaskLogic().setLogic("executionId != -1");
- try {
- mte.prepare();
- mte.execute(-1, new Properties(), incomingParameters);
- fail("test should throw an exception here");
- } catch (Exception mteException) {
- assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0",
- mteException.getMessage());
- }
+ mte.prepare();
+ assertThatThrownBy(() -> mte.execute(-1, new Properties(), incomingParameters))
+ .hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0");
- try {
- mte.prepare();
- Map<String, Object> returnMap = mte.execute(0, new Properties(), incomingParameters);
- assertEquals(0, returnMap.size());
- mte.cleanUp();
- } catch (Exception mteException) {
- fail("test should not throw an exception here");
- }
+ mte.prepare();
+ Map<String, Object> returnMap = mte.execute(0, new Properties(), incomingParameters);
+ assertEquals(0, returnMap.size());
+ mte.cleanUp();
}
}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java
index cd458fdac..d81c3d13b 100644
--- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.mvel;
+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.fail;
import java.util.Properties;
import org.junit.After;
@@ -35,6 +36,7 @@ import org.onap.policy.apex.context.parameters.LockManagerParameters;
import org.onap.policy.apex.context.parameters.PersistorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@@ -67,76 +69,37 @@ public class MvelTaskSelectExecutorTest {
}
@Test
- public void testJavaTaskSelectExecutor() {
+ public void testJavaTaskSelectExecutor() throws StateMachineException, ContextException {
MvelTaskSelectExecutor mtse = new MvelTaskSelectExecutor();
assertNotNull(mtse);
- try {
- mtse.prepare();
- fail("test should throw an exception here");
- } catch (Exception mtseException) {
- assertEquals(java.lang.NullPointerException.class, mtseException.getClass());
- }
-
+ assertThatThrownBy(mtse::prepare)
+ .isInstanceOf(java.lang.NullPointerException.class);
AxState state = new AxState();
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+ internalContext = new ApexInternalContext(new AxPolicyModel());
mtse.setContext(null, state, internalContext);
state.getTaskSelectionLogic().setLogic("x > 1 2 ()");
- try {
- mtse.prepare();
- fail("test should throw an exception here");
- } catch (Exception mtseException) {
- assertEquals("failed to compile MVEL code for state NULL:0.0.0:NULL:NULL", mtseException.getMessage());
- }
-
+ assertThatThrownBy(mtse::prepare)
+ .hasMessage("failed to compile MVEL code for state NULL:0.0.0:NULL:NULL");
state.getTaskSelectionLogic().setLogic("java.lang.String");
- try {
- mtse.prepare();
- } catch (Exception mtseException) {
- fail("test should not throw an exception here");
- }
-
- try {
- mtse.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception mtseException) {
- assertEquals(java.lang.NullPointerException.class, mtseException.getClass());
- }
+ mtse.prepare();
+ assertThatThrownBy(() -> mtse.execute(-1, new Properties(), null))
+ .isInstanceOf(java.lang.NullPointerException.class);
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- try {
- mtse.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception mtseException) {
- assertEquals("failed to execute MVEL code for state NULL:0.0.0:NULL:NULL",
- mtseException.getMessage());
- }
-
+ assertThatThrownBy(() -> mtse.execute(-1, new Properties(), event))
+ .hasMessage("failed to execute MVEL code for state NULL:0.0.0:NULL:NULL");
state.getTaskSelectionLogic().setLogic("executionId != -1");
- try {
- mtse.prepare();
- mtse.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception mtseException) {
- assertEquals("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"",
- mtseException.getMessage());
- }
-
- try {
- mtse.prepare();
- AxArtifactKey taskKey = mtse.execute(0, new Properties(), event);
- assertEquals("NULL:0.0.0", taskKey.getId());
- mtse.cleanUp();
- } catch (Exception mtseException) {
- fail("test should not throw an exception here");
- }
+ mtse.prepare();
+ assertThatThrownBy(() -> mtse.execute(-1, new Properties(), event))
+ .hasMessageContaining("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"");
+ mtse.prepare();
+ AxArtifactKey taskKey = mtse.execute(0, new Properties(), event);
+ assertEquals("NULL:0.0.0", taskKey.getId());
+ mtse.cleanUp();
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java
index d31a9fa37..079be6bd2 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/engdep/EngDepMessageListenerTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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,9 +21,9 @@
package org.onap.policy.apex.service.engine.engdep;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.net.InetSocketAddress;
import java.util.ArrayList;
@@ -75,13 +76,8 @@ public class EngDepMessageListenerTest {
EngDepMessageListener listener = new EngDepMessageListener(dummyEngineService);
listener.startProcessorThread();
- try {
- listener.onMessage("bad string message");
- fail("test should throw an exception");
- } catch (Exception uoe) {
- assertEquals("String messages are not supported on the EngDep protocol", uoe.getMessage());
- }
-
+ assertThatThrownBy(() -> listener.onMessage("bad string message"))
+ .hasMessage("String messages are not supported on the EngDep protocol");
List<Message> messageList = new ArrayList<>();
messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
@@ -131,40 +127,36 @@ public class EngDepMessageListenerTest {
await().until(messageQueue::isEmpty);
assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
- try {
- messageList.clear();
- messageList.add(new Response(new AxArtifactKey("UpdateModel:0.0.1"), false,
- new GetEngineInfo(new AxArtifactKey("EngineInfo:0.0.1"))));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
-
- messageList.clear();
- Message badMessage0 = new DummyMessage(null, null);
- messageList.add(badMessage0);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Message badMessage1 = new DummyMessage(new DummyAction(null), null);
- messageList.add(badMessage1);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Message badMessage2 = new DummyMessage(new DummyAction("throw exception"), null);
- messageList.add(badMessage2);
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
-
- messageList.clear();
- Mockito.doReturn(false).when(webSocketMock).isOpen();
- messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
- listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
- await().until(messageQueue::isEmpty);
- } catch (Exception e) {
- fail("test should not throw exceptions on bad messages");
- }
+ messageList.clear();
+ messageList.add(new Response(new AxArtifactKey("UpdateModel:0.0.1"), false,
+ new GetEngineInfo(new AxArtifactKey("EngineInfo:0.0.1"))));
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+ assertEquals("UpdateModel:0.0.1", dummyEngineService.getUpdateModelKey().getId());
+ messageList.clear();
+ Message badMessage0 = new DummyMessage(null, null);
+ messageList.add(badMessage0);
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
+ messageList.clear();
+ Message badMessage1 = new DummyMessage(new DummyAction(null), null);
+ messageList.add(badMessage1);
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
+ messageList.clear();
+ Message badMessage2 = new DummyMessage(new DummyAction("throw exception"), null);
+ messageList.add(badMessage2);
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
+ messageList.clear();
+ Mockito.doReturn(false).when(webSocketMock).isOpen();
+ messageList.add(new StartEngine(new AxArtifactKey("Start:0.0.1")));
+ listener.onMessage(new MessageBlock<>(messageList, webSocketMock));
+ await().until(messageQueue::isEmpty);
+
listener.stopProcessorThreads();
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
index 99b2654ab..ceadc4aae 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
@@ -1,27 +1,27 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.service.engine.event;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Test;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter;
@@ -37,69 +37,27 @@ public class JsonEventConverterTest {
public void testJsonEventConverter() {
Apex2JsonEventConverter converter = new Apex2JsonEventConverter();
- try {
- converter.init(null);
- fail("test should throw an exception");
- } catch (Exception ie) {
- assertEquals("specified consumer properties are not applicable to the JSON event protocol",
- ie.getMessage());
- }
-
- try {
- converter.init(new EventProtocolParameters() {
- });
- fail("test should throw an exception");
- } catch (Exception ie) {
- assertEquals("specified consumer properties are not applicable to the JSON event protocol",
- ie.getMessage());
- }
-
+ assertThatThrownBy(() -> converter.init(null))
+ .hasMessage("specified consumer properties are not applicable to the JSON event protocol");
+ assertThatThrownBy(() -> converter.init(new EventProtocolParameters() {}))
+ .hasMessage("specified consumer properties are not applicable to the JSON event protocol");
JsonEventProtocolParameters pars = new JsonEventProtocolParameters();
converter.init(pars);
- try {
- converter.toApexEvent(null, null);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("event processing failed, event is null", tae.getMessage());
- }
-
- try {
- converter.toApexEvent(null, 1);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("error converting event \"1\" to a string", tae.getMessage());
- }
-
- try {
- converter.toApexEvent(null, "[{\"aKey\": 1},{\"aKey\": 2}]");
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" "
- + "on configuration or on event, event=[{\"aKey\": 1},{\"aKey\": 2}]", tae.getMessage());
- }
-
- try {
- converter.toApexEvent(null, "[1,2,3]");
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("Failed to unmarshal JSON event: incoming event ([1,2,3]) is a JSON object array "
- + "containing an invalid object 1.0, event=[1,2,3]", tae.getMessage());
- }
-
- try {
- converter.fromApexEvent(null);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("event processing failed, Apex event is null", tae.getMessage());
- }
-
- try {
- converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space", "here", "there"));
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service",
- tae.getMessage());
- }
+ assertThatThrownBy(() -> converter.toApexEvent(null, null))
+ .hasMessage("event processing failed, event is null");
+ assertThatThrownBy(() -> converter.toApexEvent(null, 1))
+ .hasMessage("error converting event \"1\" to a string");
+ assertThatThrownBy(() -> converter.toApexEvent(null, "[{\"aKey\": 1},{\"aKey\": 2}]"))
+ .hasMessage("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" "
+ + "on configuration or on event, event=[{\"aKey\": 1},{\"aKey\": 2}]");
+ assertThatThrownBy(() -> converter.toApexEvent(null, "[1,2,3]"))
+ .hasMessage("Failed to unmarshal JSON event: incoming event ([1,2,3]) is a JSON object array "
+ + "containing an invalid object 1.0, event=[1,2,3]");
+ assertThatThrownBy(() -> converter.fromApexEvent(null))
+ .hasMessage("event processing failed, Apex event is null");
+ assertThatThrownBy(() -> converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space",
+ "here", "there")))
+ .hasMessage("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
index b21f41190..de84acca1 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.service.engine.event;
+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.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -216,35 +216,16 @@ public class JsonEventHandlerForPojoTest {
logger.debug("input event\n" + apexEventJsonStringIn);
- try {
- jsonEventConverter.toApexEvent("PojoEvent", apexEventJsonStringIn);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing PojoEvent:0.0.1 event from Json. "
- + "Field BAD_POJO_PAR not found on POJO event definition.",
- tae.getMessage().substring(0, 133));
- }
-
+ assertThatThrownBy(() -> jsonEventConverter.toApexEvent("PojoEvent", apexEventJsonStringIn))
+ .hasMessageContaining("Failed to unmarshal JSON event: error parsing PojoEvent:0.0.1 event from Json. "
+ + "Field BAD_POJO_PAR not found on POJO event definition.");
pars.setPojoField("POJO_PAR");
- try {
- jsonEventConverter.toApexEvent("PojoNoFieldEvent", apexEventJsonStringIn);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing PojoNoFieldEvent:0.0.1 event from Json, "
- + "Field POJO_PAR not found, no fields defined on event.",
- tae.getMessage().substring(0, 139));
- }
-
- try {
- jsonEventConverter.toApexEvent("PojoTooManyFieldsEvent", apexEventJsonStringIn);
- fail("test should throw an exception");
- } catch (Exception tae) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing PojoTooManyFieldsEvent:0.0.1 event from Json, "
- + "Field POJO_PAR, one and only one field may be defined on a POJO event definition.",
- tae.getMessage().substring(0, 173));
- }
+ assertThatThrownBy(() -> jsonEventConverter.toApexEvent("PojoNoFieldEvent", apexEventJsonStringIn))
+ .hasMessageContaining("Failed to unmarshal JSON event: error parsing PojoNoFieldEvent:0.0.1 "
+ + "event from Json, Field POJO_PAR not found, no fields defined on event.");
+ assertThatThrownBy(() -> jsonEventConverter.toApexEvent("PojoTooManyFieldsEvent", apexEventJsonStringIn))
+ .hasMessageContaining("Failed to unmarshal JSON event: error parsing PojoTooManyFieldsEvent:0.0.1"
+ + " event from Json, Field POJO_PAR, one and only one field may be defined on a "
+ + "POJO event definition.");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
index b65ebd3dc..241c92978 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
@@ -21,11 +21,11 @@
package org.onap.policy.apex.service.engine.event;
+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.io.ByteArrayInputStream;
import java.io.IOException;
@@ -103,35 +103,30 @@ public class JsonEventHandlerTest {
*/
@Test
public void testJsontoApexEvent() throws ApexException {
- try {
- final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
- assertNotNull(jsonEventConverter);
- jsonEventConverter.init(new JsonEventProtocolParameters());
+ final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
+ assertNotNull(jsonEventConverter);
+ jsonEventConverter.init(new JsonEventProtocolParameters());
- final String apexEventJsonStringIn = SupportJsonEventGenerator.jsonEvent();
+ final String apexEventJsonStringIn = SupportJsonEventGenerator.jsonEvent();
- logger.debug("input event\n" + apexEventJsonStringIn);
+ logger.debug("input event\n" + apexEventJsonStringIn);
- final List<ApexEvent> apexEventList = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- for (final ApexEvent apexEvent : apexEventList) {
- assertNotNull(apexEvent);
+ final List<ApexEvent> apexEventList = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ for (final ApexEvent apexEvent : apexEventList) {
+ assertNotNull(apexEvent);
- logger.debug(apexEvent.toString());
+ logger.debug(apexEvent.toString());
- assertEquals("BasicEvent", apexEvent.getName());
- assertEquals("0.0.1", apexEvent.getVersion());
- assertEquals("org.onap.policy.apex.events", apexEvent.getNameSpace());
- assertEquals("test", apexEvent.getSource());
- assertEquals("apex", apexEvent.getTarget());
- assertEquals(12345, apexEvent.get("intPar"));
-
- final Object testMatchCaseSelected = apexEvent.get("TestMatchCaseSelected");
- assertNull(testMatchCaseSelected);
- }
- } catch (final Exception e) {
- e.printStackTrace();
- throw new ApexException("Exception reading Apex event JSON file", e);
+ assertEquals("BasicEvent", apexEvent.getName());
+ assertEquals("0.0.1", apexEvent.getVersion());
+ assertEquals("org.onap.policy.apex.events", apexEvent.getNameSpace());
+ assertEquals("test", apexEvent.getSource());
+ assertEquals("apex", apexEvent.getTarget());
+ assertEquals(12345, apexEvent.get("intPar"));
+ final Object testMatchCaseSelected = apexEvent.get("TestMatchCaseSelected");
+ assertNull(testMatchCaseSelected);
}
+
}
/**
@@ -141,142 +136,96 @@ public class JsonEventHandlerTest {
*/
@Test
public void testJsontoApexBadEvent() throws ApexException {
- try {
- final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
- assertNotNull(jsonEventConverter);
- jsonEventConverter.init(new JsonEventProtocolParameters());
+ final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
+ assertNotNull(jsonEventConverter);
+ jsonEventConverter.init(new JsonEventProtocolParameters());
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoName();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: event received without "
+ + "mandatory parameter \"name\" ");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadName();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"name\" with value \"%%%%\" is invalid");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExName();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: an event definition for an event named \"I_DONT_EXI");
+ String apexEventJsonStringIn1 = null;
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoVersion();
+ ApexEvent event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("0.0.1", event.getVersion());
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadVersion();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"version\" with value \"#####\" is invalid");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExVersion();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: an event definition for an event named "
+ + "\"BasicEvent\" with version \"1.2.3\" not found in Apex model");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoNamespace();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("org.onap.policy.apex.events", event.getNameSpace());
+
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadNamespace();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: " + "field \"nameSpace\" with value \"hello.&&&&\" "
+ + "is invalid");
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExNamespace();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: namespace \"pie.in.the.sky\" "
+ + "on event \"BasicEvent\" does not" + " match namespace \"org.onap.policy.apex.events\" "
+ + "for that event in the Apex model");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoSource();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("source", event.getSource());
+
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadSource();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"source\" with value \"%!@**@!\" is invalid");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNoTarget();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals("target", event.getTarget());
+
+ assertThatThrownBy(() -> {
+ String apexEventJsonStringIn = null;
+ apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadTarget();
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: field \"target\" with value \"KNIO(*S)A(S)D\" "
+ + "is invalid");
+ assertThatThrownBy(() -> {
String apexEventJsonStringIn = null;
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoName();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" ",
- e.getMessage().substring(0, 82));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadName();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"name\" with value \"%%%%\" is invalid",
- e.getMessage().substring(0, 73));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExName();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: an event definition for an event named \"I_DONT_EXI",
- e.getMessage().substring(0, 82));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoVersion();
- ApexEvent event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("0.0.1", event.getVersion());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadVersion();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"version\" with value \"#####\" is invalid",
- e.getMessage().substring(0, 77));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExVersion();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals(
- "Failed to unmarshal JSON event: an event definition for an event named "
- + "\"BasicEvent\" with version \"1.2.3\" not found in Apex model",
- e.getMessage().substring(0, 128));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoNamespace();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("org.onap.policy.apex.events", event.getNameSpace());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadNamespace();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals(
- "Failed to unmarshal JSON event: " + "field \"nameSpace\" with value \"hello.&&&&\" is invalid",
- e.getMessage().substring(0, 84));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoExNamespace();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: namespace \"pie.in.the.sky\" "
- + "on event \"BasicEvent\" does not" + " match namespace \"org.onap.policy.apex.events\" "
- + "for that event in the Apex model", e.getMessage().substring(0, 168));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoSource();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("source", event.getSource());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadSource();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"source\" with value \"%!@**@!\" is invalid",
- e.getMessage().substring(0, 78));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNoTarget();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals("target", event.getTarget());
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventBadTarget();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals("Failed to unmarshal JSON event: field \"target\" with value \"KNIO(*S)A(S)D\" is invalid",
- e.getMessage().substring(0, 84));
- }
-
- try {
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventMissingFields();
- jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
- fail("Test should throw an exception here");
- } catch (final ApexEventException e) {
- assertEquals(
- "Failed to unmarshal JSON event: error parsing BasicEvent:0.0.1 "
- + "event from Json. Field \"intPar\" is missing, but is mandatory.",
- e.getMessage().substring(0, 124));
- }
-
- apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventNullFields();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals(null, event.get("TestSlogan"));
- assertEquals(-1, event.get("intPar"));
-
- // Set the missing fields as optional in the model
- final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get("BasicEvent");
- eventDefinition.getParameterMap().get("intPar").setOptional(true);
-
apexEventJsonStringIn = SupportJsonEventGenerator.jsonEventMissingFields();
- event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn).get(0);
- assertEquals(null, event.get("TestSlogan"));
- assertEquals(null, event.get("intPar"));
- } catch (final Exception e) {
- e.printStackTrace();
- throw new ApexException("Exception reading Apex event JSON file", e);
- }
+ jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
+ }).hasMessageContaining("Failed to unmarshal JSON event: error parsing BasicEvent:0.0.1 "
+ + "event from Json. Field \"intPar\" is missing, but is mandatory.");
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNullFields();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals(null, event.get("TestSlogan"));
+ assertEquals(-1, event.get("intPar"));
+
+ // Set the missing fields as optional in the model
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get("BasicEvent");
+ eventDefinition.getParameterMap().get("intPar").setOptional(true);
+
+ apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventMissingFields();
+ event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
+ assertEquals(null, event.get("TestSlogan"));
+ assertEquals(null, event.get("intPar"));
}
/**
@@ -286,31 +235,26 @@ public class JsonEventHandlerTest {
*/
@Test
public void testApexEventToJson() throws ApexException {
- try {
- final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
- jsonEventConverter.init(new JsonEventProtocolParameters());
- assertNotNull(jsonEventConverter);
+ final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
+ jsonEventConverter.init(new JsonEventProtocolParameters());
+ assertNotNull(jsonEventConverter);
- final Map<String, Object> basicEventMap = new HashMap<String, Object>();
- basicEventMap.put("intPar", 12345);
+ final Map<String, Object> basicEventMap = new HashMap<String, Object>();
+ basicEventMap.put("intPar", 12345);
- final ApexEvent basicEvent =
- new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex");
- basicEvent.putAll(basicEventMap);
+ final ApexEvent basicEvent =
+ new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex");
+ basicEvent.putAll(basicEventMap);
- final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent);
+ final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent);
- logger.debug(apexEvent0000JsonString);
+ logger.debug(apexEvent0000JsonString);
- assertTrue(apexEvent0000JsonString.contains("\"name\": \"BasicEvent\""));
- assertTrue(apexEvent0000JsonString.contains("\"version\": \"0.0.1\""));
- assertTrue(apexEvent0000JsonString.contains("\"nameSpace\": \"org.onap.policy.apex.events\""));
- assertTrue(apexEvent0000JsonString.contains("\"source\": \"test\""));
- assertTrue(apexEvent0000JsonString.contains("\"target\": \"apex\""));
- assertTrue(apexEvent0000JsonString.contains("\"intPar\": 12345"));
- } catch (final Exception e) {
- e.printStackTrace();
- throw new ApexException("Exception reading Apex event JSON file", e);
- }
+ assertTrue(apexEvent0000JsonString.contains("\"name\": \"BasicEvent\""));
+ assertTrue(apexEvent0000JsonString.contains("\"version\": \"0.0.1\""));
+ assertTrue(apexEvent0000JsonString.contains("\"nameSpace\": \"org.onap.policy.apex.events\""));
+ assertTrue(apexEvent0000JsonString.contains("\"source\": \"test\""));
+ assertTrue(apexEvent0000JsonString.contains("\"target\": \"apex\""));
+ assertTrue(apexEvent0000JsonString.contains("\"intPar\": 12345"));
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
index 40375b1f6..09fbe91fe 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
@@ -1,28 +1,28 @@
/*-
* ============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.service.engine.main;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.After;
import org.junit.Test;
@@ -30,7 +30,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
* Test Apex Command Line Arguments.
- *
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class ApexCommandLineArgumentsTest {
@@ -40,223 +40,138 @@ public class ApexCommandLineArgumentsTest {
}
@Test
- public void testCommandLineArguments() {
+ public void testCommandLineArguments() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex configuration file was not specified as an argument", e.getMessage());
- }
-
+ }).hasMessage("Apex configuration file was not specified as an argument");
final String[] args01 =
{ "-h" };
- try {
- final String result = apexArguments.parse(args01);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result = apexArguments.parse(args01);
+ assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args02 =
{ "-v" };
- try {
- final String result = apexArguments.parse(args02);
- assertTrue(result.startsWith("Apex Adaptive Policy Engine"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ final String result02 = apexArguments.parse(args02);
+ assertTrue(result02.startsWith("Apex Adaptive Policy Engine"));
final String[] args03 =
{ "-v", "-h" };
- try {
- final String result = apexArguments.parse(args03);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result03 = apexArguments.parse(args03);
+ assertTrue(result03.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args04 =
{ "-h", "-v" };
- try {
- final String result = apexArguments.parse(args04);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ final String result04 = apexArguments.parse(args04);
+ assertTrue(result04.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args05 =
{ "-a" };
- try {
- apexArguments.parse(args05);
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
- }
-
+ assertThatThrownBy(() -> apexArguments.parse(args05))
+ .hasMessage("invalid command line arguments specified : Unrecognized option: -a");
final String[] args06 =
{ "-c", "hello", "-m", "goodbye", "-h", "-v" };
- try {
- final String result = apexArguments.parse(args06);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Unrecognized option: -a", e.getMessage());
- }
+ final String result06 = apexArguments.parse(args06);
+ assertTrue(result06.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
final String[] args07 =
{ "-c", "hello", "-m", "goodbye", "-h", "aaa" };
- try {
- final String result = apexArguments.parse(args07);
- assertTrue(result.startsWith("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
- } catch (final ApexException e) {
- assertEquals("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]",
- e.getMessage());
- }
+ assertThatThrownBy(() -> apexArguments.parse(args07))
+ .hasMessage("too many command line arguments specified : [-c, hello, -m, goodbye, -h, aaa]");
}
@Test
- public void testCommandLineFileParameters() {
+ public void testCommandLineFileParameters() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "-c", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex configuration file \"zooby\" does not exist", e.getMessage());
- }
-
+ }).hasMessage("Apex configuration file \"zooby\" does not exist");
final String[] args01 =
{ "-c" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args01);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: c", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: c");
final String[] args02 =
{ "-c", "src/test/resources/parameters/goodParams.json" };
- try {
- apexArguments.parse(args02);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ apexArguments.parse(args02);
+ apexArguments.validate();
final String[] args03 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args03);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("Apex model file \"zooby\" does not exist", e.getMessage());
- }
-
+ }).hasMessage("Apex model file \"zooby\" does not exist");
final String[] args04 =
{ "-m" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args04);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: m");
final String[] args05 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args05);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: m", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: m");
final String[] args06 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-m",
"src/test/resources/main/DummyModelFile.json" };
- try {
- apexArguments.parse(args06);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+ apexArguments.parse(args06);
+ apexArguments.validate();
final String[] args07 =
{ "-c", "parameters/goodParams.json", "-m", "main/DummyModelFile.json" };
- try {
- apexArguments.parse(args07);
- apexArguments.validate();
- } catch (final ApexException e) {
- e.printStackTrace();
- fail("Test should not throw an exception");
- }
+
+ apexArguments.parse(args07);
+ apexArguments.validate();
}
@Test
- public void testCommandLineRelativeRootParameters() {
+ public void testCommandLineRelativeRootParameters() throws ApexException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "zooby" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args00);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertTrue(e.getMessage().contains("zooby\" does not exist or is not a directory"));
- }
-
+ }).hasMessageContaining("zooby\" does not exist or is not a directory");
final String[] args01 =
{ "-rfr" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args01);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertEquals("invalid command line arguments specified : Missing argument for option: rfr", e.getMessage());
- }
-
+ }).hasMessage("invalid command line arguments specified : Missing argument for option: rfr");
final String[] args02 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "pom.xml" };
- try {
+ assertThatThrownBy(() -> {
apexArguments.parse(args02);
apexArguments.validate();
- fail("Test should throw an exception here");
- } catch (final ApexException e) {
- assertTrue(e.getMessage().contains("pom.xml\" does not exist or is not a directory"));
- }
-
+ }).hasMessageContaining("pom.xml\" does not exist or is not a directory");
final String[] args03 =
{ "-c", "src/test/resources/parameters/goodParams.json", "-rfr", "target" };
- try {
- apexArguments.parse(args03);
- apexArguments.validate();
- } catch (final ApexException e) {
- fail("Test should not throw an exception here");
- }
+
+ apexArguments.parse(args03);
+ apexArguments.validate();
final String[] args04 =
{ "-c", "src/test/resources/parameters/goodParamsRelative.json", "-rfr", "src/test/resources" };
- try {
- apexArguments.parse(args04);
- apexArguments.validate();
- } catch (final ApexException e) {
- fail("Test should not throw an exception here");
- }
+
+ apexArguments.parse(args04);
+ apexArguments.validate();
+
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
index ff97eaec2..330de42dd 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.service.engine.parameters;
+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.assertNotNull;
@@ -44,16 +45,13 @@ public class ApexParametersTest {
final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesOK.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertTrue(parameters.checkJavaPropertiesSet());
- assertEquals("property0", parameters.getJavaProperties()[0][0]);
- assertEquals("property0Value", parameters.getJavaProperties()[0][1]);
- assertEquals("property1", parameters.getJavaProperties()[1][0]);
- assertEquals("property1Value", parameters.getJavaProperties()[1][1]);
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertTrue(parameters.checkJavaPropertiesSet());
+ assertEquals("property0", parameters.getJavaProperties()[0][0]);
+ assertEquals("property0Value", parameters.getJavaProperties()[0][1]);
+ assertEquals("property1", parameters.getJavaProperties()[1][0]);
+ assertEquals("property1Value", parameters.getJavaProperties()[1][1]);
+
}
@Test
@@ -61,12 +59,9 @@ public class ApexParametersTest {
final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesEmpty.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertFalse(parameters.checkJavaPropertiesSet());
- } catch (final ParameterException pe) {
- fail("This test should not throw an exception");
- }
+ ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertFalse(parameters.checkJavaPropertiesSet());
+
}
@Test
@@ -74,15 +69,11 @@ public class ApexParametersTest {
final String[] args = {"-c", "src/test/resources/parameters/javaPropertiesBad.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException pe) {
- assertTrue(pe.getMessage().contains("java properties array entries must have one key and one value"));
- assertTrue(pe.getMessage().contains("java properties key is null or blank"));
- assertTrue(pe.getMessage().contains("java properties value is null or blank"));
- assertTrue(pe.getMessage().contains("java properties array entry is null"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("java properties array entries must have one key and one value")
+ .hasMessageContaining("java properties key is null or blank")
+ .hasMessageContaining("java properties value is null or blank")
+ .hasMessageContaining("java properties array entry is null");
}
@Test
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
index f6d39f029..018fda668 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.service.engine.parameters;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -43,14 +44,10 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextNoParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/serviceContextNoParams.json\"\n"
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/serviceContextNoParams.json\"\n"
+ "(ParameterRuntimeException):could not find field \"parameterClassName\" in "
- + "\"contextParameters\" entry", e.getMessage());
- }
+ + "\"contextParameters\" entry");
}
@Test
@@ -58,15 +55,11 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/serviceContextBadParams.json\""
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/serviceContextBadParams.json\""
+ "\n(ParameterRuntimeException):failed to deserialize the parameters for "
+ "\"contextParameters\" to parameter class "
- + "\"hello\"\njava.lang.ClassNotFoundException: hello", e.getMessage());
- }
+ + "\"hello\"\njava.lang.ClassNotFoundException: hello");
}
@Test
@@ -74,15 +67,11 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadPluginNameParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadPluginNameParams.json\"\n"
- + "(ParameterRuntimeException):could not find field \"parameterClassName\" in "
- + "\"contextParameters\" entry", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadPluginNameParams.json\"\n"
+ + "(ParameterRuntimeException):could not find field \"parameterClassName\" in "
+ + "\"contextParameters\" entry");
}
@Test
@@ -90,19 +79,13 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassParams.json\""
- + "\n(ParameterRuntimeException):failed to deserialize "
- + "the parameters for \"contextParameters\""
- + " to parameter class \"java.lang.Integer\"\ncom.google.gson.JsonSyntaxException: "
- + "java.lang.IllegalStateException: Expected NUMBER but was BEGIN_OBJECT at path $",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassParams.json\""
+ + "\n(ParameterRuntimeException):failed to deserialize "
+ + "the parameters for \"contextParameters\""
+ + " to parameter class \"java.lang.Integer\"\ncom.google.gson.JsonSyntaxException: "
+ + "java.lang.IllegalStateException: Expected NUMBER but was BEGIN_OBJECT at path $");
}
@Test
@@ -110,126 +93,106 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadPluginClassParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadPluginClassParams.json\""
- + "\n(ClassCastException):class org.onap.policy.apex.service.engine.parameters."
- + "dummyclasses.SuperDooperExecutorParameters"
- + " cannot be cast to class org.onap.policy.apex.context.parameters.ContextParameters "
- + "(org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters and "
- + "org.onap.policy.apex.context.parameters.ContextParameters are "
- + "in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadPluginClassParams.json\""
+ + "\n(ClassCastException):class org.onap.policy.apex.service.engine.parameters."
+ + "dummyclasses.SuperDooperExecutorParameters"
+ + " cannot be cast to class org.onap.policy.apex.context.parameters.ContextParameters "
+ + "(org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters and "
+ + "org.onap.policy.apex.context.parameters.ContextParameters are "
+ + "in unnamed module of loader 'app')");
}
@Test
- public void testOkFlushParamTest() {
+ public void testOkFlushParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKFlushParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
}
@Test
- public void testOkDefaultParamTest() {
+ public void testOkDefaultParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKDefaultParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
}
@Test
- public void testOkDistParamTest() {
+ public void testOkDistParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKDistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getDistributorParameters().getClass().getName());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getDistributorParameters().getClass().getName());
+
}
@Test
- public void testOkFullDefaultParamTest() {
+ public void testOkFullDefaultParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getDistributorParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getLockManagerParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getClass().getName());
- assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.DistributorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getDistributorParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getLockManagerParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getClass().getName());
+ assertEquals(300000, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
}
@Test
- public void testOkFullParamTest() {
+ public void testOkFullParamTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextOKFullParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
- .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getLockManagerParameters().getClass().getName());
- assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
- parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getClass().getName());
- assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters().getFlushPeriod());
-
- final SuperDooperDistributorParameters infinispanParameters =
- (SuperDooperDistributorParameters) parameters.getEngineServiceParameters().getEngineParameters()
- .getContextParameters().getDistributorParameters();
- assertEquals("org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperDistributorParameters",
- infinispanParameters.getClass().getName());
- assertEquals("my/lovely/configFile.xml", infinispanParameters.getConfigFile());
- assertEquals("holy/stone.xml", infinispanParameters.getJgroupsFile());
- assertEquals(false, infinispanParameters.isPreferIPv4Stack());
- assertEquals("fatherted", infinispanParameters.getJgroupsBindAddress());
-
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals("org.onap.policy.apex.context.parameters.ContextParameters", parameters
+ .getEngineServiceParameters().getEngineParameters().getContextParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.LockManagerParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getLockManagerParameters().getClass().getName());
+ assertEquals("org.onap.policy.apex.context.parameters.PersistorParameters",
+ parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getClass().getName());
+ assertEquals(123456, parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
+ .getPersistorParameters().getFlushPeriod());
+
+ final SuperDooperDistributorParameters infinispanParameters =
+ (SuperDooperDistributorParameters) parameters.getEngineServiceParameters().getEngineParameters()
+ .getContextParameters().getDistributorParameters();
+ assertEquals("org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperDistributorParameters",
+ infinispanParameters.getClass().getName());
+ assertEquals("my/lovely/configFile.xml", infinispanParameters.getConfigFile());
+ assertEquals("holy/stone.xml", infinispanParameters.getJgroupsFile());
+ assertEquals(false, infinispanParameters.isPreferIPv4Stack());
+ assertEquals("fatherted", infinispanParameters.getJgroupsBindAddress());
+
}
@Test
@@ -237,18 +200,14 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassDistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassDistParams.json\"\n"
- + "(ClassCastException):class "
- + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class"
- + " org.onap.policy.apex.context.parameters.DistributorParameters (org.onap.policy.apex.context."
- + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.DistributorParameters "
- + "are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassDistParams.json\"\n"
+ + "(ClassCastException):class "
+ + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class"
+ + " org.onap.policy.apex.context.parameters.DistributorParameters (org.onap.policy.apex.context."
+ + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.DistributorParameters "
+ + "are in unnamed module of loader 'app')");
}
@Test
@@ -256,18 +215,14 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassLockParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassLockParams.json\"\n"
- + "(ClassCastException):class "
- + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
- + "org.onap.policy.apex.context.parameters.LockManagerParameters (org.onap.policy.apex.context."
- + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.LockManagerParameters "
- + "are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassLockParams.json\"\n"
+ + "(ClassCastException):class "
+ + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
+ + "org.onap.policy.apex.context.parameters.LockManagerParameters (org.onap.policy.apex.context."
+ + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.LockManagerParameters "
+ + "are in unnamed module of loader 'app')");
}
@Test
@@ -275,17 +230,13 @@ public class ContextParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceContextBadClassPersistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceContextBadClassPersistParams.json\"\n"
- + "(ClassCastException):class "
- + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
- + "org.onap.policy.apex.context.parameters.PersistorParameters (org.onap.policy.apex.context."
- + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.PersistorParameters "
- + "are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassPersistParams.json\"\n"
+ + "(ClassCastException):class "
+ + "org.onap.policy.apex.context.parameters.ContextParameters cannot be cast to class "
+ + "org.onap.policy.apex.context.parameters.PersistorParameters (org.onap.policy.apex.context."
+ + "parameters.ContextParameters and org.onap.policy.apex.context.parameters.PersistorParameters "
+ + "are in unnamed module of loader 'app')");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
index 16a892f93..5d1b3f726 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.service.engine.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;
import org.junit.After;
import org.junit.Test;
@@ -44,17 +44,14 @@ public class ExecutorParameterTests {
}
@Test
- public void testNoParamsTest() {
+ public void testNoParamsTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorNoParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(0,
- parameters.getEngineServiceParameters().getEngineParameters().getExecutorParameterMap().size());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(0,
+ parameters.getEngineServiceParameters().getEngineParameters().getExecutorParameterMap().size());
+
}
@Test
@@ -62,15 +59,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ "\"src/test/resources/parameters/serviceExecutorBadParams.json\"\n"
+ "(ParameterRuntimeException):value of \"executorParameters:ZOOBY\" entry is not "
- + "a parameter JSON object", e.getMessage());
- }
+ + "a parameter JSON object");
}
@Test
@@ -78,15 +71,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorNoExecutorParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorNoExecutorParams.json\"\n"
- + "(ParameterRuntimeException):no \"executorParameters\" entry found in parameters,"
- + " at least one executor parameter entry must be specified", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorNoExecutorParams.json\"\n"
+ + "(ParameterRuntimeException):no \"executorParameters\" entry found in parameters,"
+ + " at least one executor parameter entry must be specified");
}
@Test
@@ -94,15 +83,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorEmptyParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorEmptyParams.json\"\n"
- + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
- + "in \"executorParameters:ZOOBY\" entry", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorEmptyParams.json\"\n"
+ + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
+ + "in \"executorParameters:ZOOBY\" entry");
}
@Test
@@ -110,15 +95,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginNameParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorBadPluginNameParams.json\"\n"
- + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
- + "in \"executorParameters:ZOOBY\" entry", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorBadPluginNameParams.json\"\n"
+ + "(ParameterRuntimeException):could not find field \"parameterClassName\" "
+ + "in \"executorParameters:ZOOBY\" entry");
}
@Test
@@ -126,15 +107,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginValueObjectParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorBadPluginValueObjectParams.json\"\n"
- + "(ParameterRuntimeException):value for field \"parameterClassName\" "
- + "of \"executorParameters:LOOBY\" entry is not a plain string", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorBadPluginValueObjectParams.json\"\n"
+ + "(ParameterRuntimeException):value for field \"parameterClassName\" "
+ + "of \"executorParameters:LOOBY\" entry is not a plain string");
}
@Test
@@ -142,15 +119,11 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginValueBlankParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorBadPluginValueBlankParams.json\"\n"
- + "(ParameterRuntimeException):value for field \"parameterClassName\" "
- + "in \"executorParameters:LOOBY\" entry is not specified or is blank", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceExecutorBadPluginValueBlankParams.json\"\n"
+ + "(ParameterRuntimeException):value for field \"parameterClassName\" "
+ + "in \"executorParameters:LOOBY\" entry is not specified or is blank");
}
@Test
@@ -158,38 +131,31 @@ public class ExecutorParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/serviceExecutorBadPluginValueParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from"
- + " \"src/test/resources/parameters/serviceExecutorBadPluginValueParams.json\"\n"
- + "(ParameterRuntimeException):failed to deserialize the parameters "
- + "for \"executorParameters:LOOBY\" to parameter class \"helloworld\"\n"
- + "java.lang.ClassNotFoundException: helloworld", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from"
+ + " \"src/test/resources/parameters/serviceExecutorBadPluginValueParams.json\"\n"
+ + "(ParameterRuntimeException):failed to deserialize the parameters "
+ + "for \"executorParameters:LOOBY\" to parameter class \"helloworld\"\n"
+ + "java.lang.ClassNotFoundException: helloworld");
}
@Test
- public void testGoodParametersTest() {
+ public void testGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+
}
@Test
- public void testRelativeParametersTest() {
+ public void testRelativeParametersTest() throws ParameterException {
// @formatter:off
final String[] args = {
"-rfr",
@@ -200,18 +166,14 @@ public class ExecutorParameterTests {
// @formatter:on
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- assertTrue(parameters.getEngineServiceParameters().getPolicyModelFileName()
- .endsWith("policymodels/SmallModel.json"));
- } catch (final ParameterException e) {
- fail("This test should not throw any exception: " + e.getMessage());
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+ assertTrue(parameters.getEngineServiceParameters().getPolicyModelFileName()
+ .endsWith("policymodels/SmallModel.json"));
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
index cbd9ee058..4948ab5f3 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
@@ -21,10 +21,10 @@
package org.onap.policy.apex.service.engine.parameters;
+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.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Arrays;
import org.junit.Test;
@@ -51,13 +51,9 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/invalidNoFile.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertTrue(e.getMessage().startsWith("error reading parameters from \"src"));
- assertTrue(e.getMessage().contains("FileNotFoundException"));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageStartingWith("error reading parameters from \"src")
+ .hasMessageContaining("FileNotFoundException");
}
@Test
@@ -65,13 +61,9 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/empty.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertTrue(e.getMessage()
- .startsWith("validation error(s) on parameters from \"src/test/resources/parameters/empty.json\""));
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageStartingWith("validation error(s) on parameters from \"src/test/resources/parameters/empty"
+ + ".json\"");
}
@Test
@@ -79,20 +71,16 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/noParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/noParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "engine service parameters are not specified\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "at least one event output must be specified\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "at least one event input must be specified\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/noParams.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
+ + "engine service parameters are not specified\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "at least one event output must be specified\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "at least one event input must be specified\n");
}
@Test
@@ -100,24 +88,19 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/blankParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
-
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/blankParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"ENGINE_SERVICE_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " field \"id\" type \"int\" value \"-1\" INVALID, "
- + "id not specified or specified value [-1] invalid, must be specified as id >= 0\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "at least one event output must be specified\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "at least one event input must be specified\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/blankParams.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"ENGINE_SERVICE_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
+ + "INVALID, parameter group has status INVALID\n"
+ + " field \"id\" type \"int\" value \"-1\" INVALID, "
+ + "id not specified or specified value [-1] invalid, must be specified as id >= 0\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "at least one event output must be specified\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "at least one event input must be specified\n");
}
@Test
@@ -125,45 +108,41 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/badParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/badParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"hello there\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " field \"name\" type \"java.lang.String\" value \"hello there\" INVALID, "
- + "name is invalid, it must match regular expression[A-Za-z0-9\\-_\\.]+\n"
- + " field \"id\" type \"int\" value \"-45\" INVALID, id not specified or "
- + "specified value [-45] invalid, must be specified as id >= 0\n"
- + " field \"instanceCount\" type \"int\" value \"-345\" INVALID, "
- + "instanceCount [-345] invalid, must be specified as instanceCount >= 1\n"
- + " field \"deploymentPort\" type \"int\" value \"65536\" INVALID, "
- + "deploymentPort [65536] invalid, must be specified as 1024 <= port <= 65535\n"
- + " field \"policyModelFileName\" type \"java.lang.String\" "
- + "value \"/some/file/name.xml\" INVALID, not found\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"FirstProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"TheFileConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/badParams.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"hello there\" type "
+ + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
+ + "INVALID, parameter group has status INVALID\n"
+ + " field \"name\" type \"java.lang.String\" value \"hello there\" INVALID, "
+ + "name is invalid, it must match regular expression[A-Za-z0-9\\-_\\.]+\n"
+ + " field \"id\" type \"int\" value \"-45\" INVALID, id not specified or "
+ + "specified value [-45] invalid, must be specified as id >= 0\n"
+ + " field \"instanceCount\" type \"int\" value \"-345\" INVALID, "
+ + "instanceCount [-345] invalid, must be specified as instanceCount >= 1\n"
+ + " field \"deploymentPort\" type \"int\" value \"65536\" INVALID, "
+ + "deploymentPort [65536] invalid, must be specified as 1024 <= port <= 65535\n"
+ + " field \"policyModelFileName\" type \"java.lang.String\" "
+ + "value \"/some/file/name.xml\" INVALID, not found\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"FirstProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"TheFileConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n");
}
@Test
@@ -171,125 +150,111 @@ public class ParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/badParamsModelNotFile.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "validation error(s) on parameters from "
- + "\"src/test/resources/parameters/badParamsModelNotFile.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"MyApexEngine\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n" + " field \"policyModelFileName\" "
- + "type \"java.lang.String\" value \"src/test\" INVALID, is not a plain file\n",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/badParamsModelNotFile.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group \"MyApexEngine\" type "
+ + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
+ + "INVALID, parameter group has status INVALID\n" + " field \"policyModelFileName\" "
+ + "type \"java.lang.String\" value \"src/test\" INVALID, is not a plain file\n");
}
@Test
- public void testGoodParametersTest() {
+ public void testGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals(2, parameters.getEventInputParameters().size());
- assertEquals(2, parameters.getEventOutputParameters().size());
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertTrue(parameters.getEventOutputParameters().containsKey("FirstProducer"));
- assertTrue(parameters.getEventOutputParameters().containsKey("MyOtherProducer"));
- assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventOutputParameters()
- .get("MyOtherProducer").getCarrierTechnologyParameters().getEventProducerPluginClass());
- assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventOutputParameters()
- .get("MyOtherProducer").getCarrierTechnologyParameters().getEventConsumerPluginClass());
- assertEquals("JSON",
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
- assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getEventProtocolParameters().getLabel());
+ assertEquals(2, parameters.getEventInputParameters().size());
+ assertEquals(2, parameters.getEventOutputParameters().size());
+ assertTrue(parameters.getEventOutputParameters().containsKey("FirstProducer"));
+ assertTrue(parameters.getEventOutputParameters().containsKey("MyOtherProducer"));
+ assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventOutputParameters()
+ .get("MyOtherProducer").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventOutputParameters()
+ .get("MyOtherProducer").getCarrierTechnologyParameters().getEventConsumerPluginClass());
+ assertEquals("JSON",
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
+ assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getEventProtocolParameters().getLabel());
- assertTrue(parameters.getEventInputParameters().containsKey("TheFileConsumer1"));
- assertTrue(parameters.getEventInputParameters().containsKey("MySuperDooperConsumer1"));
- assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getEventProtocolParameters().getLabel());
- assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getEventProtocolParameters().getLabel());
- assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventInputParameters()
- .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
- assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventInputParameters()
- .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
- assertEquals(SuperDooperEventProducer.class.getName(), parameters.getEventInputParameters()
- .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
- assertEquals(SuperDooperEventSubscriber.class.getName(), parameters.getEventInputParameters()
- .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ assertTrue(parameters.getEventInputParameters().containsKey("TheFileConsumer1"));
+ assertTrue(parameters.getEventInputParameters().containsKey("MySuperDooperConsumer1"));
+ assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getEventProtocolParameters().getLabel());
+ assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getEventProtocolParameters().getLabel());
+ assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventInputParameters()
+ .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventInputParameters()
+ .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
+ assertEquals(SuperDooperEventProducer.class.getName(), parameters.getEventInputParameters()
+ .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ assertEquals(SuperDooperEventSubscriber.class.getName(), parameters.getEventInputParameters()
+ .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
}
@Test
- public void testSuperDooperParametersTest() {
+ public void testSuperDooperParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/superDooperParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(345, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(345, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+ final CarrierTechnologyParameters prodCarrierTech =
+ parameters.getEventOutputParameters().get("FirstProducer").getCarrierTechnologyParameters();
+ final EventProtocolParameters prodEventProt =
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters();
+ final CarrierTechnologyParameters consCarrierTech =
+ parameters.getEventInputParameters().get("MySuperDooperConsumer1").getCarrierTechnologyParameters();
+ final EventProtocolParameters consEventProt =
+ parameters.getEventInputParameters().get("MySuperDooperConsumer1").getEventProtocolParameters();
- final CarrierTechnologyParameters prodCarrierTech =
- parameters.getEventOutputParameters().get("FirstProducer").getCarrierTechnologyParameters();
- final EventProtocolParameters prodEventProt =
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters();
- final CarrierTechnologyParameters consCarrierTech =
- parameters.getEventInputParameters().get("MySuperDooperConsumer1").getCarrierTechnologyParameters();
- final EventProtocolParameters consEventProt =
- parameters.getEventInputParameters().get("MySuperDooperConsumer1").getEventProtocolParameters();
+ assertEquals("SUPER_DOOPER", prodCarrierTech.getLabel());
+ assertEquals("SUPER_TOK_DEL", prodEventProt.getLabel());
+ assertEquals("SUPER_DOOPER", consCarrierTech.getLabel());
+ assertEquals("JSON", consEventProt.getLabel());
- assertEquals("SUPER_DOOPER", prodCarrierTech.getLabel());
- assertEquals("SUPER_TOK_DEL", prodEventProt.getLabel());
- assertEquals("SUPER_DOOPER", consCarrierTech.getLabel());
- assertEquals("JSON", consEventProt.getLabel());
+ assertTrue(prodCarrierTech instanceof SuperDooperCarrierTechnologyParameters);
- assertTrue(prodCarrierTech instanceof SuperDooperCarrierTechnologyParameters);
+ final SuperDooperCarrierTechnologyParameters superDooperParameters =
+ (SuperDooperCarrierTechnologyParameters) prodCarrierTech;
+ assertEquals("somehost:12345", superDooperParameters.getBootstrapServers());
+ assertEquals("0", superDooperParameters.getAcks());
+ assertEquals(25, superDooperParameters.getRetries());
+ assertEquals(98765, superDooperParameters.getBatchSize());
+ assertEquals(21, superDooperParameters.getLingerTime());
+ assertEquals(50505050, superDooperParameters.getBufferMemory());
+ assertEquals("first-group-id", superDooperParameters.getGroupId());
+ assertFalse(superDooperParameters.isEnableAutoCommit());
+ assertEquals(441, superDooperParameters.getAutoCommitTime());
+ assertEquals(987, superDooperParameters.getSessionTimeout());
+ assertEquals("producer-out", superDooperParameters.getProducerTopic());
+ assertEquals(101, superDooperParameters.getConsumerPollTime());
+ assertEquals("some.key.serailizer", superDooperParameters.getKeySerializer());
+ assertEquals("some.value.serailizer", superDooperParameters.getValueSerializer());
+ assertEquals("some.key.deserailizer", superDooperParameters.getKeyDeserializer());
+ assertEquals("some.value.deserailizer", superDooperParameters.getValueDeserializer());
- final SuperDooperCarrierTechnologyParameters superDooperParameters =
- (SuperDooperCarrierTechnologyParameters) prodCarrierTech;
- assertEquals("somehost:12345", superDooperParameters.getBootstrapServers());
- assertEquals("0", superDooperParameters.getAcks());
- assertEquals(25, superDooperParameters.getRetries());
- assertEquals(98765, superDooperParameters.getBatchSize());
- assertEquals(21, superDooperParameters.getLingerTime());
- assertEquals(50505050, superDooperParameters.getBufferMemory());
- assertEquals("first-group-id", superDooperParameters.getGroupId());
- assertFalse(superDooperParameters.isEnableAutoCommit());
- assertEquals(441, superDooperParameters.getAutoCommitTime());
- assertEquals(987, superDooperParameters.getSessionTimeout());
- assertEquals("producer-out", superDooperParameters.getProducerTopic());
- assertEquals(101, superDooperParameters.getConsumerPollTime());
- assertEquals("some.key.serailizer", superDooperParameters.getKeySerializer());
- assertEquals("some.value.serailizer", superDooperParameters.getValueSerializer());
- assertEquals("some.key.deserailizer", superDooperParameters.getKeyDeserializer());
- assertEquals("some.value.deserailizer", superDooperParameters.getValueDeserializer());
+ final String[] consumerTopics = {"consumer-out-0", "consumer-out-1", "consumer-out-2"};
+ assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
- final String[] consumerTopics = {"consumer-out-0", "consumer-out-1", "consumer-out-2"};
- assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
index df1960aa0..a80aa09c8 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.service.engine.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;
@@ -39,37 +40,33 @@ import org.onap.policy.common.parameters.ParameterException;
*/
public class ProducerConsumerTests {
@Test
- public void testGoodParametersTest() {
+ public void testGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
- assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON",
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
- assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getEventProtocolParameters().getLabel());
- assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getEventProtocolParameters().getLabel());
- assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getCarrierTechnologyParameters().getLabel());
- assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getEventProtocolParameters().getLabel());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+ assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON",
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
+ assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
+ .getEventProtocolParameters().getLabel());
+ assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
+ .getEventProtocolParameters().getLabel());
+ assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getCarrierTechnologyParameters().getLabel());
+ assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
+ .getEventProtocolParameters().getLabel());
}
@Test
@@ -77,20 +74,16 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoCT.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoCT.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "event handler carrierTechnologyParameters not specified or blank\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoCT.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
+ + "event handler carrierTechnologyParameters not specified or blank\n");
}
@Test
@@ -98,29 +91,25 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoEP.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoEP.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "event handler eventProtocolParameters not specified or blank\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoEP.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
+ + "event handler eventProtocolParameters not specified or blank\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n");
}
@Test
@@ -128,14 +117,10 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/prodConsNoCTParClass.json\"\n"
- + "(ParameterRuntimeException):carrier technology \"SUPER_DOOPER\" "
- + "parameter \"parameterClassName\" value \"null\" invalid in JSON file", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/prodConsNoCTParClass.json\"\n"
+ + "(ParameterRuntimeException):carrier technology \"SUPER_DOOPER\" "
+ + "parameter \"parameterClassName\" value \"null\" invalid in JSON file");
}
@Test
@@ -143,18 +128,14 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsMismatchCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/prodConsMismatchCTParClass.json\"\n"
- + "(ParameterRuntimeException):carrier technology \"SUPER_LOOPER\" "
- + "does not match plugin \"SUPER_DOOPER\" in \"" + "org.onap.policy.apex.service.engine."
- + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters"
- + "\", specify correct carrier technology parameter plugin "
- + "in parameter \"parameterClassName\"", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsMismatchCTParClass.json\"\n"
+ + "(ParameterRuntimeException):carrier technology \"SUPER_LOOPER\" "
+ + "does not match plugin \"SUPER_DOOPER\" in \"" + "org.onap.policy.apex.service.engine."
+ + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters"
+ + "\", specify correct carrier technology parameter plugin "
+ + "in parameter \"parameterClassName\"");
}
@Test
@@ -162,38 +143,31 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsWrongTypeCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n"
- + "(ParameterRuntimeException):could not create default parameters for carrier technology "
- + "\"SUPER_DOOPER\"\n" + "class org.onap.policy.apex.service.engine.parameters.dummyclasses."
- + "SuperTokenDelimitedEventProtocolParameters cannot be cast to class "
- + "org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters (org.onap."
- + "policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters "
- + "and org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters are in"
- + " unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n"
+ + "(ParameterRuntimeException):could not create default parameters for carrier technology "
+ + "\"SUPER_DOOPER\"\n" + "class org.onap.policy.apex.service.engine.parameters.dummyclasses."
+ + "SuperTokenDelimitedEventProtocolParameters cannot be cast to class "
+ + "org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters (org.onap."
+ + "policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters "
+ + "and org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters are in"
+ + " unnamed module of loader 'app')");
}
@Test
- public void testOkFileNameCarrierTechnology() {
+ public void testOkFileNameCarrierTechnology() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/prodConsOKFileName.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- final FileCarrierTechnologyParameters fileParams = (FileCarrierTechnologyParameters) parameters
- .getEventOutputParameters().get("aProducer").getCarrierTechnologyParameters();
- assertTrue(fileParams.getFileName().endsWith("target/aaa.json"));
- assertEquals(false, fileParams.isStandardError());
- assertEquals(false, fileParams.isStandardIo());
- assertEquals(false, fileParams.isStreamingMode());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ final FileCarrierTechnologyParameters fileParams = (FileCarrierTechnologyParameters) parameters
+ .getEventOutputParameters().get("aProducer").getCarrierTechnologyParameters();
+ assertTrue(fileParams.getFileName().endsWith("target/aaa.json"));
+ assertEquals(false, fileParams.isStandardError());
+ assertEquals(false, fileParams.isStandardIo());
+ assertEquals(false, fileParams.isStreamingMode());
+
}
@Test
@@ -201,25 +175,21 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsBadFileName.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/prodConsBadFileName.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " field \"fileName\" type "
- + "\"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/prodConsBadFileName.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, parameter group has status INVALID\n" + " parameter group \"FILE\" type "
+ + "\"org.onap.policy.apex.service.engine.event.impl."
+ + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " field \"fileName\" type "
+ + "\"java.lang.String\" value \"null\" INVALID, "
+ + "\"null\" invalid, must be specified as a non-empty string\n");
}
@Test
@@ -227,18 +197,12 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsBadEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "error reading parameters from \"src/test/resources/parameters/prodConsBadEPParClass.json\"\n"
- + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" "
- + "does not match plugin \"JSON\" in \"org.onap.policy.apex.service.engine.event.impl"
- + ".jsonprotocolplugin.JsonEventProtocolParameters"
- + "\", specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/prodConsBadEPParClass.json\"\n"
+ + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" "
+ + "does not match plugin \"JSON\" in \"org.onap.policy.apex.service.engine.event.impl"
+ + ".jsonprotocolplugin.JsonEventProtocolParameters"
+ + "\", specify correct event protocol parameter plugin in parameter \"parameterClassName\"");
}
@Test
@@ -246,14 +210,10 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsNoEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from \"src/test/resources/parameters/prodConsNoEPParClass.json\"\n"
- + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" parameter "
- + "\"parameterClassName\" value \"null\" invalid in JSON file", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from \"src/test/resources/parameters/prodConsNoEPParClass.json\"\n"
+ + "(ParameterRuntimeException):event protocol \"SUPER_TOK_DEL\" parameter "
+ + "\"parameterClassName\" value \"null\" invalid in JSON file");
}
@Test
@@ -261,20 +221,14 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsMismatchEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "error reading parameters from "
- + "\"src/test/resources/parameters/prodConsMismatchEPParClass.json\"\n"
- + "(ParameterRuntimeException):event protocol \"SUPER_TOK_BEL\" "
- + "does not match plugin \"SUPER_TOK_DEL\" in "
- + "\"org.onap.policy.apex.service.engine.parameters.dummyclasses."
- + "SuperTokenDelimitedEventProtocolParameters\", "
- + "specify correct event protocol parameter plugin in parameter \"parameterClassName\"",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsMismatchEPParClass.json\"\n"
+ + "(ParameterRuntimeException):event protocol \"SUPER_TOK_BEL\" "
+ + "does not match plugin \"SUPER_TOK_DEL\" in "
+ + "\"org.onap.policy.apex.service.engine.parameters.dummyclasses."
+ + "SuperTokenDelimitedEventProtocolParameters\", "
+ + "specify correct event protocol parameter plugin in parameter \"parameterClassName\"");
}
@Test
@@ -282,19 +236,15 @@ public class ProducerConsumerTests {
final String[] args = {"-c", "src/test/resources/parameters/prodConsWrongTypeEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("error reading parameters from "
- + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n"
- + "(ParameterRuntimeException):could not create default parameters for event protocol "
- + "\"SUPER_TOK_DEL\"\n" + "class org.onap.policy.apex.service.engine."
- + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters "
- + "cannot be cast to class org.onap.policy.apex.service."
- + "parameters.eventprotocol.EventProtocolParameters (org.onap.policy.apex.service.engine.parameters"
- + ".dummyclasses.SuperDooperCarrierTechnologyParameters and org.onap.policy.apex.service.parameters"
- + ".eventprotocol.EventProtocolParameters are in unnamed module of loader 'app')", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n"
+ + "(ParameterRuntimeException):could not create default parameters for event protocol "
+ + "\"SUPER_TOK_DEL\"\n" + "class org.onap.policy.apex.service.engine."
+ + "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters "
+ + "cannot be cast to class org.onap.policy.apex.service."
+ + "parameters.eventprotocol.EventProtocolParameters (org.onap.policy.apex.service.engine.parameters"
+ + ".dummyclasses.SuperDooperCarrierTechnologyParameters and org.onap.policy.apex.service.parameters"
+ + ".eventprotocol.EventProtocolParameters are in unnamed module of loader 'app')");
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
index be2c22c93..91f8c6699 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.service.engine.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;
import java.util.Arrays;
import org.junit.Test;
@@ -48,21 +48,17 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", specified peered mode \"SYNCHRONOUS\" "
- + "peer is illegal on eventOutputParameters \"SyncProducer0\" \n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", specified peered mode \"SYNCHRONOUS\" "
+ + "peer is illegal on eventOutputParameters \"SyncProducer0\" \n");
}
@Test
@@ -70,21 +66,17 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", specified peered mode \"SYNCHRONOUS\" peer is illegal "
- + "on eventOutputParameters \"SyncProducer0\" \n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", specified peered mode \"SYNCHRONOUS\" peer is illegal "
+ + "on eventOutputParameters \"SyncProducer0\" \n");
}
@Test
@@ -92,32 +84,28 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsBadPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsBadPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n" + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsBadPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n" + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n" + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS does not exist "
+ + "or is not defined with the same peered mode\n");
}
@Test
@@ -125,34 +113,30 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsInvalidTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsInvalidTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " specified peered mode \"SYNCHRONOUS\" timeout value \"-10\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-3\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-1\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " specified peered mode \"SYNCHRONOUS\" timeout value \"-99999999\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsInvalidTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " specified peered mode \"SYNCHRONOUS\" timeout value \"-10\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-3\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-1\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n"
+ + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " specified peered mode \"SYNCHRONOUS\" timeout value \"-99999999\" is illegal, "
+ + "specify a non-negative timeout value in milliseconds\n");
}
@Test
@@ -160,21 +144,17 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsBadTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsBadTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"MyOtherProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" "
- + "timeout is illegal on eventOutputParameters \"MyOtherProducer\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsBadTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" "
+ + "INVALID, parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"MyOtherProducer\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, specified peered mode \"SYNCHRONOUS\" "
+ + "timeout is illegal on eventOutputParameters \"MyOtherProducer\"\n");
}
@Test
@@ -182,36 +162,30 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncBadParamsUnpairedTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsUnpairedTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS timeout 10 on event handler "
- + "\"SyncProducer0\" does not equal timeout 1 on event handler \"SyncConsumer0\"\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 3 on event handler "
- + "\"SyncProducer1\" does not equal timeout 99999999 on event handler \"SyncConsumer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS timeout 1 on event handler "
- + "\"SyncConsumer0\" does not equal timeout 10 on event handler \"SyncProducer0\"\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 99999999 on event handler "
- + "\"SyncConsumer1\" does not equal timeout 3 on event handler \"SyncProducer1\"\n" + "",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncBadParamsUnpairedTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS timeout 10 on event handler "
+ + "\"SyncProducer0\" does not equal timeout 1 on event handler \"SyncConsumer0\"\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 3 on event handler "
+ + "\"SyncProducer1\" does not equal timeout 99999999 on event handler \"SyncConsumer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS timeout 1 on event handler "
+ + "\"SyncConsumer0\" does not equal timeout 10 on event handler \"SyncProducer0\"\n"
+ + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 99999999 on event handler "
+ + "\"SyncConsumer1\" does not equal timeout 3 on event handler \"SyncProducer1\"\n" + "");
}
@Test
@@ -219,19 +193,16 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParamsProducerTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (final Exception e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+
}
@Test
@@ -239,19 +210,16 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParamsConsumerTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (final Exception e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+
}
@Test
@@ -259,19 +227,16 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParamsBothTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- } catch (final Exception e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+ assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+
}
@Test
@@ -279,28 +244,24 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncUnusedConsumerPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncUnusedConsumerPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, peer \"SyncConsumer0 for peered mode SYNCHRONOUS, "
- + "value \"SyncProducer0\" on peer \"SyncConsumer0\" "
- + "does not equal event handler \"SyncProducer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, peer \"SyncProducer1 for peered mode SYNCHRONOUS, "
- + "value \"SyncConsumer0\" on peer \"SyncProducer1\" "
- + "does not equal event handler \"SyncConsumer1\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncUnusedConsumerPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, peer \"SyncConsumer0 for peered mode SYNCHRONOUS, "
+ + "value \"SyncProducer0\" on peer \"SyncConsumer0\" "
+ + "does not equal event handler \"SyncProducer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
+ + "INVALID, peer \"SyncProducer1 for peered mode SYNCHRONOUS, "
+ + "value \"SyncConsumer0\" on peer \"SyncProducer1\" "
+ + "does not equal event handler \"SyncConsumer1\"\n");
}
@Test
@@ -308,36 +269,30 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncMismatchedPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals(
- "validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncMismatchedPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS, value \"SyncProducer1\" "
- + "on peer \"SyncConsumer1\" does not equal event handler \"SyncProducer0\"\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer0\" "
- + "on peer \"SyncConsumer0\" does not equal event handler \"SyncProducer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" "
- + "on peer \"SyncProducer0\" does not equal event handler \"SyncConsumer0\"\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer0\" "
- + "on peer \"SyncProducer1\" does not equal event handler \"SyncConsumer1\"\n",
- e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncMismatchedPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS, value \"SyncProducer1\" "
+ + "on peer \"SyncConsumer1\" does not equal event handler \"SyncProducer0\"\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer0\" "
+ + "on peer \"SyncConsumer0\" does not equal event handler \"SyncProducer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" "
+ + "on peer \"SyncProducer0\" does not equal event handler \"SyncConsumer0\"\n"
+ + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer0\" "
+ + "on peer \"SyncProducer1\" does not equal event handler \"SyncConsumer1\"\n");
}
@Test
@@ -345,26 +300,22 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncUnusedProducerPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncUnusedProducerPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer1\" on peer "
- + "\"SyncConsumer0\" does not equal event handler \"SyncProducer0\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, parameter group map has status "
- + "INVALID\n parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" on peer "
- + "\"SyncProducer1\" does not equal event handler \"SyncConsumer0\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncUnusedProducerPeers.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n"
+ + " parameter group map \"eventOutputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer1\" on peer "
+ + "\"SyncConsumer0\" does not equal event handler \"SyncProducer0\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, parameter group map has status "
+ + "INVALID\n parameter group \"SyncConsumer0\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
+ + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" on peer "
+ + "\"SyncProducer1\" does not equal event handler \"SyncConsumer0\"\n");
}
@Test
@@ -372,100 +323,92 @@ public class SyncParameterTests {
final String[] args = {"-c", "src/test/resources/parameters/syncMismatchedTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- new ApexParameterHandler().getParameters(arguments);
- fail("This test should throw an exception");
- } catch (final ParameterException e) {
- assertEquals("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncMismatchedTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group map \"eventOutputParameters\" "
- + "INVALID, parameter group map has status INVALID\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 456 "
- + "on event handler \"SyncProducer1\" does not equal timeout 123 "
- + "on event handler \"SyncConsumer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 123 "
- + "on event handler \"SyncConsumer1\" does not equal timeout 456 "
- + "on event handler \"SyncProducer1\"\n", e.getMessage());
- }
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessage("validation error(s) on parameters from "
+ + "\"src/test/resources/parameters/syncMismatchedTimeout.json\"\n"
+ + "parameter group \"APEX_PARAMETERS\" type "
+ + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
+ + "parameter group has status INVALID\n" + " parameter group map \"eventOutputParameters\" "
+ + "INVALID, parameter group map has status INVALID\n"
+ + " parameter group \"SyncProducer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 456 "
+ + "on event handler \"SyncProducer1\" does not equal timeout 123 "
+ + "on event handler \"SyncConsumer1\"\n"
+ + " parameter group map \"eventInputParameters\" INVALID, "
+ + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
+ + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
+ + " peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 123 "
+ + "on event handler \"SyncConsumer1\" does not equal timeout 456 "
+ + "on event handler \"SyncProducer1\"\n");
}
@Test
- public void testSyncGoodParametersTest() {
+ public void testSyncGoodParametersTest() throws ParameterException {
final String[] args = {"-c", "src/test/resources/parameters/syncGoodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- try {
- final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
-
- assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
- assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
- assertEquals(45, parameters.getEngineServiceParameters().getId());
- assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
- assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
-
- final CarrierTechnologyParameters prodCT0 =
- parameters.getEventOutputParameters().get("SyncProducer0").getCarrierTechnologyParameters();
- final EventProtocolParameters prodEP0 =
- parameters.getEventOutputParameters().get("SyncProducer0").getEventProtocolParameters();
- final CarrierTechnologyParameters consCT0 =
- parameters.getEventInputParameters().get("SyncConsumer0").getCarrierTechnologyParameters();
- final EventProtocolParameters consEP0 =
- parameters.getEventInputParameters().get("SyncConsumer0").getEventProtocolParameters();
- final CarrierTechnologyParameters prodCT1 =
- parameters.getEventOutputParameters().get("SyncProducer1").getCarrierTechnologyParameters();
- final EventProtocolParameters prodEP1 =
- parameters.getEventOutputParameters().get("SyncProducer1").getEventProtocolParameters();
- final CarrierTechnologyParameters consCT1 =
- parameters.getEventInputParameters().get("SyncConsumer1").getCarrierTechnologyParameters();
- final EventProtocolParameters consEP1 =
- parameters.getEventInputParameters().get("SyncConsumer1").getEventProtocolParameters();
-
- assertEquals("FILE", prodCT0.getLabel());
- assertEquals("JSON", prodEP0.getLabel());
- assertEquals("FILE", consCT0.getLabel());
- assertEquals("JSON", consEP0.getLabel());
- assertEquals("FILE", prodCT1.getLabel());
- assertEquals("JSON", prodEP1.getLabel());
- assertEquals("SUPER_DOOPER", consCT1.getLabel());
- assertEquals("SUPER_TOK_DEL", consEP1.getLabel());
-
- assertTrue(consCT1 instanceof SuperDooperCarrierTechnologyParameters);
- assertTrue(consEP1 instanceof SuperTokenDelimitedEventProtocolParameters);
-
- final SuperDooperCarrierTechnologyParameters superDooperParameters =
- (SuperDooperCarrierTechnologyParameters) consCT1;
- assertEquals("localhost:9092", superDooperParameters.getBootstrapServers());
- assertEquals("all", superDooperParameters.getAcks());
- assertEquals(0, superDooperParameters.getRetries());
- assertEquals(16384, superDooperParameters.getBatchSize());
- assertEquals(1, superDooperParameters.getLingerTime());
- assertEquals(33554432, superDooperParameters.getBufferMemory());
- assertEquals("default-group-id", superDooperParameters.getGroupId());
- assertTrue(superDooperParameters.isEnableAutoCommit());
- assertEquals(1000, superDooperParameters.getAutoCommitTime());
- assertEquals(30000, superDooperParameters.getSessionTimeout());
- assertEquals("apex-out", superDooperParameters.getProducerTopic());
- assertEquals(100, superDooperParameters.getConsumerPollTime());
- assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
- superDooperParameters.getKeySerializer());
- assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
- superDooperParameters.getValueSerializer());
- assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
- superDooperParameters.getKeyDeserializer());
- assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
- superDooperParameters.getValueDeserializer());
-
- final String[] consumerTopics = {"apex-in"};
- assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
- } catch (final ParameterException e) {
- fail("This test should not throw an exception");
- }
+ final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ assertEquals("MyApexEngine", parameters.getEngineServiceParameters().getName());
+ assertEquals("0.0.1", parameters.getEngineServiceParameters().getVersion());
+ assertEquals(45, parameters.getEngineServiceParameters().getId());
+ assertEquals(19, parameters.getEngineServiceParameters().getInstanceCount());
+ assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
+
+ final CarrierTechnologyParameters prodCT0 =
+ parameters.getEventOutputParameters().get("SyncProducer0").getCarrierTechnologyParameters();
+ final EventProtocolParameters prodEP0 =
+ parameters.getEventOutputParameters().get("SyncProducer0").getEventProtocolParameters();
+ final CarrierTechnologyParameters consCT0 =
+ parameters.getEventInputParameters().get("SyncConsumer0").getCarrierTechnologyParameters();
+ final EventProtocolParameters consEP0 =
+ parameters.getEventInputParameters().get("SyncConsumer0").getEventProtocolParameters();
+ final CarrierTechnologyParameters prodCT1 =
+ parameters.getEventOutputParameters().get("SyncProducer1").getCarrierTechnologyParameters();
+ final EventProtocolParameters prodEP1 =
+ parameters.getEventOutputParameters().get("SyncProducer1").getEventProtocolParameters();
+ final CarrierTechnologyParameters consCT1 =
+ parameters.getEventInputParameters().get("SyncConsumer1").getCarrierTechnologyParameters();
+ final EventProtocolParameters consEP1 =
+ parameters.getEventInputParameters().get("SyncConsumer1").getEventProtocolParameters();
+
+ assertEquals("FILE", prodCT0.getLabel());
+ assertEquals("JSON", prodEP0.getLabel());
+ assertEquals("FILE", consCT0.getLabel());
+ assertEquals("JSON", consEP0.getLabel());
+ assertEquals("FILE", prodCT1.getLabel());
+ assertEquals("JSON", prodEP1.getLabel());
+ assertEquals("SUPER_DOOPER", consCT1.getLabel());
+ assertEquals("SUPER_TOK_DEL", consEP1.getLabel());
+
+ assertTrue(consCT1 instanceof SuperDooperCarrierTechnologyParameters);
+ assertTrue(consEP1 instanceof SuperTokenDelimitedEventProtocolParameters);
+
+ final SuperDooperCarrierTechnologyParameters superDooperParameters =
+ (SuperDooperCarrierTechnologyParameters) consCT1;
+ assertEquals("localhost:9092", superDooperParameters.getBootstrapServers());
+ assertEquals("all", superDooperParameters.getAcks());
+ assertEquals(0, superDooperParameters.getRetries());
+ assertEquals(16384, superDooperParameters.getBatchSize());
+ assertEquals(1, superDooperParameters.getLingerTime());
+ assertEquals(33554432, superDooperParameters.getBufferMemory());
+ assertEquals("default-group-id", superDooperParameters.getGroupId());
+ assertTrue(superDooperParameters.isEnableAutoCommit());
+ assertEquals(1000, superDooperParameters.getAutoCommitTime());
+ assertEquals(30000, superDooperParameters.getSessionTimeout());
+ assertEquals("apex-out", superDooperParameters.getProducerTopic());
+ assertEquals(100, superDooperParameters.getConsumerPollTime());
+ assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
+ superDooperParameters.getKeySerializer());
+ assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
+ superDooperParameters.getValueSerializer());
+ assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
+ superDooperParameters.getKeyDeserializer());
+ assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
+ superDooperParameters.getValueDeserializer());
+
+ final String[] consumerTopics = {"apex-in"};
+ assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
index 4b79dc589..d39cbecf0 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * 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,9 +21,9 @@
package org.onap.policy.apex.services.onappf.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;
import java.io.FileNotFoundException;
import org.junit.Test;
@@ -44,13 +45,9 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments emptyArguments = new ApexStarterCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
- try {
- new ApexStarterParameterHandler().getParameters(emptyArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getCause() instanceof CoderException);
- assertTrue(e.getCause().getCause() instanceof FileNotFoundException);
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(emptyArguments))
+ .hasCauseInstanceOf(CoderException.class)
+ .hasRootCauseInstanceOf(FileNotFoundException.class);
}
@Test
@@ -60,12 +57,8 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new ApexStarterParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("no parameters found"));
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("no parameters found");
}
@Test
@@ -75,13 +68,9 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments invalidArguments = new ApexStarterCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
- try {
- new ApexStarterParameterHandler().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 ApexStarterParameterHandler().getParameters(invalidArguments))
+ .hasMessageStartingWith("error reading parameters from")
+ .hasCauseInstanceOf(CoderException.class);
}
@Test
@@ -91,11 +80,8 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new ApexStarterParameterHandler().getParameters(noArguments);
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains("is null"));
- }
+ assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(noArguments))
+ .hasMessageContaining("is null");
}
@Test
@@ -118,13 +104,9 @@ public class TestApexStarterParameterHandler {
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
arguments.parse(apexStarterConfigParameters);
- try {
- new ApexStarterParameterHandler().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 ApexStarterParameterHandler().getParameters(arguments))
+ .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a "
+ + "non-blank string");
}
@Test
@@ -147,10 +129,7 @@ public class TestApexStarterParameterHandler {
public void testApexStarterInvalidOption() throws ApexStarterException {
final String[] apexStarterConfigParameters = { "-d" };
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
- try {
- arguments.parse(apexStarterConfigParameters);
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
- }
+ assertThatThrownBy(() -> arguments.parse(apexStarterConfigParameters))
+ .hasMessageStartingWith("invalid command line arguments specified");
}
}
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java
index 3d6519a65..6af2959ed 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java
@@ -21,8 +21,8 @@
package org.onap.policy.apex.tools.model.generator;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -77,40 +77,30 @@ public class SchemaUtilsTest {
@Test
public void testSchemaUtilsErrors() throws ApexEventException {
AxEvent event = avroModel.getEvents().get("CustomerContextEventIn");
- AxContextSchema avroCtxtSchema = avroModel.getSchemas().get("ctxtTopologyNodesDecl");
- AxArtifactKey topoNodesKey = new AxArtifactKey("albumTopoNodes", "0.0.1");
- try {
- SchemaUtils.getEventSchema(event);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
- + " not found in model service", apEx.getMessage());
- }
-
- try {
+ assertThatThrownBy(() -> SchemaUtils.getEventSchema(event))
+ .hasMessage("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
+ + " not found in model service");
+
+ assertThatThrownBy(() -> {
Map<String, Schema> preexistingParamSchemas = new LinkedHashMap<>();
SchemaUtils.getEventParameterSchema(event.getParameterMap().get("links"), preexistingParamSchemas);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
- + " not found in model service", apEx.getMessage());
- }
+ }).hasMessage("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
+ + " not found in model service");
List<Field> skeletonFields = SchemaUtils.getSkeletonEventSchemaFields();
assertEquals(5, skeletonFields.size());
- try {
+ AxContextSchema avroCtxtSchema = avroModel.getSchemas().get("ctxtTopologyNodesDecl");
+ AxArtifactKey topoNodesKey = new AxArtifactKey("albumTopoNodes", "0.0.1");
+ assertThatThrownBy(() -> {
AvroSchemaHelper schemaHelper = (AvroSchemaHelper) new SchemaHelperFactory()
.createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
Map<String, Schema> schemaMap = new LinkedHashMap<>();
SchemaUtils.processSubSchemas(schemaHelper.getAvroSchema(), schemaMap);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
- + " not found in model service", apEx.getMessage());
- }
+ }).hasMessage("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
+ + " not found in model service");
}
@Test
@@ -124,8 +114,6 @@ public class SchemaUtilsTest {
ModelService.registerModel(AxContextSchemas.class, avroModel.getSchemas());
AxEvent event = avroModel.getEvents().get("CustomerContextEventIn");
- AxContextSchema avroCtxtSchema = avroModel.getSchemas().get("ctxtTopologyNodesDecl");
- AxArtifactKey topoNodesKey = new AxArtifactKey("albumTopoNodes", "0.0.1");
Schema eventSchema = SchemaUtils.getEventSchema(event);
assertEquals("{\"type\":\"record\",\"name\":\"CustomerContextEventIn\"",
@@ -136,19 +124,18 @@ public class SchemaUtilsTest {
SchemaUtils.getEventParameterSchema(event.getParameterMap().get("links"), preexistingParamSchemas);
assertEquals("\"string\"", epSchema.toString());
+ AxContextSchema avroCtxtSchema = avroModel.getSchemas().get("ctxtTopologyNodesDecl");
+ AxArtifactKey topoNodesKey = new AxArtifactKey("albumTopoNodes", "0.0.1");
List<Field> skeletonFields = SchemaUtils.getSkeletonEventSchemaFields();
assertEquals(5, skeletonFields.size());
- try {
+ assertThatThrownBy(() -> {
AvroSchemaHelper schemaHelper = (AvroSchemaHelper) new SchemaHelperFactory()
.createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
Map<String, Schema> schemaMap = new LinkedHashMap<>();
SchemaUtils.processSubSchemas(schemaHelper.getAvroSchema(), schemaMap);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("context schema helper parameters not found for context schema \"Avro\"", apEx.getMessage());
- }
+ }).hasMessage("context schema helper parameters not found for context schema \"Avro\"");
schemaParameters.getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters());
@@ -156,11 +143,7 @@ public class SchemaUtilsTest {
(AvroSchemaHelper) new SchemaHelperFactory().createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
Map<String, Schema> schemaMap = new LinkedHashMap<>();
- try {
- SchemaUtils.processSubSchemas(schemaHelper.getAvroSchema(), schemaMap);
- } catch (Exception exc) {
- fail("test should not throw an exception");
- }
+ SchemaUtils.processSubSchemas(schemaHelper.getAvroSchema(), schemaMap);
eventSchema = SchemaUtils.getEventSchema(event);
assertEquals("{\"type\":\"record\",\"name\":\"CustomerContextEventIn\"",
@@ -179,12 +162,8 @@ public class SchemaUtilsTest {
assertEquals(5, skeletonFields.size());
schemaParameters.getSchemaHelperParameterMap().put("Avro", new JavaSchemaHelperParameters());
- try {
- ep2Schema = SchemaUtils.getEventParameterSchema(inField, preexistingParamSchemas);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("FieldParent:0.0.1:NULL:Field: class/type", apEx.getMessage().substring(0, 40));
- }
+ assertThatThrownBy(() -> SchemaUtils.getEventParameterSchema(inField, preexistingParamSchemas))
+ .hasMessageContaining("FieldParent:0.0.1:NULL:Field: class/type");
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ModelService.clear();
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java
index a109e47da..1263dc4fd 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java
@@ -22,7 +22,6 @@
package org.onap.policy.apex.tools.model.generator.model2cli;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -36,13 +35,9 @@ import org.junit.Test;
public class Model2CliTest {
@Test
public void testModel2Cli() {
- try {
- final String[] cliArgs = {"-h"};
+ final String[] cliArgs = {"-h"};
- Model2CliMain.main(cliArgs);
- } catch (Exception exc) {
- fail("test should not throw an exception");
- }
+ Model2CliMain.main(cliArgs);
}
@Test
@@ -104,27 +99,27 @@ public class Model2CliTest {
}
@Test
- public void testModel2CliAnomaly() {
+ public void testModel2CliAnomaly() throws IOException {
testModel2CliModel("target/examples/models/Adaptive", "AnomalyDetectionPolicyModel");
}
@Test
- public void testModel2CliAutoLearn() {
+ public void testModel2CliAutoLearn() throws IOException {
testModel2CliModel("target/examples/models/Adaptive", "AutoLearnPolicyModel");
}
@Test
- public void testModel2CliJms() {
+ public void testModel2CliJms() throws IOException {
testModel2CliModel("target/examples/models/JMS", "JMSTestModel");
}
@Test
- public void testModel2CliMfp() {
+ public void testModel2CliMfp() throws IOException {
testModel2CliModel("target/examples/models/MyFirstPolicy/2", "MyFirstPolicyModel_0.0.1");
}
@Test
- public void testModel2CliSample() {
+ public void testModel2CliSample() throws IOException {
testModel2CliModel("target/examples/models/SampleDomain", "SamplePolicyModelJAVASCRIPT");
}
@@ -151,26 +146,23 @@ public class Model2CliTest {
*
* @param modelName the name of the model file
*/
- private void testModel2CliModel(final String modelPath, final String modelName) {
- try {
- File tempFile = File.createTempFile(modelName, ".apex");
- tempFile.deleteOnExit();
-
- // @formatter:off
- final String[] cliArgs = {
- "-m",
- modelPath + "/" + modelName + ".json",
- "-o",
- tempFile.getCanonicalPath(),
- "-ow"
- };
- // @formatter:on
- runModel2Cli(cliArgs);
-
- assertTrue(tempFile.isFile());
- assertTrue(tempFile.length() > 0);
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ private void testModel2CliModel(final String modelPath, final String modelName) throws IOException {
+ File tempFile = File.createTempFile(modelName, ".apex");
+ tempFile.deleteOnExit();
+
+ // @formatter:off
+ final String[] cliArgs = {
+ "-m",
+ modelPath + "/" + modelName + ".json",
+ "-o",
+ tempFile.getCanonicalPath(),
+ "-ow"
+ };
+ // @formatter:on
+ runModel2Cli(cliArgs);
+
+ assertTrue(tempFile.isFile());
+ assertTrue(tempFile.length() > 0);
+
}
}
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java
index f7c913054..58c860d1c 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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=========================================================
*/
@@ -21,14 +22,12 @@
package org.onap.policy.apex.tools.model.generator.model2event;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
/**
* Test the Model2Event utility.
@@ -36,14 +35,11 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
public class Model2EventTest {
@Test
public void testModel2Event() {
- try {
- final String[] EventArgs =
- { "-h" };
-
- Model2EventMain.main(EventArgs);
- } catch (Exception exc) {
- fail("test should not throw an exception");
- }
+ final String[] EventArgs =
+ { "-h" };
+
+ Model2EventMain.main(EventArgs);
+
}
@Test
@@ -112,28 +108,28 @@ public class Model2EventTest {
}
@Test
- public void testModel2EventAnomaly() {
+ public void testModel2EventAnomaly() throws IOException {
testModel2EventModel("AnomalyDetectionPolicyModel");
}
@Test
- public void testModel2EventAutoLearn() {
+ public void testModel2EventAutoLearn() throws IOException {
testModel2EventModel("AutoLearnPolicyModel");
}
@Test
- public void testModel2EventMfp() {
+ public void testModel2EventMfp() throws IOException {
testModel2EventModel("MyFirstPolicyModel");
}
@Test
- public void testModel2EventSample() {
+ public void testModel2EventSample() throws IOException {
testModel2EventModel("SamplePolicyModelJAVASCRIPT");
}
/**
* Run the application.
- *
+ *
* @param eventArgs the command arguments
* @return a string containing the command output
*/
@@ -151,31 +147,27 @@ public class Model2EventTest {
/**
* Test Event generation.
- *
+ *
* @param modelName the name of the model file
*/
- private void testModel2EventModel(String modelName) {
- try {
- File tempFile = File.createTempFile(modelName, ".apex");
- tempFile.deleteOnExit();
+ private void testModel2EventModel(String modelName) throws IOException {
+ File tempFile = File.createTempFile(modelName, ".apex");
+ tempFile.deleteOnExit();
- final String[] eventArgs0 =
- { "-m", "src/test/resources/models/" + modelName + ".json", "-t", "stimuli" };
- final String outputString0 = runModel2Event(eventArgs0);
+ final String[] eventArgs0 =
+ { "-m", "src/test/resources/models/" + modelName + ".json", "-t", "stimuli" };
+ final String outputString0 = runModel2Event(eventArgs0);
- assertTrue(outputString0.contains("type: stimuli"));
+ assertTrue(outputString0.contains("type: stimuli"));
- final String[] eventArgs1 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "response" };
- final String outputString1 = runModel2Event(eventArgs1);
+ final String[] eventArgs1 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "response" };
+ final String outputString1 = runModel2Event(eventArgs1);
- assertTrue(outputString1.contains("type: response"));
+ assertTrue(outputString1.contains("type: response"));
- final String[] eventArgs2 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "internal" };
- final String outputString2 = runModel2Event(eventArgs2);
+ final String[] eventArgs2 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "internal" };
+ final String outputString2 = runModel2Event(eventArgs2);
- assertTrue(outputString2.contains("type: internal"));
- } catch (Exception e) {
- throw new ApexRuntimeException("test should not throw an exception", e);
- }
+ assertTrue(outputString2.contains("type: internal"));
}
}
diff --git a/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java b/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java
index 9ca7e9296..8ff185504 100644
--- a/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java
+++ b/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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=========================================================
*/
@@ -21,7 +22,6 @@
package org.onap.policy.apex.tools.simple.wsclient;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -35,14 +35,10 @@ import org.junit.Test;
public class WsClientTest {
@Test
public void testWsClient() {
- try {
- final String[] EventArgs =
- { "-h" };
-
- WsClientMain.main(EventArgs);
- } catch (Exception exc) {
- fail("test should not throw an exception");
- }
+ final String[] EventArgs =
+ { "-h" };
+
+ WsClientMain.main(EventArgs);
}
@Test