generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
374cda9
commit aff1840
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
src/test/java/de/muenchen/dave/services/messstelle/auswertung/SpreadsheetServiceTest.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,105 @@ | ||
package de.muenchen.dave.services.messstelle.auswertung; | ||
|
||
import de.muenchen.dave.domain.dtos.messstelle.auswertung.MessstelleAuswertungIdDTO; | ||
import de.muenchen.dave.domain.dtos.messstelle.auswertung.MessstelleAuswertungOptionsDTO; | ||
import de.muenchen.dave.domain.elasticsearch.detektor.Messquerschnitt; | ||
import de.muenchen.dave.domain.elasticsearch.detektor.Messstelle; | ||
import de.muenchen.dave.domain.enums.TagesTyp; | ||
import de.muenchen.dave.services.messstelle.MessstelleService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.poi.ss.usermodel.Cell; | ||
import org.apache.poi.ss.usermodel.Row; | ||
import org.apache.poi.ss.usermodel.Sheet; | ||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.mockito.quality.Strictness; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
class SpreadsheetServiceTest { | ||
|
||
@Mock | ||
private MessstelleService messstelleService; | ||
|
||
private SpreadsheetService spreadsheetService; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
spreadsheetService = new SpreadsheetService(messstelleService); | ||
Mockito.reset(messstelleService); | ||
} | ||
|
||
@Test | ||
void addMetaHeaderToSheet() { | ||
|
||
final var spreadsheetDocument = new XSSFWorkbook(); | ||
final Sheet sheet = spreadsheetDocument.createSheet(); | ||
|
||
final MessstelleAuswertungOptionsDTO options = new MessstelleAuswertungOptionsDTO(); | ||
final MessstelleAuswertungIdDTO messstelleAuswertungIdDTO1 = new MessstelleAuswertungIdDTO(); | ||
messstelleAuswertungIdDTO1.setMstId("123"); | ||
messstelleAuswertungIdDTO1.setMqIds(Set.of("12301", "12302")); | ||
final MessstelleAuswertungIdDTO messstelleAuswertungIdDTO2 = new MessstelleAuswertungIdDTO(); | ||
messstelleAuswertungIdDTO2.setMstId("456"); | ||
messstelleAuswertungIdDTO2.setMqIds(Set.of("45601", "45602")); | ||
options.setTagesTyp(TagesTyp.MO_SO); | ||
options.setMessstelleAuswertungIds(Set.of(messstelleAuswertungIdDTO1, messstelleAuswertungIdDTO2)); | ||
|
||
spreadsheetService.addMetaDataToSheet(sheet, options); | ||
|
||
Assertions.assertThat(sheet.getPhysicalNumberOfRows()).isEqualTo(2); | ||
Row row = sheet.getRow(1); | ||
Assertions.assertThat(row.getPhysicalNumberOfCells()).isEqualTo(2); | ||
Cell cell0 = row.getCell(0); | ||
Assertions.assertThat(cell0.getStringCellValue()).isEqualTo(options.getTagesTyp().getBeschreibung()); | ||
Cell cell1 = row.getCell(1); | ||
Assertions.assertThat(cell1.getStringCellValue()).isEqualTo("Alle Messquerschnitte"); | ||
|
||
final Messstelle mockedMessstelle = new Messstelle(); | ||
mockedMessstelle.setMstId("123"); | ||
mockedMessstelle.setMessquerschnitte(new ArrayList<>()); | ||
final Messquerschnitt messquerschnitt1 = new Messquerschnitt(); | ||
messquerschnitt1.setMqId("12301"); | ||
messquerschnitt1.setFahrtrichtung("W"); | ||
messquerschnitt1.setStandort("Standort MQ1"); | ||
final Messquerschnitt messquerschnitt2 = new Messquerschnitt(); | ||
messquerschnitt2.setMqId("12302"); | ||
messquerschnitt2.setFahrtrichtung("O"); | ||
messquerschnitt2.setStandort("Standort MQ2"); | ||
mockedMessstelle.getMessquerschnitte().add(messquerschnitt1); | ||
mockedMessstelle.getMessquerschnitte().add(messquerschnitt2); | ||
|
||
Mockito.when(messstelleService.getMessstelleByMstId("123")).thenReturn(mockedMessstelle); | ||
|
||
options.setMessstelleAuswertungIds(Set.of(messstelleAuswertungIdDTO1)); | ||
spreadsheetService.addMetaDataToSheet(sheet, options); | ||
|
||
Assertions.assertThat(sheet.getPhysicalNumberOfRows()).isEqualTo(2); | ||
row = sheet.getRow(1); | ||
Assertions.assertThat(row.getPhysicalNumberOfCells()).isEqualTo(2); | ||
cell0 = row.getCell(0); | ||
Assertions.assertThat(cell0.getStringCellValue()).isEqualTo(options.getTagesTyp().getBeschreibung()); | ||
cell1 = row.getCell(1); | ||
|
||
final List<String> cellValue = new ArrayList<>(); | ||
mockedMessstelle.getMessquerschnitte().forEach(messquerschnitt -> { | ||
cellValue.add(String.format("%s - %s - %s", messquerschnitt.getMqId(), messquerschnitt.getFahrtrichtung(), | ||
messquerschnitt.getStandort())); | ||
}); | ||
Assertions.assertThat(cell1.getStringCellValue()).isEqualTo(String.join(", ", cellValue)); | ||
} | ||
|
||
// TODO restliche Hilfsmethoden abtesten | ||
} |