summaryrefslogtreecommitdiff
path: root/src/core/JUTests/data/MVDataEntryTest.java
blob: 19ccb46bab78de63c00e15bf7dcf71fdcabf5871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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<String, String> 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<String, String> 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<String, String> 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<String, String> 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);
	}

}