summaryrefslogtreecommitdiffstats
path: root/policy-management/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management/src/test/java')
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java105
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java44
2 files changed, 147 insertions, 2 deletions
diff --git a/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
index 8cd4ee6e..15a0b18f 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -54,12 +54,23 @@ public class SystemPersistenceTest {
*/
private static final String TEST_CONTROLLER_NAME = "foo";
+
/**
* Test JUnit Topic Name.
*/
private static final String TEST_TOPIC_NAME = TEST_CONTROLLER_NAME;
/**
+ * Test JUnit HTTP Server Name.
+ */
+ private static final String TEST_HTTP_SERVER_NAME = TEST_CONTROLLER_NAME;
+
+ /**
+ * Test JUnit HTTP Client Name.
+ */
+ private static final String TEST_HTTP_CLIENT_NAME = TEST_CONTROLLER_NAME;
+
+ /**
* Test JUnit Controller File.
*/
private static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
@@ -80,6 +91,28 @@ public class SystemPersistenceTest {
private static final String TEST_TOPIC_FILE_BAK = TEST_TOPIC_FILE + ".bak";
/**
+ * Test JUnit Http Server File.
+ */
+ private static final String TEST_HTTP_SERVER_FILE = TEST_CONTROLLER_NAME
+ + FileSystemPersistence.PROPERTIES_FILE_HTTP_SERVER_SUFFIX;
+
+ /**
+ * Test JUnit Backup Http Server File.
+ */
+ private static final String TEST_HTTP_SERVER_FILE_BAK = TEST_HTTP_SERVER_FILE + ".bak";
+
+ /**
+ * Test JUnit Http Client File.
+ */
+ private static final String TEST_HTTP_CLIENT_FILE = TEST_CONTROLLER_NAME
+ + FileSystemPersistence.PROPERTIES_FILE_HTTP_CLIENT_SUFFIX;
+
+ /**
+ * Test JUnit Backup Http Server File.
+ */
+ private static final String TEST_HTTP_CLIENT_FILE_BAK = TEST_HTTP_CLIENT_FILE + ".bak";
+
+ /**
* Test JUnit Environment/Engine properties.
*/
private static final String ENV_PROPS = TEST_CONTROLLER_NAME;
@@ -188,7 +221,67 @@ public class SystemPersistenceTest {
}
@Test
- public void test4Controller() {
+ public void test4HttpServer() {
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+
+ Path httpServerPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_SERVER_FILE);
+
+ Path httpServerBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_SERVER_FILE_BAK);
+
+ assertTrue(Files.notExists(httpServerPath));
+ assertTrue(Files.notExists(httpServerBakPath));
+
+ SystemPersistenceConstants.getManager().storeHttpServer(TEST_HTTP_SERVER_NAME, new Properties());
+
+ assertTrue(Files.exists(httpServerPath));
+
+ Properties properties = SystemPersistenceConstants.getManager().getHttpServerProperties(TEST_HTTP_SERVER_NAME);
+ assertNotNull(properties);
+
+ List<Properties> httpServerPropsList = SystemPersistenceConstants.getManager().getHttpServerProperties();
+ assertEquals(1, httpServerPropsList.size());
+
+ SystemPersistenceConstants.getManager().backupHttpServer(TEST_HTTP_SERVER_NAME);
+ assertTrue(Files.exists(httpServerBakPath));
+
+ SystemPersistenceConstants.getManager().deleteHttpServer(TEST_HTTP_SERVER_NAME);
+ assertTrue(Files.notExists(httpServerPath));
+ }
+
+ @Test
+ public void test5HttpClient() {
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+
+ Path httpClientPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_CLIENT_FILE);
+
+ Path httpClientBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_CLIENT_FILE_BAK);
+
+ assertTrue(Files.notExists(httpClientPath));
+ assertTrue(Files.notExists(httpClientBakPath));
+
+ SystemPersistenceConstants.getManager().storeHttpClient(TEST_HTTP_CLIENT_NAME, new Properties());
+
+ assertTrue(Files.exists(httpClientPath));
+
+ Properties properties = SystemPersistenceConstants.getManager().getHttpClientProperties(TEST_HTTP_CLIENT_NAME);
+ assertNotNull(properties);
+
+ List<Properties> httpClientPropsList = SystemPersistenceConstants.getManager().getHttpClientProperties();
+ assertEquals(1, httpClientPropsList.size());
+
+ SystemPersistenceConstants.getManager().backupHttpClient(TEST_HTTP_CLIENT_NAME);
+ assertTrue(Files.exists(httpClientBakPath));
+
+ SystemPersistenceConstants.getManager().deleteHttpClient(TEST_HTTP_CLIENT_NAME);
+ assertTrue(Files.notExists(httpClientPath));
+ }
+
+ @Test
+ public void test6Controller() {
SystemPersistenceConstants.getManager().setConfigurationDir(null);
Path controllerPath = Paths
@@ -233,6 +326,8 @@ public class SystemPersistenceTest {
}
SystemPersistenceConstants.getManager().deleteTopic(TEST_TOPIC_NAME);
+ SystemPersistenceConstants.getManager().deleteHttpServer(TEST_HTTP_SERVER_NAME);
+ SystemPersistenceConstants.getManager().deleteHttpClient(TEST_HTTP_CLIENT_NAME);
final Path testControllerBakPath =
Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
@@ -240,6 +335,10 @@ public class SystemPersistenceTest {
final Path testTopicBakPath = Paths
.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_TOPIC_FILE_BAK);
+ final Path testHttpServerBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_SERVER_FILE_BAK);
+ final Path testHttpClientBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_CLIENT_FILE_BAK);
final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, FileSystemPersistence.PROPERTIES_FILE_ENGINE);
final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE);
@@ -247,6 +346,8 @@ public class SystemPersistenceTest {
Files.deleteIfExists(testControllerBakPath);
Files.deleteIfExists(testTopicBakPath);
+ Files.deleteIfExists(testHttpServerBakPath);
+ Files.deleteIfExists(testHttpClientBakPath);
Files.deleteIfExists(policyEnginePath);
Files.deleteIfExists(environmentPath);
Files.deleteIfExists(systemPath);
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index 412e704a..b5c83e43 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -52,6 +52,8 @@ import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory;
import org.onap.policy.common.utils.gson.GsonTestUtils;
@@ -109,6 +111,10 @@ public class PolicyEngineManagerTest {
private HttpServletServer server2;
private List<HttpServletServer> servers;
private HttpServletServerFactory serverFactory;
+ private HttpClientFactory clientFactory;
+ private HttpClient client1;
+ private HttpClient client2;
+ private List<HttpClient> clients;
private TopicEndpoint endpoint;
private PolicyController controller;
private PolicyController controller2;
@@ -163,6 +169,10 @@ public class PolicyEngineManagerTest {
server2 = mock(HttpServletServer.class);
servers = Arrays.asList(server1, server2);
serverFactory = mock(HttpServletServerFactory.class);
+ client1 = mock(HttpClient.class);
+ client2 = mock(HttpClient.class);
+ clients = Arrays.asList(client1, client2);
+ clientFactory = mock(HttpClientFactory.class);
endpoint = mock(TopicEndpoint.class);
controller = mock(PolicyController.class);
controller2 = mock(PolicyController.class);
@@ -216,6 +226,16 @@ public class PolicyEngineManagerTest {
when(serverFactory.build(any())).thenReturn(servers);
+ when(client1.getPort()).thenReturn(2001);
+ when(client1.start()).thenReturn(true);
+ when(client1.stop()).thenReturn(true);
+
+ when(client2.getPort()).thenReturn(2002);
+ when(client2.start()).thenReturn(true);
+ when(client2.stop()).thenReturn(true);
+
+ when(clientFactory.inventory()).thenReturn(clients);
+
when(source1.getTopic()).thenReturn("source1-topic");
when(source1.start()).thenReturn(true);
when(source1.stop()).thenReturn(true);
@@ -515,6 +535,7 @@ public class PolicyEngineManagerTest {
when(endpoint.addTopicSources(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
when(endpoint.addTopicSinks(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
when(serverFactory.build(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
+ when(clientFactory.build(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
mgr.configure(properties);
verify(prov2).afterConfigure(mgr);
@@ -763,6 +784,7 @@ public class PolicyEngineManagerTest {
when(prov1.beforeStart(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(prov1.afterStart(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(server1.waitedStart(anyLong())).thenThrow(new RuntimeException(EXPECTED));
+ when(client1.start()).thenThrow(new RuntimeException(EXPECTED));
when(source1.start()).thenThrow(new RuntimeException(EXPECTED));
when(sink1.start()).thenThrow(new RuntimeException(EXPECTED));
});
@@ -776,6 +798,9 @@ public class PolicyEngineManagerTest {
// servlet wait fails - still does everything
testStart(false, () -> when(server1.waitedStart(anyLong())).thenReturn(false));
+ // client fails - still does everything
+ testStart(false, () -> when(client1.start()).thenReturn(false));
+
// topic source is not started with start
testStart(true, () -> when(source1.start()).thenReturn(false));
@@ -841,6 +866,9 @@ public class PolicyEngineManagerTest {
verify(server1).waitedStart(anyLong());
verify(server2).waitedStart(anyLong());
+ verify(client1).start();
+ verify(client2).start();
+
verify(source1, never()).start();
verify(source2, never()).start();
@@ -866,6 +894,7 @@ public class PolicyEngineManagerTest {
when(prov1.beforeStop(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(prov1.afterStop(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(server1.stop()).thenThrow(new RuntimeException(EXPECTED));
+ when(client1.stop()).thenThrow(new RuntimeException(EXPECTED));
when(source1.stop()).thenThrow(new RuntimeException(EXPECTED));
when(sink1.stop()).thenThrow(new RuntimeException(EXPECTED));
});
@@ -881,6 +910,7 @@ public class PolicyEngineManagerTest {
verify(sink1, never()).stop();
verify(endpoint, never()).stop();
verify(server1, never()).stop();
+ verify(client1, never()).stop();
verify(prov1, never()).afterStop(mgr);
verify(prov2, never()).afterStop(mgr);
@@ -902,6 +932,9 @@ public class PolicyEngineManagerTest {
// servlet fails to stop - still does everything
testStop(false, () -> when(server1.stop()).thenReturn(false));
+ // client fails to stop - still does everything
+ testStop(false, () -> when(client1.stop()).thenReturn(false));
+
// lock manager fails to stop - still does everything
testStop(false, () -> when(lockmgr.stop()).thenReturn(false));
@@ -954,6 +987,9 @@ public class PolicyEngineManagerTest {
verify(server1).stop();
verify(server2).stop();
+ verify(client1).stop();
+ verify(client2).stop();
+
verify(prov1).afterStop(mgr);
verify(prov2).afterStop(mgr);
}
@@ -1017,6 +1053,7 @@ public class PolicyEngineManagerTest {
verify(controllerFactory).shutdown();
verify(endpoint).shutdown();
verify(serverFactory).destroy();
+ verify(clientFactory).destroy();
assertTrue(jmxStopped);
@@ -1058,6 +1095,8 @@ public class PolicyEngineManagerTest {
verify(server1).shutdown();
verify(server2).shutdown();
+
+ verify(clientFactory).destroy();
}
@Test
@@ -1910,6 +1949,11 @@ public class PolicyEngineManagerTest {
}
@Override
+ protected HttpClientFactory getHttpClientFactory() {
+ return clientFactory;
+ }
+
+ @Override
protected PolicyControllerFactory getControllerFactory() {
return controllerFactory;
}