summaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-uservice-test/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-11-06 12:02:46 +0000
committerliamfallon <liam.fallon@ericsson.com>2018-11-07 12:41:09 +0000
commit53d8916cc60d97e2ce7ae345f8cc25f5602567da (patch)
treeee2f3a8e543c31993c51a58257354ccffb648dfe /testsuites/integration/integration-uservice-test/src/test/java
parent9dc414a0cabc9074e87a7c9cd5c3e5ceee733e5a (diff)
Refactor unit test data
There were many copies of test policies and examples strewn through the Apex unit tests. This change cleans up the unit tests so that a single version of all example policies is used in all tests. Also added a new relative file root command line parameter to Apex to allow the root of relative paths in configuration files to be set. Apologies for the size of this review but unfortunately all of this must be done in one shot. Issue-ID: POLICY-1252 Change-Id: Ibbb18fbf18e3897a1c61301d0a65e62bc643a0e9 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'testsuites/integration/integration-uservice-test/src/test/java')
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java36
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java66
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java24
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java5
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java14
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java16
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestPing.java147
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java52
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java50
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java13
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java171
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServerVpnContext.java136
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsClient.java13
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsServer.java13
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java13
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java16
16 files changed, 349 insertions, 436 deletions
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java
index 5483501b2..709c67c87 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2File.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
@@ -33,19 +34,26 @@ import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.apex.service.engine.main.ApexMain;
public class TestFile2File {
+ /**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
@Test
public void testJsonFileEvents() throws MessagingException, ApexException, IOException {
- final String[] args = {"src/test/resources/prodcons/File2FileJsonEvent.json"};
+ final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileJsonEvent.json"};
- testFileEvents(args, "src/test/resources/events/EventsOut.json", 48956);
+ testFileEvents(args, "target/examples/events/SampleDomain/EventsOut.json", 42200);
}
@Test
public void testXmlFileEvents() throws MessagingException, ApexException, IOException {
- final String[] args = {"src/test/resources/prodcons/File2FileXmlEvent.json"};
+ final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileXmlEvent.json"};
- testFileEvents(args, "src/test/resources/events/EventsOut.xmlfile", 106739);
+ testFileEvents(args, "target/examples/events/SampleDomain/EventsOut.xmlfile", 100000);
}
private void testFileEvents(final String[] args, final String outFilePath, final long expectedFileSize)
@@ -61,7 +69,7 @@ public class TestFile2File {
// Wait for the file to be filled
long outFileSize = 0;
while (true) {
- final String fileString = TextFileUtils.getTextFileAsString(outFilePath).replaceAll("\\s+", "");
+ final String fileString = stripVariableLengthText(outFilePath);
outFileSize = fileString.length();
if (outFileSize > 0 && outFileSize >= expectedFileSize) {
break;
@@ -70,8 +78,22 @@ public class TestFile2File {
}
apexMain.shutdown();
- outFile.delete();
- assertEquals(outFileSize, expectedFileSize);
+ assertEquals(expectedFileSize, outFileSize);
+ }
+
+ /**
+ * Strip variable length text from file string.
+ *
+ * @param textFileAsString the file to read and strip
+ * @return the stripped string
+ * @throws IOException on out file read exceptions
+ */
+ private String stripVariableLengthText(final String outFile) throws IOException {
+ return TextFileUtils.getTextFileAsString(outFile)
+ .replaceAll("\\s+", "")
+ .replaceAll(":\\d*\\.?\\d*,", ":0,")
+ .replaceAll(":\\d*}", ":0}")
+ .replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>");
}
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java
index 48cd6c013..6c7af80fd 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileFiltered.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
@@ -33,48 +34,60 @@ import org.onap.policy.apex.model.utilities.TextFileUtils;
import org.onap.policy.apex.service.engine.main.ApexMain;
public class TestFile2FileFiltered {
+ /**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
@Test
public void testJsonFilteredFileInOutEvents() throws MessagingException, ApexException, IOException {
- final String[] args = {"src/test/resources/prodcons/File2FileFilteredInOutJsonEvent.json"};
+ final String[] args =
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileFilteredInOutJsonEvent.json" };
- final String[] outFilePaths = {
- "src/test/resources/events/Events0004Out.json",
- "src/test/resources/events/Events0104Out.json"
- };
+ final String[] outFilePaths =
+ { "target/examples/events/SampleDomain/Events0004Out.json",
+ "target/examples/events/SampleDomain/Events0104Out.json" };
- final long[] expectedFileSizes = {25949, 23007};
+ final long[] expectedFileSizes =
+ { 22366, 19834 };
testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
}
@Test
public void testJsonFilteredFileOutEvents() throws MessagingException, ApexException, IOException {
- final String[] args = {"src/test/resources/prodcons/File2FileFilteredOutJsonEvent.json"};
+ final String[] args =
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileFilteredOutJsonEvent.json" };
- final String[] outFilePaths = {
- "src/test/resources/events/Events0004Out.json",
- "src/test/resources/events/Events0104Out.json"
- };
+ final String[] outFilePaths =
+ { "target/examples/events/SampleDomain/Events0004Out.json",
+ "target/examples/events/SampleDomain/Events0104Out.json" };
- final long[] expectedFileSizes = {25949, 23007};
+ final long[] expectedFileSizes =
+ { 22366, 19834 };
testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
}
@Test
public void testJsonFilteredFileInEvents() throws MessagingException, ApexException, IOException {
- final String[] args = {"src/test/resources/prodcons/File2FileFilteredInJsonEvent.json"};
+ final String[] args =
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2FileFilteredInJsonEvent.json" };
- final String[] outFilePaths = {"src/test/resources/events/Events0004Out.json"};
+ final String[] outFilePaths =
+ { "target/examples/events/SampleDomain/Events0004Out.json" };
- final long[] expectedFileSizes = {25949};
+ final long[] expectedFileSizes =
+ { 22366 };
testFilteredFileEvents(args, outFilePaths, expectedFileSizes);
}
private void testFilteredFileEvents(final String[] args, final String[] outFilePaths,
- final long[] expectedFileSizes) throws MessagingException, ApexException, IOException {
+ final long[] expectedFileSizes) throws MessagingException, ApexException, IOException {
final ApexMain apexMain = new ApexMain(args);
final File outFile0 = new File(outFilePaths[0]);
@@ -86,7 +99,7 @@ public class TestFile2FileFiltered {
// Wait for the file to be filled
long outFile0Size = 0;
for (int i = 0; i < 4; i++) {
- final String fileString = TextFileUtils.getTextFileAsString(outFilePaths[0]).replaceAll("\\s+", "");
+ final String fileString = stripVariableLengthText(outFilePaths[0]);
outFile0Size = fileString.length();
if (outFile0Size > 0 && outFile0Size >= expectedFileSizes[0]) {
break;
@@ -100,13 +113,28 @@ public class TestFile2FileFiltered {
final long[] actualFileSizes = new long[expectedFileSizes.length];
for (int i = 0; i < outFilePaths.length; i++) {
- final String fileString = TextFileUtils.getTextFileAsString(outFilePaths[i]).replaceAll("\\s+", "");
+ final String fileString = stripVariableLengthText(outFilePaths[i]);
actualFileSizes[i] = fileString.length();
new File(outFilePaths[i]).delete();
}
for (int i = 0; i < actualFileSizes.length; i++) {
- assertEquals(actualFileSizes[i], expectedFileSizes[i]);
+ assertEquals(expectedFileSizes[i], actualFileSizes[i]);
}
}
+
+ /**
+ * Strip variable length text from file string.
+ *
+ * @param textFileAsString the file to read and strip
+ * @return the stripped string
+ * @throws IOException on out file read exceptions
+ */
+ private String stripVariableLengthText(final String outFile) throws IOException {
+ return TextFileUtils.getTextFileAsString(outFile)
+ .replaceAll("\\s+", "")
+ .replaceAll(":\\d*\\.?\\d*,", ":0,")
+ .replaceAll(":\\d*}", ":0}")
+ .replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>");
+ }
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java
index 49c7a96d1..b3fa512d5 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java
@@ -35,9 +35,10 @@ import org.onap.policy.apex.service.engine.main.ApexMain;
* The Class TestFile2FileIgnore.
*/
public class TestFile2FileIgnore {
-
// This test is used just to bring up an instance of Apex for manual testing and demonstrations
// It should always be ignored in automated testing because it holds Apex up for a very long
+ // time
+
/**
* The main method.
*
@@ -46,9 +47,8 @@ public class TestFile2FileIgnore {
* @throws ApexException the apex exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- // time
public static void main(final String[] args) throws MessagingException, ApexException, IOException {
- final String[] apexArgs = {"src/test/resources/prodcons/File2FileJsonEvent.json"};
+ final String[] apexArgs = {"-rfr", "target", "-c", "examples/config/SampleDomain/File2FileJsonEvent.json"};
testFileEvents(apexArgs, "src/test/resources/events/EventsOut.json", 48656);
}
@@ -76,7 +76,7 @@ public class TestFile2FileIgnore {
// Wait for the file to be filled
long outFileSize = 0;
while (true) {
- final String fileString = TextFileUtils.getTextFileAsString(outFilePath).replaceAll("\\s+", "");
+ final String fileString = stripVariableLengthText(outFilePath);
outFileSize = fileString.length();
if (outFileSize > 0 && outFileSize >= expectedFileSize) {
break;
@@ -91,6 +91,22 @@ public class TestFile2FileIgnore {
outFile.delete();
assertEquals(outFileSize, expectedFileSize);
}
+
+
+ /**
+ * Strip variable length text from file string.
+ *
+ * @param textFileAsString the file to read and strip
+ * @return the stripped string
+ * @throws IOException on out file read exceptions
+ */
+ private static String stripVariableLengthText(final String outFile) throws IOException {
+ return TextFileUtils.getTextFileAsString(outFile)
+ .replaceAll("\\s+", "")
+ .replaceAll(":\\d*\\.?\\d*,", ":0,")
+ .replaceAll(":\\d*}", ":0}")
+ .replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>");
+ }
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java
index 6a7e61739..ab2f45c22 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java
@@ -31,6 +31,7 @@ import javax.jms.Topic;
import org.apache.activemq.command.ActiveMQTopic;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.testsuites.integration.common.testclasses.PingTestClass;
import org.onap.policy.apex.testsuites.integration.uservice.adapt.events.EventGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -87,7 +88,7 @@ public class JmsEventProducer implements Runnable {
public void run() {
final Topic jmsTopic = new ActiveMQTopic(topic);
try (final Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- final MessageProducer jmsProducer = jmsSession.createProducer(jmsTopic);) {
+ final MessageProducer jmsProducer = jmsSession.createProducer(jmsTopic)) {
while (producerThread.isAlive() && !stopFlag) {
ThreadUtilities.sleep(50);
@@ -127,7 +128,7 @@ public class JmsEventProducer implements Runnable {
Message jmsMessage = null;
if (sendObjects) {
- jmsMessage = jmsSession.createObjectMessage(new TestPing());
+ jmsMessage = jmsSession.createObjectMessage(new PingTestClass());
} else {
jmsMessage = jmsSession.createTextMessage(EventGenerator.jsonEvent());
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java
index d1af8c39a..9dd58c817 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java
@@ -34,6 +34,7 @@ import org.apache.activemq.command.ActiveMQTopic;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.testsuites.integration.common.testclasses.PingTestClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +52,6 @@ public class JmsEventSubscriber implements Runnable {
private final Thread subscriberThread;
private final Connection connection;
-
/**
* Instantiates a new jms event subscriber.
*
@@ -62,7 +62,7 @@ public class JmsEventSubscriber implements Runnable {
* @throws JMSException the JMS exception
*/
public JmsEventSubscriber(final String topic, final ConnectionFactory connectionFactory, final String username,
- final String password) throws JMSException {
+ final String password) throws JMSException {
this.topic = topic;
connection = connectionFactory.createConnection(username, password);
connection.start();
@@ -71,14 +71,16 @@ public class JmsEventSubscriber implements Runnable {
subscriberThread.start();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
final Topic jmsTopic = new ActiveMQTopic(topic);
try (final Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- final MessageConsumer jmsConsumer = jmsSession.createConsumer(jmsTopic);) {
+ final MessageConsumer jmsConsumer = jmsSession.createConsumer(jmsTopic)) {
while (subscriberThread.isAlive() && !subscriberThread.isInterrupted()) {
try {
@@ -88,13 +90,13 @@ public class JmsEventSubscriber implements Runnable {
}
if (message instanceof ObjectMessage) {
- final TestPing testPing = (TestPing) ((ObjectMessage) message).getObject();
+ final PingTestClass testPing = (PingTestClass) ((ObjectMessage) message).getObject();
testPing.verify();
} else if (message instanceof TextMessage) {
((TextMessage) message).getText();
} else {
throw new ApexEventException("unknowm message \"" + message + "\" of type \""
- + message.getClass().getCanonicalName() + "\" received");
+ + message.getClass().getCanonicalName() + "\" received");
}
eventsReceivedCount++;
} catch (final Exception e) {
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java
index 422a97a11..ca2d3ecc0 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java
@@ -36,6 +36,7 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.security.AuthenticationUser;
import org.apache.activemq.security.SimpleAuthenticationPlugin;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
@@ -55,7 +56,7 @@ public class TestJms2Jms {
private static final int SLEEP_TIME = 1500;
private static final String GROUP_ROLE = "guests";
- private static final String PACKAGE_NAME = "org.onap.policy.apex.testsuites.integration.uservice.adapt.jms";
+ private static final String PACKAGE_NAME = "org.onap.policy.apex.testsuites.integration.common.testclasses";
private static final String USERNAME = "guest";
private static final String PASSWORD = "IAmAGuest";
private static final String URL = "tcp://" + HOST + ":" + PORT;
@@ -72,7 +73,6 @@ public class TestJms2Jms {
public static ActiveMQConnectionFactory connectionFactory;
-
/**
* Setup embedded jms server.
*
@@ -98,6 +98,14 @@ public class TestJms2Jms {
}
/**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
+ /**
* Gets the authentication broker plugin.
*
* @return the authentication broker plugin
@@ -134,7 +142,7 @@ public class TestJms2Jms {
*/
@Test
public void testJmsObjectEvents() throws ApexException, JMSException {
- final String[] args = { "src/test/resources/prodcons/JMS2JMSObjectEvent.json" };
+ final String[] args = { "-rfr", "target", "-c", "target/examples/config/JMS/JMS2JMSObjectEvent.json" };
testJmsEvents(args, true);
}
@@ -146,7 +154,7 @@ public class TestJms2Jms {
*/
@Test
public void testJmsJsonEvents() throws ApexException, JMSException {
- final String[] args = { "src/test/resources/prodcons/JMS2JMSJsonEvent.json" };
+ final String[] args = { "-rfr", "target", "-c", "target/examples/config/JMS/JMS2JMSJsonEvent.json" };
testJmsEvents(args, false);
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestPing.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestPing.java
deleted file mode 100644
index b0dfb553a..000000000
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestPing.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. 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=========================================================
- */
-
-package org.onap.policy.apex.testsuites.integration.uservice.adapt.jms;
-
-import java.io.Serializable;
-
-import org.onap.policy.apex.service.engine.event.ApexEventException;
-
-/**
- * The Class TestPing.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class TestPing implements Serializable {
- private static final long serialVersionUID = -3400711508992955886L;
-
- private String name = "Rose";
- private String description = "A rose by any other name would smell as sweet";
- private long pingTime = System.currentTimeMillis();
- private long pongTime = -1;
-
- /**
- * Gets the name.
- *
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the name.
- *
- * @param name the new name
- */
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
- * Gets the description.
- *
- * @return the description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Sets the description.
- *
- * @param description the new description
- */
- public void setDescription(final String description) {
- this.description = description;
- }
-
- /**
- * Gets the ping time.
- *
- * @return the ping time
- */
- public long getPingTime() {
- return pingTime;
- }
-
- /**
- * Sets the ping time.
- *
- * @param pingTime the new ping time
- */
- public void setPingTime(final long pingTime) {
- this.pingTime = pingTime;
- }
-
- /**
- * Gets the pong time.
- *
- * @return the pong time
- */
- public long getPongTime() {
- return pongTime;
- }
-
- /**
- * Sets the pong time.
- *
- * @param pongTime the new pong time
- */
- public void setPongTime(final long pongTime) {
- this.pongTime = pongTime;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "TestPing [name=" + name + ", description=" + description + ", pingTime=" + pingTime + ", pongTime="
- + pongTime + "]";
- }
-
- /**
- * Verify.
- *
- * @throws ApexEventException the apex event exception
- */
- public void verify() throws ApexEventException {
- if (!name.startsWith("Rose")) {
- throw new ApexEventException("TestPing is not valid");
- }
-
- if (name.length() <= 4) {
- throw new ApexEventException("TestPing is not valid");
- }
-
- if (!description.startsWith("A rose by any other name would smell as sweet")) {
- throw new ApexEventException("TestPing is not valid");
- }
-
- if (description.length() <= 44) {
- throw new ApexEventException("TestPing is not valid");
- }
-
- if (pongTime <= pingTime) {
- throw new ApexEventException("TestPing is not valid");
- }
- }
-}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java
index 6ab910506..5c8eb7eb1 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/TestKafka2Kafka.java
@@ -28,6 +28,7 @@ import com.salesforce.kafka.test.junit4.SharedKafkaTestResource;
import java.io.File;
import java.io.IOException;
+import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
@@ -45,6 +46,14 @@ public class TestKafka2Kafka {
private static final int EVENT_COUNT = 100;
private static final int EVENT_INTERVAL = 20;
+ /**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
@ClassRule
public static final SharedKafkaTestResource sharedKafkaTestResource = new SharedKafkaTestResource()
// Start a cluster with 1 brokers.
@@ -60,8 +69,10 @@ public class TestKafka2Kafka {
*/
@Test
public void testJsonKafkaEvents() throws MessagingException, ApexException {
+ final String conditionedConfigFile = getConditionedConfigFile(
+ "target" + File.separator + "examples/config/SampleDomain/Kafka2KafkaJsonEvent.json");
final String[] args =
- { "src/test/resources/prodcons/Kafka2KafkaJsonEvent.json" };
+ { "-rfr", "target", "-c", conditionedConfigFile };
testKafkaEvents(args, false, "json");
}
@@ -73,8 +84,11 @@ public class TestKafka2Kafka {
*/
@Test
public void testXmlKafkaEvents() throws MessagingException, ApexException {
+ final String conditionedConfigFile = getConditionedConfigFile(
+ "target" + File.separator + "examples/config/SampleDomain/Kafka2KafkaXmlEvent.json");
final String[] args =
- { "src/test/resources/prodcons/Kafka2KafkaXmlEvent.json" };
+ { "-rfr", "target", "-c", conditionedConfigFile };
+
testKafkaEvents(args, true, "xml");
}
@@ -90,18 +104,6 @@ public class TestKafka2Kafka {
private void testKafkaEvents(String[] args, final Boolean xmlEvents, final String topicSuffix)
throws MessagingException, ApexException {
- try {
- File tempConfigFile = File.createTempFile("Kafka_", ".json");
- tempConfigFile.deleteOnExit();
- String configAsString = TextFileUtils.getTextFileAsString(args[0]).replaceAll("localhost:39902",
- sharedKafkaTestResource.getKafkaConnectString());
- TextFileUtils.putStringAsFile(configAsString, tempConfigFile.getCanonicalFile());
- args[0] = tempConfigFile.getCanonicalPath();
-
- } catch (IOException e) {
- fail("test should not throw an exception");
- }
-
sharedKafkaTestResource.getKafkaTestUtils().createTopic("apex-out-" + topicSuffix, 1, (short) 1);
sharedKafkaTestResource.getKafkaTestUtils().createTopic("apex-in-" + topicSuffix, 1, (short) 1);
@@ -115,7 +117,7 @@ public class TestKafka2Kafka {
EVENT_COUNT, xmlEvents, EVENT_INTERVAL);
producer.sendEvents();
-
+
final long testStartTime = System.currentTimeMillis();
// Wait for the producer to send all tis events
@@ -131,11 +133,25 @@ public class TestKafka2Kafka {
ThreadUtilities.sleep(1000);
- assertEquals(producer.getEventsSentCount(), subscriber.getEventsReceivedCount());
-
apexMain.shutdown();
subscriber.shutdown();
producer.shutdown();
- ThreadUtilities.sleep(1000);
+
+ assertEquals(producer.getEventsSentCount(), subscriber.getEventsReceivedCount());
+ }
+
+ private String getConditionedConfigFile(final String configurationFileName) {
+ try {
+ File tempConfigFile = File.createTempFile("Kafka_", ".json");
+ tempConfigFile.deleteOnExit();
+ String configAsString = TextFileUtils.getTextFileAsString(configurationFileName)
+ .replaceAll("localhost:39902", sharedKafkaTestResource.getKafkaConnectString());
+ TextFileUtils.putStringAsFile(configAsString, tempConfigFile.getCanonicalFile());
+
+ return tempConfigFile.getCanonicalPath();
+ } catch (IOException e) {
+ fail("test should not throw an exception");
+ return null;
+ }
}
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java
index d681fd471..9a9b48bad 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java
@@ -39,17 +39,22 @@ import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexMain;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
/**
* The Class TestFile2Rest.
*/
public class TestFile2Rest {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestFile2Rest.class);
+
private static final String BASE_URI = "http://localhost:32801/TestFile2Rest";
private static HttpServer server;
@@ -85,6 +90,14 @@ public class TestFile2Rest {
}
/**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
+ /**
* Test file events post.
*
* @throws MessagingException the messaging exception
@@ -96,16 +109,21 @@ public class TestFile2Rest {
final Client client = ClientBuilder.newClient();
final String[] args =
- { "src/test/resources/prodcons/File2RESTJsonEventPost.json" };
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2RESTJsonEventPost.json" };
final ApexMain apexMain = new ApexMain(args);
+ Response response = null;
+
// Wait for the required amount of events to be received or for 10 seconds
for (int i = 0; i < 100; i++) {
ThreadUtilities.sleep(100);
- final Response response = client.target("http://localhost:32801/TestFile2Rest/apex/event/Stats")
+ response = client.target("http://localhost:32801/TestFile2Rest/apex/event/Stats")
.request("application/json").get();
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ if (Response.Status.OK.getStatusCode() != response.getStatus()) {
+ break;
+ }
+
final String responseString = response.readEntity(String.class);
@SuppressWarnings("unchecked")
@@ -116,6 +134,8 @@ public class TestFile2Rest {
}
apexMain.shutdown();
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
/**
@@ -128,18 +148,23 @@ public class TestFile2Rest {
@Test
public void testFileEventsPut() throws MessagingException, ApexException, IOException {
final String[] args =
- { "src/test/resources/prodcons/File2RESTJsonEventPut.json" };
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/File2RESTJsonEventPut.json" };
final ApexMain apexMain = new ApexMain(args);
final Client client = ClientBuilder.newClient();
+ Response response = null;
+
// Wait for the required amount of events to be received or for 10 seconds
for (int i = 0; i < 100; i++) {
ThreadUtilities.sleep(100);
- final Response response = client.target("http://localhost:32801/TestFile2Rest/apex/event/Stats")
+ response = client.target("http://localhost:32801/TestFile2Rest/apex/event/Stats")
.request("application/json").get();
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ if (Response.Status.OK.getStatusCode() != response.getStatus()) {
+ break;
+ }
+
final String responseString = response.readEntity(String.class);
@SuppressWarnings("unchecked")
@@ -150,6 +175,8 @@ public class TestFile2Rest {
}
apexMain.shutdown();
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
/**
@@ -176,6 +203,7 @@ public class TestFile2Rest {
System.setOut(stdout);
System.setErr(stderr);
+ LOGGER.info("NoUrl-OUTSTRING=\n" + outString + "\nEnd-NoUrl");
assertTrue(outString.contains(" no URL has been set for event sending on REST client"));
}
@@ -195,7 +223,7 @@ public class TestFile2Rest {
{ "src/test/resources/prodcons/File2RESTJsonEventBadURL.json" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ ThreadUtilities.sleep(2000);
apexMain.shutdown();
final String outString = outContent.toString();
@@ -203,6 +231,7 @@ public class TestFile2Rest {
System.setOut(stdout);
System.setErr(stderr);
+ LOGGER.info("BadUrl-OUTSTRING=\n" + outString + "\nEnd-BadUrl");
assertTrue(outString.contains(
"send of event to URL \"http://localhost:32801/TestFile2Rest/apex/event/Bad\" using HTTP \"POST\" failed with status code 404"));
}
@@ -231,6 +260,7 @@ public class TestFile2Rest {
System.setOut(stdout);
System.setErr(stderr);
+ LOGGER.info("BadHttpMethod-OUTSTRING=\n" + outString + "\nEnd-BadHttpMethod");
assertTrue(outString.contains(
"specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\" and \"PUT\" "
+ "are supproted for event sending on REST client producer"));
@@ -252,7 +282,7 @@ public class TestFile2Rest {
{ "src/test/resources/prodcons/File2RESTJsonEventPostBadResponse.json" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(500);
+ ThreadUtilities.sleep(2000);
apexMain.shutdown();
final String outString = outContent.toString();
@@ -260,7 +290,9 @@ public class TestFile2Rest {
System.setOut(stdout);
System.setErr(stderr);
+ LOGGER.info("BadResponse-OUTSTRING=\n" + outString + "\nEnd-BadResponse");
assertTrue(outString.contains(
- "send of event to URL \"http://localhost:32801/TestFile2Rest/apex/event/PostEventBadResponse\" using HTTP \"POST\" failed with status code 400"));
+ "send of event to URL \"http://localhost:32801/TestFile2Rest/apex/event/PostEventBadResponse\""
+ + " using HTTP \"POST\" failed with status code 400"));
}
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java
index ec41de5fb..cb98ec76b 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java
@@ -56,6 +56,14 @@ public class TestRest2File {
private final PrintStream stderr = System.err;
/**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
+ /**
* Sets the up.
*
* @throws Exception the exception
@@ -98,14 +106,15 @@ public class TestRest2File {
@Test
public void testRestEventsIn() throws MessagingException, ApexException, IOException {
final String[] args =
- { "src/test/resources/prodcons/REST2FileJsonEvent.json" };
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/REST2FileJsonEvent.json" };
final ApexMain apexMain = new ApexMain(args);
ThreadUtilities.sleep(1000);
apexMain.shutdown();
- final String outputEventText = TextFileUtils.getTextFileAsString("src/test/resources/events/EventsOut.json");
+ final String outputEventText = TextFileUtils
+ .getTextFileAsString("target/examples/events/SampleDomain/EventsOut.json");
assertTrue(outputEventText.contains("04\",\n" + " \"version\": \"0.0.1\",\n"
+ " \"nameSpace\": \"org.onap.policy.apex.sample.events\""));
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java
index 59cc2ceea..5514caab6 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java
@@ -36,16 +36,21 @@ import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexMain;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
/**
* The Class TestRestServer.
*/
public class TestRestServer {
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestRestServer.class);
+
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
@@ -55,34 +60,53 @@ public class TestRestServer {
private static int eventsSent = 0;
/**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
+ /**
* Test rest server put.
*
* @throws MessagingException the messaging exception
* @throws ApexException the apex exception
* @throws IOException Signals that an I/O exception has occurred.
*/
+ @SuppressWarnings("unchecked")
@Test
public void testRestServerPut() throws MessagingException, ApexException, IOException {
+ LOGGER.info("testRestServerPut start");
+
final String[] args =
- { "src/test/resources/prodcons/RESTServerJsonEvent.json" };
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json" };
final ApexMain apexMain = new ApexMain(args);
final Client client = ClientBuilder.newClient();
+ Response response = null;
+ Map<String, Object> jsonMap = null;
+
for (int i = 0; i < 20; i++) {
- final Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
- .request("application/json").put(Entity.json(getEvent()));
+ response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
+ .put(Entity.json(getEvent()));
+
+ if (Response.Status.OK.getStatusCode() != response.getStatus()) {
+ break;
+ }
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
final String responseString = response.readEntity(String.class);
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
- assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
- assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan"));
+ jsonMap = new Gson().fromJson(responseString, Map.class);
}
apexMain.shutdown();
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
+ assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan"));
+ LOGGER.info("testRestServerPut end");
}
/**
@@ -92,28 +116,36 @@ public class TestRestServer {
* @throws ApexException the apex exception
* @throws IOException Signals that an I/O exception has occurred.
*/
+ @SuppressWarnings("unchecked")
@Test
public void testRestServerPost() throws MessagingException, ApexException, IOException {
final String[] args =
- { "src/test/resources/prodcons/RESTServerJsonEvent.json" };
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json" };
final ApexMain apexMain = new ApexMain(args);
final Client client = ClientBuilder.newClient();
+ Response response = null;
+ Map<String, Object> jsonMap = null;
+
for (int i = 0; i < 20; i++) {
- final Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
- .request("application/json").post(Entity.json(getEvent()));
+ response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
+ .post(Entity.json(getEvent()));
+
+ if (Response.Status.OK.getStatusCode() != response.getStatus()) {
+ break;
+ }
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
final String responseString = response.readEntity(String.class);
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
- assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
- assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan"));
+ jsonMap = new Gson().fromJson(responseString, Map.class);
}
apexMain.shutdown();
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
+ assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan"));
}
/**
@@ -126,35 +158,47 @@ public class TestRestServer {
@Test
public void testRestServerGetStatus() throws MessagingException, ApexException, IOException {
final String[] args =
- { "src/test/resources/prodcons/RESTServerJsonEvent.json" };
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json" };
final ApexMain apexMain = new ApexMain(args);
final Client client = ClientBuilder.newClient();
+ Response postResponse = null;
+ Response putResponse = null;
+
// trigger 10 POST & PUT events
for (int i = 0; i < 10; i++) {
- final Response postResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
+ postResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
.request("application/json").post(Entity.json(getEvent()));
- final Response putResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
- .request("application/json").put(Entity.json(getEvent()));
- assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
- assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
+ if (Response.Status.OK.getStatusCode() != postResponse.getStatus()) {
+ break;
+ }
+ putResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
+ .put(Entity.json(getEvent()));
+
+ if (Response.Status.OK.getStatusCode() != putResponse.getStatus()) {
+ break;
+ }
}
final Response statResponse = client.target("http://localhost:23324/apex/FirstConsumer/Status")
.request("application/json").get();
- assertEquals(Response.Status.OK.getStatusCode(), statResponse.getStatus());
final String responseString = statResponse.readEntity(String.class);
+ apexMain.shutdown();
+
+ assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+ assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
+ assertEquals(Response.Status.OK.getStatusCode(), statResponse.getStatus());
+
@SuppressWarnings("unchecked")
final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
- assertEquals("[FirstConsumer", ((String)jsonMap.get("INPUTS")).substring(0, 14));
+ assertEquals("[FirstConsumer", ((String) jsonMap.get("INPUTS")).substring(0, 14));
assertEquals(1.0, jsonMap.get("STAT"));
- assertTrue((double)jsonMap.get("POST") >= 10.0);
- assertTrue((double)jsonMap.get("PUT") >= 10.0);
+ assertTrue((double) jsonMap.get("POST") >= 10.0);
+ assertTrue((double) jsonMap.get("PUT") >= 10.0);
- apexMain.shutdown();
}
/**
@@ -164,39 +208,54 @@ public class TestRestServer {
* @throws ApexException the apex exception
* @throws IOException Signals that an I/O exception has occurred.
*/
+ @SuppressWarnings("unchecked")
@Test
public void testRestServerMultiInputs() throws MessagingException, ApexException, IOException {
final String[] args =
- { "src/test/resources/prodcons/RESTServerJsonEventMultiIn.json" };
+ { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEventMultiIn.json" };
final ApexMain apexMain = new ApexMain(args);
final Client client = ClientBuilder.newClient();
+ Response firstResponse = null;
+ Response secondResponse = null;
+
+ Map<String, Object> firstJsonMap = null;
+ Map<String, Object> secondJsonMap = null;
+
for (int i = 0; i < 20; i++) {
- final Response firstResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
+ firstResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
.request("application/json").post(Entity.json(getEvent()));
- assertEquals(Response.Status.OK.getStatusCode(), firstResponse.getStatus());
+ if (Response.Status.OK.getStatusCode() != firstResponse.getStatus()) {
+ break;
+ }
+
final String firstResponseString = firstResponse.readEntity(String.class);
- @SuppressWarnings("unchecked")
- final Map<String, Object> firstJsonMap = new Gson().fromJson(firstResponseString, Map.class);
- assertEquals("org.onap.policy.apex.sample.events", firstJsonMap.get("nameSpace"));
- assertEquals("Test slogan for External Event0", firstJsonMap.get("TestSlogan"));
+ firstJsonMap = new Gson().fromJson(firstResponseString, Map.class);
- final Response secondResponse = client.target("http://localhost:23324/apex/SecondConsumer/EventIn")
+ secondResponse = client.target("http://localhost:23324/apex/SecondConsumer/EventIn")
.request("application/json").post(Entity.json(getEvent()));
- assertEquals(Response.Status.OK.getStatusCode(), secondResponse.getStatus());
+ if (Response.Status.OK.getStatusCode() != secondResponse.getStatus()) {
+ break;
+ }
+
final String secondResponseString = secondResponse.readEntity(String.class);
- @SuppressWarnings("unchecked")
- final Map<String, Object> secondJsonMap = new Gson().fromJson(secondResponseString, Map.class);
- assertEquals("org.onap.policy.apex.sample.events", secondJsonMap.get("nameSpace"));
- assertEquals("Test slogan for External Event0", secondJsonMap.get("TestSlogan"));
+ secondJsonMap = new Gson().fromJson(secondResponseString, Map.class);
}
apexMain.shutdown();
+
+ assertEquals(Response.Status.OK.getStatusCode(), firstResponse.getStatus());
+ assertEquals("org.onap.policy.apex.sample.events", firstJsonMap.get("nameSpace"));
+ assertEquals("Test slogan for External Event0", firstJsonMap.get("TestSlogan"));
+
+ assertEquals(Response.Status.OK.getStatusCode(), secondResponse.getStatus());
+ assertEquals("org.onap.policy.apex.sample.events", secondJsonMap.get("nameSpace"));
+ assertEquals("Test slogan for External Event0", secondJsonMap.get("TestSlogan"));
}
/**
@@ -395,38 +454,6 @@ public class TestRestServer {
}
/**
- * Test rest server divide by zero.
- *
- * @throws MessagingException the messaging exception
- * @throws ApexException the apex exception
- * @throws IOException Signals that an I/O exception has occurred.
- */
- @Test
- public void testRestServerDivideByZero() throws MessagingException, ApexException, IOException {
- final String[] args =
- { "src/test/resources/prodcons/RESTServerJsonEventDivideByZero.json" };
- final ApexMain apexMain = new ApexMain(args);
-
- final Client client = ClientBuilder.newClient();
-
- for (int i = 0; i < 20; i++) {
- final Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
- .request("application/json").put(Entity.json(getEvent()));
-
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
- final String responseString = response.readEntity(String.class);
-
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
- assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
- assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan"));
- assertTrue(((String) jsonMap.get("exceptionMessage")).contains("caused by: / by zero"));
- }
-
- apexMain.shutdown();
- }
-
- /**
* Gets the event.
*
* @return the event
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServerVpnContext.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServerVpnContext.java
deleted file mode 100644
index 1791033e6..000000000
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServerVpnContext.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. 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=========================================================
- */
-
-package org.onap.policy.apex.testsuites.integration.uservice.adapt.restserver;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.Response;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
-import org.onap.policy.apex.service.engine.main.ApexMain;
-
-
-public class TestRestServerVpnContext {
- private static int eventsSent = 0;
-
- @Ignore
- @Test
- public void testRestServerPut() throws MessagingException, ApexException, IOException {
- final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventContextJava.json"};
- final ApexMain apexMain = new ApexMain(args);
-
- final Client client = ClientBuilder.newClient();
-
- Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
- .request("application/json").put(Entity.json(setupLinkContext("L09", true)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupLinkContext("L10", true)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("A", "L09 L10", 300, 50)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("B", "L09 L10", 300, 299)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("C", "L09 L10", 300, 300)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("D", "L09 L10", 300, 400)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- ThreadUtilities.sleep(100000);
-
- apexMain.shutdown();
- }
-
- @Ignore
- @Test
- public void testRestServerPutAvro() throws MessagingException, ApexException, IOException {
- final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventContextAvro.json"};
- final ApexMain apexMain = new ApexMain(args);
-
- final Client client = ClientBuilder.newClient();
-
- Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
- .request("application/json").put(Entity.json(setupLinkContext("L09", true)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupLinkContext("L10", true)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("A", "L09 L10", 300, 50)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("B", "L09 L10", 300, 299)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("C", "L09 L10", 300, 300)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
- .put(Entity.json(setupCustomerContext("D", "L09 L10", 300, 400)));
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- ThreadUtilities.sleep(100000);
-
- apexMain.shutdown();
- }
-
- private String setupLinkContext(final String link, final Boolean isUp) {
- final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.domains.vpn.events\",\n"
- + "\"name\": \"VPNLinkCtxtTriggerEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
- + eventsSent++ + "\",\n" + "\"target\": \"apex\",\n" + "\"Link\": \"" + link + "\",\n" + "\"LinkUp\": "
- + isUp + "\n" + "}";
-
- return eventString;
- }
-
- private String setupCustomerContext(final String customerName, final String linkList, final int slaDt,
- final int ytdDt) {
- final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.domains.vpn.events\",\n"
- + "\"name\": \"VPNCustomerCtxtTriggerEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
- + eventsSent++ + "\",\n" + "\"target\": \"apex\",\n" + "\"CustomerName\": \"" + customerName + "\",\n"
- + "\"LinkList\": \"" + linkList + "\",\n" + "\"SlaDT\": \"" + slaDt + "\",\n" + "\"YtdDT\": " + ytdDt
- + "\n" + "}";
-
- return eventString;
- }
-}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsClient.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsClient.java
index c2db95860..18c13dbfe 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsClient.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsClient.java
@@ -22,6 +22,7 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.websocket;
import static org.junit.Assert.assertEquals;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
@@ -34,15 +35,23 @@ public class TestWs2WsClient {
private static final int EVENT_COUNT = 100;
private static final int EVENT_INTERVAL = 20;
+ /**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
@Test
public void testJsonWsEvents() throws MessagingException, ApexException {
- final String[] args = {"src/test/resources/prodcons/Ws2WsClientJsonEvent.json"};
+ final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/Ws2WsClientJsonEvent.json"};
testWsEvents(args, false);
}
@Test
public void testXmlWsEvents() throws MessagingException, ApexException {
- final String[] args = {"src/test/resources/prodcons/Ws2WsClientXMLEvent.json"};
+ final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/Ws2WsClientXMLEvent.json"};
testWsEvents(args, true);
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsServer.java
index 34871e3c6..07b51a8e3 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsServer.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/TestWs2WsServer.java
@@ -22,6 +22,7 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.websocket;
import static org.junit.Assert.assertEquals;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
@@ -38,6 +39,14 @@ public class TestWs2WsServer {
private static final int EVENT_INTERVAL = 20;
/**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
+ /**
* Test json ws events.
*
* @throws MessagingException the messaging exception
@@ -45,7 +54,7 @@ public class TestWs2WsServer {
*/
@Test
public void testJsonWsEvents() throws MessagingException, ApexException {
- final String[] args = {"src/test/resources/prodcons/Ws2WsServerJsonEvent.json"};
+ final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/Ws2WsServerJsonEvent.json"};
testWsEvents(args, false);
}
@@ -57,7 +66,7 @@ public class TestWs2WsServer {
*/
@Test
public void testXmlWsEvents() throws MessagingException, ApexException {
- final String[] args = {"src/test/resources/prodcons/Ws2WsServerXMLEvent.json"};
+ final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/Ws2WsServerXMLEvent.json"};
testWsEvents(args, true);
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java
index 757a48302..d57f280ed 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/context/EventAlbumContextTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -47,6 +48,14 @@ public class EventAlbumContextTest {
@Rule
public TemporaryFolder tempTestDir = new TemporaryFolder();
+
+ /**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
@Test
public void testJavaEventAlbumContextTest() throws IOException, ApexException {
@@ -57,7 +66,7 @@ public class EventAlbumContextTest {
eventContextString = ResourceUtils.getResourceAsString("examples/scripts/TestPolicyJavaEventContext.apex");
configFile = "src/test/resources/prodcons/Context_JavaEventAlbum_file2file.json";
- outputFile = "src/test/resources/events/Context_JavaEventAlbum_EventOut.json";
+ outputFile = "target/Context_JavaEventAlbum_EventOut.json";
compareFile = "src/test/resources/events/Context_JavaEventAlbum_EventOutCompare.json";
testEventAlbumContextTest();
@@ -72,7 +81,7 @@ public class EventAlbumContextTest {
eventContextString = ResourceUtils.getResourceAsString("examples/scripts/TestPolicyAvroEventContext.apex");
configFile = "src/test/resources/prodcons/Context_AvroEventAlbum_file2file.json";
- outputFile = "src/test/resources/events/Context_AvroEventAlbum_EventOut.json";
+ outputFile = "target/Context_AvroEventAlbum_EventOut.json";
compareFile = "src/test/resources/events/Context_AvroEventAlbum_EventOutCompare.json";
testEventAlbumContextTest();
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java
index 3e5cb8721..d3a6d76d4 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java
@@ -42,7 +42,7 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
-import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters;
+import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters;
import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory;
@@ -68,6 +68,14 @@ public class EngDepMessagingTest {
private EngineServiceParameters engineServiceParameters;
/**
+ * Clear relative file root environment variable.
+ */
+ @Before
+ public void clearRelativeFileRoot() {
+ System.clearProperty("APEX_RELATIVE_FILE_ROOT");
+ }
+
+ /**
* Before test.
*/
@Before
@@ -97,8 +105,8 @@ public class EngDepMessagingTest {
engineServiceParameters.setDeploymentPort(58820);
engineServiceParameters.setInstanceCount(3);
engineServiceParameters.setId(100);
- engineServiceParameters.getEngineParameters().getExecutorParameterMap().put("MVEL",
- new MvelExecutorParameters());
+ engineServiceParameters.getEngineParameters().getExecutorParameterMap().put("JAVASCRIPT",
+ new JavascriptExecutorParameters());
ParameterService.register(engineServiceParameters, true);
ParameterService.register(engineServiceParameters.getEngineParameters(), true);
@@ -146,7 +154,7 @@ public class EngDepMessagingTest {
fail("Test server failed to start after " + MAX_START_WAIT + " ms");
}
- final AxPolicyModel apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL");
+ final AxPolicyModel apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("JAVASCRIPT");
final BatchDeployer deployer1 = new BatchDeployer("localhost", 58820, System.out);
assertNotNull(deployer1);