|
| 1 | +package org.olf.erm.usage.counter50.converter; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.assertThatCode; |
| 5 | + |
| 6 | +import com.google.common.io.Resources; |
| 7 | +import java.io.IOException; |
| 8 | +import java.nio.charset.StandardCharsets; |
| 9 | +import java.util.stream.Stream; |
| 10 | +import org.junit.Before; |
| 11 | +import org.junit.BeforeClass; |
| 12 | +import org.junit.Test; |
| 13 | +import org.olf.erm.usage.counter50.Counter5Utils; |
| 14 | +import org.olf.erm.usage.counter50.Counter5Utils.Counter5UtilsException; |
| 15 | +import org.olf.erm.usage.counter50.converter.dr.DRD1Converter; |
| 16 | +import org.olf.erm.usage.counter50.converter.tr.TRB1Converter; |
| 17 | +import org.olf.erm.usage.counter50.converter.tr.TRB3Converter; |
| 18 | +import org.olf.erm.usage.counter50.converter.tr.TRJ1Converter; |
| 19 | +import org.olf.erm.usage.counter50.converter.tr.TRJ3Converter; |
| 20 | +import org.olf.erm.usage.counter50.converter.tr.TRJ4Converter; |
| 21 | +import org.openapitools.client.model.COUNTERDatabaseReport; |
| 22 | +import org.openapitools.client.model.COUNTERTitleReport; |
| 23 | + |
| 24 | +public class MissingAttributesTest { |
| 25 | + |
| 26 | + private static String trStr; |
| 27 | + private static String drStr; |
| 28 | + private static COUNTERTitleReport tr; |
| 29 | + private static COUNTERDatabaseReport dr; |
| 30 | + |
| 31 | + @BeforeClass |
| 32 | + public static void beforeClass() throws IOException, Counter5UtilsException { |
| 33 | + trStr = |
| 34 | + Resources.toString(Resources.getResource("converter/tr/tr.json"), StandardCharsets.UTF_8); |
| 35 | + drStr = |
| 36 | + Resources.toString(Resources.getResource("converter/dr/dr.json"), StandardCharsets.UTF_8); |
| 37 | + } |
| 38 | + |
| 39 | + @Before |
| 40 | + public void setUp() throws Counter5UtilsException { |
| 41 | + tr = (COUNTERTitleReport) Counter5Utils.fromJSON(trStr); |
| 42 | + dr = (COUNTERDatabaseReport) Counter5Utils.fromJSON(drStr); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testThatConverterIsWorkingWithNullAttributesWhileFiltering() { |
| 47 | + tr.getReportItems().forEach(tu -> tu.setAccessMethod(null)); |
| 48 | + dr.getReportItems().forEach(du -> du.setAccessMethod(null)); |
| 49 | + Stream.of( |
| 50 | + new TRJ1Converter(), |
| 51 | + new TRJ3Converter(), |
| 52 | + new TRJ4Converter(), |
| 53 | + new TRB1Converter(), |
| 54 | + new TRB3Converter()) |
| 55 | + .forEach( |
| 56 | + m -> |
| 57 | + assertThatCode(() -> assertThat(m.convert(tr).getReportItems()).isEmpty()) |
| 58 | + .doesNotThrowAnyException()); |
| 59 | + assertThatCode(() -> assertThat(new DRD1Converter().convert(dr).getReportItems()).isEmpty()) |
| 60 | + .doesNotThrowAnyException(); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testThatConverterIsWorkingWithNullAttributesWhileGrouping() { |
| 65 | + tr.getReportItems().forEach(tu -> tu.setPlatform(null)); |
| 66 | + dr.getReportItems().forEach(du -> du.setPlatform(null)); |
| 67 | + Stream.of( |
| 68 | + new TRJ1Converter(), |
| 69 | + new TRJ3Converter(), |
| 70 | + new TRJ4Converter(), |
| 71 | + new TRB1Converter(), |
| 72 | + new TRB3Converter()) |
| 73 | + .forEach( |
| 74 | + m -> |
| 75 | + assertThatCode(() -> assertThat(m.convert(tr).getReportItems()).isNotEmpty()) |
| 76 | + .doesNotThrowAnyException()); |
| 77 | + assertThatCode(() -> assertThat(new DRD1Converter().convert(dr).getReportItems()).isNotEmpty()) |
| 78 | + .doesNotThrowAnyException(); |
| 79 | + } |
| 80 | +} |
0 commit comments