Commit 6d43cf8c authored by ethiraj krishnamanaidu's avatar ethiraj krishnamanaidu
Browse files

Merge branch 'fix_swagger' into 'master'

Fix Delete API in swagger

See merge request !101
parents f7233fab 18a50099
Pipeline #60786 failed with stages
in 21 minutes and 49 seconds
package org.opengroup.osdu.entitlements.v2.api;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.http.RequestInfo;
import org.opengroup.osdu.entitlements.v2.AppProperties;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.opengroup.osdu.entitlements.v2.model.deletegroup.DeleteGroupDto;
import org.opengroup.osdu.entitlements.v2.model.deletegroup.DeleteGroupServiceDto;
import org.opengroup.osdu.entitlements.v2.service.DeleteGroupService;
import org.opengroup.osdu.entitlements.v2.util.RequestInfoUtilService;
......@@ -14,17 +12,12 @@ import org.opengroup.osdu.entitlements.v2.validation.PartitionHeaderValidationSe
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
@RestController
@RequiredArgsConstructor
@Validated
public class DeleteGroupApi {
private final DeleteGroupService deleteService;
......@@ -34,12 +27,12 @@ public class DeleteGroupApi {
@DeleteMapping("/groups/{group_email}")
@PreAuthorize("@authorizationFilter.hasAnyPermission('" + AppProperties.OPS + "', '" + AppProperties.ADMIN + "')")
public ResponseEntity<Void> deleteGroup(@Valid @PathVariable("group_email") DeleteGroupDto groupInfoDto) {
public ResponseEntity<Void> deleteGroup(@PathVariable("group_email") String groupEmail) {
String partitionId = requestInfo.getHeaders().getPartitionId();
partitionHeaderValidationService.validateSinglePartitionProvided(partitionId);
String partitionDomain = requestInfoUtilService.getDomain(partitionId);
ApiInputValidation.validateEmailAndBelongsToPartition(groupInfoDto.getGroupEmail(), partitionDomain);
EntityNode groupNode = DeleteGroupDto.deleteGroupNode(groupInfoDto, partitionId);
ApiInputValidation.validateEmailAndBelongsToPartition(groupEmail, partitionDomain);
EntityNode groupNode = EntityNode.createNodeFromGroupEmail(groupEmail);
DeleteGroupServiceDto deleteGroupServiceDto = DeleteGroupServiceDto.builder()
.requesterId(requestInfoUtilService.getUserId(requestInfo.getHeaders()))
.partitionId(requestInfo.getHeaders().getPartitionId())
......
package org.opengroup.osdu.entitlements.v2.model.deletegroup;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.opengroup.osdu.entitlements.v2.model.NodeType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Generated;
import lombok.NoArgsConstructor;
@Data
@Generated
@NoArgsConstructor
@AllArgsConstructor
public class DeleteGroupDto {
private String groupEmail;
public static EntityNode deleteGroupNode(DeleteGroupDto dto, String partitionId) {
return EntityNode.builder()
.name(dto.groupEmail.split("@")[0])
.nodeId(dto.groupEmail.toLowerCase())
.type(NodeType.GROUP)
.dataPartitionId(partitionId)
.build();
}
}
package org.opengroup.osdu.entitlements.v2.api;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -11,6 +10,7 @@ import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.entitlements.v2.auth.AuthorizationService;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.opengroup.osdu.entitlements.v2.model.NodeType;
import org.opengroup.osdu.entitlements.v2.model.deletegroup.DeleteGroupServiceDto;
import org.opengroup.osdu.entitlements.v2.service.DeleteGroupService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -24,7 +24,6 @@ import org.springframework.test.web.servlet.ResultActions;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
......@@ -34,7 +33,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = DeleteGroupApi.class)
@ComponentScan("org.opengroup.osdu.entitlements.v2")
public class DeleteGroupApiTests {
public class DeleteGroupApiTest {
@Autowired
private MockMvc mockMvc;
......@@ -68,16 +67,22 @@ public class DeleteGroupApiTests {
performDeleteGroupRequest(groupId).andExpect(status().isBadRequest());
}
@Test
public void shouldCallService() throws Exception {
ArgumentCaptor<EntityNode> captor1 = ArgumentCaptor.forClass(EntityNode.class);
ArgumentCaptor<DeleteGroupServiceDto> captor2 = ArgumentCaptor.forClass(DeleteGroupServiceDto.class);
ArgumentCaptor<EntityNode> entityNodeArgumentCaptor = ArgumentCaptor.forClass(EntityNode.class);
ArgumentCaptor<DeleteGroupServiceDto> dgsDtoArgumentCaptor = ArgumentCaptor.forClass(DeleteGroupServiceDto.class);
String groupId = "service.VIEWERS@common.contoso.com";
performDeleteGroupRequest(groupId).andExpect(status().isNoContent());
verify(service, times(1)).run(captor1.capture(), captor2.capture());
assertThat(captor1.getValue().getNodeId()).isEqualTo("service.viewers@common.contoso.com");
verify(service).run(entityNodeArgumentCaptor.capture(), dgsDtoArgumentCaptor.capture());
EntityNode actualEntityNode = entityNodeArgumentCaptor.getValue();
assertThat(actualEntityNode.getNodeId()).isEqualTo("service.viewers@common.contoso.com");
assertThat(actualEntityNode.getName()).isEqualTo("service.viewers");
assertThat(actualEntityNode.getDataPartitionId()).isEqualTo("common");
assertThat(actualEntityNode.getType()).isEqualTo(NodeType.GROUP);
DeleteGroupServiceDto deleteGroupServiceDto = dgsDtoArgumentCaptor.getValue();
assertThat(deleteGroupServiceDto.getRequesterId()).isEqualTo("a@b.com");
assertThat(deleteGroupServiceDto.getPartitionId()).isEqualTo("common");
}
private ResultActions performDeleteGroupRequest(String groupEmail) throws Exception {
......
package org.opengroup.osdu.entitlements.v2.model.deletegroup;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class DeleteGroupDtoTests {
@Test
public void should_convertAllParameters_andAddId_andName(){
DeleteGroupDto sut = new DeleteGroupDto("name@dp.domain.com");
EntityNode result = DeleteGroupDto.deleteGroupNode(sut, "dp");
assertThat(result.getNodeId()).isEqualTo("name@dp.domain.com");
assertThat(result.getName()).isEqualTo("name");
}
}
Markdown is supported
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