summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGamboa, Gilbert <gilbert.g.gamboa@att.com>2019-07-18 14:37:21 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2019-07-18 14:37:21 -0400
commitce0a7807b322f16b86090899b33160825fa9fd10 (patch)
treee0354987786355ff2b30e0e9afac0a443316de82
parent97ad3ad656f2cdefb9606654b5ceacc12694fddb (diff)
Fix error updating request_processing_data
Fix error when updating existing record in request_processing_data table. Use correct field name in the toString method in RequestProcessingData bean class. RequestDbClient.updateRequestProcessingData should include entity id in the URI on the PUT request. Add new Config class ExposeEntityIdResourceConfiguration to make Spring data Rest return id in the response for RequestProcessingData. Make spring-boot-starter-data-rest not optional dependency in mso-requests-db-repositories Added unit test for RequestDbClient.updateRequestProcessingData() method. Issue-ID: SO-2120 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I733be06185e5c19a0b7112918ce0a0f2abf861d7
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/pom.xml1
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/configuration/ExposeEntityIdResourceConfiguration.java21
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java2
-rw-r--r--mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java35
4 files changed, 57 insertions, 2 deletions
diff --git a/mso-api-handlers/mso-requests-db-repositories/pom.xml b/mso-api-handlers/mso-requests-db-repositories/pom.xml
index f890dabedd..4dbf22cd87 100644
--- a/mso-api-handlers/mso-requests-db-repositories/pom.xml
+++ b/mso-api-handlers/mso-requests-db-repositories/pom.xml
@@ -30,7 +30,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/configuration/ExposeEntityIdResourceConfiguration.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/configuration/ExposeEntityIdResourceConfiguration.java
new file mode 100644
index 0000000000..575e5ff347
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/configuration/ExposeEntityIdResourceConfiguration.java
@@ -0,0 +1,21 @@
+package org.onap.so.db.request.configuration;
+
+import org.onap.so.db.request.beans.RequestProcessingData;
+import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
+import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ExposeEntityIdResourceConfiguration extends RepositoryRestConfigurerAdapter {
+
+ /**
+ * Spring Data Rest hides the ID by default, in order to have it in the JSON you have to manually configure that for
+ * your entity
+ *
+ * @param config
+ */
+ @Override
+ public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
+ config.exposeIdsFor(RequestProcessingData.class);
+ }
+}
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 7a24d14e9b..4d16d9c272 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
@@ -354,7 +354,7 @@ public class RequestsDbClient {
public void updateRequestProcessingData(RequestProcessingData requestProcessingData) {
HttpHeaders headers = getHttpHeaders();
- URI uri = getUri(requestProcessingDataURI);
+ URI uri = getUri(requestProcessingDataURI + "/" + requestProcessingData.getId());
HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers);
restTemplate.put(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
new file mode 100644
index 0000000000..fdbc04acb4
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java
@@ -0,0 +1,35 @@
+package org.onap.so.db.request.client;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.times;
+import java.net.URI;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.db.request.beans.RequestProcessingData;
+import org.springframework.http.HttpEntity;
+import org.springframework.web.client.RestTemplate;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class RequestDbClientTest {
+
+ @InjectMocks
+ protected RequestsDbClient requestsDbClient;
+
+ @Mock
+ protected RestTemplate restTemplate;
+
+ @Test
+ public void updateRequestProcessingDataTest() {
+ RequestProcessingData requestProcessingData = new RequestProcessingData();
+ requestProcessingData.setId(1);
+ URI uri = URI.create("/requestProcessingData/1");
+ requestsDbClient.updateRequestProcessingData(requestProcessingData);
+ Mockito.verify(restTemplate, times(1)).put(eq(uri), isA(HttpEntity.class));
+ }
+}