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

Merge branch 'TEIS-2073' into 'develop'

Resolve TEIS-2073

Closes TEIS-2073

See merge request teis/common-api-gateway!198
parents f7df3240 626fbb6b
package ee.sm.ti.teis.commongateway.admin;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.MessageFileReferenceDto;
import ee.sm.ti.teis.commongateway.messages.message.request.CreateMessageFileReferencesRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
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 java.util.UUID;
import static java.util.Collections.emptyList;
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
public class AdminForTestingControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/admin/";
@Autowired
AdminForTestingController controller;
MockMvcUtil mockMvcUtil;
@Test
void resetMessageEmail_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.resetMessageEmail(randomUUID(), new RequestMetaDTO()));
void resetMessageEmail_success() {
when(requestProcessingService.sendAndReceive(any(ResetMessageEmailRequest.class)))
.thenReturn(randomUUID());
mockMvcUtil.testGet(BASE_URL + "reset-message-email/" + randomUUID(), null, new TypeReference<UUID>() {
});
verify(requestProcessingService).sendAndReceive(any(ResetMessageEmailRequest.class));
}
@Test
void getMessages_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.createFileReferences(randomUUID(), emptyList(), new RequestMetaDTO()));
}
void createFileReferences_success() {
when(requestProcessingService.sendAndReceive(any(CreateMessageFileReferencesRequest.class)))
.thenReturn(List.of(new FileReferenceDto()));
mockMvcUtil.testPost(BASE_URL + "message/" + randomUUID() + "/file-references", List.of(new MessageFileReferenceDto()),
new TypeReference<List<FileReferenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateMessageFileReferencesRequest.class));
}
}
package ee.sm.ti.teis.commongateway.admin;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.LocalDateTime;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class DeadlineControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/deadline";
@Autowired
DeadlineController controller;
MockMvcUtil mockMvcUtil;
@Test
void getDeadline_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getDeadline(new GetDeadlineDto(), new RequestMetaDTO()));
}
void getDeadline_success() {
when(requestProcessingService.sendAndReceive(any(CalculateDeadlineGwRequest.class)))
.thenReturn(LocalDateTime.now());
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<LocalDateTime>() {
});
verify(requestProcessingService).sendAndReceive(any(CalculateDeadlineGwRequest.class));
}
}
package ee.sm.ti.teis.commongateway.admin;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
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
class FeatureFlagControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/feature-flags/";
@Autowired
FeatureFlagController controller;
MockMvcUtil mockMvcUtil;
@Test
void getFeatureFlag_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getFeatureFlag("", new RequestMetaDTO()));
}
void getFeatureFlag_success() {
when(requestProcessingService.sendAndReceive(any(FeatureFlagRequest.class)))
.thenReturn(new FeatureFlagDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<FeatureFlagDto>() {
});
verify(requestProcessingService).sendAndReceive(any(FeatureFlagRequest.class));
}
}
package ee.sm.ti.teis.commongateway.classifier;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.classifier.search.ClassifierItemSearchFilterDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List;
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
class ClassifierControllerTest extends CommonApiGatewayTestBase {
@Autowired
ClassifierController controller;
MockMvcUtil mockMvcUtil;
@Test
void getClassifier_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getClassifier("id", null, null, new RequestMetaDTO()));
void getClassifiers_success() {
when(requestProcessingService.sendAndReceive(any(ClassifierItemsRequest.class)))
.thenReturn(List.of(new ClassifierItemDto()));
mockMvcUtil.testGet("/classifier-items", null, new TypeReference<List<ClassifierItemDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(ClassifierItemsRequest.class));
}
@Test
void getClassifiers_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getClassifiers(new ClassifierItemSearchFilterDto(), new RequestMetaDTO()));
void getClassifier_success() {
when(requestProcessingService.sendAndReceive(any(ClassifierItemRequest.class)))
.thenReturn(new ClassifierItemDto());
mockMvcUtil.testGet("/classifier-items/" + randomUUID(), null, new TypeReference<ClassifierItemDto>() {
});
verify(requestProcessingService).sendAndReceive(any(ClassifierItemRequest.class));
}
@Test
void getDefinition_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getDefinition("id", new RequestMetaDTO()));
}
void getDefinition_success() {
when(requestProcessingService.sendAndReceive(any(ClassifierDefinitionRequest.class)))
.thenReturn(new ClassifierItemDto());
mockMvcUtil.testGet("/classifier-definitions/" + randomUUID() + "/default-value", null, new TypeReference<ClassifierItemDto>() {
});
verify(requestProcessingService).sendAndReceive(any(ClassifierDefinitionRequest.class));
}
}
package ee.sm.ti.teis.commongateway.dumonitor;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
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 org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class DUMonitorTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
private static final String BASE_URL = "/dumonitor";
@Autowired
DUMonitorTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void send_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.send(new PersonalDataUsageDto(), REQUEST_META_DTO));
when(requestProcessingService.sendAndReceive(any(SendPersonalDataUsageRequest.class)))
.thenReturn("{}");
mockMvcUtil.testPost(BASE_URL, new PersonalDataUsageDto(), new TypeReference<String>() {
}, true);
verify(requestProcessingService).sendAndReceive(any(SendPersonalDataUsageRequest.class));
}
}
package ee.sm.ti.teis.commongateway.violation;
package ee.sm.ti.teis.commongateway.file;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.file.FileController;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
......
package ee.sm.ti.teis.commongateway.location;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
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 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
class LocationControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(randomUUID().toString()).build();
private static final String BASE_URL = "/locations/";
@Autowired
LocationController controller;
MockMvcUtil mockMvcUtil;
@Test
void create_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.create(new LocationDto(), REQUEST_META_DTO));
void getLocation_success() {
when(requestProcessingService.sendAndReceive(any(LocationRequest.class)))
.thenReturn(new LocationDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<LocationDto>() {
});
verify(requestProcessingService).sendAndReceive(any(LocationRequest.class));
}
@Test
void delete_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.delete(randomUUID(), REQUEST_META_DTO));
void getLocations_success() {
when(requestProcessingService.sendAndReceive(any(LocationsRequest.class)))
.thenReturn(List.of(new LocationDto()));
parameters.add("employerId", randomUUID().toString());
mockMvcUtil.testGet(BASE_URL, parameters, new TypeReference<List<LocationDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(LocationsRequest.class));
}
@Test
void getLocation_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getLocation(randomUUID(), REQUEST_META_DTO));
void create_success() {
when(requestProcessingService.sendAndReceive(any(CreateLocationRequest.class)))
.thenReturn(new LocationDto());
mockMvcUtil.testPost(BASE_URL, new LocationDto(), new TypeReference<LocationDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateLocationRequest.class));
}
@Test
void getLocations_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getLocations(randomUUID(), REQUEST_META_DTO));
void update_success() {
when(requestProcessingService.sendAndReceive(any(UpdateLocationRequest.class)))
.thenReturn(new LocationDto());
mockMvcUtil.testPut(BASE_URL + randomUUID(), new LocationDto(), new TypeReference<LocationDto>() {
});
verify(requestProcessingService).sendAndReceive(any(UpdateLocationRequest.class));
}
@Test
void update_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.update(randomUUID(), new LocationDto(), REQUEST_META_DTO));
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteLocationRequest.class));
}
@Test
void createLocationsFromTor_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createLocationsFromTor(randomUUID(), REQUEST_META_DTO));
void createLocationsFromTor_success() {
mockMvcUtil.testPost(BASE_URL + "fromTor/" + randomUUID(), randomUUID(), null, true);
verify(requestProcessingService).sendAndReceive(any(CreateLocationsRequest.class));
}
}
package ee.sm.ti.teis.commongateway.messages.message;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.messages.message.dto.CreateMessageDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.MessageDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.MessageWithEmployerDto;
import ee.sm.ti.teis.commongateway.messages.message.dto.PatchMessageDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.messages.message.request.*;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
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 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
public class MessageControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/messages/";
@Autowired
MessageController controller;
MockMvcUtil mockMvcUtil;
@Test
void getMessages() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessages(randomUUID(), "", new RequestMetaDTO()));
void getMessages_success() {
when(requestProcessingService.sendAndReceive(any(MessagesRequest.class)))
.thenReturn(List.of(new MessageDto()));
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<List<MessageDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(MessagesRequest.class));
}
@Test
void patch() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.patch(randomUUID(), new PatchMessageDto(), new RequestMetaDTO()));
void patch_success() {
when(requestProcessingService.sendAndReceive(any(PatchMessageRequest.class)))
.thenReturn(new MessageDto());
mockMvcUtil.testPatch(BASE_URL + randomUUID(), new PatchMessageDto(), new TypeReference<MessageDto>() {
});
verify(requestProcessingService).sendAndReceive(any(PatchMessageRequest.class));
}
@Test
void create() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.create(new CreateMessageDto(), new RequestMetaDTO()));
void create_success() {
when(requestProcessingService.sendAndReceive(any(CreateMessageRequest.class)))
.thenReturn(new MessageDto());
mockMvcUtil.testPost(BASE_URL, new CreateMessageDto(), new TypeReference<MessageDto>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateMessageRequest.class));
}
@Test
void delete() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(randomUUID(), new RequestMetaDTO()));
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteMessageRequest.class));
}
@Test
void getMessagesByAddressee() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessagesByAddressee(null, null, "", new RequestMetaDTO()));
void getMessagesByAddressee_success() {
when(requestProcessingService.sendAndReceive(any(MessagesByAddresseeRequest.class)))
.thenReturn(List.of(new MessageWithEmployerDto()));
mockMvcUtil.testGet(BASE_URL + "by-addressee", null, new TypeReference<List<MessageWithEmployerDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(MessagesByAddresseeRequest.class));
}
}
package ee.sm.ti.teis.commongateway.messages.message;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.commongateway.messages.message.dto.MessageTestDto;
import ee.sm.ti.teis.commongateway.messages.message.request.MessageRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
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
public class MessageTestControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/messages/test/";
@Autowired
MessageTestController controller;
MockMvcUtil mockMvcUtil;
@Test
void getMessage_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessage(randomUUID(), new RequestMetaDTO()));
void getMessage_success() {
when(requestProcessingService.sendAndReceive(any(MessageRequest.class)))
.thenReturn(new MessageTestDto());
mockMvcUtil.testGet(BASE_URL + randomUUID(), null, new TypeReference<MessageTestDto>() {
});
verify(requestProcessingService).sendAndReceive(any(MessageRequest.class));
}
}
......@@ -37,7 +37,7 @@ public class ClaimTestControllerTest extends CommonApiGatewayTestBase {
@Test
void patch_success() {
mockMvcUtil.testPatch(BASE_URL, new PatchClaimDto());
mockMvcUtil.testPatch(BASE_URL, new PatchClaimDto(), null);
verify(requestProcessingService).sendAndReceive(any(PatchClaimRequest.class));
}
......
package ee.sm.ti.teis.commongateway.person;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import static java.math.BigInteger.ONE;
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;