Commit dbfdbaae authored by Siiri's avatar Siiri
Browse files

TEIS-2109: improved tests.

parent 086bc362
package ee.sm.ti.teis.officegateway.role.definition;
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.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.officegateway.role.definition.privilege.dto.AdminRolePrivilegeDto;
import ee.sm.ti.teis.officegateway.role.definition.privilege.request.AdminPrivilegesRequest;
import ee.sm.ti.teis.officegateway.role.definition.request.CreateRoleDefinitionRequest;
import ee.sm.ti.teis.officegateway.role.definition.request.DeleteRoleDefinitionRequest;
import ee.sm.ti.teis.officegateway.role.definition.request.UpdateRoleDefinitionRequest;
import org.junit.jupiter.api.Test;
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 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 RoleDefinitionControllerTest extends OfficeApiGatewayTestBase {
private static final String BASE_URL = "/role-definitions/";
@Autowired
RoleDefinitionController controller;
MockMvcUtil mockMvcUtil;
@Test
void create_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.create(new RoleDefinitionDto(), new RequestMetaDTO()));
void create_success() {
when(requestProcessingService.sendAndReceive(any(CreateRoleDefinitionRequest.class)))
.thenReturn(new RoleDefinitionDto());
mockMvcUtil.testPost(BASE_URL, new RoleDefinitionDto(), new TypeReference<RoleDefinitionDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateRoleDefinitionRequest.class));
}
@Test
void update_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.update(randomUUID(), new RoleDefinitionDto(), new RequestMetaDTO()));
void update_success() {
when(requestProcessingService.sendAndReceive(any(UpdateRoleDefinitionRequest.class)))
.thenReturn(new RoleDefinitionDto());
mockMvcUtil.testPut(BASE_URL + randomUUID(), new RoleDefinitionDto(), new TypeReference<RoleDefinitionDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateRoleDefinitionRequest.class));
}
@Test
void delete_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(randomUUID(), new RequestMetaDTO()));
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteRoleDefinitionRequest.class));
}
@Test
void getAdminPrivileges_badRequest() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getAdminPrivileges(randomUUID(), new RequestMetaDTO()));
void getAdminPrivileges_success() {
when(requestProcessingService.sendAndReceive(any(AdminPrivilegesRequest.class)))
.thenReturn(List.of(new AdminRolePrivilegeDto()));
mockMvcUtil.testGet(BASE_URL + randomUUID() + "/privileges", null, new TypeReference<List<AdminRolePrivilegeDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(AdminPrivilegesRequest.class));
}
}
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