Commit 2e602895 authored by Siiri Tann's avatar Siiri Tann
Browse files

Resolve TEIS-2109 "Refactos"

parent 0f5cd605
package ee.sm.ti.teis.officegateway.official; 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.OfficeApiGatewayTestBase;
import ee.sm.ti.teis.officegateway.official.controller.OfficesController; import ee.sm.ti.teis.officegateway.official.dto.OfficeDto;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.officegateway.official.request.OfficesRequest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows; import static ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase.MOCK_ROLE;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser(roles = MOCK_ROLE)
public class OfficesControllerTest extends OfficeApiGatewayTestBase { public class OfficesControllerTest extends OfficeApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
@Autowired @Autowired
OfficesController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void findOffices_test() { void findOffices_success() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getOffices(REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(OfficesRequest.class)))
.thenReturn(List.of(new OfficeDto()));
mockMvcUtil.testGet("/offices", null, new TypeReference<List<OfficeDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(OfficesRequest.class));
} }
} }
package ee.sm.ti.teis.officegateway.official; 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.OfficeApiGatewayTestBase;
import ee.sm.ti.teis.officegateway.official.controller.OfficialsController; import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserUpdateData; import ee.sm.ti.teis.officegateway.official.dto.OfficialUserUpdateData;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; 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 org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID; import java.util.List;
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 OfficialsControllerTest extends OfficeApiGatewayTestBase { class OfficialsControllerTest extends OfficeApiGatewayTestBase {
private static final UUID OFFICIAL_USER_ID = UUID.fromString("3dac227f-a8af-4771-8d8b-01409ac7fef0"); private static final String BASE_URL = "/officials/";
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
@Autowired @Autowired
OfficialsController officialsController; MockMvcUtil mockMvcUtil;
@Test @Test
void findOfficialUser_test() { void getOfficialUser_success() {
assertThrows(NoResponseFromRabbitException.class, () -> officialsController.getOfficialUser(OFFICIAL_USER_ID, REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(OfficialUserRequest.class)))
.thenReturn(new OfficialUserDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<OfficialUserDto>() {
});
verify(requestProcessingService).sendAndReceive(any(OfficialUserRequest.class));
} }
@Test @Test
void findOfficialUsers_test() { void getOfficialUsers_success() {
assertThrows(NoResponseFromRabbitException.class, when(requestProcessingService.sendAndReceive(any(OfficialUsersRequest.class)))
() -> officialsController.getOfficialUsers("36609107656", OFFICIAL_USER_ID, "CURRENT", REQUEST_META_DTO)); .thenReturn(List.of(new OfficialUserDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<OfficialUserDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(OfficialUsersRequest.class));
} }
@Test @Test
void patchOfficialUser_test() { void update_success() {
OfficialUserUpdateData userUpdateData = new OfficialUserUpdateData(); when(requestProcessingService.sendAndReceive(any(UpdateOfficialUserRequest.class)))
userUpdateData.setOfficialsGroupId(OFFICIAL_USER_ID); .thenReturn(new OfficialUserDto());
mockMvcUtil.testPatch(BASE_URL + randomUUID() + "/official-group", new OfficialUserUpdateData(),
new TypeReference<OfficialUserDto>() {
});
assertThrows(NoResponseFromRabbitException.class, () -> officialsController.update(OFFICIAL_USER_ID, userUpdateData, REQUEST_META_DTO)); verify(requestProcessingService).sendAndReceive(any(UpdateOfficialUserRequest.class));
} }
} }
package ee.sm.ti.teis.officegateway.official; 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.OfficeApiGatewayTestBase;
import ee.sm.ti.teis.officegateway.official.controller.OfficialsGroupsController; import ee.sm.ti.teis.officegateway.official.controller.OfficialsGroupsController;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupData; import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupData;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupDto;
import ee.sm.ti.teis.officegateway.official.request.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID; import java.util.List;
import static java.util.Collections.emptyList; import static ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase.MOCK_ROLE;
import static org.junit.jupiter.api.Assertions.assertThrows; 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 OfficialsGroupsControllerTest extends OfficeApiGatewayTestBase { class OfficialsGroupsControllerTest extends OfficeApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build(); private static final String BASE_URL = "/officials-groups/";
@Autowired @Autowired
OfficialsGroupsController groupsController; OfficialsGroupsController groupsController;
@Autowired
MockMvcUtil mockMvcUtil;
@Test @Test
void findOfficialsGroups_test() { void getOfficialsGroups_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsController.getOfficialsGroups(null, REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(OfficialsGroupsRequest.class)))
.thenReturn(List.of(new OfficialsGroupDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<OfficialsGroupDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(OfficialsGroupsRequest.class));
} }
@Test @Test
void findOfficialGroups_test() { void getOfficialGroup_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsController.getOfficialsGroup(null, REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(OfficialsGroupRequest.class)))
.thenReturn(new OfficialsGroupDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<OfficialsGroupDto>() {
});
verify(requestProcessingService).sendAndReceive(any(OfficialsGroupRequest.class));
} }
@Test @Test
void createOfficialsGroups_test() { void create_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsController.create(new OfficialsGroupData(), REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(CreateOfficialsGroupRequest.class)))
.thenReturn(new OfficialsGroupDto());
mockMvcUtil.testPost(BASE_URL, new OfficialsGroupData(), new TypeReference<OfficialsGroupDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateOfficialsGroupRequest.class));
} }
@Test @Test
void deleteOfficialsGroups_test() { void update_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsController.delete(null, REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(UpdateOfficialsGroupRequest.class)))
.thenReturn(new OfficialsGroupDto());
mockMvcUtil.testPut(BASE_URL + randomUUID(), new OfficialsGroupData(), new TypeReference<OfficialsGroupDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateOfficialsGroupRequest.class));
} }
@Test @Test
void updateOfficialsGroups_test() { void delete_success() {
assertThrows( mockMvcUtil.testDelete(BASE_URL + randomUUID());
NoResponseFromRabbitException.class,
() -> groupsController.update(UUID.randomUUID(), new OfficialsGroupData(), REQUEST_META_DTO)); verify(requestProcessingService).sendAndReceive(any(DeleteOfficialsGroupRequest.class));
} }
@Test @Test
void addOfficialsToGroup_test() { void addOfficialsToGroup_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsController.addOfficialsToGroup(null, emptyList(), REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(AddOfficialsGroupMembersRequest.class)))
.thenReturn(List.of(new OfficialUserDto()));
mockMvcUtil.testPost(BASE_URL + randomUUID() + "/officials", List.of(randomUUID()), new TypeReference<List<OfficialUserDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(AddOfficialsGroupMembersRequest.class));
} }
@Test @Test
void deleteOfficialFromGroup_test() { void deleteOfficialFromGroup_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsController.deleteOfficialFromGroup(null, null, REQUEST_META_DTO)); mockMvcUtil.testDelete(BASE_URL + randomUUID() + "/officials/" + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteOfficialsGroupMemberRequest.class));
} }
} }
package ee.sm.ti.teis.officegateway.official; 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.OfficeApiGatewayTestBase;
import ee.sm.ti.teis.officegateway.official.controller.OfficialsGroupsEmtakController; import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupEmtakCodesData;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupEmtakDto;
import ee.sm.ti.teis.officegateway.official.request.CreateOfficialsGroupEmtakCodesRequest;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialsGroupEmtakRequest;
import ee.sm.ti.teis.officegateway.official.request.OfficialsGroupEmtakCodesRequest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.UUID; import java.util.List;
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)
public class OfficialsGroupsEmtakControllerTest extends OfficeApiGatewayTestBase { public class OfficialsGroupsEmtakControllerTest extends OfficeApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build(); private static final String BASE_URL = "/officials-groups-emtak/";
@Autowired @Autowired
OfficialsGroupsEmtakController groupsEmtakController; MockMvcUtil mockMvcUtil;
@Test @Test
void findOfficialsGroupEmtakCodes_test() { void getOfficialsGroupEmtakCodes_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsEmtakController.getOfficialsGroupEmtakCodes(null, null, null, REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(OfficialsGroupEmtakCodesRequest.class)))
.thenReturn(List.of(new OfficialsGroupEmtakDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<OfficialsGroupEmtakDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(OfficialsGroupEmtakCodesRequest.class));
} }
@Test @Test
void createOfficialsGroupEmtakCodes_test() { void create_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsEmtakController.create(null, REQUEST_META_DTO)); when(requestProcessingService.sendAndReceive(any(CreateOfficialsGroupEmtakCodesRequest.class)))
.thenReturn(List.of(new OfficialsGroupEmtakDto()));
mockMvcUtil.testPost(BASE_URL, new OfficialsGroupEmtakCodesData(), new TypeReference<List<OfficialsGroupEmtakDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateOfficialsGroupEmtakCodesRequest.class));
} }
@Test @Test
void deleteOfficialsGroupEmtak_test() { void deleteOfficialsGroupEmtak_success() {
assertThrows(NoResponseFromRabbitException.class, () -> groupsEmtakController.delete(null, REQUEST_META_DTO)); mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteOfficialsGroupEmtakRequest.class));
} }
} }
package ee.sm.ti.teis.officegateway.parameter; package ee.sm.ti.teis.officegateway.parameter;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.parameter.dto.AdminParameterDto;
import ee.sm.ti.teis.commongateway.parameter.dto.UpdateParameterValueDto;
import ee.sm.ti.teis.commongateway.parameter.request.AdminParametersRequest;
import ee.sm.ti.teis.commongateway.parameter.request.UpdateParameterValueRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase; import ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.Set;
import static ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase.MOCK_ROLE;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser(roles = MOCK_ROLE)
public class ParameterControllerTest extends OfficeApiGatewayTestBase { public class ParameterControllerTest extends OfficeApiGatewayTestBase {
private static final String BASE_URL = "/parameters/";
@Autowired @Autowired
ParameterController controller; ParameterController controller;
@Autowired
MockMvcUtil mockMvcUtil;
@Test @Test
void getParameters_badRequest() { void getParameters_badRequest() {
...@@ -19,7 +37,24 @@ public class ParameterControllerTest extends OfficeApiGatewayTestBase { ...@@ -19,7 +37,24 @@ public class ParameterControllerTest extends OfficeApiGatewayTestBase {
} }
@Test @Test
void getAdminParameters_badRequest() { void getAdminParameters_success() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getAdminParameters(new RequestMetaDTO())); when(requestProcessingService.sendAndReceive(any(AdminParametersRequest.class)))
.thenReturn(Set.of(new AdminParameterDto()));
mockMvcUtil.testGet(BASE_URL + "admin", null, new TypeReference<Set<AdminParameterDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(AdminParametersRequest.class));
}
@Test
void updateParameterValue_success() {
when(requestProcessingService.sendAndReceive(any(UpdateParameterValueRequest.class)))
.thenReturn(new AdminParameterDto());
mockMvcUtil.testPatch(BASE_URL + "code/value", new UpdateParameterValueDto(), new TypeReference<AdminParameterDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateParameterValueRequest.class));
} }
} }
package ee.sm.ti.teis.officegateway.payments.claim; package ee.sm.ti.teis.officegateway.payments.claim;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimDefinitionDto; import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimDefinitionDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase; import ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.officegateway.payments.payment.request.ClaimDefinitionsRequest;
import ee.sm.ti.teis.officegateway.payments.payment.request.UpdateClaimDefinitionRequest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static ee.sm.ti.teis.officegateway.OfficeApiGatewayTestBase.MOCK_ROLE;
import static java.util.UUID.randomUUID; import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser(roles = MOCK_ROLE)
class ClaimDefinitionsControllerTest extends OfficeApiGatewayTestBase { class ClaimDefinitionsControllerTest extends OfficeApiGatewayTestBase {
private static final String BASE_URL = "/claim-definitions/";
@Autowired @Autowired
ClaimDefinitionsController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void create_badRequest() { void getClaimDefinitions_success() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getClaimDefinitions(new RequestMetaDTO())); when(requestProcessingService.sendAndReceive(any(ClaimDefinitionsRequest.class)))
.thenReturn(List.of(new ClaimDefinitionDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<ClaimDefinitionDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(ClaimDefinitionsRequest.class));
} }
@Test @Test
void update_badRequest() { void updateClaimDefinition_success() {
assertThrows(NoResponseFromRabbitException.class, () -> when(requestProcessingService.sendAndReceive(any(UpdateClaimDefinitionRequest.class)))
controller.updateClaimDefinition(randomUUID(), new ClaimDefinitionDto(), new RequestMetaDTO())); .thenReturn(new ClaimDefinitionDto());
mockMvcUtil.testPut(BASE_URL + randomUUID(), new ClaimDefinitionDto(), new TypeReference<ClaimDefinitionDto>() {
});