summaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.so/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-01-26 14:31:09 +0000
committerliamfallon <liam.fallon@ericsson.com>2018-01-28 20:21:43 +0000
commit7767c5643349e5e6691a07afd5c4acd3ef9d5617 (patch)
treef5d4441392f44a91cf23de6f275bfa127c9bc8f6 /controlloop/common/actors/actor.so/src/test/java
parente285764b0eddab0d4195128f55a9f524beee3f05 (diff)
Fix Tech Debt/JUnit on SO actor
Unit test for SO actor added. SO actor service provider class refactored to remove technical debt. Change-Id: I6186ede5661ce483917184f03ee44d57a124b6a4 Issue-ID: POLICY-455 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'controlloop/common/actors/actor.so/src/test/java')
-rw-r--r--controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
new file mode 100644
index 000000000..5d2134ec1
--- /dev/null
+++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/TestSOActorServiceProvider.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * TestSOActorServiceProvider
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson. 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.controlloop.actor.so;
+
+import static org.junit.Assert.*;
+
+import java.util.UUID;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.drools.http.server.HttpServletServer;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.simulators.Util;
+import org.onap.policy.so.SORequest;
+
+public class TestSOActorServiceProvider {
+ @BeforeClass
+ public static void setUpSimulator() {
+ try {
+ Util.buildAaiSim();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ HttpServletServer.factory.destroy();
+ }
+
+ @Test
+ public void testConstructRequest() {
+ VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
+ ControlLoopOperation operation = new ControlLoopOperation();
+
+ UUID requestID = UUID.randomUUID();
+ onset.setRequestID(requestID);
+
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+ PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
+ PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
+
+ Policy policy = new Policy();
+ policy.setActor("Dorothy");
+ policy.setRecipe("GoToOz");
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
+
+ policy.setActor("SO");
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
+
+ policy.setRecipe("VF Module Create");
+ assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
+
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:999999");
+ assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
+
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+ assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
+
+ SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy);
+
+ assertEquals(requestID, request.getRequestId());
+ assertEquals("policy", request.getRequestDetails().getRequestInfo().getRequestorId());
+ assertEquals("RegionOne", request.getRequestDetails().getCloudConfiguration().getLcpCloudRegionId());
+ }
+
+ @Test
+ public void testSendRequest() {
+ try {
+ SOActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null);
+ }
+ catch (Exception e) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testMethods() {
+ SOActorServiceProvider sp = new SOActorServiceProvider();
+
+ assertEquals("SO", sp.actor());
+ assertEquals(1, sp.recipes().size());
+ assertEquals("VF Module Create", sp.recipes().get(0));
+ assertEquals(0, sp.recipePayloads("VF Module Create").size());
+ }
+}