summaryrefslogtreecommitdiffstats
path: root/feature-legacy-config
diff options
context:
space:
mode:
Diffstat (limited to 'feature-legacy-config')
-rw-r--r--feature-legacy-config/lombok.config3
-rw-r--r--feature-legacy-config/pom.xml127
-rw-r--r--feature-legacy-config/src/assembly/zip.xml70
-rw-r--r--feature-legacy-config/src/main/feature/config/feature-legacy-config.properties28
-rw-r--r--feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfig.java93
-rw-r--r--feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfigFeature.java55
-rw-r--r--feature-legacy-config/src/main/java/org/onap/policy/drools/server/restful/RestLegacyConfigManager.java68
-rw-r--r--feature-legacy-config/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi1
-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
-rw-r--r--feature-legacy-config/src/test/resources/bad-properties-1/feature-legacy-config.properties17
-rw-r--r--feature-legacy-config/src/test/resources/feature-legacy-config.properties21
-rw-r--r--feature-legacy-config/src/test/resources/properties-2/feature-legacy-config.properties19
14 files changed, 765 insertions, 0 deletions
diff --git a/feature-legacy-config/lombok.config b/feature-legacy-config/lombok.config
new file mode 100644
index 00000000..2384843f
--- /dev/null
+++ b/feature-legacy-config/lombok.config
@@ -0,0 +1,3 @@
+config.stopBubbling = true
+lombok.addLombokGeneratedAnnotation = true
+lombok.nonNull.exceptionType = IllegalArgumentException
diff --git a/feature-legacy-config/pom.xml b/feature-legacy-config/pom.xml
new file mode 100644
index 00000000..e8d1db84
--- /dev/null
+++ b/feature-legacy-config/pom.xml
@@ -0,0 +1,127 @@
+<!--
+ ============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=========================================================
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>drools-pdp</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>feature-legacy-config</artifactId>
+
+ <name>feature-legacy-config</name>
+ <description>Loadable module to support the legacy configuration mode</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>zipfile</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <attach>true</attach>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <descriptors>
+ <descriptor>src/assembly/zip.xml</descriptor>
+ </descriptors>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <phase>prepare-package</phase>
+ <configuration>
+ <outputDirectory>${project.build.directory}/assembly/lib</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <useRepositoryLayout>false</useRepositoryLayout>
+ <addParentPoms>false</addParentPoms>
+ <copyPom>false</copyPom>
+ <includeScope>runtime</includeScope>
+ <excludeTransitive>true</excludeTransitive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>policy-endpoints</artifactId>
+ <version>${policy.common.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-management</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/feature-legacy-config/src/assembly/zip.xml b/feature-legacy-config/src/assembly/zip.xml
new file mode 100644
index 00000000..51d69f34
--- /dev/null
+++ b/feature-legacy-config/src/assembly/zip.xml
@@ -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=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+
+ <id>feature-legacy-config</id>
+
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory>lib/feature</outputDirectory>
+ <includes>
+ <include>feature-legacy-config-${project.version}.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target/assembly/lib</directory>
+ <outputDirectory>lib/dependencies</outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/feature/config</directory>
+ <outputDirectory>config</outputDirectory>
+ <fileMode>0644</fileMode>
+ <excludes/>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/feature/bin</directory>
+ <outputDirectory>bin</outputDirectory>
+ <fileMode>0755</fileMode>
+ <excludes/>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/feature/install</directory>
+ <outputDirectory>install</outputDirectory>
+ <fileMode>0755</fileMode>
+ <excludes/>
+ </fileSet>
+ </fileSets>
+
+</assembly>
diff --git a/feature-legacy-config/src/main/feature/config/feature-legacy-config.properties b/feature-legacy-config/src/main/feature/config/feature-legacy-config.properties
new file mode 100644
index 00000000..fad32240
--- /dev/null
+++ b/feature-legacy-config/src/main/feature/config/feature-legacy-config.properties
@@ -0,0 +1,28 @@
+# ============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=========================================================
+
+dmaap.source.topics=PDPD-CONFIGURATION
+
+dmaap.source.topics.PDPD-CONFIGURATION.servers=${envd:DMAAP_SERVERS}
+dmaap.source.topics.PDPD-CONFIGURATION.effectiveTopic=${envd:PDPD_CONFIGURATION_TOPIC}
+dmaap.source.topics.PDPD-CONFIGURATION.apiKey=${envd:PDPD_CONFIGURATION_API_KEY}
+dmaap.source.topics.PDPD-CONFIGURATION.apiSecret=${envd:PDPD_CONFIGURATION_API_SECRET}
+dmaap.source.topics.PDPD-CONFIGURATION.consumerGroup=${envd:PDPD_CONFIGURATION_CONSUMER_GROUP}
+dmaap.source.topics.PDPD-CONFIGURATION.consumerInstance=${envd:PDPD_CONFIGURATION_CONSUMER_INSTANCE}
+dmaap.source.topics.PDPD-CONFIGURATION.managed=false
+dmaap.source.topics.PDPD-CONFIGURATION.https=true
diff --git a/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfig.java b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfig.java
new file mode 100644
index 00000000..01cc3b34
--- /dev/null
+++ b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfig.java
@@ -0,0 +1,93 @@
+/*
+ * ============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 java.util.List;
+import java.util.Properties;
+import lombok.Getter;
+import org.onap.policy.common.capabilities.Startable;
+import org.onap.policy.common.endpoints.event.comm.Topic;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.event.comm.TopicListener;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Legacy Configurator.
+ */
+public class LegacyConfig implements Startable, TopicListener {
+
+ private static final Logger logger = LoggerFactory.getLogger(LegacyConfig.class);
+ private static final String CONFIGURATION_PROPERTIES_NAME = "feature-legacy-config";
+
+ @Getter
+ private final Properties properties;
+
+ @Getter
+ private TopicSource source;
+
+ /**
+ * Constructor.
+ */
+ public LegacyConfig() {
+ properties = SystemPersistenceConstants.getManager().getProperties(CONFIGURATION_PROPERTIES_NAME);
+ List<TopicSource> sources = TopicEndpointManager.getManager().addTopicSources(properties);
+ if (sources.isEmpty()) {
+ throw new IllegalStateException("LegacyConfig cannot be instantiated, no sources");
+ }
+
+ this.source = sources.get(0);
+ if (sources.size() != 1) {
+ logger.warn("LegacyConfig: more than one source is configured ({}), using {}",
+ sources.size(), this.source);
+ }
+
+ source.register(this);
+ }
+
+ @Override
+ public boolean start() {
+ return source.start();
+ }
+
+ @Override
+ public boolean stop() {
+ return source.stop();
+ }
+
+ @Override
+ public void shutdown() {
+ source.shutdown();
+ }
+
+ @Override
+ public boolean isAlive() {
+ return source.isAlive();
+ }
+
+ @Override
+ public void onTopicEvent(Topic.CommInfrastructure comm, String topic, String event) {
+ PolicyEngineConstants.getManager().onTopicEvent(comm, topic, event);
+ }
+}
diff --git a/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfigFeature.java b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfigFeature.java
new file mode 100644
index 00000000..640c32a9
--- /dev/null
+++ b/feature-legacy-config/src/main/java/org/onap/policy/drools/legacy/config/LegacyConfigFeature.java
@@ -0,0 +1,55 @@
+/*
+ * ============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 lombok.Getter;
+import org.onap.policy.drools.features.PolicyEngineFeatureApi;
+import org.onap.policy.drools.system.PolicyEngine;
+
+/**
+ * The LegacyConfigFeature enables legacy configuration mechanisms
+ * in the PDP-D.
+ */
+public class LegacyConfigFeature implements PolicyEngineFeatureApi {
+
+ protected static final int SEQNO = 1;
+
+ @Getter
+ private static final LegacyConfig legacyConfig = new LegacyConfig();
+
+ @Override
+ public int getSequenceNumber() {
+ return SEQNO;
+ }
+
+ @Override
+ public boolean afterOpen(PolicyEngine engine) {
+ getLegacyConfig().start();
+ return false;
+ }
+
+ @Override
+ public boolean beforeShutdown(PolicyEngine engine) {
+ getLegacyConfig().shutdown();
+ return false;
+ }
+
+}
diff --git a/feature-legacy-config/src/main/java/org/onap/policy/drools/server/restful/RestLegacyConfigManager.java b/feature-legacy-config/src/main/java/org/onap/policy/drools/server/restful/RestLegacyConfigManager.java
new file mode 100644
index 00000000..e8d91532
--- /dev/null
+++ b/feature-legacy-config/src/main/java/org/onap/policy/drools/server/restful/RestLegacyConfigManager.java
@@ -0,0 +1,68 @@
+/*
+ * ============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.server.restful;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import java.util.Properties;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
+import org.onap.policy.drools.legacy.config.LegacyConfigFeature;
+
+/**
+ * REST Legacy Configuration Manager.
+ */
+
+@Path("/policy/pdp/engine/legacy/config")
+@Produces({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
+@Consumes({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
+@Api
+public class RestLegacyConfigManager {
+
+ /**
+ * GET properties.
+ */
+ @GET
+ @Path("properties")
+ @ApiOperation(value = "Retrieves the legacy configuration properties",
+ notes = "Legacy Configuration Properties", response = Properties.class)
+ public Response properties() {
+ return Response.status(Response.Status.OK)
+ .entity(LegacyConfigFeature.getLegacyConfig().getProperties()).build();
+ }
+
+ /**
+ * GET the topic source.
+ */
+ @GET
+ @Path("topic/source")
+ @ApiOperation(value = "Retrieves the legacy configuration topic source",
+ notes = "Legacy Configuration Source", response = TopicSource.class)
+ public Response source() {
+ return Response.status(Response.Status.OK)
+ .entity(LegacyConfigFeature.getLegacyConfig().getSource()).build();
+ }
+}
diff --git a/feature-legacy-config/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi b/feature-legacy-config/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
new file mode 100644
index 00000000..c18510e3
--- /dev/null
+++ b/feature-legacy-config/src/main/resources/META-INF/services/org.onap.policy.drools.features.PolicyEngineFeatureApi
@@ -0,0 +1 @@
+org.onap.policy.drools.legacy.config.LegacyConfigFeature
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());
+ }
+}
+
+
+
diff --git a/feature-legacy-config/src/test/resources/bad-properties-1/feature-legacy-config.properties b/feature-legacy-config/src/test/resources/bad-properties-1/feature-legacy-config.properties
new file mode 100644
index 00000000..4c86f1f4
--- /dev/null
+++ b/feature-legacy-config/src/test/resources/bad-properties-1/feature-legacy-config.properties
@@ -0,0 +1,17 @@
+# ============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=========================================================
diff --git a/feature-legacy-config/src/test/resources/feature-legacy-config.properties b/feature-legacy-config/src/test/resources/feature-legacy-config.properties
new file mode 100644
index 00000000..9eef6115
--- /dev/null
+++ b/feature-legacy-config/src/test/resources/feature-legacy-config.properties
@@ -0,0 +1,21 @@
+# ============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=========================================================
+
+noop.source.topics=PDPD-CONFIGURATION
+noop.source.topics.PDPD-CONFIGURATION.servers=noop
+noop.source.topics.managed=false
diff --git a/feature-legacy-config/src/test/resources/properties-2/feature-legacy-config.properties b/feature-legacy-config/src/test/resources/properties-2/feature-legacy-config.properties
new file mode 100644
index 00000000..9faba61f
--- /dev/null
+++ b/feature-legacy-config/src/test/resources/properties-2/feature-legacy-config.properties
@@ -0,0 +1,19 @@
+# ============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=========================================================
+
+noop.source.topics=PDPD-CONFIGURATION-1,PDPD-CONFIGURATION-2