diff --git a/pom.xml b/pom.xml
index f4b8591368a7785006df087e5389fab90d385d59..438fef824e0cacaf6c2a7bfaeaef5570dfe2f164 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.opengroup.osdu
os-core-common
- 0.3.20
+ 0.3.21
jar
diff --git a/src/main/java/org/opengroup/osdu/core/common/partition/IPartitionProvider.java b/src/main/java/org/opengroup/osdu/core/common/partition/IPartitionProvider.java
index 54a09db9fc3970bc92c3a60f6cff42b56da645c0..f97195a0df180836d58f6649537ecfa76bb8540e 100644
--- a/src/main/java/org/opengroup/osdu/core/common/partition/IPartitionProvider.java
+++ b/src/main/java/org/opengroup/osdu/core/common/partition/IPartitionProvider.java
@@ -22,6 +22,8 @@ public interface IPartitionProvider {
PartitionInfo create(String partitionId, PartitionInfo partitionInfo) throws PartitionException;
+ void update(String partitionId, PartitionInfo partitionInfo) throws PartitionException;
+
void delete(String partitionId) throws PartitionException;
List list() throws PartitionException;
diff --git a/src/main/java/org/opengroup/osdu/core/common/partition/PartitionService.java b/src/main/java/org/opengroup/osdu/core/common/partition/PartitionService.java
index 2944b9864f34ee3e92d4a0728822ace15b26de26..7cc7b30db0a8158f1d12ab74eb2431b4ae3065ba 100644
--- a/src/main/java/org/opengroup/osdu/core/common/partition/PartitionService.java
+++ b/src/main/java/org/opengroup/osdu/core/common/partition/PartitionService.java
@@ -72,7 +72,7 @@ public class PartitionService implements IPartitionProvider {
entity = new StringEntity(jsonString);
} catch (UnsupportedEncodingException e) {
throw new PartitionException(
- String.format("Error making request to Partition service, error: %s", e.getMessage()), null);
+ String.format("Error making request to Partition service create api, error: %s", e.getMessage()), null);
}
httpPost.setEntity(entity);
HttpResponse response = send(httpPost);
@@ -83,6 +83,23 @@ public class PartitionService implements IPartitionProvider {
.build();
}
+ @Override
+ public void update(String partitionId, PartitionInfo partitionInfo) throws PartitionException {
+ String url = this.createUrl(String.format("/partitions/%s", partitionId));
+ HttpPatch httpPatch = new HttpPatch(url);
+ StringEntity entity;
+ try {
+ String jsonString = this.gson.toJson(partitionInfo);
+ entity = new StringEntity(jsonString);
+ } catch (UnsupportedEncodingException e) {
+ throw new PartitionException(
+ String.format("Error making request to Partition service update api, error: %s", e.getMessage()), null);
+ }
+ httpPatch.setEntity(entity);
+ HttpResponse response = send(httpPatch);
+ getResult(response, String.class);
+ }
+
@Override
public void delete(String partitionId) throws PartitionException {
String url = this.createUrl(String.format("/partitions/%s", partitionId));
diff --git a/src/test/java/org/opengroup/osdu/core/common/partition/PartitionServiceTest.java b/src/test/java/org/opengroup/osdu/core/common/partition/PartitionServiceTest.java
index a7c1dbd70f9be8793a2474e7ac1e362592225dd7..2f567f0dca7daf51b7bc7cc08ed30e10e778309c 100644
--- a/src/test/java/org/opengroup/osdu/core/common/partition/PartitionServiceTest.java
+++ b/src/test/java/org/opengroup/osdu/core/common/partition/PartitionServiceTest.java
@@ -113,6 +113,57 @@ public class PartitionServiceTest {
}
}
+ @Test
+ public void should_return_null_when_updating_partition() throws IOException, PartitionException {
+ PartitionAPIConfig config = PartitionAPIConfig.builder().rootUrl("http://localhost").build();
+ DpsHeaders headers = new DpsHeaders();
+ CloseableHttpResponse mockResponse = getResponse(204, null);
+ when(cacheHttpClient.execute(any())).thenReturn(mockResponse);
+
+ PartitionService sut = new PartitionService(config, headers, cacheHttpClient);
+ PartitionInfo input = PartitionInfo.builder()
+ .properties(new HashMap<>())
+ .build();
+ sut.update(PARTITION_ID, input);
+ }
+
+ @Test
+ public void should_return_exception_when_updating_with_bad_partitionId() throws IOException {
+ PartitionAPIConfig config = PartitionAPIConfig.builder().rootUrl("http://localhost").build();
+ DpsHeaders headers = new DpsHeaders();
+ CloseableHttpResponse mockResponse = getResponse(400, BAD_REQUEST);
+ when(cacheHttpClient.execute(any())).thenReturn(mockResponse);
+
+ PartitionService sut = new PartitionService(config, headers, cacheHttpClient);
+ try {
+ PartitionInfo input = PartitionInfo.builder()
+ .properties(new HashMap<>())
+ .build();
+ sut.update(null, input);
+ fail("should not be here");
+ } catch (PartitionException e) {
+ assertNotNull(e);
+ assertEquals(BAD_REQUEST, e.getHttpResponse().getBody());
+ }
+ }
+
+ @Test
+ public void should_return_exception_when_updating_with_bad_partitionInfo() throws IOException {
+ PartitionAPIConfig config = PartitionAPIConfig.builder().rootUrl("http://localhost").build();
+ DpsHeaders headers = new DpsHeaders();
+ CloseableHttpResponse mockResponse = getResponse(400, BAD_REQUEST);
+ when(cacheHttpClient.execute(any())).thenReturn(mockResponse);
+
+ PartitionService sut = new PartitionService(config, headers, cacheHttpClient);
+ try {
+ sut.update(PARTITION_ID, null);
+ fail("should not be here");
+ } catch (PartitionException e) {
+ assertNotNull(e);
+ assertEquals(BAD_REQUEST, e.getHttpResponse().getBody());
+ }
+ }
+
@Test
public void should_return_partition_204_after_deleting() throws IOException, PartitionException {
PartitionAPIConfig config = PartitionAPIConfig.builder().rootUrl("http://localhost").build();