aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-common/src/test
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-04-08 14:14:34 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-04-08 14:24:59 -0400
commitf47919f1fe367b612fa9c96d34c59f01a541e882 (patch)
tree5b6aa2fc36747d868897e68ccbec0c6db0aee81c /mso-api-handlers/mso-api-handler-common/src/test
parent54452b80a1cf4d22ef750bc1377f8c1b05431d57 (diff)
Replaced all tabs with spaces in java and pom.xml
Added in maven plugins to enforce coding style rules Added in eclipse java formatting xml Change-Id: I3727bbf4ce8dc66abfd8ad21b6cfd0890c5d3ff0 Issue-ID: SO-1765 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common/src/test')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BeansTest.java60
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/BpmnRequestTest.java2
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/camundabeans/CamundaMacroRequestSerializerTest.java6
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/AllTestsTestSuite.java5
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java122
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java24
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/ResponseHandlerTest.java103
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java54
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/recipe/CamundaClientErrorHandlerTest.java101
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java32
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/TestAppender.java12
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java107
12 files changed, 317 insertions, 311 deletions
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
index b596636f6d..af582fb868 100644
--- 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
@@ -21,7 +21,6 @@
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;
@@ -39,34 +38,33 @@ 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/");
- }
- }
+ 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
index 7087e90b73..7291f87554 100644
--- 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
@@ -175,4 +175,4 @@ public class BpmnRequestTest {
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
index 36966342b2..4636fcc90d 100644
--- 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
@@ -28,9 +28,11 @@ import org.junit.Test;
*/
public class CamundaMacroRequestSerializerTest {
@Test
- public void testWithAllParameters() throws Exception{
+ 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);
+ 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
index 47c166eff9..d1558a2a2c 100644
--- 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
@@ -21,13 +21,12 @@
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
+ // 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
index edab3b07b6..36d004e87d 100644
--- 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
@@ -29,11 +29,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-
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;
@@ -50,7 +48,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.mock.env.MockEnvironment;
-
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -60,7 +57,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
*
*
*/
-public class CamundaClientTest{
+public class CamundaClientTest {
@@ -74,31 +71,31 @@ public class CamundaClientTest{
}
@Test
- public void tesCamundaPost() throws JsonGenerationException,
- JsonMappingException, IOException {
+ 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}";
+ 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);
ArgumentCaptor<HttpPost> httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class);
- Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class)))
- .thenReturn(mockResponse);
+ Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class))).thenReturn(mockResponse);
String reqXML = "<xml>test</xml>";
String orchestrationURI = "/engine-rest/process-definition/key/dummy/start";
MockEnvironment environment = new MockEnvironment();
-
+
environment.setProperty("mso.camundaUR", "yourValue1");
- environment.setProperty("mso.camundaAuth", "E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE");
+ environment.setProperty("mso.camundaAuth",
+ "E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE");
environment.setProperty("org.onap.so.adapters.network.encryptionKey", "aa3871669d893c7fb8abbcda31b88b4f");
-
-
+
+
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);
@@ -107,22 +104,21 @@ public class CamundaClientTest{
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);
- verify(mockHttpClient,times(2)).execute(httpPostCaptor.capture());
+ verify(mockHttpClient, times(2)).execute(httpPostCaptor.capture());
assertThat(httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty();
- Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue());
+ Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",
+ httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue());
}
- private HttpResponse createResponse(int respStatus,
- String respBody) {
- HttpResponse response = new BasicHttpResponse(
- new BasicStatusLine(
- new ProtocolVersion("HTTP", 1, 1), respStatus, ""));
+ 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));
@@ -132,62 +128,64 @@ public class CamundaClientTest{
}
return response;
}
-
- public String inputStream(String JsonInput)throws IOException{
+
+ 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 pnfCorrelationId = "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 instanceGroupId = "ff305d54-75b4-431b-adb2-eb6b9e5ff000";
-
- String testResult = testClient.wrapVIDRequest(requestId, isBaseVfModule, recipeTimeout, requestAction, serviceInstanceId, pnfCorrelationId,
- vnfId, vfModuleId, volumeGroupId, networkId, configurationId, serviceType,
- vnfType, vfModuleType, networkType, requestDetails, apiVersion, aLaCarte, requestUri, "", instanceGroupId);
- String expected = inputStream("/WrappedVIDRequest.json");
-
- assertEquals(expected, testResult);
+ 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 pnfCorrelationId = "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 instanceGroupId = "ff305d54-75b4-431b-adb2-eb6b9e5ff000";
+
+ String testResult = testClient.wrapVIDRequest(requestId, isBaseVfModule, recipeTimeout, requestAction,
+ serviceInstanceId, pnfCorrelationId, vnfId, vfModuleId, volumeGroupId, networkId, configurationId,
+ serviceType, vnfType, vfModuleType, networkType, requestDetails, apiVersion, aLaCarte, requestUri, "",
+ instanceGroupId);
+ String expected = inputStream("/WrappedVIDRequest.json");
+
+ assertEquals(expected, testResult);
}
@Test
- public void testPost() throws Exception{
+ public void testPost() throws Exception {
CamundaClient testClient = new CamundaClient();
String orchestrationURI = "/engine-rest/process-definition/key/dummy/start";
MockEnvironment environment = new MockEnvironment();
-
+
environment.setProperty("mso.camundaUR", "yourValue1");
testClient.setProps(environment);
testClient.setClient(mockHttpClient);
-
+
testClient.setUrl(orchestrationURI);
-
- 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}";
+
+ 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}";
assertNull(testClient.post(responseBody));
-
+
}
@Test
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
index 2ba0e4a173..9e9ab6048e 100644
--- 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
@@ -25,11 +25,9 @@ import static org.mockito.ArgumentMatchers.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;
@@ -47,8 +45,8 @@ import org.springframework.core.env.Environment;
@RunWith(MockitoJUnitRunner.class)
public class CamundaTaskClientTest {
- @Mock
- private Environment env;
+ @Mock
+ private Environment env;
private CamundaTaskClient testedObject = new CamundaTaskClient();
private HttpClient httpClientMock;
private static final String JSON_REQUEST = "{\"value1\": \"aaa\",\"value2\": \"bbb\"}";
@@ -61,7 +59,8 @@ public class CamundaTaskClientTest {
@Before
public void init() {
- when(env.getProperty(eq(CommonConstants.CAMUNDA_AUTH))).thenReturn("E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE");
+ when(env.getProperty(eq(CommonConstants.CAMUNDA_AUTH))).thenReturn(
+ "E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE");
when(env.getProperty(eq(CommonConstants.ENCRYPTION_KEY_PROP))).thenReturn("aa3871669d893c7fb8abbcda31b88b4f");
testedObject = new CamundaTaskClient();
httpClientMock = mock(HttpClient.class);
@@ -75,8 +74,8 @@ public class CamundaTaskClientTest {
testedObject.post(JSON_REQUEST);
verify(httpClientMock).execute(httpPostCaptor.capture());
checkUri(httpPostCaptor.getValue());
- assertThat(httpPostCaptor.getValue().getEntity().getContentType().getValue()).
- isEqualTo(CommonConstants.CONTENT_TYPE_JSON);
+ assertThat(httpPostCaptor.getValue().getEntity().getContentType().getValue())
+ .isEqualTo(CommonConstants.CONTENT_TYPE_JSON);
assertThat(getJsonFromEntity(httpPostCaptor.getValue().getEntity())).isEqualTo(JSON_REQUEST);
}
@@ -87,7 +86,8 @@ public class CamundaTaskClientTest {
testedObject.post(JSON_REQUEST);
verify(httpClientMock).execute(httpPostCaptor.capture());
assertThat(httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty();
- Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue());
+ Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",
+ httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue());
}
@Test
@@ -106,7 +106,8 @@ public class CamundaTaskClientTest {
testedObject.get();
verify(httpClientMock).execute(httpGetCaptor.capture());
assertThat(httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty();
- Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue());
+ Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",
+ httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue());
}
@Test(expected = UnsupportedOperationException.class)
@@ -127,8 +128,7 @@ public class CamundaTaskClientTest {
}
private String getJsonFromEntity(HttpEntity httpEntity) throws IOException {
- BufferedReader rd = new BufferedReader(
- new InputStreamReader(httpEntity.getContent()));
+ BufferedReader rd = new BufferedReader(new InputStreamReader(httpEntity.getContent()));
StringBuilder result = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
@@ -137,4 +137,4 @@ public class CamundaTaskClientTest {
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
index 0d4778b5b6..2095a9117d 100644
--- 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
@@ -19,7 +19,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
+
package org.onap.so.apihandler.common;
@@ -28,7 +28,6 @@ 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 org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolVersion;
@@ -46,100 +45,98 @@ import org.onap.so.apihandlerinfra.exceptions.ValidateException;
*
*
*/
-public class ResponseHandlerTest{
+public class ResponseHandlerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
- public void tesParseCamundaResponse () throws ApiException {
+ 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>xml</xml>\"," + "\"messageCode\": 200,"
- + "\"message\": \"Successfully started the process\"}";
+ + "\"message\": \"Successfully started the process\"}";
- HttpResponse response = createResponse (200, body, "application/json");
+ 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");
+ 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 tesParseCamundaResponseForCamundaTaskType () throws ApiException {
- String body = "{ \"response\": \"<xml>xml</xml>\"," + "\"messageCode\": 200,"
- + "\"message\": \"Successfully started the process\"}";
+ public void tesParseCamundaResponseForCamundaTaskType() throws ApiException {
+ String body = "{ \"response\": \"<xml>xml</xml>\"," + "\"messageCode\": 200,"
+ + "\"message\": \"Successfully started the process\"}";
+
+ HttpResponse response = createResponse(200, body, "application/json");
- HttpResponse response = createResponse (200, body, "application/json");
+ ResponseHandler respHandler = new ResponseHandler(response, 2);
- ResponseHandler respHandler = new ResponseHandler (response, 2);
-
- int status = respHandler.getStatus ();
- assertEquals (status, HttpStatus.SC_ACCEPTED);
- assertEquals (respHandler.getResponseBody(), body);
+ int status = respHandler.getStatus();
+ assertEquals(status, HttpStatus.SC_ACCEPTED);
+ assertEquals(respHandler.getResponseBody(), body);
}
+
@Test
- public void tesParseBpelResponse () throws ApiException{
+ public void tesParseBpelResponse() throws ApiException {
String body = "<test:service-response xmlns:test=\"http://org.onap/so/test\">"
- + "<test:request-id>req5</test:request-id>"
- + "<test:request-action>test</test:request-action>"
- + "<test:source>test</test:source>"
- + "<test:ack-final-indicator>n</test:ack-final-indicator>"
- + "</test:service-response>";
+ + "<test:request-id>req5</test:request-id>" + "<test:request-action>test</test:request-action>"
+ + "<test:source>test</test:source>" + "<test:ack-final-indicator>n</test:ack-final-indicator>"
+ + "</test:service-response>";
- HttpResponse response = createResponse (200, body, "text/xml");
+ HttpResponse response = createResponse(200, body, "text/xml");
- ResponseHandler respHandler = new ResponseHandler (response, 0);
+ ResponseHandler respHandler = new ResponseHandler(response, 0);
- int status = respHandler.getStatus ();
- assertEquals (status, HttpStatus.SC_ACCEPTED);
- assertTrue (respHandler.getResponseBody () != null);
+ int status = respHandler.getStatus();
+ assertEquals(status, HttpStatus.SC_ACCEPTED);
+ assertTrue(respHandler.getResponseBody() != null);
}
@Test
- public void tesMappingErrorResponse () throws ApiException {
+ public void tesMappingErrorResponse() throws ApiException {
thrown.expect(ValidateException.class);
thrown.expectMessage(startsWith("Cannot parse Camunda Response"));
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, "<html>error</html>", "text/html");
- ResponseHandler respHandler = new ResponseHandler (response, 1);
- int status = respHandler.getStatus ();
+ HttpResponse response = createResponse(HttpStatus.SC_NOT_FOUND, "<html>error</html>", "text/html");
+ ResponseHandler respHandler = new ResponseHandler(response, 1);
+
+ int status = respHandler.getStatus();
- assertEquals (HttpStatus.SC_NOT_IMPLEMENTED, status);
+ assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, status);
}
@Test
- public void tesGenricErrorResponse () throws ApiException {
+ public void tesGenricErrorResponse() throws ApiException {
String body = "{ \"response\": \"<xml>xml</xml>\"," + "\"messageCode\": 500,"
- + "\"message\": \"Something went wrong\"}";
+ + "\"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");
+ 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);
+ 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);
+ response.setEntity(new StringEntity(respBody));
+ response.setHeader("Content-Type", contentType);
} catch (Exception e) {
- e.printStackTrace ();
+ e.printStackTrace();
}
return response;
}
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
index dae6542b8b..6c674db9f4 100644
--- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
@@ -2,11 +2,8 @@ package org.onap.so.apihandler.filters;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
-
import java.io.IOException;
-
import javax.ws.rs.container.ContainerRequestContext;
-
import org.apache.http.HttpStatus;
import org.junit.Rule;
import org.junit.Test;
@@ -29,40 +26,41 @@ public class RequestIdFilterTest {
@Mock
ContainerRequestContext mockContext;
-
- @Mock
- protected RequestsDbClient requestsDbClient;
-
+
+ @Mock
+ protected RequestsDbClient requestsDbClient;
+
@InjectMocks
@Spy
RequestIdFilter requestIdFilter;
-
+
@Rule
public ExpectedException thrown = ExpectedException.none();
-
- @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
-
- @Test
- public void filterTest() throws IOException {
-
- String requestId = "32807a28-1a14-4b88-b7b3-2950918aa769";
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
-
- //ExpectedRecord InfraActiveRequests
+
+ @Rule
+ public MockitoRule mockitoRule = MockitoJUnit.rule();
+
+ @Test
+ public void filterTest() throws IOException {
+
+ String requestId = "32807a28-1a14-4b88-b7b3-2950918aa769";
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+
+ // ExpectedRecord InfraActiveRequests
InfraActiveRequests infraActiveRequests = new InfraActiveRequests();
infraActiveRequests.setRequestStatus("FAILED");
infraActiveRequests.setProgress(100L);
infraActiveRequests.setLastModifiedBy("APIH");
infraActiveRequests.setRequestScope("network");
infraActiveRequests.setRequestAction("deleteInstance");
- infraActiveRequests.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa769");
-
- doReturn(infraActiveRequests).when(requestsDbClient).getInfraActiveRequestbyRequestId(requestId);
-
- requestIdFilter.filter(mockContext);
-
- Mockito.verify( requestIdFilter, Mockito.times(1)).filter(mockContext);
- assertEquals(MDC.get(ONAPLogConstants.MDCs.RESPONSE_CODE), String.valueOf(HttpStatus.SC_BAD_REQUEST));
-
- }
+ infraActiveRequests.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa769");
+
+ doReturn(infraActiveRequests).when(requestsDbClient).getInfraActiveRequestbyRequestId(requestId);
+
+ requestIdFilter.filter(mockContext);
+
+ Mockito.verify(requestIdFilter, Mockito.times(1)).filter(mockContext);
+ assertEquals(MDC.get(ONAPLogConstants.MDCs.RESPONSE_CODE), String.valueOf(HttpStatus.SC_BAD_REQUEST));
+
+ }
}
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
index 564121b7b5..9065a1a9ea 100644
--- 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
@@ -1,30 +1,23 @@
/*
- * ============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
+ * ============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
+ * 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.
+ * 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;
@@ -32,41 +25,41 @@ 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
+
+ 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);
+ }
+
+}
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
index 42190a4a1e..2cdf4f1a3f 100644
--- 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
@@ -26,15 +26,12 @@ 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.ErrorLoggerInfo;
import org.onap.so.logger.ErrorCode;
import org.onap.so.logger.MessageEnum;
-
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;
@@ -52,7 +49,8 @@ public class ApiExceptionTest {
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();
+ RecipeNotFoundException testException = new RecipeNotFoundException.Builder("Test Message",
+ HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).message("Message rewritten").build();
throw testException;
}
@@ -65,8 +63,9 @@ public class ApiExceptionTest {
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();
+ 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;
}
@@ -81,32 +80,39 @@ public class ApiExceptionTest {
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();
+ 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, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
+ ErrorLoggerInfo testLog =
+ new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, 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();
+ 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 {
+ public void testValidateException() throws ApiException {
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)));
- ValidateException testException = new ValidateException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).messageID(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
+ ValidateException testException =
+ new ValidateException.Builder("Test Message", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER)
+ .messageID(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
throw testException;
}
@@ -117,7 +123,9 @@ public class ApiExceptionTest {
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();
+ 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
index 48711a2595..1beb3b37a7 100644
--- 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
@@ -27,11 +27,11 @@ import ch.qos.logback.core.AppenderBase;
-public class TestAppender extends AppenderBase<ILoggingEvent> {
+public class TestAppender extends AppenderBase<ILoggingEvent> {
public static List<ILoggingEvent> events = new ArrayList<>();
-
- @Override
- protected void append(ILoggingEvent loggingEvent) {
- events.add(loggingEvent);
- }
+
+ @Override
+ protected void append(ILoggingEvent loggingEvent) {
+ events.add(loggingEvent);
+ }
}
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java
index 1962f00d52..2922aaa896 100644
--- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java
@@ -32,19 +32,15 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-
-
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.List;
-
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
-
import org.apache.http.HttpStatus;
import org.junit.Before;
import org.junit.Test;
@@ -62,7 +58,6 @@ import org.onap.so.apihandlerinfra.exceptions.ClientConnectionException;
import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException;
-
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -70,93 +65,111 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(MockitoJUnitRunner.class)
public class ApiExceptionMapperTest {
- @Mock
- private HttpHeaders headers;
- @Mock
- private Marshaller marshaller;
-
- @InjectMocks
+ @Mock
+ private HttpHeaders headers;
+ @Mock
+ private Marshaller marshaller;
+
+ @InjectMocks
ApiExceptionMapper mapper = new ApiExceptionMapper();
- @Before
- public void setUp() {
- when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_JSON_TYPE));
- }
+ @Before
+ public void setUp() {
+ when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_JSON_TYPE));
+ }
+
@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();
+ ValidateException validateException = new ValidateException.Builder("Test", 0, null).build();
ApiExceptionMapper mockedException = Mockito.spy(mapper);
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"));
+ /// 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();
+ 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();
+ 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);
+ 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);
+ 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);
+ 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);
}
-
+
@Test
public void verifyXMLPath() throws JAXBException {
- when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_XML_TYPE));
- BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).build();
+ when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_XML_TYPE));
+ BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,
+ ErrorNumbers.SVC_BAD_PARAMETER).build();
ApiExceptionMapper mapperSpy = Mockito.spy(mapper);
doReturn(marshaller).when(mapperSpy).getMarshaller();
- Response resp = mapperSpy.toResponse((ApiException) bpmnException);
+ Response resp = mapperSpy.toResponse((ApiException) bpmnException);
verify(marshaller, times(1)).marshal(any(Object.class), any(Writer.class));
}
-
+
@Test
public void verifyMediaType() {
- ApiExceptionMapper mapperSpy = Mockito.spy(mapper);
- BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).build();
- when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_XML_TYPE.withCharset("UTF-8")));
- mapperSpy.toResponse(bpmnException);
- verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class), ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_XML_TYPE));
- when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8")));
- mapperSpy = Mockito.spy(mapper);
- mapperSpy.toResponse(bpmnException);
- verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class), ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE));
- when(headers.getAcceptableMediaTypes()).thenReturn(null);
- mapperSpy = Mockito.spy(mapper);
- mapperSpy.toResponse(bpmnException);
- verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE));
+ ApiExceptionMapper mapperSpy = Mockito.spy(mapper);
+ BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,
+ ErrorNumbers.SVC_BAD_PARAMETER).build();
+ when(headers.getAcceptableMediaTypes())
+ .thenReturn(Arrays.asList(MediaType.APPLICATION_XML_TYPE.withCharset("UTF-8")));
+ mapperSpy.toResponse(bpmnException);
+ verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),
+ ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_XML_TYPE));
+ when(headers.getAcceptableMediaTypes())
+ .thenReturn(Arrays.asList(MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8")));
+ mapperSpy = Mockito.spy(mapper);
+ mapperSpy.toResponse(bpmnException);
+ verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),
+ ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE));
+ when(headers.getAcceptableMediaTypes()).thenReturn(null);
+ mapperSpy = Mockito.spy(mapper);
+ mapperSpy.toResponse(bpmnException);
+ verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),
+ ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE));
}
}