generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #482 from it-at-m/149-implementierung-auskunft-ueb…
…er-fortschritt-von-asynchronen-prozess 149 implementierung auskunft ueber fortschritt von asynchronen prozess
- Loading branch information
Showing
9 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...n/oss/wahllokalsystem/basisdatenservice/rest/wahltermindaten/AsyncProgressController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahltermindaten; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltermindaten.AsyncProgress; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/businessActions/asyncProgress") | ||
@RequiredArgsConstructor | ||
public class AsyncProgressController { | ||
|
||
private final AsyncProgress asyncProgress; | ||
private final AsyncProgressDTOMapper asyncProgressDTOMapper; | ||
|
||
@Operation( | ||
description = "Abrufen des Fortschrittes bei der Importierung der Wahltermindaten.", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", description = "Importfortschritt wurde geliefert." | ||
) | ||
} | ||
) | ||
@GetMapping | ||
public AsyncProgressDTO getAsyncProgress() { | ||
return asyncProgressDTOMapper.toDto(asyncProgress); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...muenchen/oss/wahllokalsystem/basisdatenservice/rest/wahltermindaten/AsyncProgressDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahltermindaten; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
public record AsyncProgressDTO( | ||
LocalDate forWahltag, | ||
String wahlNummer, | ||
LocalDateTime lastStartTime, | ||
LocalDateTime lastFinishTime, | ||
boolean wahlvorschlaegeLoadingActive, | ||
int wahlvorschlaegeTotal, | ||
int wahlvorschlageFinished, | ||
String wahlvorschlaegeNext, | ||
boolean referendumLoadingActive, | ||
int referendumVorlagenTotal, | ||
int referendumVorlagenFinished, | ||
String referendumVorlagenNext | ||
) { | ||
} |
10 changes: 10 additions & 0 deletions
10
...en/oss/wahllokalsystem/basisdatenservice/rest/wahltermindaten/AsyncProgressDTOMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahltermindaten; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltermindaten.AsyncProgress; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper | ||
public interface AsyncProgressDTOMapper { | ||
|
||
AsyncProgressDTO toDto(AsyncProgress asyncProgress); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...system/basisdatenservice/rest/wahltermindaten/AsyncProgressControllerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahltermindaten; | ||
|
||
import static de.muenchen.oss.wahllokalsystem.basisdatenservice.TestConstants.SPRING_NO_SECURITY_PROFILE; | ||
import static de.muenchen.oss.wahllokalsystem.basisdatenservice.TestConstants.SPRING_TEST_PROFILE; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.MicroServiceApplication; | ||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltermindaten.AsyncProgress; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
@SpringBootTest(classes = MicroServiceApplication.class) | ||
@AutoConfigureMockMvc | ||
@ActiveProfiles(profiles = { SPRING_TEST_PROFILE, SPRING_NO_SECURITY_PROFILE }) | ||
class AsyncProgressControllerIntegrationTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@Autowired | ||
AsyncProgress asyncProgress; | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@Nested | ||
class GetAsyncProgress { | ||
|
||
@Test | ||
void should_returnCurrentAsyncProgress_when_requested() throws Exception { | ||
val expectedAsyncProgressDTO = setupAsyncProgressStateAndReturnExpectedDTO(); | ||
|
||
val request = MockMvcRequestBuilders.get("/businessActions/asyncProgress"); | ||
val mockMvcPerform = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); | ||
|
||
val responseBodyAsAsyncProgressDTO = objectMapper.readValue(mockMvcPerform.getResponse().getContentAsString(), AsyncProgressDTO.class); | ||
Assertions.assertThat(responseBodyAsAsyncProgressDTO).isEqualTo(expectedAsyncProgressDTO); | ||
} | ||
|
||
private AsyncProgressDTO setupAsyncProgressStateAndReturnExpectedDTO() { | ||
val wahltag = LocalDate.now(); | ||
val wahlnummer = "wahlnummer"; | ||
val lastStartTime = LocalDateTime.now().minusDays(2); | ||
val lastFinishTime = LocalDateTime.now().minusDays(1); | ||
val wahlvorschlaegeIsLoading = true; | ||
val wahlvorschlaegeTotal = 23; | ||
val wahlvorschlaegeFinished = 12; | ||
val wahlvorschlaegeNext = "wahlvorschlagID13"; | ||
val referendumvorlagenIsLoading = false; | ||
val referendumvorlagenTotal = 21; | ||
val referendumvorlagenFinished = 20; | ||
val referendumvorlagenNext = "referendumvorlagenID13"; | ||
|
||
asyncProgress.setForWahltag(wahltag); | ||
asyncProgress.setWahlNummer(wahlnummer); | ||
asyncProgress.setLastStartTime(lastStartTime); | ||
asyncProgress.setLastFinishTime(lastFinishTime); | ||
asyncProgress.setWahlvorschlaegeLoadingActive(wahlvorschlaegeIsLoading); | ||
asyncProgress.setWahlvorschlaegeTotal(wahlvorschlaegeTotal); | ||
asyncProgress.setWahlvorschlageFinished(wahlvorschlaegeFinished); | ||
asyncProgress.setWahlvorschlaegeNext(wahlvorschlaegeNext); | ||
asyncProgress.setReferendumLoadingActive(referendumvorlagenIsLoading); | ||
asyncProgress.setReferendumVorlagenTotal(referendumvorlagenTotal); | ||
asyncProgress.setReferendumVorlagenFinished(referendumvorlagenFinished); | ||
asyncProgress.setReferendumVorlagenNext(referendumvorlagenNext); | ||
|
||
return new AsyncProgressDTO(wahltag, wahlnummer, lastStartTime, lastFinishTime, wahlvorschlaegeIsLoading, wahlvorschlaegeTotal, | ||
wahlvorschlaegeFinished, wahlvorschlaegeNext, referendumvorlagenIsLoading, referendumvorlagenTotal, referendumvorlagenFinished, | ||
referendumvorlagenNext); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...s/wahllokalsystem/basisdatenservice/rest/wahltermindaten/AsyncProgressControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahltermindaten; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltermindaten.AsyncProgress; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AsyncProgressControllerTest { | ||
|
||
@Mock | ||
AsyncProgress asyncProgress; | ||
|
||
@Mock | ||
AsyncProgressDTOMapper asyncProgressDTOMapper; | ||
|
||
@InjectMocks | ||
AsyncProgressController unitUnderTest; | ||
|
||
@Nested | ||
class GetAsyncProgress { | ||
|
||
@Test | ||
void should_returnCurrentProgressStateAsDTO_when_called() { | ||
val mockedProgressDTO = new AsyncProgressDTO(null, null, null, null, false, 0, 1, null, true, 3, 4, null); | ||
|
||
Mockito.when(asyncProgressDTOMapper.toDto(asyncProgress)).thenReturn(mockedProgressDTO); | ||
|
||
Assertions.assertThat(unitUnderTest.getAsyncProgress()).isEqualTo(mockedProgressDTO); | ||
} | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ss/wahllokalsystem/basisdatenservice/rest/wahltermindaten/AsyncProgressDTOMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package de.muenchen.oss.wahllokalsystem.basisdatenservice.rest.wahltermindaten; | ||
|
||
import de.muenchen.oss.wahllokalsystem.basisdatenservice.services.wahltermindaten.AsyncProgress; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import lombok.val; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
class AsyncProgressDTOMapperTest { | ||
|
||
AsyncProgressDTOMapper unitUnderTest = Mappers.getMapper(AsyncProgressDTOMapper.class); | ||
|
||
@Nested | ||
class ToDTO { | ||
|
||
@Test | ||
void should_returnDTO_when_asyncProgressIsDelivered() { | ||
val wahltag = LocalDate.now(); | ||
val wahlnummer = "wahlnummer"; | ||
val lastStartTime = LocalDateTime.now().minusDays(2); | ||
val lastFinishTime = LocalDateTime.now().minusDays(1); | ||
val wahlvorschlaegeIsLoading = true; | ||
val wahlvorschlaegeTotal = 23; | ||
val wahlvorschlaegeFinished = 12; | ||
val wahlvorschlaegeNext = "wahlvorschlagID13"; | ||
val referendumvorlagenIsLoading = false; | ||
val referendumvorlagenTotal = 21; | ||
val referendumvorlagenFinished = 20; | ||
val referendumvorlagenNext = "referendumvorlagenID13"; | ||
|
||
val asyncProgress = new AsyncProgress(wahltag, wahlnummer, lastStartTime, lastFinishTime, wahlvorschlaegeIsLoading, wahlvorschlaegeTotal, | ||
wahlvorschlaegeFinished, wahlvorschlaegeNext, referendumvorlagenIsLoading, referendumvorlagenTotal, referendumvorlagenFinished, | ||
referendumvorlagenNext); | ||
|
||
val result = unitUnderTest.toDto(asyncProgress); | ||
|
||
val expectedResult = new AsyncProgressDTO(wahltag, wahlnummer, lastStartTime, lastFinishTime, wahlvorschlaegeIsLoading, wahlvorschlaegeTotal, | ||
wahlvorschlaegeFinished, wahlvorschlaegeNext, referendumvorlagenIsLoading, referendumvorlagenTotal, referendumvorlagenFinished, | ||
referendumvorlagenNext); | ||
|
||
Assertions.assertThat(result).isEqualTo(expectedResult); | ||
} | ||
|
||
@Test | ||
void should_returnNull_when_parameterIsNull() { | ||
Assertions.assertThat(unitUnderTest.toDto(null)).isNull(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters