diff options
Diffstat (limited to 'aai-resources/src')
7 files changed, 41 insertions, 40 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java b/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java index 61ada79..1d20744 100644 --- a/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java +++ b/aai-resources/src/main/java/org/onap/aai/interceptors/post/InvalidResponseStatus.java @@ -33,6 +33,7 @@ import javax.ws.rs.core.MediaType; import org.onap.aai.exceptions.AAIException; import org.onap.aai.interceptors.AAIContainerFilter; import org.onap.aai.logging.ErrorLogHelper; +import org.springframework.http.HttpStatus; @Priority(AAIResponseFilterPriority.INVALID_RESPONSE_STATUS) public class InvalidResponseStatus extends AAIContainerFilter implements ContainerResponseFilter { @@ -41,9 +42,9 @@ public class InvalidResponseStatus extends AAIContainerFilter implements Contain public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { - if (responseContext.getStatus() == 405) { + if (responseContext.getStatus() == HttpStatus.METHOD_NOT_ALLOWED.value()) { - responseContext.setStatus(400); + responseContext.setStatus(HttpStatus.BAD_REQUEST.value()); AAIException e = new AAIException("AAI_3012"); ArrayList<String> templateVars = new ArrayList<>(); diff --git a/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java b/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java index 14c1f01..2d0dcdc 100644 --- a/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java +++ b/aai-resources/src/main/java/org/onap/aai/interceptors/pre/RequestTransactionLogging.java @@ -91,7 +91,7 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con requestContext.getHeaders().putSingle(CONTENT_TYPE, DEFAULT_CONTENT_TYPE); } - if (WILDCARD.equals(acceptType) || StringUtils.isEmpty(acceptType) || acceptType.contains(TEXT_PLAIN)) { + if (WILDCARD.equals(acceptType) || acceptType.isEmpty() || !StringUtils.hasLength(acceptType) || acceptType.contains(TEXT_PLAIN)) { UriInfo uriInfo = requestContext.getUriInfo(); if (uriInfo != null) { MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); diff --git a/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java b/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java index 5208726..c685071 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java @@ -21,7 +21,6 @@ package org.onap.aai.rest; import io.micrometer.core.annotation.Timed; -import io.swagger.jaxrs.PATCH; import java.io.UnsupportedEncodingException; import java.net.URI; diff --git a/aai-resources/src/main/resources/application.properties b/aai-resources/src/main/resources/application.properties index 3905dd8..66a8e53 100644 --- a/aai-resources/src/main/resources/application.properties +++ b/aai-resources/src/main/resources/application.properties @@ -20,9 +20,9 @@ spring.jersey.application-path=${schema.uri.base.path} spring.profiles.active=production,one-way-ssl,dmaap #The max number of active threads in this pool -jetty.threadPool.maxThreads=200 +server.jetty.threads.max=200 #The minimum number of threads always kept alive -jetty.threadPool.minThreads=8 +server.jetty.threads.min=8 #The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads server.tomcat.max-idle-time=60000 diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java index 357ea41..8cc28fc 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java @@ -27,7 +27,6 @@ import com.jayway.jsonpath.JsonPath; import java.io.UnsupportedEncodingException; import java.util.Arrays; -import java.util.Base64; import java.util.Collections; import java.util.UUID; @@ -72,28 +71,29 @@ public class ConfigurationTest extends AbstractSpringRestTest { @Value("${local.management.port}") private int mgtPort; - private HttpEntity<String> httpEntity; + private HttpEntity<String> httpEntityGet; private HttpEntity<String> httpEntityPut; private HttpEntity<String> httpEntityPatch; private String baseUrl; private String actuatorurl; - private HttpHeaders headers; + private HttpHeaders headersGet; + private HttpHeaders headersPutPatch; @Before public void setup() throws UnsupportedEncodingException { - headers = new HttpHeaders(); + headersGet = new HttpHeaders(); + headersGet.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headersGet.add("Real-Time", "true"); + headersGet.add("X-FromAppId", "JUNIT"); + headersGet.add("X-TransactionId", "JUNIT"); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.add("Real-Time", "true"); - headers.add("X-FromAppId", "JUNIT"); - headers.add("X-TransactionId", "JUNIT"); + headersGet.setBasicAuth("AAI","AAI"); - String authorization = Base64.getEncoder().encodeToString("AAI:AAI".getBytes("UTF-8")); - headers.add("Authorization", "Basic " + authorization); - - httpEntity = new HttpEntity<String>(headers); + headersPutPatch = new HttpHeaders(); + headersPutPatch.putAll(headersGet); + headersPutPatch.setContentType(MediaType.APPLICATION_JSON); + httpEntityGet = new HttpEntity<String>(headersGet); baseUrl = "http://localhost:" + randomPort; actuatorurl = "http://localhost:" + mgtPort; } @@ -105,7 +105,7 @@ public class ConfigurationTest extends AbstractSpringRestTest { ResponseEntity<String> responseEntity = null; - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); // String putBody = " configuration-id, configuration-type configuration-sub-type"; @@ -113,31 +113,31 @@ public class ConfigurationTest extends AbstractSpringRestTest { + "\"configuration-sub-type\": \"subtype1\", " + "\"operational-status\": \"example1\", " + "\"orchestration-status\": \"example1\", " + "\"configuration-selflink\": \"example1\", " + "\"model-customization-id\": \"example1\" " + "}"; - httpEntityPut = new HttpEntity<String>(putBody, headers); + httpEntityPut = new HttpEntity<String>(putBody, headersPutPatch); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntityPut, String.class); assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); String vertexId = responseEntity.getHeaders().getFirst("vertex-id"); responseEntity = restTemplate.exchange(baseUrl + "/aai/v12/resources/id/" + vertexId, HttpMethod.GET, - httpEntity, String.class); + httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); String patchBody = "{" + "\"configuration-id\": \"" + cid + "\"," + "\"configuration-type\": \"type2\"," + "\"configuration-sub-type\": \"subtype2\", " + "\"operational-status\": \"example1\", " + "\"orchestration-status\": \"example1\", " + "\"configuration-selflink\": \"example1\", " + "\"model-customization-id\": \"example1\" " + "}"; - headers.put("Content-Type", Arrays.asList("application/merge-patch+json")); - headers.add("X-HTTP-Method-Override", "PATCH"); + headersPutPatch.put("Content-Type", Arrays.asList("application/merge-patch+json")); + headersPutPatch.add("X-HTTP-Method-Override", "PATCH"); - httpEntityPatch = new HttpEntity<String>(patchBody, headers); + httpEntityPatch = new HttpEntity<String>(patchBody, headersPutPatch); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.POST, httpEntityPatch, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); String body = responseEntity.getBody().toString(); @@ -148,11 +148,11 @@ public class ConfigurationTest extends AbstractSpringRestTest { patchBody = "{" + "\"configuration-id\": \"" + cid + "\"," + "\"configuration-type\": \"type3\"," + "\"configuration-sub-type\": \"subtype3\" " + "}"; - httpEntityPatch = new HttpEntity<String>(patchBody, headers); + httpEntityPatch = new HttpEntity<String>(patchBody, headersPutPatch); responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.PATCH, httpEntityPatch, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntity, String.class); + responseEntity = restTemplate.exchange(baseUrl + endpoint, HttpMethod.GET, httpEntityGet, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); body = responseEntity.getBody().toString(); @@ -163,15 +163,16 @@ public class ConfigurationTest extends AbstractSpringRestTest { } @Test - public void TestManagementEndpointConfiguration() { + public void testManagementEndpointConfiguration() { ResponseEntity<String> responseEntity = null; String responseBody = null; // set Accept as text/plain in order to get access of endpoint "/actuator/prometheus" - headers.set("Accept", "text/plain"); - httpEntity = new HttpEntity<String>(headers); + headersGet.set("Accept", "text/plain"); + headersGet.setAccept(Arrays.asList(MediaType.TEXT_PLAIN)); + httpEntityGet = new HttpEntity<String>(headersGet); responseEntity = - restTemplate.exchange(actuatorurl + "/actuator/prometheus", HttpMethod.GET, httpEntity, String.class); + restTemplate.exchange(actuatorurl + "/actuator/prometheus", HttpMethod.GET, httpEntityGet, String.class); responseBody = (String) responseEntity.getBody(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertTrue(responseBody.contains("group_id")); @@ -179,16 +180,16 @@ public class ConfigurationTest extends AbstractSpringRestTest { // Set Accept as MediaType.APPLICATION_JSON in order to get access of endpoint "/actuator/info" and // "/actuator/health" - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - httpEntity = new HttpEntity<String>(headers); + headersGet.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + httpEntityGet = new HttpEntity<String>(headersGet); responseEntity = - restTemplate.exchange(actuatorurl + "/actuator/info", HttpMethod.GET, httpEntity, String.class); + restTemplate.exchange(actuatorurl + "/actuator/info", HttpMethod.GET, httpEntityGet, String.class); responseBody = (String) responseEntity.getBody(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertTrue(responseBody.contains("aai-resources")); responseEntity = - restTemplate.exchange(actuatorurl + "/actuator/health", HttpMethod.GET, httpEntity, String.class); + restTemplate.exchange(actuatorurl + "/actuator/health", HttpMethod.GET, httpEntityGet, String.class); responseBody = (String) responseEntity.getBody(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertTrue(responseBody.contains("UP")); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java index a804ee5..27f702f 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java @@ -65,7 +65,7 @@ public class ExceptionHandlerTest extends AAISetup { @Before public void setup() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); MultivaluedHashMap<String, String> headersMultiMap = new MultivaluedHashMap<>(); diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties index 4c2b8d0..21e4ca7 100644 --- a/aai-resources/src/test/resources/application-test.properties +++ b/aai-resources/src/test/resources/application-test.properties @@ -20,9 +20,9 @@ spring.autoconfigure.exclude=\ spring.profiles.active=production #The max number of active threads in this pool -server.tomcat.max-threads=200 +server.tomcat.threads.max=200 #The minimum number of threads always kept alive -server.tomcat.min-Spare-Threads=25 +server.tomcat.threads.min-spare=25 #The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads server.tomcat.max-idle-time=60000 |