Commit 6635516b authored by Siiri Tann's avatar Siiri Tann
Browse files

TEIS-2199: new endpoint and request and response objects for testing getting...

TEIS-2199: new endpoint and request and response objects for testing getting officials from sequence.
parent 4afd4bd6
package ee.sm.ti.teis.officegateway.official.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.UUID;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OfficialUserInSequenceDto {
private UUID officialUserId;
private String firstName;
private String lastName;
}
package ee.sm.ti.teis.officegateway.official.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
public class GetOfficialFromSequenceTestRequest extends AbstractDTO<String, ErrorDTO> {
public static final String ROUTING_KEY = "api.GetOfficialFromSequenceTestRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.officegateway.official.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserInSequenceDto;
public class GetOfficialFromSequenceTestResponse extends AbstractDTO<OfficialUserInSequenceDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.GetOfficialFromSequenceTestResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.officegateway.official;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase;
import ee.sm.ti.teis.officegateway.official.controller.OfficialsTestController;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserData;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserInSequenceDto;
import ee.sm.ti.teis.officegateway.official.request.CreateOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.request.GetOfficialFromSequenceTestRequest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase.MOCK_ROLE;
import static java.util.UUID.randomUUID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser(roles = MOCK_ROLE)
class OfficialsTestControllerTest extends OfficeApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
private static final String BASE_URL = "/officials/";
@Autowired
OfficialsTestController officialsController;
MockMvcUtil mockMvcUtil;
@Test
void createOfficialUser_success() {
when(requestProcessingService.sendAndReceive(any(CreateOfficialUserRequest.class)))
.thenReturn(new OfficialUserDto());
mockMvcUtil.testPost(BASE_URL, new OfficialUserData(), new TypeReference<OfficialUserDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateOfficialUserRequest.class));
}
@Test
void createOfficialUser_test() {
OfficialUserData newUser = new OfficialUserData();
newUser.setFirstName("First");
newUser.setLastName("Last");
newUser.setIdCode("idCode");
void deleteOfficialUser_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
assertThrows(NoResponseFromRabbitException.class, () -> officialsController.create(newUser, REQUEST_META_DTO));
verify(requestProcessingService).sendAndReceive(any(DeleteOfficialUserRequest.class));
}
@Test
void deleteOfficialUser_test() {
assertThrows(NoResponseFromRabbitException.class, () -> officialsController.delete(UUID.randomUUID(), REQUEST_META_DTO));
void getOfficialFromSequence_success() {
when(requestProcessingService.sendAndReceive(any(GetOfficialFromSequenceTestRequest.class)))
.thenReturn(new OfficialUserInSequenceDto());
parameters.add("code", "code");
mockMvcUtil.testGet(BASE_URL + "official-from-sequence", parameters, new TypeReference<OfficialUserInSequenceDto>() {
});
verify(requestProcessingService).sendAndReceive(any(GetOfficialFromSequenceTestRequest.class));
}
}
package ee.sm.ti.teis.officegateway.official.controller;
import ee.sm.ti.teis.gatewaycommon.controller.TeisBaseController;
import ee.sm.ti.teis.gatewaycommon.rabbit.RequestProcessingService;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserData;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserInSequenceDto;
import ee.sm.ti.teis.officegateway.official.request.CreateOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.service.OfficialsProcessingService;
import ee.sm.ti.teis.officegateway.official.request.GetOfficialFromSequenceTestRequest;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
......@@ -20,7 +22,7 @@ import java.util.UUID;
@RequiredArgsConstructor
public class OfficialsTestController extends TeisBaseController {
private final OfficialsProcessingService processingService;
private final RequestProcessingService service;
@ApiOperation(value = "${teis.api.messages.post-officials}", response = OfficialUserDto.class)
@PostMapping
......@@ -28,7 +30,7 @@ public class OfficialsTestController extends TeisBaseController {
CreateOfficialUserRequest request = new CreateOfficialUserRequest();
request.setPayload(new CreateOfficialUserRequest.Parameters(fromDataToDto(item)), requestMetaDTO);
return processingService.create(request);
return (OfficialUserDto) service.sendAndReceive(request);
}
@ApiOperation(value = "${teis.api.messages.delete-officials}")
......@@ -37,7 +39,16 @@ public class OfficialsTestController extends TeisBaseController {
DeleteOfficialUserRequest request = new DeleteOfficialUserRequest();
request.setPayload(id, requestMetaDTO);
processingService.delete(request);
service.sendAndReceive(request);
}
@ApiOperation(value = "${teis.api.messages.get-official-from-sequence}", response = OfficialUserInSequenceDto.class)
@GetMapping("official-from-sequence")
public OfficialUserInSequenceDto getOfficialFromSequence(@RequestParam String code, RequestMetaDTO requestMetaDTO) {
GetOfficialFromSequenceTestRequest request = new GetOfficialFromSequenceTestRequest();
request.setPayload(code, requestMetaDTO);
return (OfficialUserInSequenceDto) service.sendAndReceive(request);
}
private OfficialUserDto fromDataToDto(OfficialUserData data) {
......
......@@ -2,8 +2,12 @@ package ee.sm.ti.teis.officegateway.official.service;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.request.*;
import ee.sm.ti.teis.officegateway.official.response.*;
import ee.sm.ti.teis.officegateway.official.request.OfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialUsersRequest;
import ee.sm.ti.teis.officegateway.official.request.UpdateOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.response.OfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.response.OfficialUsersResponse;
import ee.sm.ti.teis.officegateway.official.response.UpdateOfficialUserResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
......@@ -17,14 +21,6 @@ public class OfficialsProcessingService {
private final RabbitTemplate gwRabbitTemplate;
public OfficialUserDto create(CreateOfficialUserRequest request) {
CreateOfficialUserResponse response = (CreateOfficialUserResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
public OfficialUserDto getOfficialUser(OfficialUserRequest request) {
OfficialUserResponse response = (OfficialUserResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
......@@ -41,15 +37,6 @@ public class OfficialsProcessingService {
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
public void delete(DeleteOfficialUserRequest request) {
DeleteOfficialUserResponse response = (DeleteOfficialUserResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
response.processResponse();
return;
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
public OfficialUserDto update(UpdateOfficialUserRequest request) {
UpdateOfficialUserResponse response = (UpdateOfficialUserResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
......
......@@ -5,6 +5,7 @@ teis.api.messages.get-officials.idCode: Töötaja isikukood.
teis.api.messages.get-officials.officialsGroupId: Rakkerühma kood.
teis.api.messages.get-officials.objectStatus: Vaikimisi CURRENT, kehtivad andmed. Kui objectStatus = X, tagastatakse kõik andmeobjektid.
teis.api.messages.delete-officials: Teenus kustutab TI töötaja andmed.
teis.api.messages.get-official-from-sequence: Teenus väljastab järjekorrast ühe TI töötaja (OfficialUser) andmeobjekti. Teenust kasutab teine teenus, näiteks tööõnnetuste teenus kasutab selleks, et valida tööõnnetuse haldaja.
teis.api.messages.patch-officials: Teenus salvestab TI töötajate andmetesse rakkerühma kuulumise andmed.
teis.api.messages.get-officials-groups: Teenus väljastab TI valdkondade andmed.
......
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