summaryrefslogtreecommitdiffstats
path: root/controlloop/templates/template.demo/src/test
diff options
context:
space:
mode:
authorCharles Cole <cc847m@att.com>2017-09-01 17:33:32 -0500
committerCOLE <cc847m@att.com>2017-09-01 17:35:19 -0500
commitb2bdc20c1ce3a390dd7928144c2ccb17a98b1363 (patch)
treef804e9cc3133fa917fb33304dbf41dc4347cc560 /controlloop/templates/template.demo/src/test
parentf8a0665b7e1b3724bb43d81e9eae3bff4a0c7069 (diff)
Add vFC and MSO Simulators
Added vFC and MSO Simulators for jUnit testing Issue-ID: POLICY-201, POLICY-202 Change-Id: Ia30ff6ec74a8ee4fa71ce0456eb6dcb60c897695 Signed-off-by: Charles Cole <cc847m@att.com>
Diffstat (limited to 'controlloop/templates/template.demo/src/test')
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorJaxRs.java37
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorTest.java59
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java14
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorJaxRs.java44
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorTest.java70
5 files changed, 224 insertions, 0 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorJaxRs.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorJaxRs.java
new file mode 100644
index 000000000..14e12da7f
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorJaxRs.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * demo
+ * ================================================================================
+ * Copyright (C) 2017 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.template.demo;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+@Path("/serviceInstances")
+public class MsoSimulatorJaxRs {
+
+ @POST
+ @Path("/v2/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModulesHTTPS/1.1")
+ public String msoPostQuery(@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId)
+ {
+ return "{\"requestReferences\": {\"instanceId\": \"ff305d54-75b4-ff1b-bdb2-eb6b9e5460ff\", \"requestId\": \"rq1234d1-5a33-ffdf-23ab-12abad84e331\"}}";
+ }
+
+}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorTest.java
new file mode 100644
index 000000000..e2b1114be
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorTest.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * demo
+ * ================================================================================
+ * Copyright (C) 2017 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.template.demo;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.drools.http.server.HttpServletServer;
+import org.onap.policy.mso.MSOResponse;
+import org.onap.policy.mso.util.Serialization;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+
+public class MsoSimulatorTest {
+
+ @BeforeClass
+ public static void setUpSimulator() {
+ try {
+ Util.buildMsoSim();
+ } catch (InterruptedException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ HttpServletServer.factory.destroy();
+ }
+
+ @Test
+ public void testResponse(){
+ Pair<Integer, String> httpDetails = RESTManager.post("http://localhost:6667/serviceInstances/v2/12345/vnfs/12345/vfModulesHTTPS/1.1", "username", "password", new HashMap<String, String>(), "application/json", "Some Request Here");
+ assertNotNull(httpDetails);
+ MSOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, MSOResponse.class);
+ assertNotNull(response);
+ }
+}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
index 9bba63b82..61be1535e 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
@@ -120,6 +120,20 @@ public final class Util {
return testServer;
}
+ public static HttpServletServer buildMsoSim() throws InterruptedException {
+ HttpServletServer testServer = HttpServletServer.factory.build("testServer", "localhost", 6667, "/", false, true);
+ testServer.addServletClass("/*", MsoSimulatorJaxRs.class.getName());
+ testServer.waitedStart(5000);
+ return testServer;
+ }
+
+ public static HttpServletServer buildVfcSim() throws InterruptedException {
+ HttpServletServer testServer = HttpServletServer.factory.build("testServer", "localhost", 6668, "/", false, true);
+ testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName());
+ testServer.waitedStart(5000);
+ return testServer;
+ }
+
private static String generatePolicy(String ruleContents,
String closedLoopControlName,
String policyScope,
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorJaxRs.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorJaxRs.java
new file mode 100644
index 000000000..d85a9fb8a
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorJaxRs.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * demo
+ * ================================================================================
+ * Copyright (C) 2017 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.template.demo;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+@Path("/api/nslcm/v1")
+public class VfcSimulatorJaxRs {
+
+ @POST
+ @Path("/ns/{nsInstanceId}/heal")
+ public String vfcPostQuery(@PathParam("nsInstanceId") String nsInstanceId)
+ {
+ return "{\"jobId\":\"1\"}";
+ }
+
+ @GET
+ @Path("/jobs/{jobId}&responseId={responseId}")
+ public String vfcGetQuery(@PathParam("jobId") String jobId, @PathParam("responseId") String responseId){
+ return "{\"jobId\" : "+jobId+",\"responseDescriptor\" : {\"progress\" : \"40\",\"status\" : \"proccessing\",\"statusDescription\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\": "+responseId+",\"responseHistoryList\": [{\"progress\" : \"40\",\"status\" : \"proccessing\",\"statusDescription\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"1\"}, {\"progress\" : \"41\",\"status\" : \"proccessing\",\"statusDescription\" : \"OMC VMs are decommissioned in VIM\",\"errorCode\" : null,\"responseId\" : \"2\"}]}}";
+ }
+
+}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorTest.java
new file mode 100644
index 000000000..340404136
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorTest.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * demo
+ * ================================================================================
+ * Copyright (C) 2017 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.template.demo;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onap.policy.drools.http.server.HttpServletServer;
+import org.onap.policy.vfc.VFCResponse;
+import org.onap.policy.vfc.util.Serialization;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+
+public class VfcSimulatorTest {
+
+ @BeforeClass
+ public static void setUpSimulator() {
+ try {
+ Util.buildVfcSim();
+ } catch (InterruptedException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ HttpServletServer.factory.destroy();
+ }
+
+ @Test
+ public void testPost(){
+ Pair<Integer, String> httpDetails = RESTManager.post("http://localhost:6668/api/nslcm/v1/ns/1234567890/heal", "username", "password", new HashMap<String, String>(), "application/json", "Some Request Here");
+ assertNotNull(httpDetails);
+ VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class);
+ assertNotNull(response);
+ }
+
+ //This test case fails because the model code does not match the response I was given, I do not know which is wrong
+ @Ignore
+ @Test
+ public void testGet(){
+ Pair<Integer, String> httpDetails = RESTManager.get("http://localhost:6668/api/nslcm/v1/jobs/1234&responseId=5678", "username", "password", new HashMap<String, String>());
+ assertNotNull(httpDetails);
+ VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class);
+ assertNotNull(response);
+ }
+}