Skip to content
Snippets Groups Projects
Commit 86aa2955 authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

Merge branch 'master' into table-storage

parents e31f79ac cf959a19
No related branches found
No related tags found
1 merge request!14update API to delegate secret retrieval via service and change azure backend to table storage
......@@ -118,10 +118,6 @@ paths:
schema:
$ref: '#/definitions/PartitionInfo'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/PartitionInfo'
'201':
description: Created
'401':
......
......@@ -23,8 +23,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.RequestScope;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import javax.validation.Valid;
import java.net.URI;
import java.util.Map;
@RestController
......@@ -38,8 +40,10 @@ public class PartitionApi {
@PostMapping("/{partitionId}")
@PreAuthorize("@authorizationFilter.hasPermissions()")
public ResponseEntity<PartitionInfo> create(@PathVariable("partitionId") String partitionId, @RequestBody @Valid PartitionInfo partitionInfo) {
return ResponseEntity.ok(this.partitionService.createPartition(partitionId, partitionInfo));
public ResponseEntity create(@PathVariable("partitionId") String partitionId, @RequestBody @Valid PartitionInfo partitionInfo) {
this.partitionService.createPartition(partitionId, partitionInfo);
URI partitionLocation = ServletUriComponentsBuilder.fromCurrentRequest().buildAndExpand().toUri();
return ResponseEntity.created(partitionLocation).build();
}
@GetMapping("/{partitionId}")
......
......@@ -23,18 +23,27 @@ import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.model.Property;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionService;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import javax.servlet.http.HttpServletRequest;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
@RunWith(MockitoJUnitRunner.class)
@RunWith(PowerMockRunner.class)
@PrepareForTest(ServletUriComponentsBuilder.class)
public class PartitionApiTest {
private final AppException NOT_FOUND_EXCEPTION =
......@@ -50,15 +59,22 @@ public class PartitionApiTest {
@Mock
private PartitionInfo partitionInfo;
@Test
public void should_return201AndPartitionId_when_givenValidPartitionId() {
String partitionId = "partition1";
when(partitionService.createPartition(anyString(), any(PartitionInfo.class))).thenReturn(partitionInfo);
mockStatic(ServletUriComponentsBuilder.class);
ResponseEntity<PartitionInfo> result = this.sut.create(partitionId, partitionInfo);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(partitionInfo, result.getBody());
ServletUriComponentsBuilder builder = spy(ServletUriComponentsBuilder.class);
when(ServletUriComponentsBuilder.fromCurrentRequest()).thenReturn(builder);
ResponseEntity result = this.sut.create(partitionId, partitionInfo);
assertEquals(HttpStatus.CREATED, result.getStatusCode());
assertNull(result.getBody());
assertNotNull(result.getHeaders().get(HttpHeaders.LOCATION));
}
@Test
......
......@@ -49,7 +49,7 @@ public abstract class CreatePartitionTest extends BaseTestTemplate {
@Override
protected int expectedOkResponseCode() {
return HttpStatus.OK.value();
return HttpStatus.CREATED.value();
}
@Test
......
......@@ -64,7 +64,7 @@ public abstract class DeletePartitionTest extends BaseTestTemplate {
ClientResponse createResponse = this.descriptor.run(this.getId(), this.testUtils.getAccessToken());
Assert.assertEquals(this.error((String) createResponse.getEntity(String.class))
, HttpStatus.OK.value(), (long) createResponse.getStatus());
, HttpStatus.CREATED.value(), (long) createResponse.getStatus());
this.descriptor = oldDescriptor;
}
......
......@@ -47,7 +47,7 @@ public abstract class GetPartitionByIdApitTest extends BaseTestTemplate {
ClientResponse createResponse = createPartitionDescriptor.run(this.getId(), this.testUtils.getAccessToken());
assertEquals(this.error((String) createResponse.getEntity(String.class))
, HttpStatus.OK.value(), (long) createResponse.getStatus());
, HttpStatus.CREATED.value(), (long) createResponse.getStatus());
}
public GetPartitionByIdApitTest() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment