From 025301d08b061482c1f046d562bf017c8cbcfe8d Mon Sep 17 00:00:00 2001 From: ChrisC Date: Tue, 31 Jan 2017 11:40:03 +0100 Subject: Initial OpenECOMP MSO commit Change-Id: Ia6a7574859480717402cc2f22534d9973a78fa6d Signed-off-by: ChrisC --- .../mso/camunda/tests/BPELRestClientTest.java | 126 ++++++++++++++++++++ .../mso/camunda/tests/CamundaClientTest.java | 123 +++++++++++++++++++ .../mso/camunda/tests/CamundaRequestTest.java | 81 +++++++++++++ .../mso/camunda/tests/CamundaResponseTest.java | 59 ++++++++++ .../mso/camunda/tests/ResponseHandlerTest.java | 131 +++++++++++++++++++++ 5 files changed, 520 insertions(+) create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/BPELRestClientTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaRequestTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java (limited to 'mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests') diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/BPELRestClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/BPELRestClientTest.java new file mode 100644 index 0000000000..46e3a4602f --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/BPELRestClientTest.java @@ -0,0 +1,126 @@ +/*- + * ============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.camunda.tests; + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.Properties; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.ProtocolVersion; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import org.openecomp.mso.apihandler.common.CommonConstants; +import org.openecomp.mso.apihandler.common.RequestClient; +import org.openecomp.mso.apihandler.common.RequestClientFactory; +import org.openecomp.mso.properties.MsoJavaProperties; + + +/** + * This class implements test methods of Camunda Beans. + * + * + */ +public class BPELRestClientTest { + + + + @Mock + private HttpClient mockHttpClient; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void tesBPELPost() throws JsonGenerationException, + JsonMappingException, IOException { + + + String responseBody ="" + + "req5" + + "Layer3ServiceActivateRequest" + + "OMX" + + "n" + + ""; + + HttpResponse mockResponse = createResponse(200, responseBody); + mockHttpClient = Mockito.mock(HttpClient.class); + Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class))) + .thenReturn(mockResponse); + + String reqXML = "test"; + String orchestrationURI = "/active-bpel/services/REST/MsoLayer3ServiceActivate"; + + MsoJavaProperties props = new MsoJavaProperties(); + props.setProperty(CommonConstants.BPEL_URL, "http://localhost:8089"); + props.setProperty("bpelAuth", "786864AA53D0DCD881AED1154230C0C3058D58B9339D2EFB6193A0F0D82530E1"); + + RequestClient requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props); + requestClient.setClient(mockHttpClient); + HttpResponse response = requestClient.post(reqXML, "reqId", "timeout", "version", null, null); + + + int statusCode = response.getStatusLine().getStatusCode(); + assertEquals(requestClient.getType(), CommonConstants.BPEL); + assertEquals(statusCode, HttpStatus.SC_OK); + + + } + + private HttpResponse createResponse(int respStatus, + String respBody) { + HttpResponse response = new BasicHttpResponse( + new BasicStatusLine( + new ProtocolVersion("HTTP", 1, 1), respStatus, "")); + response.setStatusCode(respStatus); + try { + response.setEntity(new StringEntity(respBody)); + response.setHeader("Content-Type", "text/xml"); + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } + + + + + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java new file mode 100644 index 0000000000..d8c0e52005 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java @@ -0,0 +1,123 @@ +/*- + * ============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.camunda.tests; + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import java.util.Properties; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.ProtocolVersion; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import org.openecomp.mso.apihandler.common.CommonConstants; +import org.openecomp.mso.apihandler.common.RequestClient; +import org.openecomp.mso.apihandler.common.RequestClientFactory; +import org.openecomp.mso.properties.MsoJavaProperties; + + +/** + * This class implements test methods of Camunda Beans. + * + * + */ +public class CamundaClientTest { + + + + @Mock + private HttpClient mockHttpClient; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void tesCamundaPost() throws JsonGenerationException, + JsonMappingException, IOException { + + + String responseBody ="{\"links\":[{\"method\":\"GET\",\"href\":\"http://localhost:9080/engine-rest/process-instance/2047c658-37ae-11e5-9505-7a1020524153\",\"rel\":\"self\"}],\"id\":\"2047c658-37ae-11e5-9505-7a1020524153\",\"definitionId\":\"dummy:10:73298961-37ad-11e5-9505-7a1020524153\",\"businessKey\":null,\"caseInstanceId\":null,\"ended\":true,\"suspended\":false}"; + + HttpResponse mockResponse = createResponse(200, responseBody); + mockHttpClient = Mockito.mock(HttpClient.class); + Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class))) + .thenReturn(mockResponse); + + String reqXML = "test"; + String orchestrationURI = "/engine-rest/process-definition/key/dummy/start"; + + MsoJavaProperties props = new MsoJavaProperties(); + props.setProperty(CommonConstants.CAMUNDA_URL, "http://localhost:8089"); + + RequestClient requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props); + requestClient.setClient(mockHttpClient); + HttpResponse response = requestClient.post(reqXML, "reqId", "timeout", "version", null, null); + + + int statusCode = response.getStatusLine().getStatusCode(); + assertEquals(requestClient.getType(), CommonConstants.CAMUNDA); + assertEquals(statusCode, HttpStatus.SC_OK); + + props.setProperty (CommonConstants.CAMUNDA_AUTH, "ABCD1234"); + requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props); + requestClient.setClient(mockHttpClient); + response = requestClient.post(null, "reqId", null, null, null, null); + assertEquals(requestClient.getType(), CommonConstants.CAMUNDA); + assertEquals(statusCode, HttpStatus.SC_OK); + } + + private HttpResponse createResponse(int respStatus, + String respBody) { + HttpResponse response = new BasicHttpResponse( + new BasicStatusLine( + new ProtocolVersion("HTTP", 1, 1), respStatus, "")); + response.setStatusCode(respStatus); + try { + response.setEntity(new StringEntity(respBody)); + response.setHeader("Content-Type", "application/json"); + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } + + + + + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaRequestTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaRequestTest.java new file mode 100644 index 0000000000..bd2fee6f1e --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaRequestTest.java @@ -0,0 +1,81 @@ +/*- + * ============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.camunda.tests; + + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.junit.Test; + +import org.openecomp.mso.apihandler.camundabeans.CamundaInput; +import org.openecomp.mso.apihandler.camundabeans.CamundaRequest; +import org.openecomp.mso.apihandler.common.CommonConstants; + +/** + * This class implements test methods of Camunda Beans. + * + * + */ +public class CamundaRequestTest { + + @Test + public final void testSerialization() throws JsonGenerationException, + JsonMappingException, IOException { + CamundaRequest camundaRequest = new CamundaRequest(); + CamundaInput camundaInput = new CamundaInput(); + CamundaInput host = new CamundaInput(); + CamundaInput schema = new CamundaInput(); + CamundaInput reqid = new CamundaInput(); + CamundaInput svcid = new CamundaInput(); + CamundaInput timeout = new CamundaInput(); + camundaInput + .setValue(" 155415ab-b4a7-4382-b4c6-d17d950604Layer3ServiceActivateRequestOMXhttps://csi-tst-q22.it.att.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws50515631 SDN-ETHERNET-INTERNETHI/VLXM/950604//SW_INTERNETSubName01 MTSNJA4LCP1 "); + camundaRequest.setServiceInput(camundaInput); + host.setValue("localhost"); + camundaRequest.setHost(host); + schema.setValue("v1"); + camundaRequest.setSchema(schema); + reqid.setValue("reqid123"); + camundaRequest.setReqid(reqid); + svcid.setValue("svcid123"); + camundaRequest.setSvcid(svcid); + timeout.setValue(""); + camundaRequest.setTimeout(timeout); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true); + + String json = mapper.writeValueAsString(camundaRequest); + System.out.println(json); + assertEquals( + "{\"variables\":{\""+CommonConstants.CAMUNDA_SERVICE_INPUT+"\":{\"value\":\" 155415ab-b4a7-4382-b4c6-d17d950604Layer3ServiceActivateRequestOMXhttps://csi-tst-q22.it.att.com:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws50515631 SDN-ETHERNET-INTERNETHI/VLXM/950604//SW_INTERNETSubName01 MTSNJA4LCP1 \",\"type\":\"String\"}" + + ",\"host\":{\"value\":\"localhost\",\"type\":\"String\"},\"att-mso-schema-version\":{\"value\":\"v1\",\"type\":\"String\"},\"att-mso-request-id\":{\"value\":\"reqid123\",\"type\":\"String\"},\"att-mso-service-instance-id\":{\"value\":\"svcid123\",\"type\":\"String\"},\"att-mso-service-request-timeout\":{\"value\":\"\",\"type\":\"String\"}}}", + json); + + } + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java new file mode 100644 index 0000000000..aff8ab2a2c --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.camunda.tests; + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Test; + +import org.openecomp.mso.apihandler.camundabeans.CamundaResponse; + +/** + * This class implements test methods of Camunda Beans. + * + * + */ +public class CamundaResponseTest { + + @Test + public final void testDeserialization() throws JsonGenerationException, + JsonMappingException, IOException { + ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally + mapper.enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + String responseBody = "{ \"response\": \"xml\","+ + "\"messageCode\": 200,"+ + "\"message\": \"Successfully started the process\"," + + "\"processInstanceID\":null,\"variables\":null}"; + + CamundaResponse response = mapper.readValue(responseBody, CamundaResponse.class); + assertEquals(response.toString(), "CamundaResponse [response=xml, messageCode=200, message=Successfully started the process]"); + + } + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java new file mode 100644 index 0000000000..ba2c5524b5 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java @@ -0,0 +1,131 @@ +/*- + * ============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.camunda.tests; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.ProtocolVersion; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; +import org.junit.Test; + +import org.openecomp.mso.apihandler.common.ResponseHandler; + +/** + * This class implements test methods of CamundaResoponseHandler. + * + * + */ +public class ResponseHandlerTest { + + @Test + public void tesParseCamundaResponse () throws JsonGenerationException, JsonMappingException, IOException { + // String body + // ="{\"links\":[{\"method\":\"GET\",\"href\":\"http://localhost:9080/engine-rest/process-instance/2047c658-37ae-11e5-9505-7a1020524153\",\"rel\":\"self\"}],\"id\":\"2047c658-37ae-11e5-9505-7a1020524153\",\"definitionId\":\"dummy:10:73298961-37ad-11e5-9505-7a1020524153\",\"businessKey\":null,\"caseInstanceId\":null,\"ended\":true,\"suspended\":false}"; + + String body = "{ \"response\": \"xml\"," + "\"messageCode\": 200," + + "\"message\": \"Successfully started the process\"}"; + + HttpResponse response = createResponse (200, body, "application/json"); + + ResponseHandler respHandler = new ResponseHandler (response, 1); + + int status = respHandler.getStatus (); + assertEquals (status, HttpStatus.SC_ACCEPTED); + assertEquals (respHandler.getResponse ().getMessage (), "Successfully started the process"); + + } + + @Test + public void tesParseBpelResponse () throws JsonGenerationException, JsonMappingException, IOException { + String body = "" + + "req5" + + "Layer3ServiceActivateRequest" + + "OMX" + + "n" + + ""; + + HttpResponse response = createResponse (200, body, "text/xml"); + + ResponseHandler respHandler = new ResponseHandler (response, 0); + + int status = respHandler.getStatus (); + assertEquals (status, HttpStatus.SC_ACCEPTED); + assertTrue (respHandler.getResponseBody () != null); + } + + @Test + public void tes404ErrorResponse () throws JsonGenerationException, JsonMappingException, IOException { + + + HttpResponse response = createResponse (HttpStatus.SC_NOT_FOUND, "error", "text/html"); + ResponseHandler respHandler = new ResponseHandler (response, 1); + + int status = respHandler.getStatus (); + + assertEquals (HttpStatus.SC_NOT_IMPLEMENTED, status); + + } + + @Test + public void tesGenricErrorResponse () throws JsonGenerationException, JsonMappingException, IOException { + + String body = "{ \"response\": \"xml\"," + "\"messageCode\": 500," + + "\"message\": \"Something went wrong\"}"; + + HttpResponse response = createResponse (500, body, "application/json"); + + ResponseHandler respHandler = new ResponseHandler (response, 1); + + int status = respHandler.getStatus (); + assertEquals (HttpStatus.SC_BAD_GATEWAY, status); + assertEquals (respHandler.getResponse ().getMessage (), "Something went wrong"); + System.out.println (respHandler.getResponseBody ()); + + } + + private HttpResponse createResponse (int respStatus, String respBody, String contentType) { + HttpResponse response = new BasicHttpResponse (new BasicStatusLine (new ProtocolVersion ("HTTP", 1, 1), + respStatus, + "")); + response.setStatusCode (respStatus); + try { + response.setEntity (new StringEntity (respBody)); + response.setHeader ("Content-Type", contentType); + } catch (Exception e) { + e.printStackTrace (); + } + return response; + } + +} -- cgit 1.2.3-korg