aboutsummaryrefslogtreecommitdiffstats
path: root/models-sim/models-sim-dmaap/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'models-sim/models-sim-dmaap/src/test/java')
-rw-r--r--models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/CommonRestServer.java17
-rw-r--r--models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/e2e/EndToEndTest.java4
-rw-r--r--models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/DmaapSimActivatorTest.java9
-rw-r--r--models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/MainTest.java15
4 files changed, 28 insertions, 17 deletions
diff --git a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/CommonRestServer.java b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/CommonRestServer.java
index 7e30c5a4c..f0ce201c7 100644
--- a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/CommonRestServer.java
+++ b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/models/sim/dmaap/rest/CommonRestServer.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@ import lombok.Getter;
import org.glassfish.jersey.client.ClientProperties;
import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.network.NetworkUtil;
@@ -56,6 +55,8 @@ public class CommonRestServer {
public static final String NAME = "DMaaP Simulator";
public static final String ENDPOINT_PREFIX = "events/";
+ protected static final String CONFIG_FILE = "src/test/resources/parameters/TestConfigParams.json";
+
@Getter
private static int port;
@@ -66,20 +67,24 @@ public class CommonRestServer {
/**
* Allocates a port for the server, writes a config file, and then starts Main.
*
+ * @param shouldStartMain {@code true} if Main should be started, {@code false}
+ * otherwise
+ *
* @throws Exception if an error occurs
*/
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ public static void reconfigure(boolean shouldStartMain) throws Exception {
port = NetworkUtil.allocPort();
httpPrefix = "http://localhost:" + port + "/";
String json = new CommonTestData().getParameterGroupAsString(port);
- makeConfigFile("src/test/resources/parameters/TestConfigParams.json", json);
+ makeConfigFile(CONFIG_FILE, json);
HttpServletServerFactoryInstance.getServerFactory().destroy();
- startMain();
+ if (shouldStartMain) {
+ startMain();
+ }
}
/**
diff --git a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/e2e/EndToEndTest.java b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/e2e/EndToEndTest.java
index 50c319837..94fbc4fd3 100644
--- a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/e2e/EndToEndTest.java
+++ b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/e2e/EndToEndTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -78,7 +78,7 @@ public class EndToEndTest extends CommonRestServer {
public static void setUpBeforeClass() throws Exception {
TopicEndpointManager.getManager().shutdown();
- CommonRestServer.setUpBeforeClass();
+ CommonRestServer.reconfigure(true);
queue = new LinkedBlockingQueue<>();
queue2 = new LinkedBlockingQueue<>();
diff --git a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/DmaapSimActivatorTest.java b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/DmaapSimActivatorTest.java
index 380a72423..30b65806f 100644
--- a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/DmaapSimActivatorTest.java
+++ b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/DmaapSimActivatorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInst
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterHandler;
+import org.onap.policy.models.sim.dmaap.rest.CommonRestServer;
import org.onap.policy.models.sim.dmaap.startstop.DmaapSimActivator;
import org.onap.policy.models.sim.dmaap.startstop.DmaapSimCommandLineArguments;
@@ -38,7 +39,7 @@ import org.onap.policy.models.sim.dmaap.startstop.DmaapSimCommandLineArguments;
/**
* Class to perform unit test of {@link DmaapSimActivator}}.
*/
-public class DmaapSimActivatorTest {
+public class DmaapSimActivatorTest extends CommonRestServer {
private DmaapSimActivator activator;
@@ -52,7 +53,9 @@ public class DmaapSimActivatorTest {
Registry.newRegistry();
HttpServletServerFactoryInstance.getServerFactory().destroy();
- final String[] papConfigParameters = {"-c", "parameters/NormalParameters.json"};
+ CommonRestServer.reconfigure(false);
+
+ final String[] papConfigParameters = {"-c", CONFIG_FILE};
final DmaapSimCommandLineArguments arguments = new DmaapSimCommandLineArguments(papConfigParameters);
final DmaapSimParameterGroup parGroup = new DmaapSimParameterHandler().getParameters(arguments);
diff --git a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/MainTest.java b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/MainTest.java
index baa13a1bb..b3f83ddde 100644
--- a/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/MainTest.java
+++ b/models-sim/models-sim-dmaap/src/test/java/org/onap/policy/sim/dmaap/startstop/MainTest.java
@@ -29,7 +29,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.models.sim.dmaap.DmaapSimException;
+import org.onap.policy.models.sim.dmaap.rest.CommonRestServer;
import org.onap.policy.models.sim.dmaap.startstop.Main;
import org.onap.policy.sim.dmaap.parameters.CommonTestData;
@@ -38,7 +38,7 @@ import org.onap.policy.sim.dmaap.parameters.CommonTestData;
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-public class MainTest {
+public class MainTest extends CommonRestServer {
private Main main;
/**
@@ -63,8 +63,9 @@ public class MainTest {
}
@Test
- public void testMain() throws DmaapSimException {
- final String[] NormalParameters = {"-c", "parameters/NormalParameters.json"};
+ public void testMain() throws Exception {
+ CommonRestServer.reconfigure(false);
+ final String[] NormalParameters = {"-c", CONFIG_FILE};
main = new Main(NormalParameters);
assertTrue(main.getParameters().isValid());
assertEquals(CommonTestData.SIM_GROUP_NAME, main.getParameters().getName());
@@ -80,9 +81,11 @@ public class MainTest {
}
@Test
- public void testMain_InvalidArguments() {
+ public void testMain_InvalidArguments() throws Exception {
+ CommonRestServer.reconfigure(false);
+
// note: this is missing the "-c" argument, thus the ARGUMENTS are invalid
- final String[] NormalParameters = {"parameters/NormalParameters.json"};
+ final String[] NormalParameters = {CONFIG_FILE};
main = new Main(NormalParameters);
assertNull(main.getParameters());
}