summaryrefslogtreecommitdiffstats
path: root/controlloop/common/feature-controlloop-management/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/feature-controlloop-management/src/test')
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java46
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java183
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/resources/op-http.properties5
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/resources/op.drl29
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/resources/op.kmodule26
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/resources/op.pom45
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/resources/settings.xml89
-rw-r--r--controlloop/common/feature-controlloop-management/src/test/resources/vCPE.yaml37
8 files changed, 460 insertions, 0 deletions
diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java
new file mode 100644
index 000000000..ac9bff93b
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/apps/controlloop/feature/management/ControlLoopManagementFeatureTest.java
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2018 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.apps.controlloop.feature.management;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Control Loop Management Feature Test.
+ */
+public class ControlLoopManagementFeatureTest {
+
+ /**
+ * Sequence Number Test.
+ */
+ @Test
+ public void getSequenceNumber() {
+ Assert.assertEquals(1000, new ControlLoopManagementFeature().getSequenceNumber());
+ }
+
+ /**
+ * Name Test.
+ */
+ @Test
+ public void getName() {
+ Assert.assertEquals("controlloop-management", new ControlLoopManagementFeature().getName());
+ }
+} \ No newline at end of file
diff --git a/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
new file mode 100644
index 000000000..3ed1adfe3
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/java/org/onap/policy/drools/server/restful/RestControlLoopManagerTest.java
@@ -0,0 +1,183 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2018 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.awaitility.Awaitility.await;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Response.Status;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.kie.api.builder.ReleaseId;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.drools.persistence.SystemPersistence;
+import org.onap.policy.drools.properties.DroolsProperties;
+import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.util.KieUtils;
+import org.onap.policy.drools.utils.logging.LoggerUtil;
+
+/**
+ * Test RestControlLoopManager.
+ */
+public class RestControlLoopManagerTest {
+
+ private static final String KSESSION = "op";
+ private static final String KMODULE_DRL_PATH = "src/test/resources/op.drl";
+ private static final String KMODULE_POM_PATH = "src/test/resources/op.pom";
+ private static final String KMODULE_PATH = "src/test/resources/op.kmodule";
+ private static final String KJAR_DRL_PATH = "src/main/resources/kbop/org/onap/policy/drools/test/op.drl";
+
+ private static final String CONTROLLER = KSESSION;
+ private static final String CONTROLOOP_NAME = "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e";
+
+ private static final String CLIENT_CONFIG = "op-http";
+
+ private static final String URL_CONTEXT_PATH_CONTROLLERS = "controllers/";
+ private static final String URL_CONTEXT_PATH_CONTROLLER = URL_CONTEXT_PATH_CONTROLLERS + CONTROLLER;
+ private static final String URL_CONTEXT_PATH_KSESSION = URL_CONTEXT_PATH_CONTROLLER + "/drools/facts/" + KSESSION;
+ private static final String URL_CONTEXT_PATH_CONTROLLOOPS = URL_CONTEXT_PATH_KSESSION + "/controlloops/";
+ private static final String URL_CONTEXT_PATH_CONTROLLOOP = URL_CONTEXT_PATH_CONTROLLOOPS + CONTROLOOP_NAME;
+ private static final String URL_CONTEXT_PATH_CONTROLLOOP_POLICY = URL_CONTEXT_PATH_CONTROLLOOP + "/policy";
+
+ private static final String POLICY = "src/test/resources/vCPE.yaml";
+
+ private static final String CONTROLLER_FILE = "op-controller.properties";
+ private static final String CONTROLLER_FILE_BAK = "op-controller.properties.bak";
+
+ /**
+ * test set up.
+ *
+ * @throws Exception if failure to complete the set up.
+ */
+ @BeforeClass
+ public static void setUp() throws Exception {
+ System.setProperty("kie.maven.settings.custom", "src/test/resources/settings.xml");
+ LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "WARN");
+
+ SystemPersistence.manager.setConfigurationDir("src/test/resources");
+ PolicyEngine.manager.configure(PolicyEngine.manager.defaultTelemetryConfig());
+
+ ReleaseId releaseId =
+ KieUtils.installArtifact(Paths.get(KMODULE_PATH).toFile(), Paths.get(KMODULE_POM_PATH).toFile(),
+ KJAR_DRL_PATH, Paths.get(KMODULE_DRL_PATH).toFile());
+
+ Properties controllerProperties = new Properties();
+ controllerProperties.put(DroolsProperties.RULES_GROUPID, releaseId.getGroupId());
+ controllerProperties.put(DroolsProperties.RULES_ARTIFACTID, releaseId.getArtifactId());
+ controllerProperties.put(DroolsProperties.RULES_VERSION, releaseId.getVersion());
+
+ PolicyEngine.manager.createPolicyController(CONTROLLER, controllerProperties);
+ PolicyEngine.manager.start();
+
+ HttpClient.factory.build(SystemPersistence.manager.getProperties(CLIENT_CONFIG));
+
+ if (!NetworkUtil.isTcpPortOpen("localhost", 9696, 6, 10000L)) {
+ throw new IllegalStateException("cannot connect to port 9696");
+ }
+
+ await().atMost(1, TimeUnit.MINUTES).until(isContainerAlive());
+ }
+
+ /**
+ * test tear down.
+ */
+ @AfterClass
+ public static void tearDown() {
+ PolicyController.factory.get(CONTROLLER).stop();
+ await().atMost(1, TimeUnit.MINUTES).until(isContainerAlive(), equalTo(Boolean.FALSE));
+
+ PolicyEngine.manager.removePolicyController(CONTROLLER);
+ PolicyEngine.manager.stop();
+
+ final Path controllerPath =
+ Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), CONTROLLER_FILE);
+ try {
+ Files.deleteIfExists(controllerPath);
+ } catch (Exception ignored) {
+ /* to satisfy checkstyle */
+ ;
+ }
+
+ Path controllerBakPath =
+ Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), CONTROLLER_FILE_BAK);
+
+ try {
+ Files.deleteIfExists(controllerBakPath);
+ } catch (Exception ignored) {
+ /* to satisfy checkstyle */
+ ;
+ }
+ }
+
+ /**
+ * Test Operational Policies.
+ */
+ @Test
+ public void testOperationalPolicy() throws IOException {
+ assertEquals(Status.OK.getStatusCode(),
+ HttpClient.factory.get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOPS).getStatus());
+
+ assertEquals(Status.OK.getStatusCode(),
+ HttpClient.factory.get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOP).getStatus());
+
+ assertEquals(Status.NOT_FOUND.getStatusCode(),
+ HttpClient.factory.get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY).getStatus());
+
+ String policyFromFile = new String(Files.readAllBytes(Paths.get(POLICY)));
+ HttpClient.factory.get(CONTROLLER)
+ .put(URL_CONTEXT_PATH_CONTROLLOOP_POLICY, Entity.text(policyFromFile), Collections.emptyMap());
+
+ assertEquals(Status.OK.getStatusCode(),
+ HttpClient.factory.get(CONTROLLER).get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY).getStatus());
+
+ String policyFromPdpD = HttpClient.factory.get(CONTROLLER)
+ .get(URL_CONTEXT_PATH_CONTROLLOOP_POLICY)
+ .readEntity(String.class);
+
+ assertEquals(policyFromFile, policyFromPdpD);
+
+ assertEquals(Status.CONFLICT.getStatusCode(),
+ HttpClient.factory.get(CONTROLLER).put(URL_CONTEXT_PATH_CONTROLLOOP_POLICY,
+ Entity.text(policyFromFile), Collections.emptyMap()).getStatus());
+ }
+
+ /**
+ * Test if the session is alive
+ *
+ * @return if the container is alive.
+ */
+ private static Callable<Boolean> isContainerAlive() {
+ return () -> PolicyController.factory.get(CONTROLLER).getDrools().getContainer().isAlive();
+ }
+}
diff --git a/controlloop/common/feature-controlloop-management/src/test/resources/op-http.properties b/controlloop/common/feature-controlloop-management/src/test/resources/op-http.properties
new file mode 100644
index 000000000..b96c5d133
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/resources/op-http.properties
@@ -0,0 +1,5 @@
+http.client.services=op
+
+http.client.services.op.host=localhost
+http.client.services.op.port=9696
+http.client.services.op.contextUriPath=policy/pdp/engine
diff --git a/controlloop/common/feature-controlloop-management/src/test/resources/op.drl b/controlloop/common/feature-controlloop-management/src/test/resources/op.drl
new file mode 100644
index 000000000..48ed09929
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/resources/op.drl
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2018 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.apps.controlloop.feature.management;
+
+import org.onap.policy.controlloop.params.ControlLoopParams;
+
+rule "PARAMS"
+when
+ $params : ControlLoopParams()
+then
+end
diff --git a/controlloop/common/feature-controlloop-management/src/test/resources/op.kmodule b/controlloop/common/feature-controlloop-management/src/test/resources/op.kmodule
new file mode 100644
index 000000000..8b49eb6a0
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/resources/op.kmodule
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 2018 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=========================================================
+ -->
+
+<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
+ <kbase name="kbop">
+ <ksession name="op"/>
+ </kbase>
+</kmodule> \ No newline at end of file
diff --git a/controlloop/common/feature-controlloop-management/src/test/resources/op.pom b/controlloop/common/feature-controlloop-management/src/test/resources/op.pom
new file mode 100644
index 000000000..133387217
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/resources/op.pom
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 2018 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-applications.controlloop.common.model-impl</groupId>
+ <artifactId>model-impl</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.policy.drools.apps.test</groupId>
+ <artifactId>op</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+ <artifactId>events</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/controlloop/common/feature-controlloop-management/src/test/resources/settings.xml b/controlloop/common/feature-controlloop-management/src/test/resources/settings.xml
new file mode 100644
index 000000000..3d49366bb
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/resources/settings.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 2018 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=========================================================
+ -->
+
+
+<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
+
+ <profiles>
+
+ <profile>
+ <id>onap-releases</id>
+ <repositories>
+ <repository>
+ <id>onap-releases</id>
+ <name>onap-releases</name>
+ <url>https://nexus.onap.org/content/repositories/releases/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ </profile>
+
+ <profile>
+ <id>onap-staging</id>
+ <repositories>
+ <repository>
+ <id>onap-staging</id>
+ <name>onap-staging</name>
+ <url>https://nexus.onap.org/content/repositories/staging/</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>always</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ </profile>
+
+ <profile>
+ <id>onap-snapshots</id>
+ <repositories>
+ <repository>
+ <id>onap-snapshots</id>
+ <name>onap-snapshots</name>
+ <url>https://nexus.onap.org/content/repositories/snapshots/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>always</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+ </profile>
+ </profiles>
+
+ <activeProfiles>
+ <activeProfile>onap-releases</activeProfile>
+ <activeProfile>onap-staging</activeProfile>
+ <activeProfile>onap-snapshots</activeProfile>
+ </activeProfiles>
+
+</settings>
diff --git a/controlloop/common/feature-controlloop-management/src/test/resources/vCPE.yaml b/controlloop/common/feature-controlloop-management/src/test/resources/vCPE.yaml
new file mode 100644
index 000000000..9ab15c60e
--- /dev/null
+++ b/controlloop/common/feature-controlloop-management/src/test/resources/vCPE.yaml
@@ -0,0 +1,37 @@
+# Copyright 2018 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.
+
+controlLoop:
+ version: 2.0.0
+ controlLoopName: ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e
+ trigger_policy: unique-policy-id-1-restart
+ timeout: 3600
+ abatement: false
+
+policies:
+- id: unique-policy-id-1-restart
+ name: Restart the VM
+ description:
+ actor: APPC
+ recipe: Restart
+ target:
+ type: VM
+ retry: 3
+ timeout: 1200
+ success: final_success
+ failure: final_failure
+ failure_timeout: final_failure_timeout
+ failure_retries: final_failure_retries
+ failure_exception: final_failure_exception
+ failure_guard: final_failure_guard \ No newline at end of file