diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/DataPartitionSettingsApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/DataPartitionSetupApi.java similarity index 92% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/api/DataPartitionSettingsApi.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/api/DataPartitionSetupApi.java index cd3ddb3e9e6d9cec932484174223442ed9d7f5fd..45de58f7032df485bba04ab43545078e45b6570c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/DataPartitionSettingsApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/DataPartitionSetupApi.java @@ -14,7 +14,6 @@ package org.opengroup.osdu.indexer.api; -import lombok.extern.java.Log; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.service.IClusterConfigurationService; import org.springframework.beans.factory.annotation.Autowired; @@ -28,12 +27,10 @@ import org.springframework.web.context.annotation.RequestScope; import java.io.IOException; import java.util.ArrayList; - -@Log @RestController -@RequestMapping("/partitions/settings") +@RequestMapping("/partitions") @RequestScope -public class DataPartitionSettingsApi { +public class DataPartitionSetupApi { private static final String OPS = "users.datalake.ops"; @@ -43,7 +40,7 @@ public class DataPartitionSettingsApi { private AuditLogger auditLogger; @PreAuthorize("@authorizationFilter.hasPermission('" + OPS + "')") - @PostMapping + @PostMapping(path = "/cluster-settings", consumes = "application/json") public ResponseEntity<?> partitionInit() throws IOException { this.clusterConfigurationService.updateClusterConfiguration(); this.auditLogger.getConfigurePartition(new ArrayList<>()); diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/DataPartitionSetupApiTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/DataPartitionSetupApiTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2bf11700d0adb746c0a103055de6afa613145135 --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/DataPartitionSetupApiTest.java @@ -0,0 +1,56 @@ +// Copyright © Schlumberger +// +// 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. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.api; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.indexer.logging.AuditLogger; +import org.opengroup.osdu.indexer.service.IClusterConfigurationService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(SpringRunner.class) +public class DataPartitionSetupApiTest { + + @Mock + private AuditLogger auditLogger; + @Mock + private IClusterConfigurationService clusterConfigurationService; + @InjectMocks + private DataPartitionSetupApi sut; + + @Test + public void should_return200_when_valid_kind_provided() throws IOException { + ResponseEntity<?> response = this.sut.partitionInit(); + + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + @Test(expected = AppException.class) + public void should_throwAppException_ifUnknownExceptionCaught_reindexTest() throws IOException { + when(this.clusterConfigurationService.updateClusterConfiguration()).thenThrow(new AppException(500, "", "")); + + this.sut.partitionInit(); + } +}