summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-simulators/src/test/java
diff options
context:
space:
mode:
authordc443y <dc443y@att.com>2022-01-21 14:43:18 -0600
committerdc443y <dc443y@att.com>2022-01-21 14:59:42 -0600
commitc445d7865f1ded1c62f720abb70382b2963fff57 (patch)
tree059ff8eaa968a5e2a1c39a0a456741e6f94097ae /models-interactions/model-simulators/src/test/java
parent7a718bd9b82ac16e5d49a1a2fb2256682f020656 (diff)
Add configurable port and authentication to DMaaP simulator
Issue-ID: POLICY-3890 Signed-off-by: dc443y <dc443y@att.com> Change-Id: Idbeb3590a767e51aa0058a7a45d56a61e81301cb
Diffstat (limited to 'models-interactions/model-simulators/src/test/java')
-rw-r--r--models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/DmaapSimulatorTest.java111
1 files changed, 103 insertions, 8 deletions
diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/DmaapSimulatorTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/DmaapSimulatorTest.java
index 19c399db8..197c25f6c 100644
--- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/DmaapSimulatorTest.java
+++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/DmaapSimulatorTest.java
@@ -24,24 +24,30 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.util.HashMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.bus.DmaapTopicSink;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.utils.coder.StandardCoder;
public class DmaapSimulatorTest {
private static final int MAX_WAIT_SEC = 5;
private static final String TOPIC = "MY-TOPIC";
+ private static final String AUTH_TOPIC = "MY-AUTH-TOPIC";
+ private static final String AUTH_PORT = "3903";
+
+ private static final HashMap<String, String> savedValuesMap = new HashMap<>();
/**
* Messages from the topic are placed here by the endpoint.
@@ -61,11 +67,14 @@ public class DmaapSimulatorTest {
@Before
public void setUp() throws Exception {
assertNotNull(Util.buildDmaapSim());
+ setSystemProperties();
+ assertNotNull(Util.buildDmaapSim("org/onap/policy/simulators/dmaap/AuthDmaapParameters.json"));
- String topicJson = new String(Files.readAllBytes(
- new File("src/test/resources/org/onap/policy/simulators/dmaap/TopicParameters.json").toPath()),
- StandardCharsets.UTF_8);
- topicJson = topicJson.replace("${port}", String.valueOf(Util.DMAAPSIM_SERVER_PORT));
+ String topicJson = Files.readString(
+ new File("src/test/resources/org/onap/policy/simulators/dmaap/TopicParameters.json").toPath());
+ topicJson = topicJson
+ .replace("${port}", String.valueOf(Util.DMAAPSIM_SERVER_PORT))
+ .replace("${authPort}", AUTH_PORT);
TopicParameterGroup topicConfig = new StandardCoder().decode(topicJson, TopicParameterGroup.class);
@@ -75,6 +84,11 @@ public class DmaapSimulatorTest {
queue = new LinkedBlockingQueue<>();
}
+ @AfterClass
+ public static void tearDownAfterClass() {
+ clearSystemProperties();
+ }
+
@After
public void tearDown() {
TopicEndpointManager.getManager().shutdown();
@@ -83,15 +97,96 @@ public class DmaapSimulatorTest {
@Test
public void test() throws InterruptedException {
- TopicEndpointManager.getManager().getDmaapTopicSource(TOPIC)
- .register((infra, topic, event) -> queue.add(event));
+ // test basic DMaaP simulator (default port, http, no auth)
+ sendAndPoll(TOPIC);
+ // test custom DMaaP simulator (custom port, https, basic auth)
+ sendAndPoll(AUTH_TOPIC);
+ }
+
+ /**
+ * Sets up keystore and truststore for https test server.
+ */
+ private static void setSystemProperties() {
+ String keyStoreSystemProperty = System.getProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
+ if (keyStoreSystemProperty != null) {
+ savedValuesMap.put(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, keyStoreSystemProperty);
+ }
+
+ String keyStorePasswordSystemProperty =
+ System.getProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
+ if (keyStorePasswordSystemProperty != null) {
+ savedValuesMap.put(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
+ keyStorePasswordSystemProperty);
+ }
+
+ String trustStoreSystemProperty = System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
+ if (trustStoreSystemProperty != null) {
+ savedValuesMap.put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, trustStoreSystemProperty);
+ }
- DmaapTopicSink sink = TopicEndpointManager.getManager().getDmaapTopicSink(TOPIC);
+ String trustStorePasswordSystemProperty =
+ System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
+ if (trustStorePasswordSystemProperty != null) {
+ savedValuesMap.put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
+ trustStorePasswordSystemProperty);
+ }
+
+ System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
+ System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME, "kstest");
+
+ System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
+ System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME, "kstest");
+ }
+
+ /**
+ * Clears the keystore/truststore properties.
+ */
+ private static void clearSystemProperties() {
+ if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME)) {
+ System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME));
+ savedValuesMap.remove(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
+ } else {
+ System.clearProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
+ }
+
+ if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME)) {
+ System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME));
+ savedValuesMap.remove(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
+ } else {
+ System.clearProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
+ }
+
+ if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME)) {
+ System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME));
+ savedValuesMap.remove(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
+ } else {
+ System.clearProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
+ }
+
+ if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME)) {
+ System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME));
+ savedValuesMap.remove(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
+ } else {
+ System.clearProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
+ }
+ }
+
+ private void sendAndPoll(String topicName) throws InterruptedException {
+ TopicEndpointManager.getManager().getDmaapTopicSource(topicName)
+ .register((infra, topic, event) -> queue.add(event));
+
+ DmaapTopicSink sink = TopicEndpointManager.getManager().getDmaapTopicSink(topicName);
assertThat(queue.poll(1, TimeUnit.SECONDS)).isNull();
+
sink.send("hello");
assertEquals("hello", queue.poll(MAX_WAIT_SEC, TimeUnit.SECONDS));
sink.send("world");
assertEquals("world", queue.poll(MAX_WAIT_SEC, TimeUnit.SECONDS));
}
+
}