Skip to content

Commit

Permalink
Merge pull request #482 from it-at-m/149-implementierung-auskunft-ueb…
Browse files Browse the repository at this point in the history
…er-fortschritt-von-asynchronen-prozess

149 implementierung auskunft ueber fortschritt von asynchronen prozess
  • Loading branch information
MrSebastian authored Oct 15, 2024
2 parents 717f08e + 8e335a5 commit 95bee3f
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/features/basisdaten-service/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ sequenceDiagram
AsyncWahltermindatenService ->> AsyncWahltermindatenService : speichere Referendumvorlagen
```

### Fortschritt

Der aktuelle Stand des Imports kann über die API gerufen werden.

## Konfigurationsparameter

Alle Konfigurationsparameter beginnen mit `service.config`
Expand Down
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);
}
}
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
) {
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,19 @@ void should_permitAccess_when_accessingAuthorizedDelete() throws Exception {
}
}

@Nested
class AsyncProgress {
@Test
@WithAnonymousUser
void should_denyAccess_when_requestWithAnonymousUser() throws Exception {
api.perform(get("/businessActions/asyncProgress")).andExpect(status().isUnauthorized());
}

@Test
@WithMockUser
void should_permitAccess_when_requestWithAuthorizedUser() throws Exception {
api.perform(get("/businessActions/asyncProgress")).andExpect(status().isOk());
}
}

}
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);
}
}

}
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);
}

}
}
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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ Authorization: {{ token_type }} {{ auth_token }}

### Delete Wahltermindaten - failed cause wahltagID does not exist
DELETE {{ WLS_BASISDATEN_SERVICE_URL }}/businessActions/wahltermindaten/wahltagIDThatDoesNotExist
Authorization: {{ token_type }} {{ auth_token }}

### Get Import Progress
GET {{ WLS_BASISDATEN_SERVICE_URL }}/businessActions/asyncProgress
Authorization: {{ token_type }} {{ auth_token }}

0 comments on commit 95bee3f

Please sign in to comment.