From 67b21f3bbf54828093fd27634d4d090111c04502 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Wed, 12 Sep 2018 16:15:54 -0400 Subject: Improve test coverage for requestdbclient RequestsDbClient Junits and some fixes for RequestsDbClient Change-Id: Icc2185030220d7bf973be5a23a51b6b5e313a360 Issue-ID: SO-1033 Signed-off-by: Benjamin, Max (mb388a) --- .../so/db/request/client/RequestsDbClient.java | 83 ++++++++++++---------- 1 file changed, 45 insertions(+), 38 deletions(-) (limited to 'mso-api-handlers/mso-requests-db/src') diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 54fec3ad4d..2a61a319f3 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -20,17 +20,6 @@ package org.onap.so.db.request.client; -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; -import javax.ws.rs.core.UriBuilder; - import org.apache.http.HttpStatus; import org.onap.so.db.request.beans.ArchivedInfraRequests; import org.onap.so.db.request.beans.InfraActiveRequests; @@ -46,7 +35,6 @@ import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; @@ -60,12 +48,21 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; - import uk.co.blackpepper.bowman.Client; import uk.co.blackpepper.bowman.ClientFactory; import uk.co.blackpepper.bowman.Configuration; import uk.co.blackpepper.bowman.RestTemplateConfigurer; +import javax.annotation.PostConstruct; +import javax.ws.rs.core.UriBuilder; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + @Component("RequestsDbClient") @Primary public class RequestsDbClient { @@ -82,7 +79,6 @@ public class RequestsDbClient { private static final String TAG = "TAG"; private Client infraActiveRequestClient; - private Client operationStatusClient; private Client requestProcessingDataClient; private final Client distributionStatusClient; private final Client serviceModelStatusClient; @@ -122,9 +118,6 @@ public class RequestsDbClient { protected HttpHeaders headers; - protected ClientFactory clientFactory; - - @Autowired protected RestTemplate restTemplate; @Autowired @@ -144,6 +137,7 @@ public class RequestsDbClient { findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI; headers = new HttpHeaders(); headers.set("Authorization", msoAdaptersAuth); + restTemplate = restTemplate(); } public RequestsDbClient() { @@ -163,7 +157,6 @@ public class RequestsDbClient { } }).build().buildClientFactory(); infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class); - operationStatusClient = clientFactory.create(OperationStatus.class); requestProcessingDataClient = clientFactory.create(RequestProcessingData.class); distributionStatusClient = clientFactory.create(OperationalEnvDistributionStatus.class); serviceModelStatusClient = clientFactory.create(OperationalEnvServiceModelStatus.class); @@ -181,9 +174,21 @@ public class RequestsDbClient { throw e; } } - public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) { - return this.getSingleInfraActiveRequests(this.getUri(endpoint + "/infraActiveRequests/" + requestId)); - } + + public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) { + try { + InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody(); + if (infraActiveRequests != null) { + infraActiveRequests.setRequestId(requestId); + } + return infraActiveRequests; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } + } public List getOrchestrationFiltersFromInfraActive(Map> orchestrationMap) { URI uri = getUri(getOrchestrationFilterURI); @@ -208,12 +213,25 @@ public class RequestsDbClient { } } - - public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId){ - return this.getSingleOperationStatus(UriBuilder.fromUri(findOneByServiceIdAndOperationIdURI) - .queryParam(SERVICE_ID,serviceId) - .queryParam(OPERATION_ID,operationId) - .build()); + + public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId) { + try { + OperationStatus operationStatus = restTemplate.exchange(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)) + .queryParam(SERVICE_ID, serviceId) + .queryParam(OPERATION_ID, operationId) + .build(), HttpMethod.GET, HttpEntity.EMPTY, OperationStatus.class).getBody(); + if (operationStatus != null) { + operationStatus.setServiceId(serviceId); + operationStatus.setOperationId(operationId); + } + + return operationStatus; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } } public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(String operationalEnvironmentId, String serviceModelVersionId) { @@ -261,10 +279,6 @@ public class RequestsDbClient { private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){ return distributionStatusClient.get(uri); } - - protected InfraActiveRequests getSingleInfraActiveRequests(URI uri) { - return infraActiveRequestClient.get(uri); - } public void updateInfraActiveRequests(InfraActiveRequests request) { infraActiveRequestClient.put(request); @@ -273,12 +287,6 @@ public class RequestsDbClient { protected URI getUri(String uri) { return URI.create(uri); } - - - - public OperationStatus getSingleOperationStatus(URI uri){ - return operationStatusClient.get(uri); - } public void saveRequestProcessingData(RequestProcessingData requestProcessingData) { URI uri = getUri(endpoint + requestProcessingDataURI); @@ -322,7 +330,6 @@ public class RequestsDbClient { return requestProcessingDataClient.getAll(uri); } - @Bean public RestTemplate restTemplate() { return new RestTemplate( new HttpComponentsClientHttpRequestFactory()); } -- cgit 1.2.3-korg