From b6b7bef8bdcad15af01ac88a038dd763ce59f68f Mon Sep 17 00:00:00 2001 From: xg353y Date: Tue, 11 Apr 2017 13:30:42 +0200 Subject: [MSO-8] Update the maven dependency Update the maven depenency for sdc-distribution-client to cooperate with the sdc changes. Change-Id: I2da936e5c40cb68c7181bb78307192dd5655b5dc Signed-off-by: xg353y --- bpmn/MSOMockServer/.gitignore | 4 + bpmn/MSOMockServer/WebContent/META-INF/MANIFEST.MF | 3 + bpmn/MSOMockServer/WebContent/WEB-INF/web.xml | 3 + bpmn/MSOMockServer/pom.xml | 95 +++ .../java/org/openecomp/mso/bpmn/mock/FileUtil.java | 64 ++ .../org/openecomp/mso/bpmn/mock/MockResource.java | 207 ++++++ .../mso/bpmn/mock/MockResourceApplication.java | 52 ++ .../mso/bpmn/mock/SDNCAdapterMockTransformer.java | 141 ++++ .../SDNCAdapterNetworkTopologyMockTransformer.java | 130 ++++ .../openecomp/mso/bpmn/mock/StubResponseAAI.java | 776 +++++++++++++++++++++ .../mso/bpmn/mock/StubResponseDatabase.java | 65 ++ .../mso/bpmn/mock/StubResponseNetworkAdapter.java | 93 +++ .../mso/bpmn/mock/StubResponseSDNCAdapter.java | 138 ++++ .../mso/bpmn/mock/StubResponseVNFAdapter.java | 130 ++++ .../bpmn/mock/VnfAdapterCreateMockTransformer.java | 148 ++++ .../bpmn/mock/VnfAdapterDeleteMockTransformer.java | 146 ++++ .../bpmn/mock/VnfAdapterQueryMockTransformer.java | 160 +++++ .../mock/VnfAdapterRollbackMockTransformer.java | 147 ++++ .../bpmn/mock/VnfAdapterUpdateMockTransformer.java | 148 ++++ .../src/main/resources/__files/sdncSimResponse.xml | 19 + .../src/main/webapp/WEB-INF/jboss-web.xml | 6 + 21 files changed, 2675 insertions(+) create mode 100644 bpmn/MSOMockServer/.gitignore create mode 100644 bpmn/MSOMockServer/WebContent/META-INF/MANIFEST.MF create mode 100644 bpmn/MSOMockServer/WebContent/WEB-INF/web.xml create mode 100644 bpmn/MSOMockServer/pom.xml create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/FileUtil.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResource.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResourceApplication.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterMockTransformer.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseAAI.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseDatabase.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseNetworkAdapter.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSDNCAdapter.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseVNFAdapter.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterCreateMockTransformer.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterDeleteMockTransformer.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterQueryMockTransformer.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterRollbackMockTransformer.java create mode 100644 bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterUpdateMockTransformer.java create mode 100644 bpmn/MSOMockServer/src/main/resources/__files/sdncSimResponse.xml create mode 100644 bpmn/MSOMockServer/src/main/webapp/WEB-INF/jboss-web.xml (limited to 'bpmn/MSOMockServer') diff --git a/bpmn/MSOMockServer/.gitignore b/bpmn/MSOMockServer/.gitignore new file mode 100644 index 0000000000..f6c8fbcdef --- /dev/null +++ b/bpmn/MSOMockServer/.gitignore @@ -0,0 +1,4 @@ +/bin +/target +/target +/target diff --git a/bpmn/MSOMockServer/WebContent/META-INF/MANIFEST.MF b/bpmn/MSOMockServer/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..254272e1c0 --- /dev/null +++ b/bpmn/MSOMockServer/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/bpmn/MSOMockServer/WebContent/WEB-INF/web.xml b/bpmn/MSOMockServer/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000000..1aa8cdb8d7 --- /dev/null +++ b/bpmn/MSOMockServer/WebContent/WEB-INF/web.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/bpmn/MSOMockServer/pom.xml b/bpmn/MSOMockServer/pom.xml new file mode 100644 index 0000000000..268f392977 --- /dev/null +++ b/bpmn/MSOMockServer/pom.xml @@ -0,0 +1,95 @@ + + + org.openecomp.mso + bpmn + 1.1.0-SNAPSHOT + + 4.0.0 + org.openecomp.mso + MSOMockServer + war + + + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + true + true + false + + + + + + + + com.github.tomakehurst + wiremock + 1.56 + standalone + + + org.mortbay.jetty + jetty + + + com.google.guava + guava + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + org.apache.httpcomponents + httpclient + + + org.skyscreamer + jsonassert + + + xmlunit + xmlunit + + + com.jayway.jsonpath + json-path + + + net.sf.jopt-simple + jopt-simple + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + + + org.jboss.resteasy + resteasy-client + 3.0.8.Final + + + org.apache.httpcomponents + httpclient + + + + + \ No newline at end of file diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/FileUtil.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/FileUtil.java new file mode 100644 index 0000000000..12231c9ee5 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/FileUtil.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import java.io.IOException; +import java.io.InputStream; + +public class FileUtil { + + /** + * Read the specified resource file and return the contents as a String. + * + * @param fileName Name of the resource file + * @return the contents of the resource file as a String + * @throws IOException if there is a problem reading the file + */ + public static String readResourceFile(String fileName) { + InputStream stream; + try { + stream = getResourceAsStream(fileName); + byte[] bytes; + bytes = new byte[stream.available()]; + stream.read(bytes); + stream.close(); + return new String(bytes); + } catch (IOException e) { + return ""; + } + } + + /** + * Get an InputStream for the resource specified. + * + * @param resourceName Name of resource for which to get InputStream. + * @return an InputStream for the resource specified. + * @throws IOException If we can't get the InputStream for whatever reason. + */ + private static InputStream getResourceAsStream(String resourceName) throws IOException { + InputStream stream = + FileUtil.class.getClassLoader().getResourceAsStream(resourceName); + if (stream == null) { + throw new IOException("Can't access resource '" + resourceName + "'"); + } + return stream; + } +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResource.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResource.java new file mode 100644 index 0000000000..8b8bea6a8d --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResource.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.WireMock; + +/** + * + * Mock Resource which is used to start, stop the WireMock Server + * Also up to 50 mock properties can be added at run-time to change the properties used in transformers such as sdnc_delay in SDNCAdapterMockTransformer + * You can also selectively setup a stub (use reset before setting up), reset all stubs + */ +@Path("/server") +public class MockResource { + + private boolean started = false; + private final Integer defaultPort = 28090; + private WireMockServer wireMockServer = null; + private static Map mockProperties = new HashMap(); + + public static String getMockProperties(String key) { + return mockProperties.get(key); + } + + private synchronized void initMockServer(int portNumber) { + String path = FileUtil.class.getClassLoader().getResource("__files/sdncSimResponse.xml").getFile(); + path = path.substring(0,path.indexOf("__files/")); + + wireMockServer = new WireMockServer(wireMockConfig().port(portNumber).extensions("org.openecomp.mso.bpmn.mock.SDNCAdapterMockTransformer") + .extensions("org.openecomp.mso.bpmn.mock.SDNCAdapterNetworkTopologyMockTransformer") + .extensions("org.openecomp.mso.bpmn.mock.VnfAdapterCreateMockTransformer") + .extensions("org.openecomp.mso.bpmn.mock.VnfAdapterDeleteMockTransformer") + .extensions("org.openecomp.mso.bpmn.mock.VnfAdapterUpdateMockTransformer") + .extensions("org.openecomp.mso.bpmn.mock.VnfAdapterRollbackMockTransformer") + .extensions("org.openecomp.mso.bpmn.mock.VnfAdapterQueryMockTransformer")); + //.withRootDirectory(path)); + //Mocks were failing - commenting out for now, both mock and transformers seem to work fine + WireMock.configureFor("localhost", portNumber); + wireMockServer.start(); +// StubResponse.setupAllMocks(); + started= true; + } + + public static void main(String [] args) { + MockResource mockresource = new MockResource(); + mockresource.start(28090); + mockresource.reset(); +// mockresource.setupStub("MockCreateTenant"); + } + + /** + * Starts the wiremock server in default port + * @return + */ + @GET + @Path("/start") + @Produces("application/json") + public Response start() { + return startMockServer(defaultPort); + } + + private Response startMockServer(int port) { + if (!started) { + initMockServer(defaultPort); + System.out.println("Started Mock Server in port " + port); + return Response.status(200).entity("Started Mock Server in port " + port).build(); + } else { + return Response.status(200).entity("Mock Server is already running").build(); + } + } + + /** + * Starts the wiremock server in a different port + * @param portNumber + * @return + */ + @GET + @Path("/start/{portNumber}") + @Produces("application/json") + public Response start(@PathParam("portNumber") Integer portNumber) { + if (portNumber == null) portNumber = defaultPort; + return startMockServer(portNumber.intValue()); + } + + + /** + * Stop the wiremock server + * @return + */ + @GET + @Path("/stop") + @Produces("application/json") + public synchronized Response stop() { + if (wireMockServer.isRunning()) { + wireMockServer.stop(); + started = false; + return Response.status(200).entity("Stopped Mock Server in port ").build(); + } + return Response.status(200).entity("Mock Server is not running").build(); + } + + + /** + * Return list of mock properties + * @return + */ + @GET + @Path("/properties") + @Produces("application/json") + public Response getProperties() { + return Response.status(200).entity(mockProperties).build(); + } + + /** + * Update a particular mock property at run-time + * @param name + * @param value + * @return + */ + @POST + @Path("/properties/{name}/{value}") + public Response updateProperties(@PathParam("name") String name, @PathParam("value") String value) { + if (mockProperties.size() > 50) return Response.serverError().build(); + mockProperties.put(name, value); + return Response.status(200).build(); + } + + /** + * Reset all stubs + * @return + */ + @GET + @Path("/reset") + @Produces("application/json") + public Response reset() { + WireMock.reset(); + return Response.status(200).entity("Wiremock stubs are reset").build(); + } + + + /** + * Setup a stub selectively + * Prior to use, make sure that stub method is available in StubResponse class + * @param methodName + * @return + */ + + // commenting for now until we figure out a way to use new StubResponse classes to setupStubs +// @GET +// @Path("/stub/{methodName}") +// @Produces("application/json") +// public Response setupStub(@PathParam("methodName") String methodName) { +// +// @SuppressWarnings("rawtypes") +// Class params[] = {}; +// Object paramsObj[] = {}; +// +// try { +// Method thisMethod = StubResponse.class.getDeclaredMethod(methodName, params); +// try { +// thisMethod.invoke(StubResponse.class, paramsObj); +// } catch (IllegalAccessException | IllegalArgumentException +// | InvocationTargetException e) { +// return Response.status(200).entity("Error invoking " + methodName ).build(); +// } +// } catch (NoSuchMethodException | SecurityException e) { +// return Response.status(200).entity("Stub " + methodName + " not found...").build(); +// } +// return Response.status(200).entity("Successfully invoked " + methodName).build(); +// } + + + public static Map getMockProperties(){ + return mockProperties; + } +} \ No newline at end of file diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResourceApplication.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResourceApplication.java new file mode 100644 index 0000000000..8cf947c600 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/MockResourceApplication.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +/** + * + * JAX RS Application wiring for Mock Resource + */ +@ApplicationPath("/console") +public class MockResourceApplication extends Application { + + private Set singletons = new HashSet(); + private Set> classes = new HashSet>(); + + public MockResourceApplication() { + singletons.add(new MockResource()); + } + + @Override + public Set> getClasses() { + return classes; + } + + @Override + public Set getSingletons() { + return singletons; + } +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterMockTransformer.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterMockTransformer.java new file mode 100644 index 0000000000..f30c223449 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterMockTransformer.java @@ -0,0 +1,141 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import org.jboss.resteasy.client.ClientRequest; +import org.jboss.resteasy.client.ClientResponse; + +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; +import com.github.tomakehurst.wiremock.common.FileSource; +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; +import com.github.tomakehurst.wiremock.http.Request; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; + +/** + * + * Simulates SDNC Adapter Callback response + * + */ +public class SDNCAdapterMockTransformer extends ResponseTransformer { + + private String callbackResponse; + private String requestId; + + public SDNCAdapterMockTransformer() { + callbackResponse = FileUtil.readResourceFile("__files/sdncSimResponse.xml"); + } + + public SDNCAdapterMockTransformer(String requestId) { + this.requestId = requestId; + } + + public String name() { + return "sdnc-adapter-transformer"; + } + + /** + * Grab the incoming request xml,extract the request id and replace the stub response with the incoming request id + * so that callback response can be correlated + * + * Mock Resource can be used to add dynamic properties. If sdnc_delay is not in the list by default waits for 300ms before + * the callback response is sent + */ + @Override + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, + FileSource fileSource) { + String requestBody = request.getBodyAsString(); + + String callbackUrl = requestBody.substring(requestBody.indexOf("")+25, requestBody.indexOf("")); + String requestId = requestBody.substring(requestBody.indexOf("")+23, requestBody.indexOf("")); + + callbackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + System.out.println("callbackResponse:" + callbackResponse); + + if (this.requestId != null) { + callbackResponse = callbackResponse.replace(this.requestId, requestId); + } else { + callbackResponse = callbackResponse.replace("testRequestId", requestId); + } + + + Object sdncDelay = MockResource.getMockProperties().get("sdnc_delay"); + int delay = 300; + if (sdncDelay != null) { + delay = Integer.parseInt(sdncDelay.toString()); + } + + //Kick off callback thread + System.out.println("callback Url:" + callbackUrl + ":delay:" + delay); + CallbackResponseThread calbackResponseThread = new CallbackResponseThread(callbackUrl,callbackResponse, delay); + calbackResponseThread.start(); + + //return 200 OK with empty body + return ResponseDefinitionBuilder + .like(responseDefinition).but() + .withStatus(200).withBody("").withHeader("Content-Type", "text/xml") + .build(); + } + + @Override + public boolean applyGlobally() { + return false; + } + + /** + * + * Callback response thread which sends the callback response asynchronously + * + */ + private class CallbackResponseThread extends Thread { + + private String callbackUrl; + private String payLoad; + private int delay; + + public CallbackResponseThread(String callbackUrl, String payLoad, int delay) { + this.callbackUrl = callbackUrl; + this.payLoad = payLoad; + this.delay = delay; + } + + public void run () { + try { + //Delay sending callback response + sleep(delay); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("Sending callback response:" + callbackUrl); + ClientRequest request = new ClientRequest(callbackUrl); + request.body("text/xml", payLoad); + System.err.println(payLoad); + try { + ClientResponse result = request.post(); + //System.err.println("Successfully posted callback:" + result.getStatus()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java new file mode 100644 index 0000000000..ead12ec755 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import org.jboss.resteasy.client.ClientRequest; +import org.jboss.resteasy.client.ClientResponse; + +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; +import com.github.tomakehurst.wiremock.common.FileSource; +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; +import com.github.tomakehurst.wiremock.http.Request; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; + +public class SDNCAdapterNetworkTopologyMockTransformer extends ResponseTransformer { + + private String callbackResponse; + private String requestId; + + public SDNCAdapterNetworkTopologyMockTransformer() { + callbackResponse = ""; // FileUtil.readResourceFile("__files/sdncDeleteNetworkTopologySimResponse.xml"); + } + + public SDNCAdapterNetworkTopologyMockTransformer(String requestId) { + this.requestId = requestId; + } + + public String name() { + return "network-topology-operation-transformer"; + } + + @Override + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource fileSource) { + String requestBody = request.getBodyAsString(); + + String callbackUrl = requestBody.substring(requestBody.indexOf("")+25, requestBody.indexOf("")); + String requestId = requestBody.substring(requestBody.indexOf("")+23, requestBody.indexOf("")); + System.out.println("request callbackUrl : " + callbackUrl); + System.out.println("request requestId : " + requestId); + + System.out.println("file path/name : " + responseDefinition.getBodyFileName()); + callbackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + // extract Response responseRequestId + String responseRequestId = callbackResponse.substring(callbackResponse.indexOf("")+11, callbackResponse.indexOf("")); + System.out.println("response requestId: " + responseRequestId); + System.out.println("callbackResponse (before): " + callbackResponse); + callbackResponse = callbackResponse.replace(responseRequestId, requestId); + if (this.requestId != null) { + callbackResponse = callbackResponse.replace(this.requestId, requestId); + } else { + callbackResponse = callbackResponse.replace(responseRequestId, requestId); + } + System.out.println("callbackResponse (after):" + callbackResponse); + + Object sdncDelay = MockResource.getMockProperties().get("sdnc_delay"); + int delay = 300; + if (sdncDelay != null) { + delay = Integer.parseInt(sdncDelay.toString()); + } + + //Kick off callback thread + System.out.println("(NetworkTopologyMockTransformer) callback Url:" + callbackUrl + ":delay:" + delay); + CallbackResponseThread calbackResponseThread = new CallbackResponseThread(callbackUrl,callbackResponse, delay); + calbackResponseThread.start(); + + //return 200 OK with body + return ResponseDefinitionBuilder + .like(responseDefinition).but() + .withStatus(200).withBody(callbackResponse).withHeader("Content-Type", "text/xml") + .build(); + } + + @Override + public boolean applyGlobally() { + return false; + } + + private class CallbackResponseThread extends Thread { + + private String callbackUrl; + private String payLoad; + private int delay; + + public CallbackResponseThread(String callbackUrl, String payLoad, int delay) { + this.callbackUrl = callbackUrl; + this.payLoad = payLoad; + this.delay = delay; + } + + public void run () { + try { + //Delay sending callback response + sleep(delay); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("Sending callback response to url: " + callbackUrl); + ClientRequest request = new ClientRequest(callbackUrl); + request.body("text/xml", payLoad); + //System.err.println(payLoad); + try { + ClientResponse result = request.post(); + System.out.println("Successfully posted callback? Status: " + result.getStatus()); + } catch (Exception e) { + // TODO Auto-generated catch block + System.out.println("catch error in - request.post() "); + e.printStackTrace(); + } + } + + } +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseAAI.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseAAI.java new file mode 100644 index 0000000000..8effc08445 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseAAI.java @@ -0,0 +1,776 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; + +/** + * Reusable Mock StubResponses for AAI Endpoints + * + */ +public class StubResponseAAI { + + public static void setupAllMocks() { + + } + + + /** + * Tunnel-XConnect Mock Stub Response + */ + public static void MockPutTunnelXConnect(String globalCustId, String subscriptionType, String serviceInstanceId, String allottedResourceId, String tunnelId){ + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId + "/allotted-resources/allotted-resource/" + allottedResourceId + "/tunnel-xconnects/tunnel-xconnect/" + tunnelId)) + .willReturn(aResponse() + .withStatus(200))); + } + + + /** + * Allotted Resource Mock StubResponses below + */ + public static void MockPutAllottedResource(String globalCustId, String subscriptionType, String serviceInstanceId, String allottedResourceId) { + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId + "/allotted-resources/allotted-resource/" + allottedResourceId)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockPutAllottedResource_500(String globalCustId, String subscriptionType, String serviceInstanceId, String allottedResourceId) { + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId + "/allotted-resources/allotted-resource/" + allottedResourceId)) + .willReturn(aResponse() + .withStatus(500))); + } + + + /** + * Service Instance Mock StubResponses below + */ + public static void MockGetServiceInstance(String globalCustId, String subscriptionType, String serviceInstanceId, String responseFile) { + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetServiceInstance_404(String customer, String serviceSubscription, String serviceInstanceId){ + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "/service-instances/service-instance/" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(404))); + } + + public static void MockGetServiceInstance_500(String customer, String serviceSubscription, String serviceInstanceId){ + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "/service-instances/service-instance/" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void MockGetServiceInstance_500(String customer, String serviceSubscription, String serviceInstanceId, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "/service-instances/service-instance/" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(500) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockNodeQueryServiceInstanceByName(String serviceInstanceName, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/search/nodes-query[?]search-node-type=service-instance[&]filter=service-instance-name:EQUALS:" + serviceInstanceName)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockNodeQueryServiceInstanceByName_404(String serviceInstanceName){ + stubFor(get(urlMatching("/aai/v[0-9]+/search/nodes-query[?]search-node-type=service-instance&filter=service-instance-name:EQUALS:" + serviceInstanceName)) + .willReturn(aResponse() + .withStatus(404))); + } + + public static void MockNodeQueryServiceInstanceByName_500(String serviceInstanceName){ + stubFor(get(urlMatching("/aai/v[0-9]+/search/nodes-query[?]search-node-type=service-instance&filter=service-instance-name:EQUALS:" + serviceInstanceName)) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void MockNodeQueryServiceInstanceById(String serviceInstanceId, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/search/nodes-query[?]search-node-type=service-instance[&]filter=service-instance-id:EQUALS:" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockNodeQueryServiceInstanceById_404(String serviceInstanceId){ + stubFor(get(urlMatching("/aai/v[0-9]+/search/nodes-query[?]search-node-type=service-instance&filter=service-instance-id:EQUALS:" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(404))); + } + + public static void MockNodeQueryServiceInstanceById_500(String serviceInstanceId){ + stubFor(get(urlMatching("/aai/v[0-9]+/search/nodes-query[?]search-node-type=service-instance&filter=service-instance-id:EQUALS:" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void MockDeleteServiceInstance(String customer, String serviceSubscription, String serviceInstanceId, String resourceVersion){ + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "/service-instances/service-instance/" + serviceInstanceId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(204))); + } + + public static void MockGetServiceInstance(String customer, String serviceSubscription, String serviceInstanceId, String resourceVersion, int statusCode){ + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "/service-instances/service-instance/" + serviceInstanceId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void MockGetServiceInstance(String customer, String serviceSubscription, String resourceVersion, int statusCode){ + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml"))); + } + + public static void MockDeleteServiceInstance(String customer, String serviceSubscription, String resourceVersion, int statusCode){ + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "[?]resource-version=" +1234)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void MockDeleteServiceInstance_404(String customer, String serviceSubscription, String serviceInstanceId, String resourceVersion){ + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "/service-instances/service-instance/" + serviceInstanceId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(404))); + } + + public static void MockDeleteServiceInstance_500(String customer, String serviceSubscription, String serviceInstanceId, String resourceVersion){ + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/" + customer + "/service-subscriptions/service-subscription/" + serviceSubscription + "/service-instances/service-instance/" + serviceInstanceId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void MockPutServiceInstance(String globalCustId, String subscriptionType, String serviceInstanceId, String responseFile) { + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockPutServiceInstance_500(String globalCustId, String subscriptionType, String serviceInstanceId) { + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(500))); + } + + + /** + * Service-Subscription Mock StubResponses below + */ + public static void MockGetServiceSubscription(String globalCustId, String subscriptionType, String responseFile) { + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockDeleteServiceSubscription(String globalCustId, String subscriptionType, int statusCode) { + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void MockDeleteServiceInstanceId(String globalCustId, String subscriptionType, String serviceInstanceId) { + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType + "/service-instances/service-instance/" + serviceInstanceId)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockPutServiceSubscription(String globalCustId, String subscriptionType) { + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockGetServiceSubscription(String globalCustId, String subscriptionType, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId + "/service-subscriptions/service-subscription/" + subscriptionType)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + /** + * Customer Mock StubResponses below + */ + public static void MockGetCustomer(String globalCustId, String responseFile) { + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockDeleteCustomer(String globalCustId) { + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockPutCustomer(String globalCustId) { + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockPutCustomer_500(String globalCustId) { + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/" + globalCustId)) + .willReturn(aResponse() + .withStatus(500))); + } + + + /** + * Generic-Vnf Mock StubResponses below + */ + public static void MockGetGenericVnfById(String vnfId, String responseFile, int statusCode){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf" + vnfId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetGenericVnfByIdWithPriority(String vnfId, int statusCode, String responseFile) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf" + vnfId)) + .atPriority(1) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetGenericVnfByIdWithPriority(String vnfId, String vfModuleId, int statusCode, String responseFile, int priority) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "/vf-modules/vf-module/" + vfModuleId)) + .atPriority(priority) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetGenericVnfByIdWithDepth(String vnfId, int depth, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "[?]depth=" + depth)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetGenericVnfById_404(String vnfId){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId)) + .willReturn(aResponse() + .withStatus(404))); + } + + public static void MockGetGenericVnfById_500(String vnfId){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId)) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void MockGetGenericVnfByName(String vnfName, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf[?]vnf-name=" + vnfName)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetGenericVnfByNameWithDepth(String vnfName, int depth, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf[?]vnf-name=" + vnfName + "[&]depth=" + depth)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetGenericVnfByName_404(String vnfName){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf[?]vnf-name=" + vnfName)) + .willReturn(aResponse() + .withStatus(404))); + } + + public static void MockDeleteGenericVnf(String vnfId, String resourceVersion){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(204))); + } + + public static void MockDeleteGenericVnf(String vnfId, String resourceVersion, int statusCode){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void MockDeleteGenericVnf_500(String vnfId, String resourceVersion){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void MockPutGenericVnf(String vnfId){ + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockPutGenericVnf(String vnfId, String requestBodyContaining, int statusCode) { + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf" + vnfId)) + .withRequestBody(containing(requestBodyContaining)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void MockPutGenericVnf(String vnfId, int statusCode) { + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf" + vnfId)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void MockPutGenericVnf_Bad(String vnfId, int statusCode){ + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + + /** + * Vce Mock StubResponses below + */ + public static void MockGetVceById(String vnfId, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/vces/vce/" + vnfId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetVceByName(String vnfName, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/vces/vce[?]vnf-name=" + vnfName)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockDeleteVce(String vnfId, String resourceVersion, int statusCode){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/vces/vce/" + vnfId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void MockPutVce(String vnfId){ + stubFor(put(urlMatching("/aai/v[0-9]+/network/vces/vce/" + vnfId)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockGetGenericVceByNameWithDepth(String vnfName, int depth, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/vces/vce[?]vnf-name=" + vnfName + "[&]depth=" + depth)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetVceGenericQuery(String serviceInstanceName, int depth, int statusCode, String responseFile){ + stubFor(get(urlMatching("/aai/v[0-9]+/search/generic-query[?]key=service-instance.service-instance-name:" + serviceInstanceName + "[&]start-node-type=service-instance[&]include=vce[&]depth=" + depth)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + /** + * Tenant Mock StubResponses below + */ + public static void MockGetTenantGenericQuery(String customer, String serviceType, String responseFile) { + stubFor(get(urlMatching("/aai/v[0-9]+/search/generic-query[?]key=customer.global-customer-id:" + customer + "&key=service-subscription.service-type:" + serviceType + "&start-node-type=service-subscription&include=tenant&include=service-subscription&depth=1")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetTenant(String tenantId, String responseFile) { + stubFor(get(urlEqualTo("/aai/v2/cloud-infrastructure/tenants/tenant/" + tenantId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + /** + * Network Mock StubResponses below + */ + public static void MockGetNetwork(String networkId, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/l3-networks/l3-network/" + networkId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockPutNetwork(String networkId, int statusCode, String responseFile) { + stubFor(put(urlMatching("/aai/v[0-9]+/network/l3-networks/l3-network/" + networkId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockPutNetwork(String networkPolicyId, String responseFile, int statusCode) { + stubFor(put(urlMatching("/aai/v[0-9]+/network/network-policies/network-policy/" + networkPolicyId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetNetworkName(String networkPolicyName, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/l3-networks/l3-network[?]network-name=" + networkPolicyName)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetNetworkVpnBinding(String networkBindingId, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/vpn-bindings/vpn-binding/" + networkBindingId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetNetworkPolicy(String networkPolicy, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/network-policies/network-policy/" + networkPolicy)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetNetworkPolicyfqdn(String networkPolicy, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/network-policies/network-policy[?]network-policy-fqdn=" + networkPolicy)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetNetworkRouteTable(String networkRouteId, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/route-table-references/route-table-reference/" + networkRouteId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + + /** + * Cloud infrastructure below + */ + + public static void MockGetCloudRegion(String cloudRegionId, int statusCode, String responseFile) { + stubFor(get(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/" + cloudRegionId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + /** + * Volume Group StubResponse below + */ + public static void MockGetVolumeGroupById(String cloudRegionId, String volumeGroupId, String responseFile) { + stubFor(get(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/" + cloudRegionId + "/volume-groups/volume-group/" + volumeGroupId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockPutVolumeGroupById(String cloudRegionId, String volumeGroupId, String responseFile, int statusCode) { + stubFor(put(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/" + cloudRegionId + "/volume-groups/volume-group/" + volumeGroupId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetVolumeGroupByName(String cloudRegionId, String volumeGroupName, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/" + cloudRegionId + "/volume-groups[?]volume-group-name=" + volumeGroupName)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockDeleteVolumeGroupById(String cloudRegionId, String volumeGroupId, String resourceVersion, int statusCode) { + stubFor(delete(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/" + cloudRegionId + "/volume-groups/volume-group/" + volumeGroupId + "[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + /** + * VF-Module StubResponse below + * @param statusCode TODO + */ + public static void MockGetVfModuleId(String vnfId, String vfModuleId, String responseFile, int statusCode) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "/vf-modules/vf-module/" + vfModuleId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockGetVfModuleIdNoResponse(String vnfId, String requestContaining, String vfModuleId) { + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "/vf-modules/vf-module/" + vfModuleId)) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml"))); + } + + public static void MockPutVfModuleIdNoResponse(String vnfId, String requestContaining, String vfModuleId) { + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId +"/vf-modules/vf-module/" +vfModuleId)) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockPutVfModuleId(String vnfId, String vfModuleId) { + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "/vf-modules/vf-module/" + vfModuleId)) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockPutVfModuleId(String vnfId, String vfModuleId, int returnCode) { + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "/vf-modules/vf-module/" + vfModuleId)) + .willReturn(aResponse() + .withStatus(returnCode))); + } + + public static void MockDeleteVfModuleId(String vnfId, String vfModuleId, String resourceVersion, int returnCode) { + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + vnfId + "/vf-modules/vf-module/" + vfModuleId + "/[?]resource-version=" + resourceVersion)) + .willReturn(aResponse() + .withStatus(returnCode))); + } + + //// Deprecated Stubs below - to be deleted once unit test that reference them are refactored to use common ones above //// + @Deprecated + public static void MockGetVceById(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/vces/vce/testVnfId123?depth=1")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getVceResponse.xml"))); + } + @Deprecated + public static void MockGetVceByName(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/vces/vce[?]vnf-name=testVnfName123")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getVceByNameResponse.xml"))); + } + @Deprecated + public static void MockPutVce(){ + stubFor(put(urlMatching("/aai/v[0-9]+/network/vces/vce/testVnfId123")) + .willReturn(aResponse() + .withStatus(200))); + } + @Deprecated + public static void MockDeleteVce(){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/vces/vce/testVnfId123[?]resource-version=testReVer123")) + .willReturn(aResponse() + .withStatus(204))); + } + @Deprecated + public static void MockDeleteVce_404(){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/vces/vce/testVnfId123[?]resource-version=testReVer123")) + .willReturn(aResponse() + .withStatus(404))); + } + + @Deprecated + public static void MockDeleteServiceSubscription(){ + stubFor(delete(urlMatching("/aai/v[0-9]+/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET[?]resource-version=1234")) + .willReturn(aResponse() + .withStatus(204))); + } + @Deprecated + public static void MockGetServiceSubscription(){ + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getServiceSubscription.xml"))); + } + @Deprecated + public static void MockGetServiceSubscription_200Empty(){ + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET[?]resource-version=1234")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBody(" "))); + } + @Deprecated + public static void MockGetServiceSubscription_404() { + stubFor(get(urlMatching("/aai/v[0-9]+/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET")) + .willReturn(aResponse() + .withStatus(404))); + } + @Deprecated + public static void MockGENPSIPutServiceInstance(){ + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericPutServiceInstance/GenericPutServiceInstance_PutServiceInstance_AAIResponse_Success.xml"))); + } + + @Deprecated + public static void MockGENPSIPutServiceSubscription(){ + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericPutServiceInstance/GenericPutServiceInstance_PutServiceInstance_AAIResponse_Success.xml"))); + } + @Deprecated + public static void MockGENPSIPutServiceInstance_get500(){ + stubFor(put(urlMatching("/aai/v[0-9]+/business/customers/customer/1604-MVM-26/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET")) + .willReturn(aResponse() + .withStatus(500) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericPutServiceInstance/aaiFault.xml"))); + } + + @Deprecated + public static void MockGetGenericVnfById(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getGenericVnfByNameResponse.xml"))); + } + @Deprecated + public static void MockGetGenericVnfById_404(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123")) + .willReturn(aResponse() + .withStatus(404))); + } + @Deprecated + public static void MockGetGenericVnfByName(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf[?]vnf-name=testVnfName123")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getGenericVnfResponse.xml"))); + } + @Deprecated + public static void MockGetGenericVnfByName_hasRelationships(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf[?]vnf-name=testVnfName123")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getGenericVnfResponse_hasRelationships.xml"))); + } + @Deprecated + public static void MockGetGenericVnfById_hasRelationships(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile("GenericFlows/getGenericVnfResponse_hasRelationships.xml"))); + } + @Deprecated + public static void MockGetGenericVnfById_500(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123")) + .willReturn(aResponse() + .withStatus(500))); + } + @Deprecated + public static void MockGetGenericVnfByName_404(){ + stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf[?]vnf-name=testVnfName123")) + .willReturn(aResponse() + .withStatus(404))); + } + @Deprecated + public static void MockPutGenericVnf(){ + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123")) + .willReturn(aResponse() + .withStatus(200))); + } + @Deprecated + public static void MockPutGenericVnf_400(){ + stubFor(put(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123")) + .willReturn(aResponse() + .withStatus(400))); + } + @Deprecated + public static void MockDeleteGenericVnf(){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123[?]resource-version=testReVer123")) + .willReturn(aResponse() + .withStatus(204))); + } + @Deprecated + public static void MockDeleteGenericVnf_404(){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123[?]resource-version=testReVer123")) + .willReturn(aResponse() + .withStatus(404))); + } + @Deprecated + public static void MockDeleteGenericVnf_500(){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123[?]resource-version=testReVer123")) + .willReturn(aResponse() + .withStatus(500))); + } + @Deprecated + public static void MockDeleteGenericVnf_412(){ + stubFor(delete(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/testVnfId123[[?]]resource-version=testReVer123")) + .willReturn(aResponse() + .withStatus(412))); + } + +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseDatabase.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseDatabase.java new file mode 100644 index 0000000000..7eefa4bc39 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseDatabase.java @@ -0,0 +1,65 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +/** + * Stub response class for Database stubs + * including database adapter, catalog db, + * and other databases. + */ +public class StubResponseDatabase { + + public static void setupAllMocks() { + + } + + public static void mockUpdateRequestDB(int statusCode, String reponseFile) { + stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter")) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(reponseFile))); + } + + public static void MockGetAllottedResourcesByModelInvariantId(String modelInvariantId, String responseFile){ + stubFor(get(urlEqualTo("/v1/serviceAllottedResources?serviceModelInvariantUuid=" + modelInvariantId)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBodyFile(responseFile))); + } + + public static void MockGetAllottedResourcesByModelInvariantId_500(String modelInvariantId, String responseFile){ + stubFor(get(urlEqualTo("/v1/serviceAllottedResources?serviceModelInvariantUuid=" + modelInvariantId)) + .willReturn(aResponse() + .withStatus(500))); + } + +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseNetworkAdapter.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseNetworkAdapter.java new file mode 100644 index 0000000000..c81578a998 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseNetworkAdapter.java @@ -0,0 +1,93 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +/** + * Please describe the StubResponseNetwork.java class + * + */ +public class StubResponseNetworkAdapter { + + private static final String EOL = "\n"; + + public static void setupAllMocks() { + + } + + + public static void MockNetworkAdapter() { + stubFor(post(urlEqualTo("/networks/NetworkAdapter")) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void MockNetworkAdapter(String response) { + stubFor(post(urlEqualTo("/networks/NetworkAdapter")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(response))); + } + + public static void MockNetworkAdapter_500() { + stubFor(post(urlEqualTo("/networks/NetworkAdapter")) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void MockNetworkAdapter(String networkId, int statusCode, String responseFile) { + stubFor(delete(urlEqualTo("/networks/NetworkAdapter/" + networkId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml") + .withBodyFile(responseFile))); + } + + public static void MockNetworkAdapterContainingRequest(String requestContaining, int statusCode, String responseFile) { + stubFor(post(urlEqualTo("/networks/NetworkAdapter")) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void MockPutNetworkAdapter(String networkId, String requestContaining, int statusCode, String responseFile) { + stubFor(put(urlEqualTo("/networks/NetworkAdapter/" + networkId)) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSDNCAdapter.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSDNCAdapter.java new file mode 100644 index 0000000000..8e4b789366 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseSDNCAdapter.java @@ -0,0 +1,138 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +/** + * Please describe the StubResponseSDNC.java class + */ +public class StubResponseSDNCAdapter { + + public static void setupAllMocks() { + + } + + public static void mockSDNCAdapter(int statusCode) { + stubFor(post(urlEqualTo("/SDNCAdapter")) + .willReturn(aResponse() + .withStatus(statusCode))); + } + + public static void mockSDNCAdapter(String endpoint, int statusCode, String responseFile) { + stubFor(post(urlEqualTo(endpoint)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void mockSDNCAdapter(String responseFile) { + stubFor(post(urlEqualTo("/SDNCAdapter")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void mockSDNCAdapter(String endpoint, String requestContaining, int statusCode, String responseFile) { + stubFor(post(urlEqualTo(endpoint)) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void mockSDNCAdapterSimulator(String responseFile) { + MockResource mockResource = new MockResource(); + mockResource.updateProperties("sdnc_delay", "300"); + stubFor(post(urlEqualTo("/SDNCAdapter")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/soap+xml") + .withTransformers("sdnc-adapter-transformer") + .withBodyFile(responseFile))); + } + + public static void mockSDNCAdapterSimulator(String responseFile, String requestContaining) { + MockResource mockResource = new MockResource(); + mockResource.updateProperties("sdnc_delay", "300"); + stubFor(post(urlEqualTo("/SDNCAdapter")) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/soap+xml") + .withTransformers("sdnc-adapter-transformer") + .withBodyFile(responseFile))); + } + + public static void mockSDNCAdapterRest() { + stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc/services")) + .willReturn(aResponse() + .withStatus(202) + .withHeader("Content-Type", "application/json"))); + } + + public static void mockSDNCAdapterRest_500() { + stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc/services")) + .willReturn(aResponse() + .withStatus(500) + .withHeader("Content-Type", "application/json"))); + } + + public static void mockSDNCAdapterRest(String requestContaining) { + stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc/services")) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(202) + .withHeader("Content-Type", "application/json"))); + } + + public static void mockSDNCAdapterRest_500(String requestContaining) { + stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc/services")) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(500) + .withHeader("Content-Type", "application/json"))); + } + + public static void mockSDNCAdapterTopology(String responseFile, String requestContaining) { + MockResource mockResource = new MockResource(); + mockResource.updateProperties("sdnc_delay", "300"); + stubFor(post(urlEqualTo("/SDNCAdapter")) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withTransformers("network-topology-operation-transformer") + .withBodyFile(responseFile))); + } + + +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseVNFAdapter.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseVNFAdapter.java new file mode 100644 index 0000000000..7951a48184 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/StubResponseVNFAdapter.java @@ -0,0 +1,130 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +/** + * Please describe the StubResponseVNF.java class + */ +public class StubResponseVNFAdapter { + + public static void mockVNFAdapter() { + stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync")) + .willReturn(aResponse() + .withStatus(200))); + } + + public static void mockVNFAdapter(String responseFile) { + stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "text/xml") + .withBodyFile(responseFile))); + } + + public static void mockVNFAdapter_500() { + stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync")) + .willReturn(aResponse() + .withStatus(500))); + } + + public static void mockVNFAdapterTransformer(String transformer, String responseFile) { + MockResource mockResource = new MockResource(); + mockResource.updateProperties("vnf_delay", "300"); + stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/soap+xml") + .withTransformers(transformer) + .withBodyFile(responseFile))); + } + + public static void mockVNFAdapterTransformer(String transformer, String responseFile, String requestContaining) { + MockResource mockResource = new MockResource(); + mockResource.updateProperties("vnf_delay", "300"); + stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync")) + .withRequestBody(containing(requestContaining)) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/soap+xml") + .withTransformers(transformer) + .withBodyFile(responseFile))); + } + + public static void mockVNFPost(String vfModuleId, int statusCode, String vnfId) { + stubFor(post(urlEqualTo("/vnfs/v1/vnfs/" + vnfId + "/vf-modules" + vfModuleId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml"))); + } + + public static void mockVNFPut(String vfModuleId, int statusCode) { + stubFor(put(urlEqualTo("/vnfs/v1/vnfs/vnfId/vf-modules" + vfModuleId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml"))); + } + + public static void mockVNFPut(String vnfId, String vfModuleId, int statusCode) { + stubFor(put(urlEqualTo("/vnfs/v1/vnfs/" + vnfId + "/vf-modules" + vfModuleId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml"))); + } + + public static void mockVNFDelete(String vnfId, String vfModuleId, int statusCode) { + stubFor(delete(urlEqualTo("/vnfs/v1/vnfs/" + vnfId + "/vf-modules" + vfModuleId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml"))); + } + + public static void mockVNFRollbackDelete(String vfModuleId, int statusCode) { + stubFor(delete(urlEqualTo("/vnfs/v1/vnfs/vnfId/vf-modules" + vfModuleId + "/rollback")) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml"))); + } + + public static void mockPutVNFVolumeGroup(String volumeGroupId, int statusCode) { + stubFor(put(urlEqualTo("/vnfs/v1/volume-groups/" + volumeGroupId)) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml"))); + } + + public static void mockPostVNFVolumeGroup(int statusCode) { + stubFor(post(urlEqualTo("/vnfs/v1/volume-groups")) + .willReturn(aResponse() + .withStatus(statusCode) + .withHeader("Content-Type", "application/xml"))); + } +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterCreateMockTransformer.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterCreateMockTransformer.java new file mode 100644 index 0000000000..2afe048db4 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterCreateMockTransformer.java @@ -0,0 +1,148 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import javax.xml.ws.Endpoint; + +import org.jboss.resteasy.client.ClientRequest; +import org.jboss.resteasy.client.ClientResponse; + +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; +import com.github.tomakehurst.wiremock.common.FileSource; +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; +import com.github.tomakehurst.wiremock.http.Request; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; + +/** + * Please describe the VnfAdapterCreateMockTransformer.java class + * + */ +public class VnfAdapterCreateMockTransformer extends ResponseTransformer { + + private String notifyCallbackResponse; + private String ackResponse; + + public VnfAdapterCreateMockTransformer() { + notifyCallbackResponse = FileUtil.readResourceFile("__files/vnfAdapterMocks/vnfCreateSimResponse.xml"); // default response + } + + @Override + public String name() { + return "vnf-adapter-create-transformer"; + } + + @Override + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, + FileSource fileSource) { + + String requestBody = request.getBodyAsString(); + + String notficationUrl = requestBody.substring(requestBody.indexOf("")+17, requestBody.indexOf("")); + String messageId = requestBody.substring(requestBody.indexOf("")+11, requestBody.indexOf("")); + String responseMessageId = ""; + String updatedResponse = ""; + + try { + // try supplied response file (if any) + System.out.println(" Supplied fileName: " + responseDefinition.getBodyFileName()); + ackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + notifyCallbackResponse = ackResponse; + responseMessageId = ackResponse.substring(ackResponse.indexOf("")+11, ackResponse.indexOf("")); + updatedResponse = ackResponse.replace(responseMessageId, messageId); + } catch (Exception ex) { + System.out.println(" ******* Use default response file in '__files/vnfAdapterMocks/vnfCreateSimResponse.xml'"); + responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); + updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); + } + + System.out.println("response (mock) messageId : " + responseMessageId); + System.out.println("request (replacement) messageId: " + messageId); + + System.out.println("vnf Response (before):" + notifyCallbackResponse); + System.out.println("vnf Response (after):" + updatedResponse); + + Object vnfDelay = MockResource.getMockProperties().get("vnf_delay"); + int delay = 300; + if (vnfDelay != null) { + delay = Integer.parseInt(vnfDelay.toString()); + } + + //Kick off callback thread + System.out.println("VnfAdapterCreateMockTransformer notficationUrl: " + notficationUrl + ":delay: " + delay); + CallbackResponseThread callbackResponseThread = new CallbackResponseThread(notficationUrl,updatedResponse, delay); + callbackResponseThread.start(); + + return ResponseDefinitionBuilder + .like(responseDefinition).but() + .withStatus(200).withBody(updatedResponse).withHeader("Content-Type", "text/xml") + .build(); + + } + + @Override + public boolean applyGlobally() { + return false; + } + + private class CallbackResponseThread extends Thread { + + private String callbackUrl; + private String payLoad; + private int delay; + + public CallbackResponseThread(String callbackUrl, String payLoad, int delay) { + this.callbackUrl = callbackUrl; + this.payLoad = payLoad; + this.delay = delay; + } + + @SuppressWarnings("deprecation") + public void run () { + try { + //Delay sending callback response + sleep(delay); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("Sending callback response to url: " + callbackUrl); + ClientRequest request = new ClientRequest(callbackUrl); + request.body("text/xml", payLoad); + //System.out.println("payLoad: " + payLoad); + + try { + ClientResponse result = request.post(); + System.out.println("Successfully posted callback? Status: " + result.getStatus()); + //System.err.println("Successfully posted callback:" + result.getStatus()); + } catch (Exception e) { + // TODO Auto-generated catch block + System.out.println("catch error in - request.post() "); + e.printStackTrace(); + } + } + + } + + +} \ No newline at end of file diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterDeleteMockTransformer.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterDeleteMockTransformer.java new file mode 100644 index 0000000000..e9b67b78e5 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterDeleteMockTransformer.java @@ -0,0 +1,146 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import org.jboss.resteasy.client.ClientRequest; +import org.jboss.resteasy.client.ClientResponse; + +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; +import com.github.tomakehurst.wiremock.common.FileSource; +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; +import com.github.tomakehurst.wiremock.http.Request; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; + +/** + * Please describe the VnfAdapterCreateMockTransformer.java class + * + */ +public class VnfAdapterDeleteMockTransformer extends ResponseTransformer { + + + private String notifyCallbackResponse; + private String ackResponse; + + public VnfAdapterDeleteMockTransformer() { + notifyCallbackResponse = FileUtil.readResourceFile("__files/vnfAdapterMocks/vnfDeleteSimResponse.xml"); + } + + @Override + public String name() { + return "vnf-adapter-delete-transformer"; + } + + @Override + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, + FileSource fileSource) { + + // System.err.println("notifyCallbackResponse:" + notifyCallbackResponse); + + String requestBody = request.getBodyAsString(); + + String notficationUrl = requestBody.substring(requestBody.indexOf("")+17, requestBody.indexOf("")); + String messageId = requestBody.substring(requestBody.indexOf("")+11, requestBody.indexOf("")); + String responseMessageId = ""; + String updatedResponse = ""; + + try { + // try supplied response file (if any) + System.out.println(" Supplied fileName: " + responseDefinition.getBodyFileName()); + ackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + notifyCallbackResponse = ackResponse; + responseMessageId = ackResponse.substring(ackResponse.indexOf("")+11, ackResponse.indexOf("")); + updatedResponse = ackResponse.replace(responseMessageId, messageId); + } catch (Exception ex) { + System.out.println(" ******* Use default response file in '__files/vnfAdapterMocks/vnfDeleteSimResponse.xml'"); + responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); + updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); + } + + System.out.println("response (mock) messageId : " + responseMessageId); + System.out.println("request (replacement) messageId: " + messageId); + + System.out.println("vnf Response (before):" + notifyCallbackResponse); + System.out.println("vnf Response (after):" + updatedResponse); + + Object vnfDelay = MockResource.getMockProperties().get("vnf_delay"); + int delay = 300; + if (vnfDelay != null) { + delay = Integer.parseInt(vnfDelay.toString()); + } + + //Kick off callback thread + System.out.println("VnfAdapterDeleteMockTransformer notficationUrl: " + notficationUrl + ":delay: " + delay); + CallbackResponseThread callbackResponseThread = new CallbackResponseThread(notficationUrl,updatedResponse, delay); + callbackResponseThread.start(); + + return ResponseDefinitionBuilder + .like(responseDefinition).but() + .withStatus(200).withBody(updatedResponse).withHeader("Content-Type", "text/xml") + .build(); + + } + + @Override + public boolean applyGlobally() { + return false; + } + + private class CallbackResponseThread extends Thread { + + private String callbackUrl; + private String payLoad; + private int delay; + + public CallbackResponseThread(String callbackUrl, String payLoad, int delay) { + this.callbackUrl = callbackUrl; + this.payLoad = payLoad; + this.delay = delay; + } + + @SuppressWarnings("deprecation") + public void run () { + try { + //Delay sending callback response + sleep(delay); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("Sending callback response to url: " + callbackUrl); + ClientRequest request = new ClientRequest(callbackUrl); + request.body("text/xml", payLoad); + //System.err.println(payLoad); + try { + ClientResponse result = request.post(); + System.out.println("Successfully posted callback? Status: " + result.getStatus()); + //System.err.println("Successfully posted callback:" + result.getStatus()); + } catch (Exception e) { + // TODO Auto-generated catch block + System.out.println("catch error in - request.post() "); + e.printStackTrace(); + } + } + + } +} \ No newline at end of file diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterQueryMockTransformer.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterQueryMockTransformer.java new file mode 100644 index 0000000000..1acd8db723 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterQueryMockTransformer.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + + +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; + +import org.jboss.resteasy.client.ClientRequest; +import org.jboss.resteasy.client.ClientResponse; + +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; +import com.github.tomakehurst.wiremock.common.FileSource; +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; +import com.github.tomakehurst.wiremock.http.Request; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; + +/** + * Please describe the VnfAdapterQueryMockTransformer.java class + * + */ + + +public class VnfAdapterQueryMockTransformer extends ResponseTransformer{ + + private String notifyCallbackResponse; + private String ackResponse; + private String messageId; + + public VnfAdapterQueryMockTransformer() { + notifyCallbackResponse = FileUtil.readResourceFile("__files/vnfAdapterMocks/vnfQuerySimResponse.xml"); + } + + public VnfAdapterQueryMockTransformer(String messageId) { + this.messageId = messageId; + } + + @Override + public String name() { + return "vnf-adapter-query-transformer"; + } + + @Override + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, + FileSource fileSource) { + + String requestBody = request.getBodyAsString(); + + String notficationUrl = requestBody.substring(requestBody.indexOf("")+17, requestBody.indexOf("")); + String messageId = requestBody.substring(requestBody.indexOf("")+11, requestBody.indexOf("")); + // String updatedResponse = notifyCallbackResponse.replace("b1a82ce6-7f5c-45fd-9273-acaf88fc2137", messageId); + + String responseMessageId = ""; + String updatedResponse = ""; + + // if (ackResponse == null) { + //System.err.println("file:" + responseDefinition.getBodyFileName()); + // ackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + //} + + + try { + // try supplied response file (if any) + System.out.println(" Supplied fileName: " + responseDefinition.getBodyFileName()); + ackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + notifyCallbackResponse = ackResponse; + responseMessageId = ackResponse.substring(ackResponse.indexOf("")+11, ackResponse.indexOf("")); + updatedResponse = ackResponse.replace(responseMessageId, messageId); + } catch (Exception ex) { + System.out.println(" ******* Use default response file in '__files/vnfAdapterMocks/vnfQuerySimResponse.xml'"); + responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); + updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); + } + + System.out.println("response (mock) messageId : " + responseMessageId); + System.out.println("request (replacement) messageId: " + messageId); + + System.out.println("vnf Response (before):" + notifyCallbackResponse); + System.out.println("vnf Response (after):" + updatedResponse); + + + Object vnfDelay = MockResource.getMockProperties().get("vnf_delay"); + int delay = 300; + if (vnfDelay != null) { + delay = Integer.parseInt(vnfDelay.toString()); + } + + //Kick off callback thread + + //System.out.println("notficationUrl" + notficationUrl); + //System.out.println("updatedResponse" + updatedResponse); + System.out.println("VnfAdapterQueryMockTransformer notficationUrl: " + notficationUrl + ":delay: " + delay); + CallbackResponseThread callbackResponseThread = new CallbackResponseThread(notficationUrl,updatedResponse, delay); + System.out.println("Inside Callback" ); + callbackResponseThread.start(); + + return ResponseDefinitionBuilder + .like(responseDefinition).but() + .withStatus(200).withBody(updatedResponse).withHeader("Content-Type", "text/xml") + .build(); + } + + @Override + public boolean applyGlobally() { + return false; + } + + private class CallbackResponseThread extends Thread { + + private String callbackUrl; + private String payLoad; + private int delay; + + public CallbackResponseThread(String callbackUrl, String payLoad, int delay) { + this.callbackUrl = callbackUrl; + this.payLoad = payLoad; + this.delay = delay; + } + + public void run () { + try { + //Delay sending callback response + sleep(delay); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + ClientRequest request = new ClientRequest(callbackUrl); + request.body("text/xml", payLoad); + //System.err.println(payLoad); + try { + ClientResponse result = request.post(); + //System.err.println("Successfully posted callback:" + result.getStatus()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + } + + +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterRollbackMockTransformer.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterRollbackMockTransformer.java new file mode 100644 index 0000000000..259d2e3b4b --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterRollbackMockTransformer.java @@ -0,0 +1,147 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import org.jboss.resteasy.client.ClientRequest; +import org.jboss.resteasy.client.ClientResponse; + +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; +import com.github.tomakehurst.wiremock.common.FileSource; +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; +import com.github.tomakehurst.wiremock.http.Request; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; + +/** + * Please describe the VnfAdapterCreateMockTransformer.java class + * + */ +public class VnfAdapterRollbackMockTransformer extends ResponseTransformer { + + private String notifyCallbackResponse; + private String ackResponse; + private String messageId; + + public VnfAdapterRollbackMockTransformer() { + notifyCallbackResponse = FileUtil.readResourceFile("__files/vnfAdapterMocks/vnfRollbackSimResponse.xml"); + } + + public VnfAdapterRollbackMockTransformer(String messageId) { + this.messageId = messageId; + } + + @Override + public String name() { + return "vnf-adapter-rollback-transformer"; + } + + @Override + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, + FileSource fileSource) { + + String requestBody = request.getBodyAsString(); + + String notficationUrl = requestBody.substring(requestBody.indexOf("")+17, requestBody.indexOf("")); + String messageId = requestBody.substring(requestBody.indexOf("")+11, requestBody.indexOf("")); + String responseMessageId = ""; + String updatedResponse = ""; + + try { + // try supplied response file (if any) + System.out.println(" Supplied fileName: " + responseDefinition.getBodyFileName()); + ackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + notifyCallbackResponse = ackResponse; + responseMessageId = ackResponse.substring(ackResponse.indexOf("")+11, ackResponse.indexOf("")); + updatedResponse = ackResponse.replace(responseMessageId, messageId); + } catch (Exception ex) { + System.out.println(" ******* Use default response file in '__files/vnfAdapterMocks/vnfRollbackSimResponse.xml'"); + responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); + updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); + } + + System.out.println("response (mock) messageId : " + responseMessageId); + System.out.println("request (replacement) messageId: " + messageId); + + System.out.println("vnf Response (before):" + notifyCallbackResponse); + System.out.println("vnf Response (after):" + updatedResponse); + + Object vnfDelay = MockResource.getMockProperties().get("vnf_delay"); + int delay = 300; + if (vnfDelay != null) { + delay = Integer.parseInt(vnfDelay.toString()); + } + + //Kick off callback thread + System.out.println("VnfAdapterRollbackMockTransformer notficationUrl: " + notficationUrl + ":delay: " + delay); + CallbackResponseThread callbackResponseThread = new CallbackResponseThread(notficationUrl,updatedResponse, delay); + callbackResponseThread.start(); + + return ResponseDefinitionBuilder + .like(responseDefinition).but() + .withStatus(200).withBody(updatedResponse).withHeader("Content-Type", "text/xml") + .build(); + + } + + @Override + public boolean applyGlobally() { + return false; + } + + private class CallbackResponseThread extends Thread { + + private String callbackUrl; + private String payLoad; + private int delay; + + public CallbackResponseThread(String callbackUrl, String payLoad, int delay) { + this.callbackUrl = callbackUrl; + this.payLoad = payLoad; + this.delay = delay; + } + + public void run () { + try { + //Delay sending callback response + sleep(delay); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("Sending callback response to url: " + callbackUrl); + ClientRequest request = new ClientRequest(callbackUrl); + request.body("text/xml", payLoad); + //System.err.println(payLoad); + try { + ClientResponse result = request.post(); + System.out.println("Successfully posted callback? Status: " + result.getStatus()); + //System.err.println("Successfully posted callback:" + result.getStatus()); + } catch (Exception e) { + // TODO Auto-generated catch block + System.out.println("catch error in - request.post() "); + e.printStackTrace(); + } + } + + } +} diff --git a/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterUpdateMockTransformer.java b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterUpdateMockTransformer.java new file mode 100644 index 0000000000..d720b2410b --- /dev/null +++ b/bpmn/MSOMockServer/src/main/java/org/openecomp/mso/bpmn/mock/VnfAdapterUpdateMockTransformer.java @@ -0,0 +1,148 @@ +/* + * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property. + */ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.openecomp.mso.bpmn.mock; + +import org.jboss.resteasy.client.ClientRequest; +import org.jboss.resteasy.client.ClientResponse; + +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; +import com.github.tomakehurst.wiremock.common.FileSource; +import com.github.tomakehurst.wiremock.extension.ResponseTransformer; +import com.github.tomakehurst.wiremock.http.Request; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; + +/** + * Please describe the VnfAdapterUpdateMockTransformer.java class + * + */ +public class VnfAdapterUpdateMockTransformer extends ResponseTransformer { + + private String notifyCallbackResponse; + private String requestId; + private String ackResponse; + + public VnfAdapterUpdateMockTransformer() { + notifyCallbackResponse = FileUtil.readResourceFile("vnfAdapter/vnfUpdateSimResponse.xml"); + } + + public VnfAdapterUpdateMockTransformer(String requestId) { + this.requestId = requestId; + } + + + public String name() { + return "vnf-adapter-update-transformer"; + } + + @Override + public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, + FileSource fileSource) { + + String requestBody = request.getBodyAsString(); + + String notficationUrl = requestBody.substring(requestBody.indexOf("")+17, requestBody.indexOf("")); + String messageId = requestBody.substring(requestBody.indexOf("")+11, requestBody.indexOf("")); + String responseMessageId = ""; + String updatedResponse = ""; + + try { + // try supplied response file (if any) + System.out.println(" Supplied fileName: " + responseDefinition.getBodyFileName()); + ackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); + notifyCallbackResponse = ackResponse; + responseMessageId = ackResponse.substring(ackResponse.indexOf("")+11, ackResponse.indexOf("")); + updatedResponse = ackResponse.replace(responseMessageId, messageId); + } catch (Exception ex) { + System.out.println(" ******* Use default response file in 'vnfAdapter/vnfUpdateSimResponse.xml'"); + responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); + updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); + } + + System.out.println("response (mock) messageId : " + responseMessageId); + System.out.println("request (replacement) messageId: " + messageId); + + System.out.println("vnf Response (before):" + notifyCallbackResponse); + System.out.println("vnf Response (after):" + updatedResponse); + + Object vnfDelay = MockResource.getMockProperties().get("vnf_delay"); + int delay = 300; + if (vnfDelay != null) { + delay = Integer.parseInt(vnfDelay.toString()); + } + + //Kick off callback thread + System.out.println("VnfAdapterUpdateMockTransformer notficationUrl: " + notficationUrl + ":delay: " + delay); + CallbackResponseThread callbackResponseThread = new CallbackResponseThread(notficationUrl,updatedResponse, delay); + callbackResponseThread.start(); + + return ResponseDefinitionBuilder + .like(responseDefinition).but() + .withStatus(200).withBody(updatedResponse).withHeader("Content-Type", "text/xml") + .build(); + + } + + @Override + public boolean applyGlobally() { + return false; + } + + private class CallbackResponseThread extends Thread { + + private String callbackUrl; + private String payLoad; + private int delay; + + public CallbackResponseThread(String callbackUrl, String payLoad, int delay) { + this.callbackUrl = callbackUrl; + this.payLoad = payLoad; + this.delay = delay; + } + + public void run () { + try { + //Delay sending callback response + sleep(delay); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("Sending callback response to url: " + callbackUrl); + ClientRequest request = new ClientRequest(callbackUrl); + request.body("text/xml", payLoad); + //System.err.println(payLoad); + try { + ClientResponse result = request.post(); + System.out.println("Successfully posted callback? Status: " + result.getStatus()); + //System.err.println("Successfully posted callback:" + result.getStatus()); + } catch (Exception e) { + // TODO Auto-generated catch block + System.out.println("catch error in - request.post() "); + e.printStackTrace(); + } + } + + } +} + diff --git a/bpmn/MSOMockServer/src/main/resources/__files/sdncSimResponse.xml b/bpmn/MSOMockServer/src/main/resources/__files/sdncSimResponse.xml new file mode 100644 index 0000000000..eef8f06a90 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/resources/__files/sdncSimResponse.xml @@ -0,0 +1,19 @@ + + + + + + + d325c9a7-84c0-4081-b979-9cc773a0976d + 200 + OK + + <layer3-service-list + xmlns="com:att:sdnctl:l3api"><service-instance-id>0XX/VXXX/003717//Shakeout</service-instance-id><service-status><rpc-name>svc-topology-operation</rpc-name><rpc-action>delete</rpc-action><request-status>synccomplete</request-status><final-indicator>Y</final-indicator><l3sdn-action>DisconnectLayer3ServiceRequest</l3sdn-action><response-timestamp>2015-10-22T02:11:52.010Z</response-timestamp></service-status><service-data><svc-config-additional-data/></service-data></layer3-service-list> + + + + diff --git a/bpmn/MSOMockServer/src/main/webapp/WEB-INF/jboss-web.xml b/bpmn/MSOMockServer/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000000..cca27bb062 --- /dev/null +++ b/bpmn/MSOMockServer/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,6 @@ + + + + other + /msomock + \ No newline at end of file -- cgit 1.2.3-korg