Commit cf959a19 authored by ethiraj krishnamanaidu's avatar ethiraj krishnamanaidu
Browse files

Merge branch 'create-no-payload' into 'master'

Create partition should not return partition info from payload. Empty response is good enough.

See merge request !4
parents a3eb4651 25de8695
Pipeline #10787 passed with stages
in 14 minutes and 32 seconds
......@@ -116,10 +116,6 @@ paths:
schema:
$ref: '#/definitions/PartitionInfo'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/PartitionInfo'
'201':
description: Created
'401':
......
......@@ -22,8 +22,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
......@@ -37,8 +39,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}")
......
......@@ -22,18 +22,27 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.partition.model.PartitionInfo;
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 =
......@@ -49,15 +58,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() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment