summaryrefslogtreecommitdiffstats
path: root/feature-legacy-config/src/test/java
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2021-04-13 17:27:35 -0500
committerjhh <jorge.hernandez-herrero@att.com>2021-04-14 11:08:02 -0500
commite05a96429ac2d4823011c9dc70accdd0f581b862 (patch)
tree3b734433d1e3c4ca1a12dc407cfebee8c1fb2546 /feature-legacy-config/src/test/java
parent8f8a6d8d207e30303efbedd7f60ca397c2c61970 (diff)
Add legacy-config new feature
This feature makes the legacy configuration optional. It was used by brmsgw and other tooling to provision via its DMaaP channel. The capability to configure via PdpConfiguration object is kept in the core preserving backwards compatibility, but the DMaaP provisioning channel(s) are optional. Issue-ID: POLICY-2618 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Ia7198ac3b2810d85133c06ba5217a9c28e07ac4c Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-legacy-config/src/test/java')
-rw-r--r--feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigFeatureTest.java70
-rw-r--r--feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigTest.java87
-rw-r--r--feature-legacy-config/src/test/java/org/onap/policy/drools/server/restful/RestLegacyConfigTest.java106
3 files changed, 263 insertions, 0 deletions
diff --git a/feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigFeatureTest.java b/feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigFeatureTest.java
new file mode 100644
index 00000000..d73817b8
--- /dev/null
+++ b/feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigFeatureTest.java
@@ -0,0 +1,70 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.legacy.config;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
+
+public class LegacyConfigFeatureTest {
+
+ private LegacyConfigFeature configF;
+
+ /**
+ * Set up.
+ */
+ @Before
+ public void setUp() {
+ SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
+ configF = new LegacyConfigFeature();
+ }
+
+ /**
+ * Tear down.
+ */
+ @After
+ public void tearDown() {
+ NoopTopicFactories.getSourceFactory().destroy();
+ NoopTopicFactories.getSinkFactory().destroy();
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+ }
+
+ @Test
+ public void getSequenceNumber() {
+ assertEquals(LegacyConfigFeature.SEQNO, new LegacyConfigFeature().getSequenceNumber());
+ }
+
+ @Test
+ public void afterOpenBeforeShutdown() {
+ assertFalse(LegacyConfigFeature.getLegacyConfig().isAlive());
+ configF.afterOpen(PolicyEngineConstants.getManager());
+ assertTrue(LegacyConfigFeature.getLegacyConfig().isAlive());
+ configF.beforeShutdown(PolicyEngineConstants.getManager());
+ assertFalse(LegacyConfigFeature.getLegacyConfig().isAlive());
+ }
+} \ No newline at end of file
diff --git a/feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigTest.java b/feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigTest.java
new file mode 100644
index 00000000..d970585b
--- /dev/null
+++ b/feature-legacy-config/src/test/java/org/onap/policy/drools/legacy/config/LegacyConfigTest.java
@@ -0,0 +1,87 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.legacy.config;
+
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.Topic;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+
+public class LegacyConfigTest {
+
+ /**
+ * Set up.
+ */
+ @Before
+ public void setUp() {
+ SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
+ }
+
+ /**
+ * Tear down.
+ */
+ @After
+ public void tearDown() {
+ NoopTopicFactories.getSourceFactory().destroy();
+ NoopTopicFactories.getSinkFactory().destroy();
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+ }
+
+ @Test
+ public void testStartStop() {
+ LegacyConfig config = new LegacyConfig();
+ assertFalse(config.isAlive());
+
+ assertTrue(config.start());
+ assertTrue(config.isAlive());
+
+ config.onTopicEvent(Topic.CommInfrastructure.NOOP, "PDPD-CONFIGURATION", "{}");
+ assertTrue(config.isAlive());
+
+ assertTrue(config.stop());
+ assertFalse(config.isAlive());
+
+ config.shutdown();
+ assertFalse(config.isAlive());
+ }
+
+ @Test
+ public void testConstructors() {
+ LegacyConfig config = new LegacyConfig();
+ assertNotNull(config.getProperties());
+ assertEquals("PDPD-CONFIGURATION", config.getSource().getTopic());
+
+ SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes/bad-properties-1");
+ assertThatIllegalStateException().isThrownBy(LegacyConfig::new);
+
+ /* two sources are ok - no exception */
+ SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes/properties-2");
+ new LegacyConfig();
+ }
+} \ No newline at end of file
diff --git a/feature-legacy-config/src/test/java/org/onap/policy/drools/server/restful/RestLegacyConfigTest.java b/feature-legacy-config/src/test/java/org/onap/policy/drools/server/restful/RestLegacyConfigTest.java
new file mode 100644
index 00000000..6dd2edbc
--- /dev/null
+++ b/feature-legacy-config/src/test/java/org/onap/policy/drools/server/restful/RestLegacyConfigTest.java
@@ -0,0 +1,106 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.server.restful;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+import javax.ws.rs.core.Response;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.YamlJacksonHandler;
+import org.onap.policy.common.gson.JacksonHandler;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.drools.legacy.config.LegacyConfigFeature;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.system.PolicyControllerConstants;
+
+public class RestLegacyConfigTest {
+
+ private static HttpClient client;
+
+ /**
+ * Set up.
+ */
+ @BeforeClass
+ public static void setUp() throws Exception {
+ SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
+
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ PolicyControllerConstants.getFactory().destroy();
+
+ int port = NetworkUtil.allocPort();
+
+ HttpClientFactoryInstance.getClientFactory().build(
+ BusTopicParams.builder()
+ .clientName("legacy")
+ .hostname("localhost")
+ .port(port)
+ .basePath("policy/pdp/engine/legacy/config")
+ .managed(true)
+ .build());
+
+ HttpServletServer server =
+ HttpServletServerFactoryInstance.getServerFactory().build("legacy", "localhost", port, "/",
+ true, true);
+ server.setSerializationProvider(
+ String.join(",", JacksonHandler.class.getName(), YamlJacksonHandler.class.getName()));
+ server.addServletClass("/*", RestLegacyConfigManager.class.getName());
+ server.waitedStart(5000L);
+
+ assertTrue(NetworkUtil.isTcpPortOpen("localhost", port, 40, 250L));
+ client = HttpClientFactoryInstance.getClientFactory().get("legacy");
+ }
+
+ /**
+ * Tear down.
+ */
+ @AfterClass
+ public static void tearDown() {
+ LegacyConfigFeature.getLegacyConfig().shutdown();
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+ }
+
+ @Test
+ public void properties() {
+ Response response = client.get("properties");
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(LegacyConfigFeature.getLegacyConfig().getProperties(),
+ HttpClient.getBody(response, Properties.class));
+ }
+
+ @Test
+ public void topic() {
+ Response response = client.get("source");
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+}
+
+
+