From f89d9e0887e41de727b4e829916ae60dd6926e0e Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Thu, 21 Nov 2019 20:48:40 -0500 Subject: Updated and added to get request processing data Updated and added to get request processing data by internal data flag Committing file that I forgot to commit. Added junit test and change method to not use bowman client. Added and updated orch request unit test ran formatter so verify job will pass and not cry Added an intergration test for new jpa method. Format unit test class for the verify job build Update param key in jpa and also changed return type. Updated method name in request client to avoid confusion Issue-ID: SO-2534 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I420f1a887835dd0d9d0ad991e5b17dddb1db5376 --- mso-api-handlers/mso-requests-db/pom.xml | 5 ++++ .../so/db/request/beans/RequestProcessingData.java | 10 ++++---- .../so/db/request/client/RequestsDbClient.java | 28 +++++++++++++++++++--- .../so/db/request/client/RequestDbClientTest.java | 27 ++++++++++++++++++++- 4 files changed, 61 insertions(+), 9 deletions(-) (limited to 'mso-api-handlers/mso-requests-db') diff --git a/mso-api-handlers/mso-requests-db/pom.xml b/mso-api-handlers/mso-requests-db/pom.xml index 651f35fd5c..031f86282a 100644 --- a/mso-api-handlers/mso-requests-db/pom.xml +++ b/mso-api-handlers/mso-requests-db/pom.xml @@ -31,6 +31,11 @@ spring-boot-starter-test test + + org.glassfish.jersey.core + jersey-common + test + jar diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java index 3c81555b99..e386789c7f 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java @@ -7,9 +7,9 @@ * 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. @@ -42,7 +42,7 @@ import com.openpojo.business.annotation.BusinessKey; * persist the request identifiers created when MSO POSTs a request to PINC
*

*

- * + * * @author * @version */ @@ -54,7 +54,7 @@ import com.openpojo.business.annotation.BusinessKey; public class RequestProcessingData implements Serializable { /** - * + * */ private static final long serialVersionUID = -3497593687393936143L; @@ -87,7 +87,7 @@ public class RequestProcessingData implements Serializable { private Date created = null; @Column(name = "IS_DATA_INTERNAL") - private Boolean isDataInternal = true; + private Boolean isDataInternal = false; @Override public boolean equals(final Object other) { 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 132ec28e31..655ae60f47 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 @@ -22,6 +22,7 @@ package org.onap.so.db.request.client; import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -70,6 +71,7 @@ public class RequestsDbClient { private static final String SERVICE_ID = "SERVICE_ID"; private static final String OPERATION_ID = "OPERATION_ID"; private static final String SO_REQUEST_ID = "SO_REQUEST_ID"; + private static final String IS_INTERNAL_DATA = "IS_INTERNAL_DATA"; private static final String NAME = "NAME"; private static final String GROUPING_ID = "GROUPING_ID"; private static final String REQUEST_ID = "REQUEST_ID"; @@ -83,7 +85,7 @@ public class RequestsDbClient { protected String endpoint; @Value("${mso.adapters.requestDb.auth:#{null}}") - private String msoAdaptersAuth; + protected String msoAdaptersAuth; private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"; private static final String OPERATION_STATUS_SEARCH = "/operationStatus/search"; @@ -125,6 +127,9 @@ public class RequestsDbClient { private static final String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc"; + private static final String findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc = + "/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc"; + private static final String findByGroupingIdAndNameAndTag = "/requestProcessingData/search/findByGroupingIdAndNameAndTag"; @@ -153,8 +158,12 @@ public class RequestsDbClient { findOneByRequestId = endpoint + findOneByRequestId; } - private ClientFactory getClientFactory() { - URI baseUri = UriBuilder.fromUri(endpoint).build(); + protected String getEndpoint() { + return endpoint; + } + + protected ClientFactory getClientFactory() { + URI baseUri = UriBuilder.fromUri(getEndpoint()).build(); ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()); @@ -386,6 +395,18 @@ public class RequestsDbClient { .queryParam(SO_REQUEST_ID, soRequestId).build().toString())); } + public List getExternalRequestProcessingDataBySoRequestId(String soRequestId) { + URI uri = getUri(UriBuilder.fromUri(getEndpoint() + findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc) + .queryParam(SO_REQUEST_ID, soRequestId).queryParam(IS_INTERNAL_DATA, false).build().toString()); + ResponseEntity array = + restTemplate.exchange(uri, HttpMethod.GET, getHttpEntity(), RequestProcessingData[].class); + if (array != null) { + return Arrays.asList(array.getBody()); + } else { + return null; + } + } + public RequestProcessingData getRequestProcessingDataBySoRequestIdAndNameAndGrouping(String soRequestId, String name, String groupingId) { return getClientFactory().create(RequestProcessingData.class) @@ -424,6 +445,7 @@ public class RequestsDbClient { rpd.setSoRequestId(requestId); rpd.setValue(flowExecutionPath); rpd.setTag(BPMN_EXECUTION_DATA_TAG); + rpd.setIsDataInternal(true); HttpEntity entity = new HttpEntity<>(rpd, headers); restTemplate.postForLocation(uri, entity); diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java index fff6ad1013..0ad8d1458e 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java @@ -4,22 +4,35 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.times; import java.net.URI; +import javax.ws.rs.core.UriBuilder; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.RequestProcessingData; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; +import uk.co.blackpepper.bowman.ClientFactory; +import uk.co.blackpepper.bowman.Configuration; @RunWith(MockitoJUnitRunner.class) public class RequestDbClientTest { - + @Spy @InjectMocks protected RequestsDbClient requestsDbClient; @@ -44,4 +57,16 @@ public class RequestDbClientTest { Mockito.verify(restTemplate, times(1)).exchange(eq(uri), eq(HttpMethod.PATCH), isA(HttpEntity.class), eq(String.class)); } + + @Test + public void testGetRequestProcessingDataBySoRequestIdAndIsInternalData() { + Mockito.doReturn("host").when(requestsDbClient).getEndpoint(); + requestsDbClient.getExternalRequestProcessingDataBySoRequestId("12345"); + URI uri = URI.create(UriBuilder + .fromUri("host/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc") + .queryParam("SO_REQUEST_ID", "12345").queryParam("IS_INTERNAL_DATA", false).build().toString()); + Mockito.verify(restTemplate, times(1)).exchange(eq(uri), eq(HttpMethod.GET), isA(HttpEntity.class), + eq(RequestProcessingData[].class)); + } + } -- cgit 1.2.3-korg