package data; import static org.junit.Assert.*; import org.junit.Test; import com.google.common.collect.HashMultimap; public class MVDataEntryTest { @Test public void testMVDataEntryStringIntInt() { String expected = "{key=line1, attrValPairs={k4=[v4], k1=[v1b, v1a, v1c], k2=[v1c]}}"; MVDataEntry e1 = new MVDataEntry("line1", 1, 1); HashMultimap e1v = e1.getAttrValPairs(); e1v.put("k1", "v1a"); e1v.put("k1", "v1b"); e1v.put("k1", "v1b"); // Twice, should disappear silently e1v.put("k1", "v1c"); e1v.put("k2", "v1c"); e1v.put("k4", "v4"); assertEquals(expected, e1.toString()); } @Test public void testMerge() { // Test data MVDataEntry e1 = new MVDataEntry("10"); HashMultimap e1v = e1.getAttrValPairs(); e1v.put("k1", "v1a"); e1v.put("k1", "v1b"); e1v.put("k1", "v1c"); e1v.put("k2", "v2"); e1v.put("k4", "v4"); MVDataEntry e2 = new MVDataEntry("2"); HashMultimap e2v = e2.getAttrValPairs(); e2v.put("k2", "v2"); e2v.put("k1", "v1b"); e2v.put("k3", "v3"); MVDataEntry r1 = new MVDataEntry(e1); r1.mergeValues(true, e2); assertNotSame(r1, e1); String expected1 = "{key=10, attrValPairs={k3=[v3], k4=[v4], k1=[v1b, v1a, v1c], k2=[v2]}}"; assertEquals(expected1, r1.toString()); MVDataEntry r2 = new MVDataEntry(e2); r2.mergeValues(true, e1); assertNotSame(r2, e2); String expected2 = "{key=2, attrValPairs={k3=[v3], k4=[v4], k1=[v1b, v1a, v1c], k2=[v2]}}"; assertEquals(expected2, r2.toString()); MVDataEntry r3 = new MVDataEntry(e1); r3.mergeValues(false, e2); assertNotSame(r3, e1); String expected3 = "{key=10, attrValPairs={k3=[v3], k4=[v4], k1=[v1b], k2=[v2]}}"; //System.out.println(expected3); //System.out.println(r3.toString()); assertEquals(expected3, r3.toString()); MVDataEntry r4 = new MVDataEntry(e2); r4.mergeValues(false, e1); assertNotSame(r4, e1); String expected4 = "{key=2, attrValPairs={k3=[v3], k4=[v4], k1=[v1b, v1a, v1c], k2=[v2]}}"; assertEquals(expected4, r4.toString()); assertTrue(!r2.equals(r3)); assertEquals(r2,r4); } @Test public void testSplitAndPut() { MVDataEntry r1 = new MVDataEntry("10"); r1.splitAndPut("k1", "v1a;v1b;v1c", ";"); r1.put("k2", "v2", null); // splitAndPut does not support null regex anymore, use put() r1.splitAndPut("k4", "v4", "^$"); MVDataEntry expected1 = new MVDataEntry("10"); HashMultimap expected1v = expected1.getAttrValPairs(); expected1v.put("k1", "v1a"); expected1v.put("k1", "v1b"); expected1v.put("k1", "v1c"); expected1v.put("k2", "v2"); expected1v.put("k4", "v4"); assertEquals(r1,expected1); } }