Add vFC and MSO Simulators 21/10021/1
authorCharles Cole <cc847m@att.com>
Fri, 1 Sep 2017 22:33:32 +0000 (17:33 -0500)
committerCOLE <cc847m@att.com>
Fri, 1 Sep 2017 22:35:19 +0000 (17:35 -0500)
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>
controlloop/templates/template.demo/pom.xml
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorJaxRs.java [new file with mode: 0644]
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/MsoSimulatorTest.java [new file with mode: 0644]
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorJaxRs.java [new file with mode: 0644]
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcSimulatorTest.java [new file with mode: 0644]

index 024a8a3..c0aef20 100644 (file)
                        <version>${project.version}</version>
                        <scope>test</scope>
                </dependency>
+               <dependency>
+                       <groupId>org.onap.policy.drools-applications</groupId>
+                       <artifactId>mso</artifactId>
+                       <version>${project.version}</version>
+                       <scope>test</scope>
+               </dependency>
        </dependencies>
-</project>
+</project>
\ No newline at end of file
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 (file)
index 0000000..14e12da
--- /dev/null
@@ -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 (file)
index 0000000..e2b1114
--- /dev/null
@@ -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);
+       }
+}
index 9bba63b..61be153 100644 (file)
@@ -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 (file)
index 0000000..d85a9fb
--- /dev/null
@@ -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 (file)
index 0000000..3404041
--- /dev/null
@@ -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);
+       }
+}