From c74648bdeaa24f7defdb2912d5a0913380c3fe12 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Wed, 20 Mar 2019 14:45:11 -0400 Subject: removed unused test classes and methods removed unused test classes and methods Change-Id: I9ae5f6f49e416f208e8879ed202aa8865bc9ef83 Issue-ID: SO-1687 Signed-off-by: Benjamin, Max (mb388a) --- .../scripts/PrepareUpdateAAIVfModuleTest.groovy | 1 - .../common/scripts/UpdateAAIGenericVnfTest.groovy | 1 - .../java/org/onap/so/bpmn/mock/MockResource.java | 207 --------------------- .../onap/so/bpmn/mock/MockResourceApplication.java | 55 ------ .../so/bpmn/mock/SDNCAdapterAsyncTransformer.java | 156 ---------------- .../so/bpmn/mock/SDNCAdapterMockTransformer.java | 148 --------------- .../SDNCAdapterNetworkTopologyMockTransformer.java | 141 -------------- .../onap/so/bpmn/mock/StubResponseSDNCAdapter.java | 36 ---- .../onap/so/bpmn/mock/StubResponseVNFAdapter.java | 23 --- .../so/bpmn/mock/VnfAdapterAsyncTransformer.java | 167 ----------------- .../bpmn/mock/VnfAdapterCreateMockTransformer.java | 153 --------------- .../bpmn/mock/VnfAdapterDeleteMockTransformer.java | 149 --------------- .../bpmn/mock/VnfAdapterQueryMockTransformer.java | 158 ---------------- .../mock/VnfAdapterRollbackMockTransformer.java | 151 --------------- .../bpmn/mock/VnfAdapterUpdateMockTransformer.java | 152 --------------- 15 files changed, 1698 deletions(-) delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResource.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResourceApplication.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterAsyncTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterMockTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterAsyncTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterCreateMockTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterDeleteMockTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterQueryMockTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterRollbackMockTransformer.java delete mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterUpdateMockTransformer.java diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy index 21441b9b73..60385a7990 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/PrepareUpdateAAIVfModuleTest.groovy @@ -34,7 +34,6 @@ import org.mockito.ArgumentCaptor import org.mockito.Captor import org.mockito.MockitoAnnotations import org.mockito.runners.MockitoJUnitRunner -import org.onap.so.bpmn.mock.StubResponseAAI import static org.mockito.Mockito.* diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy index 2bd5181c31..6a4d53654b 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnfTest.groovy @@ -37,7 +37,6 @@ import org.mockito.MockitoAnnotations import org.mockito.runners.MockitoJUnitRunner import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.mock.FileUtil -import org.onap.so.bpmn.mock.StubResponseAAI import static com.github.tomakehurst.wiremock.client.WireMock.* import static org.mockito.ArgumentMatchers.any diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResource.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResource.java deleted file mode 100644 index b9a413fc96..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResource.java +++ /dev/null @@ -1,207 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.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 = "src/test/resources/" + "__files/sdncSimResponse.xml"; - path = path.substring(0,path.indexOf("__files/")); - - wireMockServer = new WireMockServer(wireMockConfig().port(portNumber).extensions("org.onap.so.bpmn.mock.SDNCAdapterMockTransformer") - .extensions("org.onap.so.bpmn.mock.SDNCAdapterNetworkTopologyMockTransformer") - .extensions("org.onap.so.bpmn.mock.VnfAdapterCreateMockTransformer") - .extensions("org.onap.so.bpmn.mock.VnfAdapterDeleteMockTransformer") - .extensions("org.onap.so.bpmn.mock.VnfAdapterUpdateMockTransformer") - .extensions("org.onap.so.bpmn.mock.VnfAdapterRollbackMockTransformer") - .extensions("org.onap.so.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); - } - - - /** - * 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; - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResourceApplication.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResourceApplication.java deleted file mode 100644 index 6c62920781..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/MockResourceApplication.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import java.util.HashSet; -import java.util.Set; - -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -import org.junit.Ignore; - -/** - * - * JAX RS Application wiring for Mock Resource - */ -@ApplicationPath("/console") -@Ignore -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/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterAsyncTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterAsyncTransformer.java deleted file mode 100644 index 8515307394..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterAsyncTransformer.java +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.BinaryFile; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; - -/** - * - * Simulates SDNC Adapter Callback response - * - */ -public class SDNCAdapterAsyncTransformer extends ResponseDefinitionTransformer { - - private String syncResponse; - private String callbackResponseWrapper; - - public SDNCAdapterAsyncTransformer() { - syncResponse = FileUtil.readResourceFile("__files/StandardSDNCSynchResponse.xml"); - callbackResponseWrapper = FileUtil.readResourceFile("__files/sdncCallbackSoapWrapper.xml"); - } - - @Override - public String getName() { - return "sdnc-adapter-vf-module-assign"; - } - - /** - * 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, Parameters parameters) { - - 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("responseDefinition: " + responseDefinition); - - // For this mock, the mapped response body is the Async callback (since the sync response is generic for all requests) - String sdncResponse = responseDefinition.getBody(); - System.out.println("sdncResponse:" + sdncResponse); - - if (sdncResponse == null) { - // Body wasn't specified. Check for a body file - String bodyFileName = responseDefinition.getBodyFileName(); - System.out.println("bodyFileName" + bodyFileName); - if (bodyFileName != null) { - System.out.println("fileSource Class: " + fileSource.getClass().getName()); - BinaryFile bodyFile = fileSource.getBinaryFileNamed(bodyFileName); - byte[] responseFile = bodyFile.readContents(); - sdncResponse = new String(responseFile); - System.out.println("sdncResponse(2):" + sdncResponse); - } - } - - // Next substitute the SDNC response into the callbackResponse (SOAP wrapper). - // Also, replace the request ID wherever it appears - String callbackResponse = callbackResponseWrapper.replace("SDNC_RESPONSE_DATA", sdncResponse).replaceAll("SDNC_REQUEST_ID", requestId); - - Object sdncDelay = MockResource.getMockProperties().get("sdnc_delay"); - int delay = 2000; - 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(syncResponse).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(); - } - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.SDNC_ADAPTER); - client.post(payLoad); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterMockTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterMockTransformer.java deleted file mode 100644 index 11788be76e..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterMockTransformer.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Simulates SDNC Adapter Callback response - * - */ -public class SDNCAdapterMockTransformer extends ResponseDefinitionTransformer { - - private static final Logger logger = LoggerFactory.getLogger(SDNCAdapterMockTransformer.class); - private String callbackResponse; - private String requestId; - - public SDNCAdapterMockTransformer() { - callbackResponse = FileUtil.readResourceFile("__files/sdncSimResponse.xml"); - } - - public SDNCAdapterMockTransformer(String requestId) { - this.requestId = requestId; - } - - @Override - public String getName() { - 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, Parameters parameters) { - 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()); - logger.info("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 - logger.info("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) { - logger.debug("Exception :", e1); - } - logger.debug("Sending callback response:" + callbackUrl); - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.SDNC_ADAPTER); - client.post(payLoad); - } catch (Exception e) { - logger.debug("Exception :", e); - } - } - - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java deleted file mode 100644 index 344c3b521d..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/SDNCAdapterNetworkTopologyMockTransformer.java +++ /dev/null @@ -1,141 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SDNCAdapterNetworkTopologyMockTransformer extends ResponseDefinitionTransformer { - - private static final Logger logger = LoggerFactory.getLogger(SDNCAdapterNetworkTopologyMockTransformer.class); - - private String callbackResponse; - private String requestId; - - public SDNCAdapterNetworkTopologyMockTransformer() { - callbackResponse = ""; // FileUtil.readResourceFile("__files/sdncDeleteNetworkTopologySimResponse.xml"); - } - - public SDNCAdapterNetworkTopologyMockTransformer(String requestId) { - this.requestId = requestId; - } - - @Override - public String getName() { - return "network-topology-operation-transformer"; - } - - @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource fileSource, Parameters parameters) { - String requestBody = request.getBodyAsString(); - - String callbackUrl = requestBody.substring(requestBody.indexOf("")+25, requestBody.indexOf("")); - String requestId = requestBody.substring(requestBody.indexOf("")+23, requestBody.indexOf("")); - logger.info("request callbackUrl : " + callbackUrl); - logger.info("request requestId : " + requestId); - - logger.info("file path/name : " + responseDefinition.getBodyFileName()); - callbackResponse = FileUtil.readResourceFile("__files/" + responseDefinition.getBodyFileName()); - // extract Response responseRequestId - String responseRequestId = callbackResponse.substring(callbackResponse.indexOf("")+11, callbackResponse.indexOf("")); - logger.info("response requestId: " + responseRequestId); - logger.info("callbackResponse (before): " + callbackResponse); - callbackResponse = callbackResponse.replace(responseRequestId, requestId); - if (this.requestId != null) { - callbackResponse = callbackResponse.replace(this.requestId, requestId); - } else { - callbackResponse = callbackResponse.replace(responseRequestId, requestId); - } - logger.info("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 - logger.info("(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 - logger.debug("Exception :", e1); - } - logger.debug("Sending callback response to url: {}", callbackUrl); - try { - HttpClient client = new HttpClientFactory() - .newTextXmlClient(UriBuilder.fromUri(callbackUrl).build().toURL(), TargetEntity.SDNC_ADAPTER); - Response response = client.post(payLoad); - logger.debug("Successfully posted callback? Status: {}", response.getStatus()); - } catch (Exception e) { - // TODO Auto-generated catch block - logger.debug("catch error in - request.post() "); - logger.debug("Exception :", e); - } - } - - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseSDNCAdapter.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseSDNCAdapter.java index e0c51b794c..66dc1f9910 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseSDNCAdapter.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseSDNCAdapter.java @@ -80,29 +80,6 @@ public class StubResponseSDNCAdapter { .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() @@ -133,17 +110,4 @@ public class StubResponseSDNCAdapter { .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/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseVNFAdapter.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseVNFAdapter.java index 91ecbd23b4..75283515af 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseVNFAdapter.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/StubResponseVNFAdapter.java @@ -53,29 +53,6 @@ public class StubResponseVNFAdapter { .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("/services/rest/v1/vnfs" + vnfId + "/vf-modules" + vfModuleId)) diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterAsyncTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterAsyncTransformer.java deleted file mode 100644 index e190535e7e..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterAsyncTransformer.java +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.BinaryFile; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; - -/** - * - * Simulates VNF Adapter Asynch Callback response. - * This should work for any of the operations. - * - * This transformer uses the mapped message as the asynchronous response. - * By definition, the async API sends a 202 (with no body) in the sync response. - * - */ -public class VnfAdapterAsyncTransformer extends ResponseDefinitionTransformer { - - public VnfAdapterAsyncTransformer() { - } - - @Override - public String getName() { - return "vnf-adapter-async"; - } - - /** - * Grab the incoming request, extract properties to be copied to the response - * (request id, vnf id, vf module ID, message ID). Then fetch the actual response - * body from its FileSource, make the replacements. - * - * The sync response is an empty 202 response. - * The transformed mapped response file is sent asynchronously after a delay. - * - * Mock Resource can be used to add dynamic properties. If vnf_delay is not in the list by - * default waits for 5s before the callback response is sent - */ - @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, - FileSource fileSource, Parameters parameters) { - - String requestBody = request.getBodyAsString(); - - // Note: Should recognize both XML and JSON. But current BPMN uses XML. - String notificationUrl = requestBody.substring(requestBody.indexOf("")+17, requestBody.indexOf("")); - - String vnfId = requestBody.substring(requestBody.indexOf("")+7, requestBody.indexOf("")); - String vfModuleId = requestBody.substring(requestBody.indexOf("")+12, requestBody.indexOf("")); - String messageId = requestBody.substring(requestBody.indexOf("")+11, requestBody.indexOf("")); - String requestId = requestBody.substring(requestBody.indexOf("")+11, requestBody.indexOf("")); - - System.out.println("responseDefinition: " + responseDefinition); - - // For this mock, the mapped response body is the Async callback (since the sync response is generic for all requests) - String vnfResponse = responseDefinition.getBody(); - System.out.println("VNF Response:" + vnfResponse); - - if (vnfResponse == null) { - // Body wasn't specified. Check for a body file - String bodyFileName = responseDefinition.getBodyFileName(); - System.out.println("bodyFileName" + bodyFileName); - if (bodyFileName != null) { - System.out.println("fileSource Class: " + fileSource.getClass().getName()); - BinaryFile bodyFile = fileSource.getBinaryFileNamed(bodyFileName); - byte[] responseFile = bodyFile.readContents(); - vnfResponse = new String(responseFile); - System.out.println("vnfResponse(2):" + vnfResponse); - } - } - - // Transform the SDNC response to escape < and > - vnfResponse = vnfResponse.replaceAll ("VNF_ID", vnfId); - vnfResponse = vnfResponse.replaceAll ("VF_MODULE_ID", vfModuleId); - vnfResponse = vnfResponse.replaceAll ("REQUEST_ID", requestId); - vnfResponse = vnfResponse.replaceAll ("MESSAGE_ID", messageId); - - Object vnfDelay = MockResource.getMockProperties().get("vnf_delay"); - int delay = 5000; - if (vnfDelay != null) { - delay = Integer.parseInt(vnfDelay.toString()); - } - - //Kick off callback thread - System.out.println("notification Url:" + notificationUrl + ":delay:" + delay); - CallbackResponseThread calbackResponseThread = new CallbackResponseThread(notificationUrl,vnfResponse, delay); - calbackResponseThread.start(); - - //return 200 OK with empty body - return ResponseDefinitionBuilder - .like(responseDefinition).but() - .withStatus(202).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(); - } - - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.VNF_ADAPTER); - client.post(payLoad); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterCreateMockTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterCreateMockTransformer.java deleted file mode 100644 index 362d9508d3..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterCreateMockTransformer.java +++ /dev/null @@ -1,153 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Please describe the VnfAdapterCreateMockTransformer.java class - * - */ -public class VnfAdapterCreateMockTransformer extends ResponseDefinitionTransformer { - - private static final Logger logger = LoggerFactory.getLogger(VnfAdapterCreateMockTransformer.class); - - private String notifyCallbackResponse; - private String ackResponse; - - public VnfAdapterCreateMockTransformer() { - notifyCallbackResponse = FileUtil.readResourceFile("__files/vnfAdapterMocks/vnfCreateSimResponse.xml"); // default response - } - - @Override - public String getName() { - return "vnf-adapter-create-transformer"; - } - - @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, - FileSource fileSource, Parameters parameters) { - - 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) { - logger.debug("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); - } - - logger.info("response (mock) messageId : {}", responseMessageId); - logger.info("request (replacement) messageId: {}", messageId); - - logger.info("vnf Response (before): {}", notifyCallbackResponse); - logger.info("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 - logger.info("VnfAdapterCreateMockTransformer notficationUrl: {} :delay: {}", notficationUrl, 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 - logger.debug("Exception :",e1); - } - logger.debug("Sending callback response to url: {}", callbackUrl); - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.VNF_ADAPTER); - Response response = client.post(payLoad); - logger.debug("Successfully posted callback? Status: {}", response.getStatus()); - } catch (Exception e) { - // TODO Auto-generated catch block - logger.debug("catch error in - request.post() "); - logger.debug("Exception :", e); - } - } - - } - - -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterDeleteMockTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterDeleteMockTransformer.java deleted file mode 100644 index b67f3dcedd..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterDeleteMockTransformer.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Please describe the VnfAdapterCreateMockTransformer.java class - * - */ -public class VnfAdapterDeleteMockTransformer extends ResponseDefinitionTransformer { - - private static final Logger logger = LoggerFactory.getLogger(VnfAdapterDeleteMockTransformer.class); - - private String notifyCallbackResponse; - private String ackResponse; - - public VnfAdapterDeleteMockTransformer() { - notifyCallbackResponse = FileUtil.readResourceFile("__files/vnfAdapterMocks/vnfDeleteSimResponse.xml"); - } - - @Override - public String getName() { - return "vnf-adapter-delete-transformer"; - } - - @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, - FileSource fileSource, Parameters parameters) { - - 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) - logger.info(" 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) { - logger.debug("Exception :",ex); - logger.info(" ******* Use default response file in '__files/vnfAdapterMocks/vnfDeleteSimResponse.xml'"); - responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); - updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); - } - - logger.info("response (mock) messageId : {}", responseMessageId); - logger.info("request (replacement) messageId: {}", messageId); - - logger.info("vnf Response (before):{}", notifyCallbackResponse); - logger.info("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 - logger.info("VnfAdapterDeleteMockTransformer notficationUrl: {} :delay: {}", notficationUrl, 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 - logger.debug("Exception :",e1); - } - - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.VNF_ADAPTER); - client.post(payLoad); - } catch (Exception e) { - // TODO Auto-generated catch block - logger.info("catch error in - request.post() "); - logger.debug("Exception :",e); - } - } - - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterQueryMockTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterQueryMockTransformer.java deleted file mode 100644 index 48ced35810..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterQueryMockTransformer.java +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - - -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Please describe the VnfAdapterQueryMockTransformer.java class - * - */ - - -public class VnfAdapterQueryMockTransformer extends ResponseDefinitionTransformer{ - - private static final Logger logger = LoggerFactory.getLogger(VnfAdapterQueryMockTransformer - .class); - - 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 getName() { - return "vnf-adapter-query-transformer"; - } - - @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, - FileSource fileSource, Parameters parameters) { - - 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) - logger.info(" 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) { - logger.debug("Exception :",ex); - logger.info(" ******* Use default response file in '__files/vnfAdapterMocks/vnfQuerySimResponse.xml'"); - responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); - updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); - } - - logger.info("response (mock) messageId : {}", responseMessageId); - logger.info("request (replacement) messageId: {}", messageId); - - logger.info("vnf Response (before):{}", notifyCallbackResponse); - logger.info("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 - logger.info("VnfAdapterQueryMockTransformer notficationUrl: {}:delay: {}", notficationUrl, delay); - CallbackResponseThread callbackResponseThread = new CallbackResponseThread(notficationUrl,updatedResponse, delay); - logger.info("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) { - logger.debug("Exception :",e1); - } - - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.VNF_ADAPTER); - client.post(payLoad); - } catch (Exception e) { - logger.debug("Exception :",e); - } - } - - } - - -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterRollbackMockTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterRollbackMockTransformer.java deleted file mode 100644 index edf05422d1..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterRollbackMockTransformer.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Please describe the VnfAdapterCreateMockTransformer.java class - * - */ -public class VnfAdapterRollbackMockTransformer extends ResponseDefinitionTransformer { - - private static final Logger logger = LoggerFactory.getLogger(VnfAdapterRollbackMockTransformer.class); - - 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 getName() { - return "vnf-adapter-rollback-transformer"; - } - - @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, - FileSource fileSource, Parameters parameters) { - - 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) - logger.info(" 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) { - logger.debug("Exception :",ex); - logger.info(" ******* Use default response file in '__files/vnfAdapterMocks/vnfRollbackSimResponse.xml'"); - responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); - updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); - } - - logger.info("response (mock) messageId : {}", responseMessageId); - logger.info("request (replacement) messageId: {}", messageId); - - logger.info("vnf Response (before):{}", notifyCallbackResponse); - logger.info("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 - logger.info("VnfAdapterRollbackMockTransformer notficationUrl: {} :delay: {}", notficationUrl, 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) { - logger.debug("Exception :",e1); - } - - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.VNF_ADAPTER); - client.post(payLoad); - } catch (Exception e) { - logger.info("catch error in - request.post() "); - logger.debug("Exception :", e); - } - } - - } -} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterUpdateMockTransformer.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterUpdateMockTransformer.java deleted file mode 100644 index 5693877574..0000000000 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/mock/VnfAdapterUpdateMockTransformer.java +++ /dev/null @@ -1,152 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.mock; - -import javax.ws.rs.core.UriBuilder; - -import org.onap.so.client.HttpClient; -import org.onap.so.client.HttpClientFactory; -import org.onap.so.utils.TargetEntity; - -import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; -import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; -import com.github.tomakehurst.wiremock.http.Request; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Please describe the VnfAdapterUpdateMockTransformer.java class - * - */ -public class VnfAdapterUpdateMockTransformer extends ResponseDefinitionTransformer { - - private static final Logger logger = LoggerFactory.getLogger(VnfAdapterUpdateMockTransformer.class); - - private String notifyCallbackResponse; - private String requestId; - private String ackResponse; - - public VnfAdapterUpdateMockTransformer() { - notifyCallbackResponse = FileUtil.readResourceFile("vnfAdapter/vnfUpdateSimResponse.xml"); - } - - public VnfAdapterUpdateMockTransformer(String requestId) { - this.requestId = requestId; - } - - @Override - public String getName() { - return "vnf-adapter-update-transformer"; - } - - @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, - FileSource fileSource, Parameters parameters) { - - 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) - logger.info(" 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) { - logger.debug("Exception :",ex); - logger.info(" ******* Use default response file in 'vnfAdapter/vnfUpdateSimResponse.xml'"); - responseMessageId = notifyCallbackResponse.substring(notifyCallbackResponse.indexOf("")+11, notifyCallbackResponse.indexOf("")); - updatedResponse = notifyCallbackResponse.replace(responseMessageId, messageId); - } - - logger.info("response (mock) messageId : {}", responseMessageId); - logger.info("request (replacement) messageId: {}", messageId); - - logger.info("vnf Response (before):{}", notifyCallbackResponse); - logger.info("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 - logger.info("VnfAdapterUpdateMockTransformer notficationUrl: {} :delay: {}", notficationUrl, 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) { - logger.debug("Exception :", e1); - } - - try { - HttpClient client = new HttpClientFactory().newTextXmlClient( - UriBuilder.fromUri(callbackUrl).build().toURL(), - TargetEntity.VNF_ADAPTER); - client.post(payLoad); - } catch (Exception e) { - logger.info("catch error in - request.post() "); - logger.debug("Exception :", e); - } - } - - } -} - -- cgit 1.2.3-korg