[4] | 1 | package tudelft.healthpsychology.traumaontologies;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertTrue;
|
---|
| 4 |
|
---|
| 5 | import java.io.IOException;
|
---|
| 6 | import java.io.InputStream;
|
---|
| 7 | import java.util.HashSet;
|
---|
| 8 | import java.util.Map;
|
---|
| 9 | import java.util.Set;
|
---|
| 10 |
|
---|
| 11 | import org.junit.Test;
|
---|
| 12 | import org.junit.runner.RunWith;
|
---|
| 13 | import org.junit.runners.Parameterized;
|
---|
| 14 | import org.junit.runners.Parameterized.Parameter;
|
---|
| 15 | import org.junit.runners.Parameterized.Parameters;
|
---|
| 16 |
|
---|
| 17 | import tudelft.utilities.translator.BasicCsvTranslator;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * Check csv translation files
|
---|
| 21 | *
|
---|
| 22 | * @author wouter
|
---|
| 23 | *
|
---|
| 24 | */
|
---|
| 25 | @RunWith(Parameterized.class)
|
---|
| 26 | public class CsvTranslationFilesTest {
|
---|
| 27 |
|
---|
| 28 | private final static String[] csvFiles = new String[] { "NL.csv",
|
---|
| 29 | "EN.csv" };
|
---|
| 30 |
|
---|
| 31 | @Parameters
|
---|
| 32 | public static Object[] data() {
|
---|
| 33 | return csvFiles;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | @Parameter
|
---|
| 37 | public String csvFile;
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * Test that all csv files have the same keys (the original language
|
---|
| 41 | * sentences)
|
---|
| 42 | *
|
---|
| 43 | * @throws IOException
|
---|
| 44 | */
|
---|
| 45 | @Test
|
---|
| 46 | public void testSameKeys() throws IOException {
|
---|
| 47 | System.out.println("testing file " + csvFile);
|
---|
| 48 |
|
---|
| 49 | MyTranslator tested = new MyTranslator(
|
---|
| 50 | getClass().getResourceAsStream("/" + csvFile));
|
---|
| 51 |
|
---|
| 52 | MyTranslator baseline = new MyTranslator(
|
---|
| 53 | getClass().getResourceAsStream("/" + csvFiles[0]));
|
---|
| 54 |
|
---|
| 55 | checkMissing(tested.getMap().keySet(), baseline.getMap().keySet(),
|
---|
| 56 | "There are keys missing in " + csvFile);
|
---|
| 57 | checkMissing(baseline.getMap().keySet(), tested.getMap().keySet(),
|
---|
| 58 | "There are keys extra in " + csvFile);
|
---|
| 59 |
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Check if values are missing in testset that are in baselineset.
|
---|
| 64 | *
|
---|
| 65 | * @param testset the set to check
|
---|
| 66 | * @param baselineset the baseline of must-have values
|
---|
| 67 | * @param message error message if there are values
|
---|
| 68 | */
|
---|
| 69 | private void checkMissing(Set<String> testkeys, Set<String> baselinekeys,
|
---|
| 70 | String message) {
|
---|
| 71 | Set<String> remaining = new HashSet<String>(baselinekeys);
|
---|
| 72 | remaining.removeAll(testkeys);
|
---|
| 73 | assertTrue(message + ":" + remaining, remaining.isEmpty());
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * Extend to access map for direct testing of map contents.
|
---|
| 80 | *
|
---|
| 81 | */
|
---|
| 82 | class MyTranslator extends BasicCsvTranslator {
|
---|
| 83 | public MyTranslator(InputStream csvResource) throws IOException {
|
---|
| 84 | super(csvResource);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public Map<String, String> getMap() {
|
---|
| 88 | return map;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|