/*
* ============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.
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;
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;
/**
* 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();
+ }
}
/**
/*-
* ============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.
public static void setUpBeforeClass() throws Exception {
TopicEndpointManager.getManager().shutdown();
- CommonRestServer.setUpBeforeClass();
+ CommonRestServer.reconfigure(true);
queue = new LinkedBlockingQueue<>();
queue2 = new LinkedBlockingQueue<>();
/*-
* ============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.
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;
/**
* Class to perform unit test of {@link DmaapSimActivator}}.
*/
-public class DmaapSimActivatorTest {
+public class DmaapSimActivatorTest extends CommonRestServer {
private DmaapSimActivator activator;
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);
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;
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-public class MainTest {
+public class MainTest extends CommonRestServer {
private Main main;
/**
}
@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());
}
@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());
}