summaryrefslogtreecommitdiff
path: root/src/core/JUTests/data/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/JUTests/data/io')
-rw-r--r--src/core/JUTests/data/io/filters/MVDataCombinerTest.java148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/core/JUTests/data/io/filters/MVDataCombinerTest.java b/src/core/JUTests/data/io/filters/MVDataCombinerTest.java
new file mode 100644
index 0000000..5d32dd8
--- /dev/null
+++ b/src/core/JUTests/data/io/filters/MVDataCombinerTest.java
@@ -0,0 +1,148 @@
+package data.io.filters;
+
+import static org.junit.Assert.*;
+
+import java.util.Iterator;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import data.MVDataEntry;
+import data.filters.MVDataCombiner;
+import data.filters.MVDataCombiner.MVDataCombineMode;
+import data.io.MVDataReader;
+import data.io.stub.StubDataReader;
+
+public class MVDataCombinerTest {
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testOutOfOrderCase() {
+ // Test Data
+ MVDataEntry e10 = new MVDataEntry("line2");
+ e10.getAttrValPairs().put("merge", "e10");
+ MVDataEntry e11 = new MVDataEntry("line1");
+ e11.getAttrValPairs().put("merge", "e11");
+
+ MVDataEntry e21 = new MVDataEntry("line2");
+ e21.getAttrValPairs().put("merge", "e21");
+
+ MVDataEntry[][] fakeEntries = new MVDataEntry[][] {
+ new MVDataEntry[] { e10, e11 },
+ new MVDataEntry[] { e21 },
+ };
+
+ MVDataCombineMode mergeModes[] = new MVDataCombineMode[]{
+ MVDataCombineMode.PRIMARY_SOURCE,
+ MVDataCombineMode.MERGE_APPEND,
+ };
+
+ // Expected results
+ MVDataEntry line1 = new MVDataEntry(e10);
+ line1.mergeValues(true, e21);
+
+ MVDataEntry expected[] = new MVDataEntry[] {
+ line1,
+ null /* Should throw UnsupportedOperationException() before comparing */
+ };
+
+ // Test run
+ exception.expect(UnsupportedOperationException.class);
+ doCombineTest(expected, fakeEntries, mergeModes);
+ }
+
+
+ @Test
+ public void testGeneralCase() {
+
+ // Test Data
+ MVDataEntry e10 = new MVDataEntry("line3");
+ e10.getAttrValPairs().put("from1", "e10");
+ e10.getAttrValPairs().put("merge", "e10");
+ MVDataEntry e11 = new MVDataEntry("line4");
+ e11.getAttrValPairs().put("from1", "e11");
+ e11.getAttrValPairs().put("merge", "e11");
+
+ MVDataEntry e20 = new MVDataEntry("line1");
+ e20.getAttrValPairs().put("from2", "e20");
+ e20.getAttrValPairs().put("merge", "e20");
+ MVDataEntry e21 = new MVDataEntry("line2");
+ e21.getAttrValPairs().put("from2", "e21");
+ e21.getAttrValPairs().put("merge", "e21");
+ MVDataEntry e22 = new MVDataEntry("line3");
+ e22.getAttrValPairs().put("from2", "e22");
+ e22.getAttrValPairs().put("merge", "e22");
+
+ MVDataEntry e30 = new MVDataEntry("line2");
+ e30.getAttrValPairs().put("from3", "e30");
+ e30.getAttrValPairs().put("merge", "e30");
+
+
+ MVDataEntry[][] fakeEntries = new MVDataEntry[][] {
+ new MVDataEntry[] { e10, e11 },
+ new MVDataEntry[] { e20, e21, e22 },
+ new MVDataEntry[] { e30 },
+ };
+
+ MVDataCombineMode mergeModes[] = new MVDataCombineMode[]{
+ MVDataCombineMode.PRIMARY_SOURCE,
+ MVDataCombineMode.MERGE_REPLACE,
+ MVDataCombineMode.MERGE_APPEND,
+ };
+
+ // Expected results
+ MVDataEntry line1 = new MVDataEntry(e20);
+
+ MVDataEntry line2 = new MVDataEntry(e21);
+ line2.mergeValues(true, e30);
+
+ MVDataEntry line3 = new MVDataEntry(e10);
+ line3.mergeValues(false, e22);
+
+ MVDataEntry line4 = new MVDataEntry(e11);
+
+ MVDataEntry expected[] = new MVDataEntry[] {
+ line1,line2,line3,line4
+ };
+
+ // Test run
+ doCombineTest(expected, fakeEntries, mergeModes);
+ }
+
+ // TODO : test all Combine modes
+
+ /**
+ * Helper function to factorise Combiner tests.
+ * @param expected
+ * @param fakeEntries
+ * @param mergeModes
+ */
+ public void doCombineTest(MVDataEntry expected[], MVDataEntry[][] fakeEntries, MVDataCombineMode mergeModes[]) {
+ // Test init
+ MVDataReader readers[] = new MVDataReader[fakeEntries.length];
+ for (int i = 0; i < fakeEntries.length; i++) {
+ readers[i] = new StubDataReader("fakeReader"+i,fakeEntries[i]);
+ }
+
+ MVDataCombiner combiner = new MVDataCombiner("combiner", readers, mergeModes);
+
+ // Test twice to check if asking a new iterator "rewinds" correctly
+ for (int i=0;i<2;i++) {
+ //System.out.println("Loop " + (i+1));
+
+ Iterator<MVDataEntry> combinerIt = combiner.iterator();
+ for (int j = 0; j < expected.length; j++) {
+ assertTrue(combinerIt.hasNext());
+ MVDataEntry item = combinerIt.next();
+ //System.out.println(expected[i]);
+ //System.out.println(item);
+ //System.out.println();
+ assertEquals(expected[j], item);
+ }
+ assertFalse(combinerIt.hasNext());
+ }
+ }
+}