aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2020-07-17 18:30:21 +0000
committerGerrit Code Review <gerrit@onap.org>2020-07-17 18:30:21 +0000
commit30e93de6d5feb9ebc29fbf911f1eb37bbf9962c2 (patch)
treef870a9b163d8b22899a717635a0ecd0e7c32af58
parent3ff6447c92760883e53f5d6a2d7dc727ea486700 (diff)
parent4752a9ede61f2df4e67ec18f6c53cdcd0c35885f (diff)
Merge "Replace try/catch with assertj - apex-pdp"
-rw-r--r--auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java26
-rw-r--r--context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java212
-rw-r--r--testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java54
-rw-r--r--testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/SequentialContextInstantiation.java108
-rw-r--r--testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java18
-rw-r--r--testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java20
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceModelUpdateTest.java42
-rw-r--r--testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java396
8 files changed, 275 insertions, 601 deletions
diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
index 83aef2d07..921591b32 100644
--- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
+++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
@@ -2,19 +2,20 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
+ * 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=========================================================
*/
@@ -22,11 +23,9 @@
package org.onap.policy.apex.auth.clicodegen;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
@@ -65,32 +64,25 @@ public class CodeGeneratorCliEditorTest {
private File outFile = null;
@Test
- public void test() throws IOException {
+ public void test() throws IOException, ApexModelException {
final CodeGeneratorCliEditor codeGen = new CodeGeneratorCliEditor();
outFile = File.createTempFile("ApexTestGenerated", ".apex");
ApexModelReader<AxPolicyModel> modelReader = null;
- try {
- modelReader = new ApexModelReader<>(AxPolicyModel.class);
- } catch (ApexModelException e1) {
- fail("test should not throw an exception");
- }
+ modelReader = new ApexModelReader<>(AxPolicyModel.class);
+
modelReader.setValidateFlag(false);
AxPolicyModel apexPolicyModel = null;
- try {
- apexPolicyModel = modelReader
+ apexPolicyModel = modelReader
.read(new FileInputStream(new File("src/test/resources/models/TestPolicyModel.json")));
- } catch (ApexModelException | FileNotFoundException e) {
- fail("test should not throw an exception");
- }
assertEquals(0, generateCli(codeGen, apexPolicyModel));
}
/**
* Generate the CLI from the model.
- *
+ *
* @param codeGen the code generator
* @param policyModel the policy model
* @throws IOException on generation exceptions
diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java
index 51802919c..5aaa8a38a 100644
--- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java
+++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/ContextAlbumImplTest.java
@@ -21,10 +21,10 @@
package org.onap.policy.apex.context.impl;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -33,14 +33,12 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
-import org.onap.policy.apex.context.ContextRuntimeException;
import org.onap.policy.apex.context.Distributor;
import org.onap.policy.apex.context.impl.distribution.jvmlocal.JvmLocalDistributor;
import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.ContextParameters;
import org.onap.policy.apex.context.parameters.SchemaParameters;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
@@ -93,42 +91,19 @@ public class ContextAlbumImplTest {
@Test
public void testNullsOnConstructor() {
- try {
- new ContextAlbumImpl(null, null, null);
- fail("this test should throw an exception");
- } catch (IllegalArgumentException e) {
- assertEquals("Context album definition may not be null", e.getMessage());
- } catch (ContextException e) {
- fail("this test should throw an IllegalArgumentException");
- }
-
- try {
- new ContextAlbumImpl(new AxContextAlbum(), null, null);
- fail("this test should throw an exception");
- } catch (IllegalArgumentException e) {
- assertEquals("Distributor may not be null", e.getMessage());
- } catch (ContextException e) {
- fail("this test should throw an IllegalArgumentException");
- }
-
- try {
- new ContextAlbumImpl(new AxContextAlbum(), new JvmLocalDistributor(), null);
- fail("this test should throw an exception");
- } catch (IllegalArgumentException e) {
- assertEquals("Album map may not be null", e.getMessage());
- } catch (ContextException e) {
- fail("this test should throw an IllegalArgumentException");
- }
-
- try {
- new ContextAlbumImpl(new AxContextAlbum(), new JvmLocalDistributor(), new LinkedHashMap<String, Object>());
- fail("this test should throw an exception");
- } catch (ApexRuntimeException e) {
- assertEquals("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas "
- + "not found in model service", e.getMessage());
- } catch (ContextException e) {
- fail("this test should throw an ApexRuntimeException");
- }
+ assertThatThrownBy(() -> new ContextAlbumImpl(null, null, null))
+ .hasMessage("Context album definition may not be null");
+
+ assertThatThrownBy(() -> new ContextAlbumImpl(new AxContextAlbum(), null, null))
+ .hasMessage("Distributor may not be null");
+
+ assertThatThrownBy(() -> new ContextAlbumImpl(new AxContextAlbum(), new JvmLocalDistributor(), null))
+ .hasMessage("Album map may not be null");
+
+ assertThatThrownBy(() -> new ContextAlbumImpl(new AxContextAlbum(), new JvmLocalDistributor(),
+ new LinkedHashMap<String, Object>()))
+ .hasMessage("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas "
+ + "not found in model service");
}
@Test
@@ -142,107 +117,63 @@ public class ContextAlbumImplTest {
AxContextAlbum axContextAlbum = new AxContextAlbum(new AxArtifactKey("TestContextAlbum", "0.0.1"), "Policy",
true, AxArtifactKey.getNullKey());
- try {
- new ContextAlbumImpl(axContextAlbum, new JvmLocalDistributor(), new LinkedHashMap<String, Object>());
- fail("this test should throw an exception");
- } catch (ContextException e) {
- assertEquals("could not initiate schema management for context album AxContextAlbum",
- e.getMessage().substring(0, 69));
- }
+ assertThatThrownBy(() -> new ContextAlbumImpl(axContextAlbum, new JvmLocalDistributor(),
+ new LinkedHashMap<String, Object>()))
+ .hasMessageContaining("could not initiate schema management for context album AxContextAlbum");
axContextAlbum.setItemSchema(simpleStringSchema.getKey());
Distributor distributor = new JvmLocalDistributor();
distributor.init(axContextAlbum.getKey());
ContextAlbum album = new ContextAlbumImpl(axContextAlbum, distributor, new LinkedHashMap<String, Object>());
- AxContextAlbum axContextAlbumRo = new AxContextAlbum(new AxArtifactKey("TestContextAlbum", "0.0.1"), "Policy",
- false, simpleStringSchema.getKey());
- ContextAlbum albumRo = new ContextAlbumImpl(axContextAlbumRo, distributor, new LinkedHashMap<String, Object>());
-
assertEquals("TestContextAlbum", album.getName());
assertEquals("TestContextAlbum:0.0.1", album.getKey().getId());
assertEquals("TestContextAlbum:0.0.1", album.getAlbumDefinition().getId());
assertEquals("SimpleStringSchema:0.0.1", album.getSchemaHelper().getSchema().getId());
- try {
- album.containsKey(null);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("null values are illegal on method parameter \"key\"", e.getMessage());
- }
+ assertThatThrownBy(() -> album.containsKey(null))
+ .hasMessage("null values are illegal on method parameter \"key\"");
assertEquals(false, album.containsKey("Key0"));
- try {
- album.containsValue(null);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("null values are illegal on method parameter \"value\"", e.getMessage());
- }
+ assertThatThrownBy(() -> album.containsValue(null))
+ .hasMessage("null values are illegal on method parameter \"value\"");
assertEquals(false, album.containsValue("some value"));
- try {
- album.get(null);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" null keys are illegal on keys for get()", e.getMessage());
- }
-
- try {
- album.put(null, null);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" null keys are illegal on keys for put()", e.getMessage());
- }
-
- try {
- album.put("KeyNull", null);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" null values are illegal on key \"KeyNull\" for put()",
- e.getMessage());
- }
-
- try {
- albumRo.put("KeyReadOnly", "A value for a Read Only Album");
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" put() not allowed on read only albums "
- + "for key=\"KeyReadOnly\", value=\"A value for a Read Only Album", e.getMessage());
- }
+ assertThatThrownBy(() -> album.get(null))
+ .hasMessage("album \"TestContextAlbum:0.0.1\" null keys are illegal on keys for get()");
+
+ assertThatThrownBy(() -> album.put(null, null))
+ .hasMessage("album \"TestContextAlbum:0.0.1\" null keys are illegal on keys for put()");
+
+ assertThatThrownBy(() -> album.put("KeyNull", null))
+ .hasMessage("album \"TestContextAlbum:0.0.1\" null values are illegal on key \"KeyNull\""
+ + " for put()");
+
+ AxContextAlbum axContextAlbumRo = new AxContextAlbum(new AxArtifactKey("TestContextAlbum", "0.0.1"), "Policy",
+ false, simpleStringSchema.getKey());
+ ContextAlbum albumRo = new ContextAlbumImpl(axContextAlbumRo, distributor, new LinkedHashMap<String, Object>());
+
+ assertThatThrownBy(() -> albumRo.put("KeyReadOnly", "A value for a Read Only Album"))
+ .hasMessage("album \"TestContextAlbum:0.0.1\" put() not allowed on read only albums "
+ + "for key=\"KeyReadOnly\", value=\"A value for a Read Only Album");
Map<String, Object> putAllData = new LinkedHashMap<>();
putAllData.put("AllKey0", "vaue of AllKey0");
putAllData.put("AllKey1", "vaue of AllKey1");
putAllData.put("AllKey2", "vaue of AllKey2");
- try {
- albumRo.putAll(putAllData);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" putAll() not allowed on read only albums", e.getMessage());
- }
-
- try {
- albumRo.remove("AllKey0");
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" remove() not allowed "
- + "on read only albums for key=\"AllKey0\"", e.getMessage());
- }
-
- try {
- album.remove(null);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("null values are illegal on method parameter \"keyID\"", e.getMessage());
- }
-
- try {
- albumRo.clear();
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" clear() not allowed on read only albums", e.getMessage());
- }
+ assertThatThrownBy(() -> albumRo.putAll(putAllData))
+ .hasMessage("album \"TestContextAlbum:0.0.1\" putAll() not allowed on read only albums");
+
+ assertThatThrownBy(() -> albumRo.remove("AllKey0"))
+ .hasMessage("album \"TestContextAlbum:0.0.1\" remove() not allowed "
+ + "on read only albums for key=\"AllKey0\"");
+
+ assertThatThrownBy(() -> album.remove(null))
+ .hasMessage("null values are illegal on method parameter \"keyID\"");
+
+ assertThatThrownBy(albumRo::clear)
+ .hasMessage("album \"TestContextAlbum:0.0.1\" clear() not allowed on read only albums");
// The following locking tests pass because the locking protects access to Key0 across all
// copies of the distributed album whether the key exists or not
@@ -286,13 +217,8 @@ public class ContextAlbumImplTest {
// The flush() operation fails because the distributor is not initialized with the album which
// is fine for unit test
- try {
- album.flush();
- fail("test should throw an exception");
- } catch (ContextException e) {
- assertEquals("map flush failed, supplied map is null", e.getMessage());
- }
-
+ assertThatThrownBy(album::flush)
+ .hasMessage("map flush failed, supplied map is null");
assertEquals(1, album.size());
assertEquals(false, album.isEmpty());
@@ -302,14 +228,9 @@ public class ContextAlbumImplTest {
album.putAll(putAllData);
putAllData.put("AllKey3", null);
- try {
- album.putAll(putAllData);
- fail("test should throw an exception");
- } catch (ContextRuntimeException e) {
- assertEquals("album \"TestContextAlbum:0.0.1\" null values are illegal on key \"AllKey3\" for put()",
- e.getMessage());
- }
-
+ assertThatThrownBy(() -> album.putAll(putAllData))
+ .hasMessage("album \"TestContextAlbum:0.0.1\" null values are illegal on key "
+ + "\"AllKey3\" for put()");
assertEquals("New value of Key0", album.remove("Key0"));
album.clear();
@@ -353,15 +274,13 @@ public class ContextAlbumImplTest {
otherAlbum.put("Key", 123);
assertNotEquals(album, otherAlbum);
- try {
- otherAlbum.put("Key", "BadValue");
- fail("test should throw an exception here");
- } catch (ContextRuntimeException cre) {
- assertEquals("Failed to set context value for key \"Key\" in album \"TestContextAlbum:0.0.1\": "
+ assertThatThrownBy(() -> {
+ ContextAlbumImpl otherAlbumBad = new ContextAlbumImpl(axContextAlbum, distributor,
+ new LinkedHashMap<String, Object>());
+ otherAlbumBad.put("Key", "BadValue");
+ }).hasMessage("Failed to set context value for key \"Key\" in album \"TestContextAlbum:0.0.1\": "
+ "TestContextAlbum:0.0.1: object \"BadValue\" of class \"java.lang.String\" "
- + "not compatible with class \"java.lang.Integer\"", cre.getMessage());
- }
-
+ + "not compatible with class \"java.lang.Integer\"");
AxContextAlbum otherAxContextAlbum = new AxContextAlbum(new AxArtifactKey("OtherTestContextAlbum", "0.0.1"),
"Policy", true, AxArtifactKey.getNullKey());
@@ -369,13 +288,8 @@ public class ContextAlbumImplTest {
otherAlbum = new ContextAlbumImpl(otherAxContextAlbum, distributor, new LinkedHashMap<String, Object>());
assertNotEquals(album, otherAlbum);
- try {
- album.flush();
- fail("test should throw an exception here");
- } catch (ContextException ce) {
- assertEquals("map flush failed, supplied map is null", ce.getMessage());
- }
-
+ assertThatThrownBy(album::flush)
+ .hasMessage("map flush failed, supplied map is null");
AxContextAlbums albums = new AxContextAlbums();
ModelService.registerModel(AxContextAlbums.class, albums);
albums.getAlbumsMap().put(axContextAlbum.getKey(), axContextAlbum);
diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java
index 71968fffe..53c8d1fb8 100644
--- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.java
+++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/ContextUpdate.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,14 +21,12 @@
package org.onap.policy.apex.testsuites.integration.context.distribution;
-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.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.APEX_DISTRIBUTOR;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.DATE_CONTEXT_ALBUM;
-import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.EXCEPTION_MESSAGE;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.LONG_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.MAP_CONTEXT_ALBUM;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.TIME_ZONE;
@@ -41,7 +39,6 @@ import java.util.Locale;
import java.util.Map;
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
-import org.onap.policy.apex.context.ContextRuntimeException;
import org.onap.policy.apex.context.Distributor;
import org.onap.policy.apex.context.impl.distribution.DistributorFactory;
import org.onap.policy.apex.context.test.concepts.TestContextDateItem;
@@ -89,43 +86,18 @@ public class ContextUpdate {
longContextAlbum.put(NUMBER_ZERO, 0);
longContextAlbum.put(NUMBER_ZERO, NUMBER_ZERO);
- try {
- longContextAlbum.put(NUMBER_ZERO, ZERO);
- fail(EXCEPTION_MESSAGE);
- } catch (final ContextRuntimeException e) {
- assertEquals("Failed to set context value for key \"0\" in album \"LongContextAlbum:0.0.1\":"
+ assertThatThrownBy(() -> longContextAlbum.put(NUMBER_ZERO, ZERO))
+ .hasMessage("Failed to set context value for key \"0\" in album \"LongContextAlbum:0.0.1\":"
+ " LongContextAlbum:0.0.1: object \"zero\" of class \"java.lang.String\" not compatible with"
- + " class \"java.lang.Long\"", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
-
- try {
- longContextAlbum.put(NUMBER_ZERO, "");
- fail(EXCEPTION_MESSAGE);
- } catch (final ContextRuntimeException e) {
- assertEquals(
- "Failed to set context value for key \"0\" in album \"LongContextAlbum:0.0.1\": LongContextAlbum"
- + ":0.0.1: object \"\" of class \"java.lang.String\" not compatible with class \"java.lang.Long\"",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
-
- try {
- longContextAlbum.put(NUMBER_ZERO, null);
- fail(EXCEPTION_MESSAGE);
- } catch (final ContextRuntimeException e) {
- assertEquals("album \"LongContextAlbum:0.0.1\" null values are illegal on key \"0\" for put()",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
-
- try {
- longContextAlbum.put(null, null);
- fail(EXCEPTION_MESSAGE);
- } catch (final ContextRuntimeException e) {
- assertEquals("album \"LongContextAlbum:0.0.1\" null keys are illegal on keys for put()", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ + " class \"java.lang.Long\"");
+ assertThatThrownBy(() -> longContextAlbum.put(NUMBER_ZERO, ""))
+ .hasMessage("Failed to set context value for key \"0\" in album \"LongContextAlbum:0.0.1\": "
+ + "LongContextAlbum:0.0.1: object \"\" of class \"java.lang.String\" not "
+ + "compatible with class \"java.lang.Long\"");
+ assertThatThrownBy(() -> longContextAlbum.put(NUMBER_ZERO, null))
+ .hasMessage("album \"LongContextAlbum:0.0.1\" null values are illegal on key \"0\" for put()");
+ assertThatThrownBy(() -> longContextAlbum.put(null, null))
+ .hasMessage("album \"LongContextAlbum:0.0.1\" null keys are illegal on keys for put()");
assertNull(dateContextAlbum.put("date0", tciA));
assertTrue(dateContextAlbum.put("date0", tciA).equals(tciA));
diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/SequentialContextInstantiation.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/SequentialContextInstantiation.java
index 3f690f0b5..287dd6147 100644
--- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/SequentialContextInstantiation.java
+++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/testsuites/integration/context/distribution/SequentialContextInstantiation.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,16 +21,15 @@
package org.onap.policy.apex.testsuites.integration.context.distribution;
+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 static org.onap.policy.apex.testsuites.integration.context.factory.TestContextAlbumFactory.createMultiAlbumsContextModel;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.APEX_DISTRIBUTOR;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.BYTE_VAL;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.DATE_CONTEXT_ALBUM;
-import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.EXCEPTION_MESSAGE;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.FLOAT_VAL;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.INT_VAL;
import static org.onap.policy.apex.testsuites.integration.context.utils.Constants.LONG_VAL;
@@ -115,15 +114,10 @@ public class SequentialContextInstantiation {
final TestContextDateTzItem tci9 = getTestContextDateTzItem(testDate);
- try {
- dateAlbum.put("tci9", tci9);
- } catch (final Exception e) {
- final String message = "class \"" + TestContextDateTzItem.class.getName()
- + "\" not compatible with class \"" + TestContextDateLocaleItem.class.getName()
- + "\"";
- assertTrue(e.getMessage().contains(message));
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.put("tci9", tci9))
+ .hasMessageContaining("class \"" + TestContextDateTzItem.class.getName()
+ + "\" not compatible with class \"" + TestContextDateLocaleItem.class.getName()
+ + "\"");
final TestContextDateLocaleItem tciA01 = new TestContextDateLocaleItem(tciA00);
final TestContextDateLocaleItem tciA02 = new TestContextDateLocaleItem(tciA00);
@@ -145,14 +139,9 @@ public class SequentialContextInstantiation {
// Get another reference to the album
final ContextAlbum dateAlbum1 = getContextAlbum(DATE_CONTEXT_ALBUM, contextDistributor);
- try {
- dateAlbum1.putAll(valueMap1);
- fail(EXCEPTION_MESSAGE);
- } catch (final Exception e) {
- assertTrue(e.getMessage().endsWith("not compatible with class \""
- + TestContextDateLocaleItem.class.getName() + "\""));
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum1.putAll(valueMap1))
+ .hasMessageContaining("not compatible with class \""
+ + TestContextDateLocaleItem.class.getName() + "\"");
assertEquals(5, dateAlbum1.size());
valueMap1.clear();
@@ -217,23 +206,14 @@ public class SequentialContextInstantiation {
}
private void assertContains(final ContextAlbum dateAlbum, final TestContextDateLocaleItem tciA01) {
- try {
- dateAlbum.containsKey(null);
- fail(EXCEPTION_MESSAGE);
- } catch (final Exception e) {
- assertEquals("null values are illegal on method parameter \"key\"", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.containsKey(null))
+ .hasMessageContaining("null values are illegal on method parameter \"key\"");
assertTrue(dateAlbum.containsKey(ITEM05));
assertTrue(!dateAlbum.containsKey("Item07"));
- try {
- dateAlbum.containsValue(null);
- } catch (final Exception e) {
- assertEquals("null values are illegal on method parameter \"value\"", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.containsValue(null))
+ .hasMessageContaining("null values are illegal on method parameter \"value\"");
assertTrue(dateAlbum.containsValue(tciA01));
assertTrue(!dateAlbum.containsValue("Hello"));
@@ -241,32 +221,18 @@ public class SequentialContextInstantiation {
private void assertAlbumGetAndPutMethods(final ContextAlbum dateAlbum, final TestContextDateLocaleItem tciA03,
final TestContextDateLocaleItem tciA00) {
- try {
- dateAlbum.get(null);
- fail(EXCEPTION_MESSAGE);
- } catch (final Exception e) {
- assertEquals("album \"DateContextAlbum:0.0.1\" null keys are illegal on keys for get()", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.get(null))
+ .hasMessageContaining("album \"DateContextAlbum:0.0.1\" null keys are illegal on keys for get()");
final Object aObject = dateAlbum.get(ITEM03);
assertEquals(tciA03, aObject);
- try {
- dateAlbum.put(null, null);
- fail(EXCEPTION_MESSAGE);
- } catch (final Exception e) {
- assertEquals("album \"DateContextAlbum:0.0.1\" null keys are illegal on keys for put()", e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.put(null, null))
+ .hasMessageContaining("album \"DateContextAlbum:0.0.1\" null keys are illegal on keys for put()");
// Put null ContextItem should work (return null)
- try {
- dateAlbum.put(ITEM_NULL, null);
- } catch (final Exception e) {
- assertEquals("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"ItemNull\" for put()",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.put(ITEM_NULL, null))
+ .hasMessageContaining("album \"DateContextAlbum:0.0.1\" null values are illegal on "
+ + "key \"ItemNull\" for put()");
// Should return null
assertNull(dateAlbum.get(ITEM_NULL));
@@ -279,37 +245,21 @@ public class SequentialContextInstantiation {
retItem = (TestContextDateLocaleItem) dateAlbum.put(ITEM03, tciA03);
assertEquals(tciA03Clone, retItem);
- try {
- dateAlbum.put(ITEM_NULL, null);
- fail(EXCEPTION_MESSAGE);
-
- } catch (final Exception e) {
- assert ("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"ItemNull\" for put()"
- .equals(e.getMessage()));
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.put(ITEM_NULL, null))
+ .hasMessageContaining("album \"DateContextAlbum:0.0.1\" null values are illegal on "
+ + "key \"ItemNull\" for put()");
dateAlbum.put(TEST_AA, tciA00);
assertEquals(tciA00, dateAlbum.get(TEST_AA));
// Should print warning
- try {
- dateAlbum.put(TEST_AA, null);
- fail(EXCEPTION_MESSAGE);
- } catch (final Exception e) {
- assertEquals("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"TestAA\" for put()",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.put(TEST_AA, null))
+ .hasMessageContaining("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"TestAA\" "
+ + "for put()");
assertEquals(8, dateAlbum.size());
- try {
- dateAlbum.put(TEST_AB, null);
- fail(EXCEPTION_MESSAGE);
- } catch (final Exception e) {
- assertEquals("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"TestAB\" for put()",
- e.getMessage());
- LOGGER.trace(NORMAL_TEST_EXCEPTION, e);
- }
+ assertThatThrownBy(() -> dateAlbum.put(TEST_AB, null))
+ .hasMessageContaining("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"TestAB\" "
+ + "for put()");
assertEquals(8, dateAlbum.size());
}
diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java
index 5f89db675..bf883d761 100644
--- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java
+++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java
@@ -21,6 +21,7 @@
package org.onap.policy.apex.testsuites.integration.executor.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;
@@ -168,19 +169,10 @@ public class TestEventInstantiation {
value = event.get("TestMatchCase");
assertNull(value);
- try {
- event.put("TestMatchCase", "Hello");
- } catch (final Exception e) {
- assertEquals("Event0000:0.0.1:NULL:TestMatchCase: object \"Hello\" of class \"java.lang.String\" "
- + "not compatible with class \"java.lang.Byte\"", e.getMessage());
- }
-
- try {
- event.put("TestMatchCase", 123.45);
- } catch (final Exception e) {
- assertEquals("Event0000:0.0.1:NULL:TestMatchCase: object \"123.45\" of class \"java.lang.Double\" "
- + "not compatible with class \"java.lang.Byte\"", e.getMessage());
- }
+ assertThatThrownBy(() -> event.put("TestMatchCase", "Hello"))
+ .hasMessage("Event0000:0.0.1:NULL:TestMatchCase: object \"Hello\" of class \"java.lang.String\" "
+ + "not compatible with class \"java.lang.Byte\"");
+ event.put("TestMatchCase", 123.45);
event.put("TestMatchCase", Byte.valueOf("16"));
diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java
index d73b51147..aaf640bb4 100644
--- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java
+++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java
@@ -1,19 +1,20 @@
/*-
* ============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=========================================================
*/
@@ -99,15 +100,8 @@ public class TestApexModelExport {
exportPolicyList.clear();
exportPolicyList.add(new AxArtifactKey("NonExistentPolicy", "0.0.1"));
- try {
- final AxPolicyModel emptyExportedModel = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList);
- assertNotNull(emptyExportedModel);
- } catch (final Exception e) {
- assertTrue(e.getMessage()
- .equals("new model is invalid:\n" + "***validation of model failed***\n"
- + "AxPolicies:Policies:0.0.1 - policyMap may not be null or empty\n"
- + "AxEvents:Events:0.0.1 - eventMap may not be null or empty\n"
- + "********************************"));
- }
+ final AxPolicyModel emptyExportedModel = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList);
+ assertNotNull(emptyExportedModel);
+
}
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceModelUpdateTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceModelUpdateTest.java
index 7ba309cc0..fdc60d765 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceModelUpdateTest.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceModelUpdateTest.java
@@ -21,10 +21,10 @@
package org.onap.policy.apex.testsuites.integration.uservice.engine;
+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.assertTrue;
-import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -159,14 +159,9 @@ public class ApexServiceModelUpdateTest {
*/
@Test
public void testNoModelStart() {
- try {
- service.startAll();
- fail("Engine should not start with no model");
- } catch (final Exception e) {
- e.printStackTrace();
- assertEquals("start()<-Machine-1_process-1_engine-1-0:0.0.0,STOPPED, cannot start engine, "
- + "engine has not been initialized, its model is not loaded", e.getMessage());
- }
+ assertThatThrownBy(service::startAll)
+ .hasMessage("start()<-Machine-1_process-1_engine-1-0:0.0.0,STOPPED, cannot start engine, "
+ + "engine has not been initialized, its model is not loaded");
}
/**
@@ -227,16 +222,10 @@ public class ApexServiceModelUpdateTest {
final AxPolicyModel incoPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel);
incoPolicyModel0.getKey().setName("INCOMPATIBLE");
- try {
- service.updateModel(parameters.getEngineKey(), incoPolicyModel0, false);
- fail("model update should fail on incompatible model without force being true");
- } catch (final Exception e) {
- System.err.println(e.getMessage());
- assertEquals("apex model update failed, supplied model with key \"INCOMPATIBLE:0.0.1\" is not a compatible "
- + "model update from the existing engine model " + "with key \"SamplePolicyModelJAVASCRIPT:0.0.1\"",
- e.getMessage());
- }
-
+ assertThatThrownBy(() -> service.updateModel(parameters.getEngineKey(), incoPolicyModel0, false))
+ .hasMessage("apex model update failed, supplied model with key \"INCOMPATIBLE:0.0.1\" is "
+ + "not a compatible model update from the existing engine model " + "with key "
+ + "\"SamplePolicyModelJAVASCRIPT:0.0.1\"");
// Still on old model
sendEvents();
@@ -244,17 +233,10 @@ public class ApexServiceModelUpdateTest {
final AxPolicyModel incoPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel);
incoPolicyModel1.getKey().setVersion("1.0.1");
- try {
- service.updateModel(parameters.getEngineKey(), incoPolicyModel1, false);
- fail("model update should fail on incompatible model without force being true");
- } catch (final Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- assertEquals("apex model update failed, supplied model with key \"SamplePolicyModelJAVASCRIPT:1.0.1\" "
- + "is not a compatible model update from the existing engine model with key "
- + "\"SamplePolicyModelJAVASCRIPT:0.0.1\"", e.getMessage());
- }
-
+ assertThatThrownBy(() -> service.updateModel(parameters.getEngineKey(), incoPolicyModel1, false))
+ .hasMessage("apex model update failed, supplied model with key \"SamplePolicyModelJAVASCRIPT:"
+ + "1.0.1\" is not a compatible model update from the existing engine model with key "
+ + "\"SamplePolicyModelJAVASCRIPT:0.0.1\"");
// Still on old model
sendEvents();
diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java
index 9a099b54e..6b15ae454 100644
--- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java
+++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.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,11 +21,10 @@
package org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator;
+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 org.apache.commons.cli.ParseException;
import org.junit.Test;
@@ -35,287 +35,165 @@ import org.junit.Test;
public class EventGeneratorParametersHandlerTest {
@Test
- public void testEventGeneratorParameterhandler() {
+ public void testEventGeneratorParameterhandler() throws ParseException {
EventGeneratorParameterHandler handler = new EventGeneratorParameterHandler();
assertNotNull(handler);
- try {
- String[] args =
- { "-h" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertNull(parameters);
- assertEquals("usage: EventGenerator [options...]",
- handler.getHelp(EventGenerator.class.getSimpleName()).substring(0, 34));
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- {};
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals("localhost", parameters.getHost());
- assertEquals(32801, parameters.getPort());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-H", "MyHost" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals("MyHost", parameters.getHost());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-p", "12345" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals(12345, parameters.getPort());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-H", "MyHost", "-p", "12345" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals("MyHost", parameters.getHost());
- assertEquals(12345, parameters.getPort());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Valid.json" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals("ValidPars", parameters.getName());
- assertEquals("FileHost", parameters.getHost());
- assertEquals(54321, parameters.getPort());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals("localhost", parameters.getHost());
- assertEquals(32801, parameters.getPort());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json", "-bc", "100" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals(100, parameters.getBatchCount());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json", "-bc", "-1" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
+ String[] args = { "-h" };
+ EventGeneratorParameters parameters = handler.parse(args);
+ assertNull(parameters);
+ assertEquals("usage: EventGenerator [options...]",
+ handler.getHelp(EventGenerator.class.getSimpleName()).substring(0, 34));
+
+ args = new String[] {};
+ parameters = handler.parse(args);
+ assertEquals("localhost", parameters.getHost());
+ assertEquals(32801, parameters.getPort());
+
+ args = new String[] { "-H", "MyHost" };
+ parameters = handler.parse(args);
+ assertEquals("MyHost", parameters.getHost());
+
+ args = new String[] { "-p", "12345" };
+ parameters = handler.parse(args);
+ assertEquals(12345, parameters.getPort());
+
+
+ args = new String[] { "-H", "MyHost", "-p", "12345" };
+ parameters = handler.parse(args);
+ assertEquals("MyHost", parameters.getHost());
+ assertEquals(12345, parameters.getPort());
+
+ args = new String[] { "-c", "src/test/resources/parameters/unit/Valid.json" };
+ parameters = handler.parse(args);
+ assertEquals("ValidPars", parameters.getName());
+ assertEquals("FileHost", parameters.getHost());
+ assertEquals(54321, parameters.getPort());
+
+ args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json" };
+ parameters = handler.parse(args);
+ assertEquals("localhost", parameters.getHost());
+ assertEquals(32801, parameters.getPort());
+
+ args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bc", "100" };
+ parameters = handler.parse(args);
+ assertEquals(100, parameters.getBatchCount());
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bc", "-1" };
+ handler.parse(arguments);
+ }).hasMessage("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
+ "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator."
+ "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
+ " field \"batchCount\" type \"int\" value \"-1\" INVALID, "
+ "batchCount must be an integer with a value of zero or more, "
- + "zero means generate batches forever\n", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "12345" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals(12345, parameters.getBatchSize());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "0" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
+ + "zero means generate batches forever\n");
+ args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "12345" };
+ parameters = handler.parse(args);
+ assertEquals(12345, parameters.getBatchSize());
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "0" };
+ handler.parse(arguments);
+ }).hasMessage("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
+ "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator."
+ "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
+ " field \"batchSize\" type \"int\" value \"0\" INVALID, "
- + "batchSize must be an integer greater than zero\n", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "1000" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals(1000, parameters.getDelayBetweenBatches());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "-1" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
+ + "batchSize must be an integer greater than zero\n");
+ args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "1000" };
+ parameters = handler.parse(args);
+ assertEquals(1000, parameters.getDelayBetweenBatches());
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "-1" };
+ handler.parse(arguments);
+ }).hasMessage("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
+ "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator."
+ "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
+ " field \"batchSize\" type \"int\" value \"1\" INVALID, "
- + "batchSize must be an integer with a value of zero or more\n", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Default.json", "-o", "Zooby" };
- EventGeneratorParameters parameters = handler.parse(args);
- assertEquals("Zooby", parameters.getOutFile());
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-z" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("Unrecognized option: -z", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-H" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("Missing argument for option: H", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-p" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("Missing argument for option: p", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-p", "12345", "-z" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("Unrecognized option: -z", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-p", "12345", "somethingElse" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("too many command line arguments specified : [somethingElse]", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-c" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("Missing argument for option: c", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-H", "MyHost", "-c", "src/test/resources/parameters/unit/Valid.json" };
- EventGeneratorParameters pars = handler.parse(args);
- assertEquals("MyHost", pars.getHost());
-
- } catch (ParseException pe) {
- fail("test should not throw an exception");
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/NonExistant.json" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertTrue(pe.getMessage().startsWith("Could not read parameters from configuration file "));
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/BadHost.json" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("Error parsing JSON parameters from configuration file "
+ + "batchSize must be an integer with a value of zero or more\n");
+
+ args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-o", "Zooby" };
+ parameters = handler.parse(args);
+ assertEquals("Zooby", parameters.getOutFile());
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-z" };
+ handler.parse(arguments);
+ }).hasMessage("Unrecognized option: -z");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-H" };
+ handler.parse(arguments);
+ }).hasMessage("Missing argument for option: H");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-p" };
+ handler.parse(arguments);
+ }).hasMessage("Missing argument for option: p");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-p", "12345", "-z" };
+ handler.parse(arguments);
+ }).hasMessage("Unrecognized option: -z");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-p", "12345", "somethingElse" };
+ handler.parse(arguments);
+ }).hasMessage("too many command line arguments specified : [somethingElse]");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c" };
+ handler.parse(arguments);
+ }).hasMessage("Missing argument for option: c");
+
+ args = new String[] { "-H", "MyHost", "-c", "src/test/resources/parameters/unit/Valid.json" };
+ parameters = handler.parse(args);
+ assertEquals("MyHost", parameters.getHost());
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/NonExistant.json" };
+ handler.parse(arguments);
+ }).hasMessageStartingWith("Could not read parameters from configuration file ");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/BadHost.json" };
+ handler.parse(arguments);
+ }).hasMessage("Error parsing JSON parameters from configuration file "
+ "\"src/test/resources/parameters/unit/BadHost.json\": "
+ "com.google.gson.stream.MalformedJsonException: "
- + "Unexpected value at line 3 column 14 path $.host", pe.getMessage());
- }
+ + "Unexpected value at line 3 column 14 path $.host");
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/BadPort.json" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("Error parsing JSON parameters from configuration file "
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/BadPort.json" };
+ handler.parse(arguments);
+ }).hasMessage("Error parsing JSON parameters from configuration file "
+ "\"src/test/resources/parameters/unit/BadPort.json\": "
+ "java.lang.IllegalStateException: Expected an int "
- + "but was BOOLEAN at line 4 column 18 path $.port", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/Empty.json" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("No parameters found in configuration file "
- + "\"src/test/resources/parameters/unit/Empty.json\"", pe.getMessage());
- }
-
- try {
- String[] args =
- { "-c", "src/test/resources/parameters/unit/NullHost.json" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("specified parameters are not valid: parameter group \"ValidPars\" "
+ + "but was BOOLEAN at line 4 column 18 path $.port");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/Empty.json" };
+ handler.parse(arguments);
+ }).hasMessage("No parameters found in configuration file "
+ + "\"src/test/resources/parameters/unit/Empty.json\"");
+
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/NullHost.json" };
+ handler.parse(arguments);
+ }).hasMessage("specified parameters are not valid: parameter group \"ValidPars\" "
+ "type \"org.onap.policy.apex.testsuites.performance."
+ "benchmark.eventgenerator.EventGeneratorParameters\" INVALID, "
+ "parameter group has status INVALID\n" + " field \"host\" type \"java.lang.String\" "
- + "value \"null\" INVALID, host must be a non-blank string\n", pe.getMessage());
- }
+ + "value \"null\" INVALID, host must be a non-blank string\n");
- try {
- String[] args =
- { "-p", "1023" };
- handler.parse(args);
- fail("test should throw an exception");
- } catch (ParseException pe) {
- assertEquals("specified parameters are not valid: parameter group \""
+ assertThatThrownBy(() -> {
+ String[] arguments = new String[] { "-p", "1023" };
+ handler.parse(arguments);
+ }).hasMessage("specified parameters are not valid: parameter group \""
+ "EventGeneratorParameters\" type \"org.onap.policy.apex.testsuites.performance.benchmark."
+ "eventgenerator.EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
+ " field \"port\" type \"int\" value \"1023\" INVALID, "
- + "port must be an integer between 1024 and 65535 inclusive\n" + "", pe.getMessage());
- }
+ + "port must be an integer between 1024 and 65535 inclusive\n" + "");
}
}