Commit 3e5ceb87 authored by Raigo Ukkivi's avatar Raigo Ukkivi
Browse files

TEIS-174. Tests.

parent 53a14cc8
......@@ -77,11 +77,11 @@ allprojects {
csv.enabled true
}
beforeEvaluate {
classDirectories = files(classDirectories.files.collect {
getClassDirectories().setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**/*MapperImpl**'
])
})
}))
}
}
......
theGroup=ee.sm.ti.teis
theVersion=0.1.0-SNAPSHOT
commonsVersion=0.10.22-SNAPSHOT
commonsVersion=0.10.25-SNAPSHOT
officeApiGatewayVersion=0.1.0-SNAPSHOT
pluginVersion=0.0.10-SNAPSHOT
mapstructVersion=1.3.0.Final
lombokVersion=1.18.2
junitVersion=5.4.2
\ No newline at end of file
junitVersion=5.4.2
......@@ -18,12 +18,15 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@ActiveProfiles("integtest")
@Testcontainers
@ContextConfiguration(initializers = { OfficialsAppTestBase.Initializer.class })
@DirtiesContext
public abstract class OfficialsAppTestBase {
@Container
private static GenericContainer rabbitMQContainer = new GenericContainer("rabbitmq:latest")
.withExposedPorts(5672);
private static GenericContainer rabbitMQContainer;
// to speed up tests, lets use static container, it is used in alla test classes that are executed inside one Spring Context
static {
rabbitMQContainer = new GenericContainer("rabbitmq:latest").withExposedPorts(5672);
rabbitMQContainer.start();
}
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
......
package ee.sm.ti.teis.officials.group;
import ee.sm.ti.teis.domain.enums.ObjectStatus;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupsRequest;
import ee.sm.ti.teis.officegateway.official.OfficialsGroupsResponse;
import ee.sm.ti.teis.officials.OfficialsAppTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Objects;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("squid:S00100")
class OfficialsGroupListenerTest extends OfficialsAppTestBase {
static final RequestMetaDTO REQUEST_META_DTO = new RequestMetaDTO();
@Autowired
OfficialsGroupListener groupListener;
@Test
void findOfficialsGroups_default_status_is_current() {
OfficialsGroupsRequest request = composeOfficialsGroupsRequest(null);
OfficialsGroupsResponse response = groupListener.findOfficialsGroups(request);
assertThat(response.getPayload().stream().allMatch(g -> g.getObjectStatus() == ObjectStatus.CURRENT)).isTrue();
}
@NotNull
private OfficialsGroupsRequest composeOfficialsGroupsRequest(String status) {
OfficialsGroupsRequest request = new OfficialsGroupsRequest();
request.setPayload(new OfficialsGroupsRequest.Parameters(status), REQUEST_META_DTO);
return request;
}
}
package ee.sm.ti.teis.officials.group;
import ee.sm.ti.teis.domain.enums.ObjectStatus;
import ee.sm.ti.teis.exceptions.TeisIllegalArgumentException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ExtendWith(MockitoExtension.class)
class OfficialsGroupServiceTest {
@Spy
OfficialsGroupMapper mapper = new OfficialsGroupMapperImpl();
@Mock
OfficialsGroupRepository repository;
@InjectMocks
OfficialsGroupService service;
@Test
void validateAndAssignDefaultStatus_should_throw_exception_if_illegal_status() {
assertThrows(TeisIllegalArgumentException.class, () -> service.validateAndAssignDefaultStatus("blah"));
}
@Test
void validateAndAssignDefaultStatus_should_return_default_status_on_empty_input() {
assertThat(service.validateAndAssignDefaultStatus(null)).isEqualTo(ObjectStatus.CURRENT);
}
@Test
void validateAndAssignDefaultStatus_should_return_null_on_X_input() {
assertThat(service.validateAndAssignDefaultStatus("X")).isNull();
}
@Test
void validateAndAssignDefaultStatus_should_return_current_status() {
assertThat(service.validateAndAssignDefaultStatus("CURRENT")).isEqualTo(ObjectStatus.CURRENT);
}
}
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