aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-common/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common/src/test/java')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java132
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java24
2 files changed, 144 insertions, 12 deletions
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
new file mode 100644
index 0000000000..f892d13599
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/apihandler/common/CamundaTaskClientTest.java
@@ -0,0 +1,132 @@
+/*-
+ * ============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<HttpPost> 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<HttpPost> 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<HttpGet> httpGetCaptor = ArgumentCaptor.forClass(HttpGet.class);
+ testedObject.get();
+ verify(httpClientMock).execute(httpGetCaptor.capture());
+ checkUri(httpGetCaptor.getValue());
+ }
+
+ @Test
+ public void getMethodSuccessfulWithCredentials() throws IOException {
+ ArgumentCaptor<HttpGet> 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/CamundaClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaClientTest.java
index 8bfc4ced76..69927e2126 100644
--- 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
@@ -24,7 +24,6 @@ package org.openecomp.mso.camunda.tests;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
-import java.util.UUID;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
@@ -42,12 +41,9 @@ 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;
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-
-
/**
* This class implements test methods of Camunda Beans.
*
@@ -66,8 +62,7 @@ public class CamundaClientTest {
}
@Test
- public void tesCamundaPost() throws JsonGenerationException,
- JsonMappingException, IOException {
+ 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);
@@ -106,8 +101,6 @@ public class CamundaClientTest {
mockHttpClient = Mockito.mock(HttpClient.class);
Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class)))
.thenReturn(mockResponse);
-
- String reqXML = "<xml>test</xml>";
String orchestrationURI = "/engine-rest/process-definition/key/dummy/start";
MsoJavaProperties props = new MsoJavaProperties();
@@ -115,9 +108,7 @@ public class CamundaClientTest {
RequestClient requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props);
requestClient.setClient(mockHttpClient);
- HttpResponse response = requestClient.post("mso-req-id", false, 180,
- "createInstance", "svc-inst-id", "vnf-id", "vf-module-id", "vg-id", "nw-id", "conf-id", "svc-type",
- "vnf-type", "vf-module-type", "nw-type", "", "");
+ HttpResponse response = requestClient.post(createParams());
assertEquals(requestClient.getType(), CommonConstants.CAMUNDA);
assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
}
@@ -137,6 +128,15 @@ public class CamundaClientTest {
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();
+ }
+