summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-engine/src/test/java')
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java90
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java44
2 files changed, 42 insertions, 92 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java
index 52d8981c3..3bdcf53d9 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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=========================================================
*/
@@ -40,91 +41,60 @@ public class JsonTaggedEventConsumerTest {
@Test
public void testGarbageText() throws IOException {
- final InputStream jsonInputStream = new ByteArrayInputStream("hello there".getBytes());
-
- final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
- taggedReader.init(jsonInputStream);
-
- final TextBlock textBlock = taggedReader.readTextBlock();
- assertNull(textBlock.getText());
- assertTrue(textBlock.isEndOfText());
+ verifyNoEvent("testGarbageText", "hello there");
}
@Test
public void testPartialEvent() throws IOException {
- final InputStream jsonInputStream = new ByteArrayInputStream("\"TestTimestamp\": 1469781869268}".getBytes());
-
- final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
- taggedReader.init(jsonInputStream);
-
- final TextBlock textBlock = taggedReader.readTextBlock();
- assertNull(textBlock.getText());
- assertTrue(textBlock.isEndOfText());
+ verifyNoEvent("testGarbageText", "\"TestTimestamp\": 1469781869268}");
}
@Test
public void testFullEvent() throws IOException {
- final InputStream jsonInputStream = new ByteArrayInputStream("{TestTimestamp\": 1469781869268}".getBytes());
-
- final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
- taggedReader.init(jsonInputStream);
-
- TextBlock textBlock = taggedReader.readTextBlock();
- assertEquals("{TestTimestamp\": 1469781869268}", textBlock.getText());
-
- textBlock = taggedReader.readTextBlock();
- assertNull(textBlock.getText());
- assertTrue(textBlock.isEndOfText());
+ verifyMulti("testFullEvent", "{TestTimestamp\": 1469781869268}", "{TestTimestamp\": 1469781869268}");
}
@Test
public void testFullEventGarbageBefore() throws IOException {
- final InputStream jsonInputStream =
- new ByteArrayInputStream("Garbage{TestTimestamp\": 1469781869268}".getBytes());
-
- final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
- taggedReader.init(jsonInputStream);
-
- TextBlock textBlock = taggedReader.readTextBlock();
- assertEquals("{TestTimestamp\": 1469781869268}", textBlock.getText());
- assertFalse(textBlock.isEndOfText());
-
- textBlock = taggedReader.readTextBlock();
- assertNull(textBlock.getText());
- assertTrue(textBlock.isEndOfText());
+ verifyMulti("testFullEventGarbageBefore", "Garbage{TestTimestamp\": 1469781869268}",
+ "{TestTimestamp\": 1469781869268}");
}
@Test
public void testFullEventGarbageBeforeAfter() throws IOException {
- final InputStream jsonInputStream =
- new ByteArrayInputStream("Garbage{TestTimestamp\": 1469781869268}Rubbish".getBytes());
+ verifyMulti("testFullEventGarbageBeforeAfter", "Garbage{TestTimestamp\": 1469781869268}Rubbish",
+ "{TestTimestamp\": 1469781869268}");
+ }
+
+ @Test
+ public void testFullEventGarbageAfter() throws IOException {
+ verifyMulti("testFullEventGarbageAfter", "{TestTimestamp\": 1469781869268}Rubbish",
+ "{TestTimestamp\": 1469781869268}");
+ }
+
+ private void verifyNoEvent(String testName, String input) throws IOException {
+ final InputStream jsonInputStream = new ByteArrayInputStream(input.getBytes());
final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
taggedReader.init(jsonInputStream);
- TextBlock textBlock = taggedReader.readTextBlock();
- assertEquals("{TestTimestamp\": 1469781869268}", textBlock.getText());
- assertFalse(textBlock.isEndOfText());
-
- textBlock = taggedReader.readTextBlock();
- assertNull(textBlock.getText());
- assertTrue(textBlock.isEndOfText());
+ final TextBlock textBlock = taggedReader.readTextBlock();
+ assertNull(testName, textBlock.getText());
+ assertTrue(testName, textBlock.isEndOfText());
}
- @Test
- public void testFullEventGarbageAfter() throws IOException {
- final InputStream jsonInputStream =
- new ByteArrayInputStream("{TestTimestamp\": 1469781869268}Rubbish".getBytes());
+ private void verifyMulti(String testName, String input, String expected) throws IOException {
+ final InputStream jsonInputStream = new ByteArrayInputStream(input.getBytes());
final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
taggedReader.init(jsonInputStream);
TextBlock textBlock = taggedReader.readTextBlock();
- assertEquals("{TestTimestamp\": 1469781869268}", textBlock.getText());
- assertFalse(textBlock.isEndOfText());
+ assertEquals(testName, expected, textBlock.getText());
+ assertFalse(testName, textBlock.isEndOfText());
textBlock = taggedReader.readTextBlock();
- assertNull(textBlock.getText());
- assertTrue(textBlock.isEndOfText());
+ assertNull(testName, textBlock.getText());
+ assertTrue(testName, textBlock.isEndOfText());
}
}
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 9f420d8fb..71ff28877 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
@@ -3,6 +3,7 @@
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -191,53 +192,32 @@ public class SyncParameterTests {
@Test
public void testSyncGoodSyncGoodTimeoutProducer() throws ParameterException {
- final String[] args = {"-p", "src/test/resources/parameters/syncGoodParamsProducerTimeout.json"};
- final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
-
- 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));
-
+ verifySyncGoodSyncGoodTimeout("src/test/resources/parameters/syncGoodParamsProducerTimeout.json");
}
@Test
public void testSyncGoodSyncGoodTimeoutConsumer() throws ParameterException {
- final String[] args = {"-p", "src/test/resources/parameters/syncGoodParamsConsumerTimeout.json"};
- final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
-
- 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));
-
+ verifySyncGoodSyncGoodTimeout("src/test/resources/parameters/syncGoodParamsConsumerTimeout.json");
}
@Test
public void testSyncGoodSyncGoodTimeoutBoth() throws ParameterException {
- final String[] args = {"-p", "src/test/resources/parameters/syncGoodParamsBothTimeout.json"};
+ verifySyncGoodSyncGoodTimeout("src/test/resources/parameters/syncGoodParamsBothTimeout.json");
+ }
+
+ private void verifySyncGoodSyncGoodTimeout(String fileName) throws ParameterException {
+ final String[] args = {"-p", fileName};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ assertEquals(fileName, 12345, parameters.getEventInputParameters().get("SyncConsumer0")
.getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ assertEquals(fileName, 1, parameters.getEventInputParameters().get("SyncConsumer1")
.getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ assertEquals(fileName, 12345, parameters.getEventOutputParameters().get("SyncProducer0")
.getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ assertEquals(fileName, 1, parameters.getEventOutputParameters().get("SyncProducer1")
.getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
-
}
@Test