From 5a6a6de6f1a26a1897e4917a0df613e25a24eb70 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 30 Jul 2018 15:56:09 -0400 Subject: Containerization feature of SO Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18 Issue-ID: SO-670 Signed-off-by: Benjamin, Max (mb388a) --- .../onap/so/apihandler/camundabeans/BeansTest.java | 72 +++++++++ .../apihandler/camundabeans/BpmnRequestTest.java | 178 +++++++++++++++++++++ .../CamundaMacroRequestSerializerTest.java | 36 +++++ .../so/apihandler/common/AllTestsTestSuite.java | 33 ++++ .../so/apihandler/common/CamundaClientTest.java | 166 +++++++++++++++++++ .../apihandler/common/CamundaTaskClientTest.java | 139 ++++++++++++++++ .../so/apihandler/common/ResponseHandlerTest.java | 139 ++++++++++++++++ .../recipe/CamundaClientErrorHandlerTest.java | 72 +++++++++ .../so/apihandlerinfra/ApiExceptionMapperTest.java | 97 +++++++++++ .../onap/so/apihandlerinfra/ApiExceptionTest.java | 128 +++++++++++++++ .../org/onap/so/apihandlerinfra/TestAppender.java | 37 +++++ .../mso/apihandler/camundabeans/BeansTest.java | 72 --------- .../apihandler/camundabeans/BpmnRequestTest.java | 178 --------------------- .../apihandler/common/CamundaTaskClientTest.java | 132 --------------- .../mso/camunda/tests/BPELRestClientTest.java | 125 --------------- .../mso/camunda/tests/CamundaClientTest.java | 144 ----------------- .../mso/camunda/tests/CamundaRequestTest.java | 81 ---------- .../mso/camunda/tests/CamundaResponseTest.java | 78 --------- .../mso/camunda/tests/ResponseHandlerTest.java | 137 ---------------- .../CamundaClientTest/WrappedVIDRequest.json | 1 + .../src/test/resources/logback-test.xml | 48 ------ 21 files changed, 1098 insertions(+), 995 deletions(-) create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BeansTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BpmnRequestTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/CamundaMacroRequestSerializerTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/AllTestsTestSuite.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/ResponseHandlerTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/recipe/CamundaClientErrorHandlerTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionMapperTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/TestAppender.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BeansTest.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BpmnRequestTest.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/BPELRestClientTest.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaRequestTest.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json delete mode 100644 mso-api-handlers/mso-api-handler-common/src/test/resources/logback-test.xml (limited to 'mso-api-handlers/mso-api-handler-common/src/test') diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BeansTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BeansTest.java new file mode 100644 index 0000000000..b596636f6d --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BeansTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.apihandler.camundabeans; + +import org.junit.Test; + +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterNonConcrete; +import com.openpojo.reflection.filters.FilterPackageInfo; +import org.onap.so.openpojo.rules.HasToStringRule; +import org.onap.so.openpojo.rules.ToStringTester; + +public class BeansTest { + + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + private PojoClassFilter enumFilter = new FilterEnum(); + + + @Test + public void pojoStructure() { + test("org.onap.so.apihandler.camundabeans"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + + + + + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + + .build(); + + + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete()); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BpmnRequestTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BpmnRequestTest.java new file mode 100644 index 0000000000..7087e90b73 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BpmnRequestTest.java @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.apihandler.camundabeans; + +import org.junit.Test; + +public class BpmnRequestTest { + + BpmnRequest bpmnRequest = new BpmnRequest(); + + @Test + public void getHostTest() throws Exception { + bpmnRequest.getHost(); + } + + @Test + public void setHostTest() throws Exception { + bpmnRequest.setHost(new CamundaInput()); + } + + @Test + public void getRequestIdTest() throws Exception { + bpmnRequest.getRequestId(); + } + + @Test + public void setRequestIdTest() throws Exception { + bpmnRequest.setRequestId(new CamundaInput()); + } + + @Test + public void getIsBaseVfModuleTest() throws Exception { + bpmnRequest.getIsBaseVfModule(); + } + + @Test + public void setIsBaseVfModuleTest() throws Exception { + bpmnRequest.setIsBaseVfModule(new CamundaBooleanInput()); + } + + @Test + public void getRecipeTimeoutTest() throws Exception { + bpmnRequest.getRecipeTimeout(); + } + + @Test + public void setRecipeTimeoutTest() throws Exception { + bpmnRequest.setRecipeTimeout(new CamundaIntegerInput()); + } + + @Test + public void getRequestActionTest() throws Exception { + bpmnRequest.getRequestAction(); + } + + @Test + public void setRequestActionTest() throws Exception { + bpmnRequest.setRequestAction(new CamundaInput()); + } + + @Test + public void getServiceInstanceIdTest() throws Exception { + bpmnRequest.getServiceInstanceId(); + } + + @Test + public void setServiceInstanceIdTest() throws Exception { + bpmnRequest.setServiceInstanceId(new CamundaInput()); + } + + @Test + public void getVnfIdTest() throws Exception { + bpmnRequest.getVnfId(); + } + + @Test + public void setVnfIdTest() throws Exception { + bpmnRequest.setVnfId(new CamundaInput()); + } + + @Test + public void getVfModuleIdTest() throws Exception { + bpmnRequest.getVnfId(); + } + + @Test + public void setVfModuleIdTest() throws Exception { + bpmnRequest.setVfModuleId(new CamundaInput()); + } + + @Test + public void getVolumeGroupIdTest() throws Exception { + bpmnRequest.getVolumeGroupId(); + } + + @Test + public void setVolumeGroupIdTest() throws Exception { + bpmnRequest.setVolumeGroupId(new CamundaInput()); + } + + @Test + public void getNetworkIdTest() throws Exception { + bpmnRequest.getNetworkId(); + } + + @Test + public void setNetworkIdTest() throws Exception { + bpmnRequest.setNetworkId(new CamundaInput()); + } + + @Test + public void getServiceTypeTest() throws Exception { + bpmnRequest.getServiceType(); + } + + @Test + public void setServiceTypeTest() throws Exception { + bpmnRequest.setServiceType(new CamundaInput()); + } + + @Test + public void getVnfTypeTest() throws Exception { + bpmnRequest.getVnfType(); + } + + @Test + public void setVnfTypeTest() throws Exception { + bpmnRequest.setVnfType(new CamundaInput()); + } + + @Test + public void getVfModuleTypeTest() throws Exception { + bpmnRequest.getVfModuleType(); + } + + @Test + public void setVfModuleTypeTest() throws Exception { + bpmnRequest.setVfModuleType(new CamundaInput()); + } + + @Test + public void getNetworkTypeTest() throws Exception { + bpmnRequest.getNetworkType(); + } + + @Test + public void setNetworkTypeTest() throws Exception { + bpmnRequest.setNetworkType(new CamundaInput()); + } + + @Test + public void getRequestDetailsTest() throws Exception { + bpmnRequest.getRequestDetails(); + } + + @Test + public void setRequestDetailsTest() throws Exception { + bpmnRequest.setRequestDetails(new CamundaInput()); + } + +} \ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/CamundaMacroRequestSerializerTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/CamundaMacroRequestSerializerTest.java new file mode 100644 index 0000000000..36966342b2 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/CamundaMacroRequestSerializerTest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.apihandler.camundabeans; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by ANANDSAN on 4/10/2018. + */ +public class CamundaMacroRequestSerializerTest { + @Test + public void testWithAllParameters() throws Exception{ + String jsonRequest = CamundaMacroRequestSerializer.getJsonRequest("requestId", "action", "serviceInstanceId"); + Assert.assertNotNull(jsonRequest); + Assert.assertEquals("{\"variables\":{\"mso-request-id\":{\"value\":\"requestId\",\"type\":\"String\"},\"gAction\":{\"value\":\"action\",\"type\":\"String\"},\"serviceInstanceId\":{\"value\":\"serviceInstanceId\",\"type\":\"String\"}}}", jsonRequest); + } +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/AllTestsTestSuite.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/AllTestsTestSuite.java new file mode 100644 index 0000000000..47c166eff9 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/AllTestsTestSuite.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.apihandler.common; + +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses("**/*Test.class") +public class AllTestsTestSuite { + // the class remains empty, + // used only as a holder for the above annotations +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java new file mode 100644 index 0000000000..d7052762ab --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java @@ -0,0 +1,166 @@ +/*- + * ============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.apihandler.common; + + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +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.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.so.apihandler.common.CamundaClient; +import org.onap.so.apihandler.common.CommonConstants; +import org.onap.so.apihandler.common.RequestClient; +import org.onap.so.apihandler.common.RequestClientFactory; +import org.springframework.mock.env.MockEnvironment; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; + + +/** + * 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"; + MockEnvironment environment = new MockEnvironment(); + + environment.setProperty("mso.camundaUR", "yourValue1"); + + + RequestClientFactory reqClientFactory = new RequestClientFactory(); + reqClientFactory.setEnv(environment); + RequestClient requestClient = reqClientFactory.getRequestClient(orchestrationURI); + + 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); + + + requestClient = reqClientFactory.getRequestClient(orchestrationURI); + 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; + } + + public String inputStream(String JsonInput)throws IOException{ + JsonInput = "src/test/resources/CamundaClientTest" + JsonInput; + String input = new String(Files.readAllBytes(Paths.get(JsonInput))); + return input; + } + + @Test + public void wrapVIDRequestTest() throws IOException{ + CamundaClient testClient = new CamundaClient(); + testClient.setUrl("/mso/async/services/CreateGenericALaCarteServiceInstance"); + + String requestId = "f7ce78bb-423b-11e7-93f8-0050569a796"; + boolean isBaseVfModule = true; + int recipeTimeout = 10000; + String requestAction = "createInstance"; + String serviceInstanceId = "12345679"; + String correlationId = "12345679"; + String vnfId = "234567891"; + String vfModuleId = "345678912"; + String volumeGroupId = "456789123"; + String networkId = "567891234"; + String configurationId = "678912345"; + String serviceType = "testService"; + String vnfType = "testVnf"; + String vfModuleType = "vfModuleType"; + String networkType = "networkType"; + String requestDetails = "{requestDetails: }"; + String apiVersion = "6"; + boolean aLaCarte = true; + String requestUri = "v7/serviceInstances/assign"; + + String testResult = testClient.wrapVIDRequest(requestId, isBaseVfModule, recipeTimeout, requestAction, serviceInstanceId, correlationId, + vnfId, vfModuleId, volumeGroupId, networkId, configurationId, serviceType, + vnfType, vfModuleType, networkType, requestDetails, apiVersion, aLaCarte, requestUri, ""); + String expected = inputStream("/WrappedVIDRequest.json"); + + assertEquals(expected, testResult); + } + + + + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java new file mode 100644 index 0000000000..69772ee7e6 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java @@ -0,0 +1,139 @@ +/*- + * ============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.apihandler.common; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.http.HttpEntity; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.apihandler.common.CamundaTaskClient; +import org.onap.so.apihandler.common.CommonConstants; +import org.onap.so.apihandler.common.RequestClientParameter; +import org.springframework.core.env.Environment; + +@RunWith(MockitoJUnitRunner.class) +public class CamundaTaskClientTest { + + @Mock + private Environment env; + private CamundaTaskClient testedObject = new CamundaTaskClient(); + private HttpClient httpClientMock; + private static final String JSON_REQUEST = "{\"value1\": \"aaa\",\"value2\": \"bbb\"}"; + private static final String URL_SCHEMA = "http"; + private static final String HOST = "testhost"; + private static final int PORT = 1234; + private static final String URL_PATH = "/requestMethodSuccessful"; + private static final String URL = URL_SCHEMA + "://" + HOST + ":" + PORT + URL_PATH; + private static final String AUTHORIZATION_HEADER_NAME = "Authorization"; + + @Before + public void init() { + when(env.getProperty(eq(CommonConstants.CAMUNDA_AUTH))).thenReturn(""); + testedObject = new CamundaTaskClient(); + httpClientMock = mock(HttpClient.class); + testedObject.setClient(httpClientMock); + testedObject.setUrl(URL); + } + + @Test + public void postMethodSuccessful() throws IOException { + ArgumentCaptor httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class); + testedObject.post(JSON_REQUEST); + verify(httpClientMock).execute(httpPostCaptor.capture()); + checkUri(httpPostCaptor.getValue()); + assertThat(httpPostCaptor.getValue().getEntity().getContentType().getValue()). + isEqualTo(CommonConstants.CONTENT_TYPE_JSON); + assertThat(getJsonFromEntity(httpPostCaptor.getValue().getEntity())).isEqualTo(JSON_REQUEST); + } + + @Test + public void postMethodSuccessfulWithCredentials() throws IOException { + ArgumentCaptor httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class); + testedObject.setProps(env); + testedObject.post(JSON_REQUEST); + verify(httpClientMock).execute(httpPostCaptor.capture()); + assertThat(httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); + } + + @Test + public void getMethodSuccessful() throws IOException { + ArgumentCaptor httpGetCaptor = ArgumentCaptor.forClass(HttpGet.class); + testedObject.get(); + verify(httpClientMock).execute(httpGetCaptor.capture()); + checkUri(httpGetCaptor.getValue()); + } + + @Test + public void getMethodSuccessfulWithCredentials() throws IOException { + ArgumentCaptor httpGetCaptor = ArgumentCaptor.forClass(HttpGet.class); + testedObject.setUrl(URL); + testedObject.setProps(env); + testedObject.get(); + verify(httpClientMock).execute(httpGetCaptor.capture()); + assertThat(httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); + } + + @Test(expected = UnsupportedOperationException.class) + public void postMethodUnsupported() { + testedObject.post("", "", "", "", "", ""); + } + + @Test(expected = UnsupportedOperationException.class) + public void postMethodUnsupported2() { + testedObject.post(new RequestClientParameter.Builder().build()); + } + + private void checkUri(HttpRequestBase httpRequestBase) { + assertThat(httpRequestBase.getURI().getScheme()).isEqualTo(URL_SCHEMA); + assertThat(httpRequestBase.getURI().getHost()).isEqualTo(HOST); + assertThat(httpRequestBase.getURI().getPort()).isEqualTo(PORT); + assertThat(httpRequestBase.getURI().getPath()).isEqualTo(URL_PATH); + } + + private String getJsonFromEntity(HttpEntity httpEntity) throws IOException { + BufferedReader rd = new BufferedReader( + new InputStreamReader(httpEntity.getContent())); + StringBuilder result = new StringBuilder(); + String line; + while ((line = rd.readLine()) != null) { + result.append(line); + } + return result.toString(); + } + +} \ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/ResponseHandlerTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/ResponseHandlerTest.java new file mode 100644 index 0000000000..7bb054c297 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/ResponseHandlerTest.java @@ -0,0 +1,139 @@ +/*- + * ============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.apihandler.common; + + +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.startsWith; +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.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.apihandler.common.ErrorNumbers; +import org.onap.so.apihandler.common.ResponseHandler; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.exceptions.BPMNFailureException; +import org.onap.so.apihandlerinfra.exceptions.ValidateException; + +/** + * This class implements test methods of CamundaResoponseHandler. + * + * + */ +public class ResponseHandlerTest{ + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void tesParseCamundaResponse () throws ApiException { + // 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 ApiException{ + String body = "" + + "req5" + + "test" + + "test" + + "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 tesMappingErrorResponse () throws ApiException { + thrown.expect(ValidateException.class); + thrown.expectMessage(startsWith("JSON Object Mapping Request")); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_BAD_REQUEST))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_BAD_PARAMETER))); + + 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 ApiException { + + 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 (status, HttpStatus.SC_BAD_GATEWAY); + assertEquals (respHandler.getResponse ().getMessage (), "Something went wrong"); + } + + 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; + } + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/recipe/CamundaClientErrorHandlerTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/recipe/CamundaClientErrorHandlerTest.java new file mode 100644 index 0000000000..564121b7b5 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/recipe/CamundaClientErrorHandlerTest.java @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 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.apihandler.recipe; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.springframework.http.HttpStatus; +import org.springframework.http.client.ClientHttpResponse; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +public class CamundaClientErrorHandlerTest { + + private ClientHttpResponse clientHttpResponse; + private CamundaClientErrorHandler clientErrorHandler; + + @Before + public void before() { + clientHttpResponse = Mockito.mock(ClientHttpResponse.class); + clientErrorHandler = new CamundaClientErrorHandler(); + } + + @Test + public void handleError_SERVER_ERROR_Test() throws IOException { + Mockito.when(clientHttpResponse.getStatusCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR); + Mockito.when(clientHttpResponse.getBody()).thenReturn(new ByteArrayInputStream("{}".getBytes())); + clientErrorHandler.handleError(clientHttpResponse); + boolean serverHasError = clientErrorHandler.hasError(clientHttpResponse); + assertEquals(true, serverHasError); + } + + @Test + public void handleError_CLIENT_ERROR_Test() throws IOException { + Mockito.when(clientHttpResponse.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST); + Mockito.when(clientHttpResponse.getBody()).thenReturn(new ByteArrayInputStream("{}".getBytes())); + clientErrorHandler.handleError(clientHttpResponse); + boolean clientHasError = clientErrorHandler.hasError(clientHttpResponse); + assertEquals(true, clientHasError); + } + + @Test + public void handleError_SUCCESS_Test() throws IOException { + Mockito.when(clientHttpResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + Mockito.when(clientHttpResponse.getBody()).thenReturn(new ByteArrayInputStream("{}".getBytes())); + clientErrorHandler.handleError(clientHttpResponse); + boolean hasNoError = clientErrorHandler.hasError(clientHttpResponse); + assertEquals(false, hasNoError); + } + +} \ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionMapperTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionMapperTest.java new file mode 100644 index 0000000000..b98c47490a --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionMapperTest.java @@ -0,0 +1,97 @@ +/*- + * ============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.apihandlerinfra; + + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.so.apihandler.common.ErrorNumbers; +import org.onap.so.apihandlerinfra.exceptions.*; + +import org.apache.http.HttpStatus; +import javax.ws.rs.core.Response; + + +import java.io.IOException; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.anyObject; +import static org.hamcrest.core.StringStartsWith.startsWith; + +public class ApiExceptionMapperTest { + + ApiExceptionMapper mapper = new ApiExceptionMapper(); + + + @Test + public void testObjectMapperError() throws JsonProcessingException { + ObjectMapper mockedMapper = Mockito.mock(ObjectMapper.class); + Mockito.when(mockedMapper.writeValueAsString(anyObject())).thenThrow(JsonProcessingException.class); + ValidateException validateException = new ValidateException.Builder("Test", 0 , null).build(); + ApiExceptionMapper mockedException = Mockito.spy(new ApiExceptionMapper()); + Mockito.doReturn(mockedMapper).when(mockedException).createObjectMapper(); + Response resp = mockedException.toResponse((ApiException) validateException); + + /// assertEquals(resp.getStatus(), HttpStatus.SC_BAD_REQUEST); + assertThat(resp.getEntity().toString(),startsWith("Exception in buildServiceErrorResponse writing exceptionType to string")); + } + + @Test + public void testValidateResponse(){ + ValidateException validateException = new ValidateException.Builder("Test Message", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).build(); + Response resp = mapper.toResponse((ApiException) validateException); + + assertEquals(resp.getStatus(), HttpStatus.SC_BAD_REQUEST); + } + + @Test + public void testBPMNFailureResponse(){ + BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).build(); + Response resp = mapper.toResponse((ApiException) bpmnException); + + assertEquals(resp.getStatus(), HttpStatus.SC_NOT_FOUND); + } + @Test + public void testClientConnectionResponse(){ + ClientConnectionException clientConnectionException = new ClientConnectionException.Builder("test", HttpStatus.SC_INTERNAL_SERVER_ERROR,ErrorNumbers.SVC_BAD_PARAMETER).build(); + Response resp = mapper.toResponse((ApiException) clientConnectionException); + + assertEquals(resp.getStatus(), HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + @Test + public void testVFModuleResponse() { + VfModuleNotFoundException vfModuleException = new VfModuleNotFoundException.Builder("Test Message", HttpStatus.SC_CONFLICT,ErrorNumbers.SVC_BAD_PARAMETER).build(); + Response resp = mapper.toResponse((ApiException) vfModuleException); + + assertEquals(resp.getStatus(), HttpStatus.SC_CONFLICT); + } + @Test + public void testDuplicateRequestResponse() throws IOException { + DuplicateRequestException duplicateRequestException = new DuplicateRequestException.Builder("Test1", "Test2","Test3","Test4", HttpStatus.SC_BAD_GATEWAY,ErrorNumbers.SVC_BAD_PARAMETER).build(); + Response resp = mapper.toResponse((ApiException) duplicateRequestException); + + assertEquals(resp.getStatus(), HttpStatus.SC_BAD_GATEWAY); + } +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java new file mode 100644 index 0000000000..bd3728c599 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java @@ -0,0 +1,128 @@ +/*- + * ============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.apihandlerinfra; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.apihandler.common.ErrorNumbers; +import org.onap.so.apihandlerinfra.exceptions.*; +import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo; +import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; +import org.onap.so.logger.MessageEnum; +import org.onap.so.logger.MsoAlarmLogger; +import org.onap.so.logger.MsoLogger; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.startsWith; + + +public class ApiExceptionTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testRecipeNotFoundException() throws ApiException { + thrown.expect(RecipeNotFoundException.class); + thrown.expectMessage("Message rewritten"); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_BAD_PARAMETER))); + RecipeNotFoundException testException = new RecipeNotFoundException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).message("Message rewritten").build(); + throw testException; + } + + + @Test + public void testBPMNFailureException() throws ApiException { + List testVariables = new LinkedList<>(); + testVariables.add("hello"); + thrown.expect(BPMNFailureException.class); + thrown.expectMessage(startsWith("Request Failed due to BPEL error with HTTP Status =")); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_BAD_PARAMETER))); + thrown.expect(hasProperty("variables",sameBeanAs(testVariables))); + BPMNFailureException testException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).variables(testVariables).build(); + throw testException; + } + + + @Test + public void testClientConnectionException() throws ApiException { + IOException ioException = new IOException(); + thrown.expect(ClientConnectionException.class); + thrown.expectMessage("Client from test failed to connect"); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_BAD_PARAMETER))); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_BAD_PARAMETER))); + thrown.expect(hasProperty("cause", sameBeanAs(ioException))); + ClientConnectionException testException = new ClientConnectionException.Builder("test", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).cause(ioException).build(); + throw testException; + } + + + @Test + public void testDuplicateRequestException() throws ApiException { + ErrorLoggerInfo testLog = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MsoLogger.ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + thrown.expect(DuplicateRequestException.class); + thrown.expectMessage(startsWith("Error: Locked instance")); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_BAD_PARAMETER))); + thrown.expect(hasProperty("errorLoggerInfo", sameBeanAs(testLog))); + DuplicateRequestException testException = new DuplicateRequestException.Builder("Test1", "Test2","Test3","Test4", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(testLog).build(); + throw testException; + } + + + @Test + public void testValidateException() throws ApiException { + AlarmLoggerInfo testLog = new AlarmLoggerInfo.Builder("MsoConfigurationError", MsoAlarmLogger.CRITICAL, + Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_SDNC_ADAPTER)).build(); + thrown.expect(ValidateException.class); + thrown.expectMessage("Test Message"); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR))); + thrown.expect(hasProperty("alarmLoggerInfo", sameBeanAs(testLog))); + ValidateException testException = new ValidateException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).messageID(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).alarmInfo(testLog).build(); + throw testException; + } + + + @Test + public void testVfModuleNotFoundException() throws ApiException { + thrown.expect(VfModuleNotFoundException.class); + thrown.expectMessage("Test Message"); + thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_CONFLICT))); + thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_BAD_PARAMETER))); + VfModuleNotFoundException testException = new VfModuleNotFoundException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).httpResponseCode(HttpStatus.SC_CONFLICT).build(); + throw testException; + } + + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/TestAppender.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/TestAppender.java new file mode 100644 index 0000000000..48711a2595 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/TestAppender.java @@ -0,0 +1,37 @@ +/*- + * ============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.apihandlerinfra; + +import java.util.ArrayList; +import java.util.List; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; + + + +public class TestAppender extends AppenderBase { + public static List events = new ArrayList<>(); + + @Override + protected void append(ILoggingEvent loggingEvent) { + events.add(loggingEvent); + } +} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BeansTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BeansTest.java deleted file mode 100644 index f9d7f87e53..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BeansTest.java +++ /dev/null @@ -1,72 +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.openecomp.mso.apihandler.camundabeans; - -import org.junit.Test; - -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.filters.FilterNonConcrete; -import com.openpojo.reflection.filters.FilterPackageInfo; -import org.openecomp.mso.openpojo.rules.HasToStringRule; -import org.openecomp.mso.openpojo.rules.ToStringTester; - -public class BeansTest { - - - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - private PojoClassFilter enumFilter = new FilterEnum(); - - - @Test - public void pojoStructure() { - test("org.openecomp.mso.apihandler.camundabeans"); - } - - private void test(String pojoPackage) { - Validator validator = ValidatorBuilder.create() - - - - - .with(new SetterTester()) - .with(new GetterTester()) - .with(new ToStringTester()) - - .build(); - - - validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete()); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } -} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BpmnRequestTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BpmnRequestTest.java deleted file mode 100644 index 6490f52a02..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/camundabeans/BpmnRequestTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei 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.apihandler.camundabeans; - -import org.junit.Test; - -public class BpmnRequestTest { - - BpmnRequest bpmnRequest = new BpmnRequest(); - - @Test - public void getHostTest() throws Exception { - bpmnRequest.getHost(); - } - - @Test - public void setHostTest() throws Exception { - bpmnRequest.setHost(new CamundaInput()); - } - - @Test - public void getRequestIdTest() throws Exception { - bpmnRequest.getRequestId(); - } - - @Test - public void setRequestIdTest() throws Exception { - bpmnRequest.setRequestId(new CamundaInput()); - } - - @Test - public void getIsBaseVfModuleTest() throws Exception { - bpmnRequest.getIsBaseVfModule(); - } - - @Test - public void setIsBaseVfModuleTest() throws Exception { - bpmnRequest.setIsBaseVfModule(new CamundaBooleanInput()); - } - - @Test - public void getRecipeTimeoutTest() throws Exception { - bpmnRequest.getRecipeTimeout(); - } - - @Test - public void setRecipeTimeoutTest() throws Exception { - bpmnRequest.setRecipeTimeout(new CamundaIntegerInput()); - } - - @Test - public void getRequestActionTest() throws Exception { - bpmnRequest.getRequestAction(); - } - - @Test - public void setRequestActionTest() throws Exception { - bpmnRequest.setRequestAction(new CamundaInput()); - } - - @Test - public void getServiceInstanceIdTest() throws Exception { - bpmnRequest.getServiceInstanceId(); - } - - @Test - public void setServiceInstanceIdTest() throws Exception { - bpmnRequest.setServiceInstanceId(new CamundaInput()); - } - - @Test - public void getVnfIdTest() throws Exception { - bpmnRequest.getVnfId(); - } - - @Test - public void setVnfIdTest() throws Exception { - bpmnRequest.setVnfId(new CamundaInput()); - } - - @Test - public void getVfModuleIdTest() throws Exception { - bpmnRequest.getVnfId(); - } - - @Test - public void setVfModuleIdTest() throws Exception { - bpmnRequest.setVfModuleId(new CamundaInput()); - } - - @Test - public void getVolumeGroupIdTest() throws Exception { - bpmnRequest.getVolumeGroupId(); - } - - @Test - public void setVolumeGroupIdTest() throws Exception { - bpmnRequest.setVolumeGroupId(new CamundaInput()); - } - - @Test - public void getNetworkIdTest() throws Exception { - bpmnRequest.getNetworkId(); - } - - @Test - public void setNetworkIdTest() throws Exception { - bpmnRequest.setNetworkId(new CamundaInput()); - } - - @Test - public void getServiceTypeTest() throws Exception { - bpmnRequest.getServiceType(); - } - - @Test - public void setServiceTypeTest() throws Exception { - bpmnRequest.setServiceType(new CamundaInput()); - } - - @Test - public void getVnfTypeTest() throws Exception { - bpmnRequest.getVnfType(); - } - - @Test - public void setVnfTypeTest() throws Exception { - bpmnRequest.setVnfType(new CamundaInput()); - } - - @Test - public void getVfModuleTypeTest() throws Exception { - bpmnRequest.getVfModuleType(); - } - - @Test - public void setVfModuleTypeTest() throws Exception { - bpmnRequest.setVfModuleType(new CamundaInput()); - } - - @Test - public void getNetworkTypeTest() throws Exception { - bpmnRequest.getNetworkType(); - } - - @Test - public void setNetworkTypeTest() throws Exception { - bpmnRequest.setNetworkType(new CamundaInput()); - } - - @Test - public void getRequestDetailsTest() throws Exception { - bpmnRequest.getRequestDetails(); - } - - @Test - public void setRequestDetailsTest() throws Exception { - bpmnRequest.setRequestDetails(new CamundaInput()); - } - -} \ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java deleted file mode 100644 index f892d13599..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java +++ /dev/null @@ -1,132 +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.openecomp.mso.apihandler.common; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import org.apache.http.HttpEntity; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpRequestBase; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.openecomp.mso.properties.MsoJavaProperties; - -public class CamundaTaskClientTest { - - private CamundaTaskClient testedObject = new CamundaTaskClient(); - private HttpClient httpClientMock; - private static final String JSON_REQUEST = "{\"value1\": \"aaa\",\"value2\": \"bbb\"}"; - private static final String URL_SCHEMA = "http"; - private static final String HOST = "testhost"; - private static final int PORT = 1234; - private static final String URL_PATH = "/requestMethodSuccessful"; - private static final String URL = URL_SCHEMA + "://" + HOST + ":" + PORT + URL_PATH; - private static final String AUTHORIZATION_HEADER_NAME = "Authorization"; - - @Before - public void init() { - testedObject = new CamundaTaskClient(); - httpClientMock = mock(HttpClient.class); - testedObject.setClient(httpClientMock); - testedObject.setUrl(URL); - } - - @Test - public void postMethodSuccessful() throws IOException { - ArgumentCaptor httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class); - testedObject.post(JSON_REQUEST); - verify(httpClientMock).execute(httpPostCaptor.capture()); - checkUri(httpPostCaptor.getValue()); - assertThat(httpPostCaptor.getValue().getEntity().getContentType().getValue()). - isEqualTo(CommonConstants.CONTENT_TYPE_JSON); - assertThat(getJsonFromEntity(httpPostCaptor.getValue().getEntity())).isEqualTo(JSON_REQUEST); - } - - @Test - public void postMethodSuccessfulWithCredentials() throws IOException { - ArgumentCaptor httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class); - testedObject.setProps(createMsoJavaProperties()); - testedObject.post(JSON_REQUEST); - verify(httpClientMock).execute(httpPostCaptor.capture()); - assertThat(httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); - } - - @Test - public void getMethodSuccessful() throws IOException { - ArgumentCaptor httpGetCaptor = ArgumentCaptor.forClass(HttpGet.class); - testedObject.get(); - verify(httpClientMock).execute(httpGetCaptor.capture()); - checkUri(httpGetCaptor.getValue()); - } - - @Test - public void getMethodSuccessfulWithCredentials() throws IOException { - ArgumentCaptor httpGetCaptor = ArgumentCaptor.forClass(HttpGet.class); - testedObject.setUrl(URL); - testedObject.setProps(createMsoJavaProperties()); - testedObject.get(); - verify(httpClientMock).execute(httpGetCaptor.capture()); - assertThat(httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); - } - - @Test(expected = UnsupportedOperationException.class) - public void postMethodUnsupported() { - testedObject.post("", "", "", "", "", ""); - } - - @Test(expected = UnsupportedOperationException.class) - public void postMethodUnsupported2() { - testedObject.post(new RequestClientParamater.Builder().build()); - } - - private void checkUri(HttpRequestBase httpRequestBase) { - assertThat(httpRequestBase.getURI().getScheme()).isEqualTo(URL_SCHEMA); - assertThat(httpRequestBase.getURI().getHost()).isEqualTo(HOST); - assertThat(httpRequestBase.getURI().getPort()).isEqualTo(PORT); - assertThat(httpRequestBase.getURI().getPath()).isEqualTo(URL_PATH); - } - - private MsoJavaProperties createMsoJavaProperties() { - MsoJavaProperties msoJavaProperties = new MsoJavaProperties(); - msoJavaProperties.setProperty(CommonConstants.CAMUNDA_AUTH, ""); - return msoJavaProperties; - } - - private String getJsonFromEntity(HttpEntity httpEntity) throws IOException { - BufferedReader rd = new BufferedReader( - new InputStreamReader(httpEntity.getContent())); - StringBuilder result = new StringBuilder(); - String line; - while ((line = rd.readLine()) != null) { - result.append(line); - } - return result.toString(); - } - -} \ No newline at end of file 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 deleted file mode 100644 index 6cc6c562e5..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/BPELRestClientTest.java +++ /dev/null @@ -1,125 +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.openecomp.mso.camunda.tests; - - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -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.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; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.databind.JsonMappingException; - - -/** - * 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 deleted file mode 100644 index 69927e2126..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java +++ /dev/null @@ -1,144 +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.openecomp.mso.camunda.tests; - - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -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.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.apihandler.common.RequestClientParamater; -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 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); - } - - @Test - public void testCamundaPostJson() throws 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 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(createParams()); - assertEquals(requestClient.getType(), CommonConstants.CAMUNDA); - assertEquals(response.getStatusLine().getStatusCode(), 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; - } - - private RequestClientParamater createParams(){ - return new RequestClientParamater.Builder().setRequestId("mso-req-id").setBaseVfModule(false). - setRecipeTimeout(180).setRequestAction("createInstance").setServiceInstanceId("svc-inst-id"). - setVnfId("vnf-id").setVfModuleId("vf-module-id").setVolumeGroupId("vg-id").setNetworkId("nw-id"). - setConfigurationId("conf-id").setServiceType("svc-type").setVnfType("vnf-type"). - setVfModuleType("vf-module-type").setNetworkType("nw-type").setRequestDetails(""). - setRecipeParamXsd("").build(); - } - - - - - -} 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 deleted file mode 100644 index 622bb1e242..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaRequestTest.java +++ /dev/null @@ -1,81 +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.openecomp.mso.camunda.tests; - - - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -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; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - -/** - * 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://localhost: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(SerializationFeature.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://localhost:22443/Services/com/cingular/csi/sdn/SendManagedNetworkStatusNotification.jws50515631 SDN-ETHERNET-INTERNETHI/VLXM/950604//SW_INTERNETSubName01 MTSNJA4LCP1 \",\"type\":\"String\"}" + - ",\"host\":{\"value\":\"localhost\",\"type\":\"String\"},\"mso-schema-version\":{\"value\":\"v1\",\"type\":\"String\"},\"mso-request-id\":{\"value\":\"reqid123\",\"type\":\"String\"},\"mso-service-instance-id\":{\"value\":\"svcid123\",\"type\":\"String\"},\"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 deleted file mode 100644 index 7fc2815b4b..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java +++ /dev/null @@ -1,78 +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.openecomp.mso.camunda.tests; - - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.openecomp.mso.apihandler.camundabeans.CamundaResponse; -import org.openecomp.mso.utils.RootIgnoringObjectMapper; - -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * This class implements test methods of Camunda Beans. - * - * - */ -public class CamundaResponseTest { - - @Test - public final void testDeserializationWithoutRootElement() throws Exception { - - ObjectMapper mapper = new RootIgnoringObjectMapper(CamundaResponse.class); - - String content = "{" - + "\"messageCode\":202" - + ",\"message\":\"Successfully started the process\"" - + ",\"content\":\"xml\"" - + ",\"processInstanceId\":\"4d3b3201a7ce\"" - + ",\"variables\":null" - + "}"; - - CamundaResponse response = mapper.readValue(content, CamundaResponse.class); - - assertEquals( - "CamundaResponse[processInstanceId=4d3b3201a7ce,messageCode=202,message=Successfully started the process,variables=null,content=xml]", - response.toString()); - } - - @Test - public final void testDeserializationWithRootElement() throws Exception { - - ObjectMapper mapper = new RootIgnoringObjectMapper(CamundaResponse.class); - - String content = "{\"WorkflowResponse\":{" - + "\"messageCode\":202" - + ",\"message\":\"Successfully started the process\"" - + ",\"content\":\"xml\"" - + ",\"processInstanceId\":\"4d3b3201a7ce\"" - + ",\"variables\":null" - + "}}"; - - CamundaResponse response = mapper.readValue(content, CamundaResponse.class); - - assertEquals( - "CamundaResponse[processInstanceId=4d3b3201a7ce,messageCode=202,message=Successfully started the process,variables=null,content=xml]", - response.toString()); - } -} \ No newline at end of file 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 deleted file mode 100644 index e04aba0ede..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java +++ /dev/null @@ -1,137 +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.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.junit.Test; -import org.openecomp.mso.apihandler.common.ResponseHandler; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.databind.JsonMappingException; - -/** - * This class implements test methods of CamundaResoponseHandler. - * - * - */ -public class ResponseHandlerTest { - - @Test - public void tesParseCamundaResponse () throws JsonGenerationException, JsonMappingException, IOException { - - String content = "{\"WorkflowResponse\":{" - + "\"messageCode\":202" - + ",\"message\":\"Successfully started the process\"" - + ",\"content\":\"xml\"" - + ",\"processInstanceId\":\"4d3b3201a7ce\"" - + "}}"; - - HttpResponse response = createResponse (200, content, "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.getContent() != 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 content = "{\"WorkflowResponse\":{" - + "\"messageCode\":500" - + ",\"message\":\"Something went wrong\"" - + ",\"content\":\"xml\"" - + ",\"processInstanceId\":\"4d3b3201a7ce\"" - + "}}"; - - HttpResponse response = createResponse (500, content, "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.getContent()); - - } - - 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; - } - -} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json b/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json new file mode 100644 index 0000000000..c4c7b030f9 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json @@ -0,0 +1 @@ +{"variables":{"bpmnRequest":{"value":"{requestDetails: }","type":"String"},"requestId":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"mso-request-id":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"isBaseVfModule":{"value":true,"type":"Boolean"},"recipeTimeout":{"value":10000,"type":"Integer"},"requestAction":{"value":"createInstance","type":"String"},"serviceInstanceId":{"value":"12345679","type":"String"},"correlationId":{"value":"12345679","type":"String"},"vnfId":{"value":"234567891","type":"String"},"vfModuleId":{"value":"345678912","type":"String"},"volumeGroupId":{"value":"456789123","type":"String"},"networkId":{"value":"567891234","type":"String"},"configurationId":{"value":"678912345","type":"String"},"serviceType":{"value":"testService","type":"String"},"vnfType":{"value":"testVnf","type":"String"},"vfModuleType":{"value":"vfModuleType","type":"String"},"networkType":{"value":"networkType","type":"String"},"recipeParams":{"value":"","type":"String"},"host":{"value":null,"type":"String"},"apiVersion":{"value":"6","type":"String"},"aLaCarte":{"value":true,"type":"Boolean"},"requestUri":{"value":"v7/serviceInstances/assign","type":"String"}}} \ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-common/src/test/resources/logback-test.xml b/mso-api-handlers/mso-api-handler-common/src/test/resources/logback-test.xml deleted file mode 100644 index d2c17192ea..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/test/resources/logback-test.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - %d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n - - - - - - - - - - - - - - - - - - - - - - -- cgit 1.2.3-korg