Skip to content
Snippets Groups Projects
Commit e082b65d authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3928 fix ITCase; refactor tests to G/W/T

parent e896bbf2
Branches
Tags
No related merge requests found
...@@ -94,12 +94,16 @@ public class CurrentUserService { ...@@ -94,12 +94,16 @@ public class CurrentUserService {
} }
public Optional<UserId> findUserId() { public Optional<UserId> findUserId() {
return Optional.ofNullable( return Optional.ofNullable(getSingleClaimValue(ATTRIBUTE_NAME_USER_ID)
getSingleClaimValue(ATTRIBUTE_NAME_USER_ID).map(UserId::from) .map(UserId::from)
.orElseGet(() -> userService.getInternalId(CurrentUserHelper.getCurrentUserId()).orElse(null))) .orElseGet(this::getInternalId))
.filter(Objects::nonNull); .filter(Objects::nonNull);
} }
private UserId getInternalId() {
return userService.getInternalId(CurrentUserHelper.getCurrentUserId()).orElse(null);
}
List<String> getOrganisationsEinheitIds(Jwt jwt) { List<String> getOrganisationsEinheitIds(Jwt jwt) {
return Optional.ofNullable(jwt) return Optional.ofNullable(jwt)
.map(token -> token.getClaim(USER_ATTRIBUTE_ORGANISATIONSEINHEIT_ID)) .map(token -> token.getClaim(USER_ATTRIBUTE_ORGANISATIONSEINHEIT_ID))
......
...@@ -36,7 +36,6 @@ import java.util.stream.Stream; ...@@ -36,7 +36,6 @@ import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hamcrest.core.StringEndsWith; import org.hamcrest.core.StringEndsWith;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -54,6 +53,7 @@ import de.ozgcloud.alfa.common.attacheditem.VorgangAttachedItemTestFactory; ...@@ -54,6 +53,7 @@ import de.ozgcloud.alfa.common.attacheditem.VorgangAttachedItemTestFactory;
import de.ozgcloud.alfa.common.clientattribute.ClientAttributeService; import de.ozgcloud.alfa.common.clientattribute.ClientAttributeService;
import de.ozgcloud.alfa.common.command.CommandController; import de.ozgcloud.alfa.common.command.CommandController;
import de.ozgcloud.alfa.common.errorhandling.ResourceNotFoundException; import de.ozgcloud.alfa.common.errorhandling.ResourceNotFoundException;
import de.ozgcloud.alfa.common.user.CurrentUserService;
import de.ozgcloud.alfa.common.user.UserProfileTestFactory; import de.ozgcloud.alfa.common.user.UserProfileTestFactory;
import de.ozgcloud.alfa.common.user.UserService; import de.ozgcloud.alfa.common.user.UserService;
import de.ozgcloud.alfa.postfach.PostfachMailController; import de.ozgcloud.alfa.postfach.PostfachMailController;
...@@ -63,7 +63,6 @@ import de.ozgcloud.alfa.statistic.StatisticTestFactory; ...@@ -63,7 +63,6 @@ import de.ozgcloud.alfa.statistic.StatisticTestFactory;
import de.ozgcloud.alfa.vorgang.forwarding.ForwardingController; import de.ozgcloud.alfa.vorgang.forwarding.ForwardingController;
import de.ozgcloud.alfa.wiedervorlage.WiedervorlageTestFactory; import de.ozgcloud.alfa.wiedervorlage.WiedervorlageTestFactory;
@Disabled
@AutoConfigureMockMvc @AutoConfigureMockMvc
@SpringBootTest @SpringBootTest
@WithMockUser @WithMockUser
...@@ -84,29 +83,23 @@ class VorgangControllerITCase { ...@@ -84,29 +83,23 @@ class VorgangControllerITCase {
@MockBean @MockBean
private VorgangAttachedItemService vorgangAttachedItemService; private VorgangAttachedItemService vorgangAttachedItemService;
@Autowired @MockBean
private MockMvc mockMvc; private CurrentUserService currentUserService;
@MockBean @MockBean
private UserService userService; private UserService userService;
@BeforeEach @Autowired
void prepareUserService() { private MockMvc mockMvc;
when(userService.getInternalId(any())).thenReturn(Optional.of(UserProfileTestFactory.INTERNAL_ID));
}
@BeforeEach @BeforeEach
void prepareStatisticController() { void mock() {
when(currentUserService.getUser()).thenReturn(UserProfileTestFactory.create());
when(userService.getInternalId(any())).thenReturn(Optional.of(UserProfileTestFactory.INTERNAL_ID));
when(statisticController.getVorgaengeStatistic()).thenReturn(StatisticTestFactory.create()); when(statisticController.getVorgaengeStatistic()).thenReturn(StatisticTestFactory.create());
}
@BeforeEach
void prepareVorgangAttachedItemService() {
when(vorgangAttachedItemService.findLoeschAnforderung(anyString())).thenReturn(Stream.of(VorgangAttachedItemTestFactory.create())); when(vorgangAttachedItemService.findLoeschAnforderung(anyString())).thenReturn(Stream.of(VorgangAttachedItemTestFactory.create()));
} }
@DisplayName("Vorganglist by page and limit") @DisplayName("Vorganglist by page and limit")
@WithMockUser
@Nested @Nested
class TestVorgangListByPage { class TestVorgangListByPage {
...@@ -122,12 +115,16 @@ class VorgangControllerITCase { ...@@ -122,12 +115,16 @@ class VorgangControllerITCase {
@Test @Test
void shouldReturnResult() throws Exception { void shouldReturnResult() throws Exception {
doRequest().andExpect(jsonPath("$._embedded.vorgangHeaderList[0].nextFrist").value(WiedervorlageTestFactory.FRIST_STR)); var response = doRequest();
response.andExpect(jsonPath("$._embedded.vorgangHeaderList[0].nextFrist").value(WiedervorlageTestFactory.FRIST_STR));
} }
@Test @Test
void shouldReturnStatusOk() throws Exception { void shouldReturnStatusOk() throws Exception {
doRequest().andExpect(status().isOk()); var response = doRequest();
response.andExpect(status().isOk());
} }
private ResultActions doRequest() throws Exception { private ResultActions doRequest() throws Exception {
...@@ -146,43 +143,56 @@ class VorgangControllerITCase { ...@@ -146,43 +143,56 @@ class VorgangControllerITCase {
@Test @Test
void shouldContainsNeu() throws Exception { void shouldContainsNeu() throws Exception {
doRequest().andExpect(jsonPath(BY_STATUS_PATH + "neu").value(ByStatusTestFactory.NEU_COUNT)); var response = doRequest();
response.andExpect(jsonPath(BY_STATUS_PATH + "neu").value(ByStatusTestFactory.NEU_COUNT));
} }
@Test @Test
void shouldContainsAngenommen() throws Exception { void shouldContainsAngenommen() throws Exception {
doRequest().andExpect(jsonPath(BY_STATUS_PATH + "angenommen").value(ByStatusTestFactory.ANGENOMMEN_COUNT)); var response = doRequest();
response.andExpect(jsonPath(BY_STATUS_PATH + "angenommen").value(ByStatusTestFactory.ANGENOMMEN_COUNT));
} }
@Test @Test
void shouldContainsInBearbeitung() throws Exception { void shouldContainsInBearbeitung() throws Exception {
doRequest().andExpect(jsonPath(BY_STATUS_PATH + "inBearbeitung").value(ByStatusTestFactory.IN_BEARBEITUNG_COUNT)); var response = doRequest();
response.andExpect(jsonPath(BY_STATUS_PATH + "inBearbeitung").value(ByStatusTestFactory.IN_BEARBEITUNG_COUNT));
} }
@Test @Test
void shouldContainsBeschieden() throws Exception { void shouldContainsBeschieden() throws Exception {
doRequest().andExpect(jsonPath(BY_STATUS_PATH + "beschieden").value(ByStatusTestFactory.BESCHIEDEN_COUNT)); var response = doRequest();
response.andExpect(jsonPath(BY_STATUS_PATH + "beschieden").value(ByStatusTestFactory.BESCHIEDEN_COUNT));
} }
@Test @Test
void shouldContainsAbgeschlossen() throws Exception { void shouldContainsAbgeschlossen() throws Exception {
doRequest().andExpect(jsonPath(BY_STATUS_PATH + "abgeschlossen").value(ByStatusTestFactory.ABGESCHLOSSEN_COUNT)); var response = doRequest();
response.andExpect(jsonPath(BY_STATUS_PATH + "abgeschlossen").value(ByStatusTestFactory.ABGESCHLOSSEN_COUNT));
} }
@Test @Test
void shouldContainsVerworfen() throws Exception { void shouldContainsVerworfen() throws Exception {
doRequest().andExpect(jsonPath(BY_STATUS_PATH + "verworfen").value(ByStatusTestFactory.VERWORFEN_COUNT)); var response = doRequest();
response.andExpect(jsonPath(BY_STATUS_PATH + "verworfen").value(ByStatusTestFactory.VERWORFEN_COUNT));
} }
} }
@Test @Test
void shouldContainsWiedervorlagen() throws Exception { void shouldContainsWiedervorlagen() throws Exception {
doRequest().andExpect(jsonPath("$.statistic.wiedervorlagen").value(StatisticTestFactory.COUNT_WIEDERVORLAGEN)); var response = doRequest();
response.andExpect(jsonPath("$.statistic.wiedervorlagen").value(StatisticTestFactory.COUNT_WIEDERVORLAGEN));
} }
} }
} }
@WithMockUser
@Nested @Nested
class TestGetSingleVorgang { class TestGetSingleVorgang {
...@@ -192,26 +202,31 @@ class VorgangControllerITCase { ...@@ -192,26 +202,31 @@ class VorgangControllerITCase {
void shouldReturnNotFound() throws Exception { void shouldReturnNotFound() throws Exception {
when(remoteService.findVorgangWithEingang(anyString(), any())).thenThrow(new ResourceNotFoundException(Vorgang.class, StringUtils.EMPTY)); when(remoteService.findVorgangWithEingang(anyString(), any())).thenThrow(new ResourceNotFoundException(Vorgang.class, StringUtils.EMPTY));
doRequest().andExpect(status().isNotFound()); var response = doRequest();
response.andExpect(status().isNotFound());
} }
@Test @Test
void shouldFormatDateTime() throws Exception { void shouldFormatDateTime() throws Exception {
when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create()); when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create());
doRequest().andExpect(status().isOk()).andExpect(jsonPath("$.createdAt").value(VorgangHeaderTestFactory.CREATED_AT_STR)); var response = doRequest();
response.andExpect(status().isOk()).andExpect(jsonPath("$.createdAt").value(VorgangHeaderTestFactory.CREATED_AT_STR));
} }
@Test @Test
void shouldHaveAnnehmenLink() throws Exception { void shouldHaveAnnehmenLink() throws Exception {
when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create()); when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create());
doRequest().andExpect(jsonPath("$._links.annehmen.href") var response = doRequest();
response.andExpect(jsonPath("$._links.annehmen.href")
.value("http://localhost/api/vorgangs/" + VorgangHeaderTestFactory.ID + "/relations/" + VorgangHeaderTestFactory.ID + "/" .value("http://localhost/api/vorgangs/" + VorgangHeaderTestFactory.ID + "/relations/" + VorgangHeaderTestFactory.ID + "/"
+ VorgangHeaderTestFactory.VERSION + "/commands")); + VorgangHeaderTestFactory.VERSION + "/commands"));
} }
@WithMockUser
@Nested @Nested
class TestLinkToAssignedUser { class TestLinkToAssignedUser {
...@@ -219,15 +234,18 @@ class VorgangControllerITCase { ...@@ -219,15 +234,18 @@ class VorgangControllerITCase {
void shouldReturnStatusOk() throws Exception { void shouldReturnStatusOk() throws Exception {
when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create()); when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create());
doRequest().andExpect(status().is2xxSuccessful()); var response = doRequest();
response.andExpect(status().is2xxSuccessful());
} }
@Test @Test
void shouldBePresentIfAssigned() throws Exception { void shouldBePresentIfAssigned() throws Exception {
when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create()); when(remoteService.findVorgangWithEingang(anyString(), any())).thenReturn(VorgangWithEingangTestFactory.create());
doRequest() var response = doRequest();
.andExpect(jsonPath("$._links.assignedTo.href")
response.andExpect(jsonPath("$._links.assignedTo.href")
.value(StringEndsWith.endsWith("/api/userProfiles/" + UserProfileTestFactory.ID))); .value(StringEndsWith.endsWith("/api/userProfiles/" + UserProfileTestFactory.ID)));
} }
...@@ -236,7 +254,9 @@ class VorgangControllerITCase { ...@@ -236,7 +254,9 @@ class VorgangControllerITCase {
when(remoteService.findVorgangWithEingang(anyString(), any())) when(remoteService.findVorgangWithEingang(anyString(), any()))
.thenReturn(VorgangWithEingangTestFactory.createBuilder().assignedTo(null).build()); .thenReturn(VorgangWithEingangTestFactory.createBuilder().assignedTo(null).build());
doRequest().andExpect(jsonPath("$._links.assignedTo.href").doesNotExist()); var response = doRequest();
response.andExpect(jsonPath("$._links.assignedTo.href").doesNotExist());
} }
} }
...@@ -247,24 +267,29 @@ class VorgangControllerITCase { ...@@ -247,24 +267,29 @@ class VorgangControllerITCase {
@Nested @Nested
class TestClientAttribute { class TestClientAttribute {
@Test @Test
void shouldReturnNoContent() throws Exception { void shouldReturnNoContent() throws Exception {
mockMvc var content = VorgangHeaderTestFactory.createHasNewPostfachNachrichtContent(false);
.perform(put("http://localhost/api/vorgangs/{0}/hasNewPostfachNachricht", VorgangHeaderTestFactory.ID)
.with(csrf()) var response = doRequest(content);
.contentType(MediaType.APPLICATION_JSON)
.content("{\"hasNewPostfachNachricht\":false}")) response.andExpect(status().isNoContent());
.andExpect(status().isNoContent());
} }
@Test @Test
void shouldReturnUnprocessableEntity() throws Exception { void shouldReturnUnprocessableEntity() throws Exception {
mockMvc var content = VorgangHeaderTestFactory.createHasNewPostfachNachrichtContent(true);
.perform(put("http://localhost/api/vorgangs/{0}/hasNewPostfachNachricht", VorgangHeaderTestFactory.ID)
.with(csrf()) var response = doRequest(content);
response.andExpect(status().isUnprocessableEntity());
}
private ResultActions doRequest(String content) throws Exception {
return mockMvc.perform(put("/api/vorgangs/{0}/hasNewPostfachNachricht", VorgangHeaderTestFactory.ID).with(csrf())
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content("{\"hasNewPostfachNachricht\":true}")) .content(content));
.andExpect(status().isUnprocessableEntity());
} }
} }
} }
\ No newline at end of file
...@@ -28,6 +28,7 @@ import java.util.UUID; ...@@ -28,6 +28,7 @@ import java.util.UUID;
import com.thedeanda.lorem.LoremIpsum; import com.thedeanda.lorem.LoremIpsum;
import de.itvsh.kop.common.test.TestUtils;
import de.ozgcloud.alfa.common.user.UserProfileTestFactory; import de.ozgcloud.alfa.common.user.UserProfileTestFactory;
import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus;
...@@ -57,4 +58,8 @@ public class VorgangHeaderTestFactory { ...@@ -57,4 +58,8 @@ public class VorgangHeaderTestFactory {
.createdAt(CREATED_AT) .createdAt(CREATED_AT)
.assignedTo(UserProfileTestFactory.ID); .assignedTo(UserProfileTestFactory.ID);
} }
public static String createHasNewPostfachNachrichtContent(boolean hasNewPostfachNachricht) {
return TestUtils.loadTextFile("jsonTemplates/command/hasNewPostfachNachricht.json.tmpl", String.valueOf(hasNewPostfachNachricht));
}
} }
\ No newline at end of file
{
"hasNewPostfachNachricht": %s
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment