Skip to content

Commit

Permalink
test case for audiodescription, signlanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
codingPF committed Nov 18, 2023
1 parent b828a4c commit 49bce56
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,13 @@ private String writeRecord08Beschreibung(AbstractMediaResource<?> in) {
}

private String writeRecord09UrlNormal(AbstractMediaResource<?> in) {
if ((in instanceof Podcast pIn) && pIn.getUrl(Resolution.NORMAL) != null)
if ((in instanceof Podcast pIn) && pIn.getUrl(Resolution.NORMAL) != null) {
return pIn.getUrl(Resolution.NORMAL).getUrl().toString();
} else if ((in instanceof Film pIn) && pIn.getAudioDescription(Resolution.NORMAL) != null) {
return pIn.getAudioDescription(Resolution.NORMAL).getUrl().toString();
} else if ((in instanceof Film pIn) && pIn.getSignLanguage(Resolution.NORMAL) != null) {
return pIn.getSignLanguage(Resolution.NORMAL).getUrl().toString();
}
return "";
}

Expand All @@ -230,6 +235,10 @@ private String writeRecord12UrlRTMP(AbstractMediaResource<?> in) {
private String writeRecord13UrlKlein(AbstractMediaResource<?> in) {
if ((in instanceof Podcast pIn) && in.getUrl(Resolution.SMALL) != null && pIn.getUrl(Resolution.NORMAL) != null) {
return reduceUrl(pIn.getUrl(Resolution.NORMAL).getUrl().toString(), pIn.getUrl(Resolution.SMALL).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getAudioDescription(Resolution.NORMAL) != null && pIn.getAudioDescription(Resolution.SMALL) != null) {
return reduceUrl(pIn.getAudioDescription(Resolution.NORMAL).getUrl().toString(), pIn.getAudioDescription(Resolution.SMALL).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getSignLanguage(Resolution.NORMAL) != null && pIn.getSignLanguage(Resolution.SMALL) != null) {
return reduceUrl(pIn.getSignLanguage(Resolution.NORMAL).getUrl().toString(), pIn.getSignLanguage(Resolution.SMALL).getUrl().toString());
}
return "";
}
Expand All @@ -241,6 +250,10 @@ private String writeRecord14UrlKleinRTMP(AbstractMediaResource<?> in) {
private String writeRecord15UrlHD(AbstractMediaResource<?> in) {
if ((in instanceof Podcast pIn) && in.getUrl(Resolution.HD) != null && in.getUrl(Resolution.NORMAL) != null) {
return reduceUrl(pIn.getUrl(Resolution.NORMAL).getUrl().toString(), pIn.getUrl(Resolution.HD).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getAudioDescription(Resolution.NORMAL) != null && pIn.getAudioDescription(Resolution.HD) != null) {
return reduceUrl(pIn.getAudioDescription(Resolution.NORMAL).getUrl().toString(), pIn.getAudioDescription(Resolution.HD).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getSignLanguage(Resolution.NORMAL) != null && pIn.getSignLanguage(Resolution.HD) != null) {
return reduceUrl(pIn.getSignLanguage(Resolution.NORMAL).getUrl().toString(), pIn.getSignLanguage(Resolution.HD).getUrl().toString());
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import de.mediathekview.mlib.daten.Film;
import de.mediathekview.mlib.daten.FilmUrl;
import de.mediathekview.mlib.daten.Filmlist;
import de.mediathekview.mlib.daten.GeoLocations;
import de.mediathekview.mlib.daten.Resolution;
import de.mediathekview.mlib.daten.Sender;
import de.mediathekview.mlib.filmlisten.reader.FilmlistOldFormatReader;
import de.mediathekview.mlib.filmlisten.writer.FilmlistOldFormatWriter;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Optional;

import java.util.UUID;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -44,6 +53,111 @@ void readFilmlistOldFormatIncludingBrokenRecords()

}

@Test
void readWriteFilmlistAndCheckAllUrlTypesDoPersist()
throws IOException {
//
Filmlist expected = expectedFilmlist();
Path tempFile = Files.createTempFile(tempDir, "TestFilmlistOldFormatWriter", ".out");
new FilmlistOldFormatWriter().write(expected, tempFile);
assertTrue( Files.exists(tempFile));
//
Optional<Filmlist> afterWriteAndRead = new FilmlistOldFormatReader().read(new FileInputStream(tempFile.toString()));
Files.deleteIfExists(tempFile);
//
assertEquals(expected.getFilms().size(), afterWriteAndRead.get().getFilms().size());
//
ArrayList<Film> aFilmlist = new ArrayList<>(expected.getFilms().values());
ArrayList<Film> bFilmlist = new ArrayList<>(afterWriteAndRead.get().getFilms().values());
//
aFilmlist.forEach( expectedFilm -> {
int index = bFilmlist.indexOf(expectedFilm);
assertTrue(index > -1);
compareFilmIncludingShifterUrls(expectedFilm, bFilmlist.get(index));
});

}

private void compareFilmIncludingShifterUrls(Film aFilm, Film bFilm) {
assertEquals(aFilm.getSenderName() , bFilm.getSenderName());
assertEquals(aFilm.getTitel() , bFilm.getTitel());
assertEquals(aFilm.getThema() , bFilm.getThema());
assertEquals(aFilm.getDuration() , bFilm.getDuration());
assertEquals(aFilm.getWebsite() , bFilm.getWebsite());
assertEquals(aFilm.getBeschreibung(), bFilm.getBeschreibung());
assertEquals(aFilm.getGeoLocations(), bFilm.getGeoLocations());
assertEquals(aFilm.getSubtitles(), bFilm.getSubtitles());
assertEquals(aFilm.getTime(), bFilm.getTime());
// after write read all videos will be urls (not audiodescriptions etc)
bFilm.getUrls().forEach( (resolution, url) -> {
if (aFilm.getUrl(resolution) != null) {
assertEquals(aFilm.getUrl(resolution).toString(), url.toString());
} else if (aFilm.getAudioDescription(resolution) != null) {
assertEquals(aFilm.getAudioDescription(resolution).toString(), url.toString());
} else if (aFilm.getSignLanguage(resolution) != null) {
assertEquals(aFilm.getSignLanguage(resolution).toString(), url.toString());
} else {
assertEquals("We did expect an url but could not find any", "");
}
});
}


private Filmlist expectedFilmlist() {
Filmlist expectedFilmlist = new Filmlist();
try {
Film completeMatchExpected = new Film();
//
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37° Totgerast");
completeMatchExpected.setBeschreibung("description");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(45));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 30, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addUrl(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/normal.mp4"), 405L));
completeMatchExpected.addUrl(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/small.mp4"), 0L));
completeMatchExpected.addUrl(Resolution.HD, new FilmUrl(new URL("https://some.host.de/hd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben (Audiodeskription)");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addAudioDescription(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionNormal.mp4"), 405L));
completeMatchExpected.addAudioDescription(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionSmall.mp4"), 0L));
completeMatchExpected.addAudioDescription(Resolution.HD, new FilmUrl(new URL("https://some.host.de/AudioDescriptionHd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben (Gebaerdensprache)");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addSignLanguage(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/SignLanguageNormal.mp4"), 405L));
completeMatchExpected.addSignLanguage(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/SignLanguageSmall.mp4"), 0L));
completeMatchExpected.addSignLanguage(Resolution.HD, new FilmUrl(new URL("https://some.host.de/SignLanguageHd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
} catch (Exception e) {
e.printStackTrace();
}
return expectedFilmlist;
}

}

0 comments on commit 49bce56

Please sign in to comment.