|
8 | 8 | import com.yahoo.bullet.record.simple.UntypedSimpleBulletRecord;
|
9 | 9 | import com.yahoo.bullet.typesystem.TypedObject;
|
10 | 10 | import org.junit.Assert;
|
| 11 | +import org.testng.annotations.BeforeMethod; |
11 | 12 | import org.testng.annotations.Test;
|
12 | 13 |
|
13 | 14 | import java.io.Serializable;
|
14 | 15 | import java.util.Map;
|
15 | 16 |
|
16 | 17 | public class LateralViewBulletRecordTest {
|
17 |
| - private LateralViewBulletRecord record = new LateralViewBulletRecord(new UntypedSimpleBulletRecord(), new UntypedSimpleBulletRecord()); |
| 18 | + private LateralViewBulletRecord record; |
| 19 | + |
| 20 | + @BeforeMethod |
| 21 | + public void setup() { |
| 22 | + record = new LateralViewBulletRecord(new UntypedSimpleBulletRecord(), new UntypedSimpleBulletRecord()); |
| 23 | + } |
18 | 24 |
|
19 | 25 | @Test
|
20 | 26 | public void testGetRawDataMap() {
|
| 27 | + Map<String, Serializable> map = record.getRawDataMap(); |
| 28 | + |
| 29 | + Assert.assertEquals(map.size(), 0); |
| 30 | + |
21 | 31 | record.getBaseRecord().setString("abc", "def");
|
22 |
| - record.getTopRecord().setString("abc", "ghi"); |
| 32 | + record.getTopRecord().setString("foo", "bar"); |
| 33 | + |
| 34 | + map = record.getRawDataMap(); |
| 35 | + |
| 36 | + Assert.assertEquals(map.size(), 2); |
| 37 | + Assert.assertEquals(map.get("abc"), "def"); |
| 38 | + Assert.assertEquals(map.get("foo"), "bar"); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testGetRawDataMapShadowedFieldAndCulledField() { |
| 43 | + record.getBaseRecord().setString("abc", "def"); |
| 44 | + record.getTopRecord().setString("abc", "bar"); |
23 | 45 |
|
24 | 46 | Map<String, Serializable> map = record.getRawDataMap();
|
25 | 47 |
|
26 | 48 | Assert.assertEquals(map.size(), 1);
|
27 |
| - Assert.assertEquals(map.get("abc"), "ghi"); |
| 49 | + Assert.assertEquals(map.get("abc"), "bar"); |
28 | 50 |
|
29 |
| - // "abc" removed from the top record and also added to culled |
30 | 51 | record.remove("abc");
|
31 | 52 |
|
32 |
| - Assert.assertEquals(record.getCulledFields().size(), 1); |
33 |
| - Assert.assertTrue(record.getCulledFields().contains("abc")); |
34 |
| - Assert.assertEquals(record.typedGet("abc"), TypedObject.NULL); |
35 |
| - |
36 | 53 | map = record.getRawDataMap();
|
37 | 54 |
|
38 | 55 | Assert.assertEquals(map.size(), 0);
|
| 56 | + } |
39 | 57 |
|
40 |
| - // "abc" set in top record and also removed from culled. New "abc" shadows the field in base record |
41 |
| - record.typedSet("abc", TypedObject.valueOf("123")); |
| 58 | + @Test |
| 59 | + public void testRemove() { |
| 60 | + record.getBaseRecord().setString("abc", "def"); |
| 61 | + record.getTopRecord().setString("abc", "bar"); |
42 | 62 |
|
| 63 | + Assert.assertTrue(record.getBaseRecord().hasField("abc")); |
| 64 | + Assert.assertTrue(record.getTopRecord().hasField("abc")); |
43 | 65 | Assert.assertEquals(record.getCulledFields().size(), 0);
|
44 |
| - Assert.assertEquals(record.typedGet("abc").getValue(), "123"); |
45 | 66 |
|
46 |
| - map = record.getRawDataMap(); |
| 67 | + // remove returns this for chaining |
| 68 | + Assert.assertSame(record.remove("abc"), record); |
47 | 69 |
|
48 |
| - Assert.assertEquals(map.size(), 1); |
49 |
| - Assert.assertEquals(map.get("abc"), "123"); |
| 70 | + Assert.assertTrue(record.getBaseRecord().hasField("abc")); |
| 71 | + Assert.assertFalse(record.getTopRecord().hasField("abc")); |
| 72 | + Assert.assertEquals(record.getCulledFields().size(), 1); |
| 73 | + Assert.assertTrue((record.getCulledFields().contains("abc"))); |
| 74 | + |
| 75 | + // remove only affects the top record |
| 76 | + record.remove("abc"); |
| 77 | + |
| 78 | + Assert.assertTrue(record.getBaseRecord().hasField("abc")); |
| 79 | + Assert.assertFalse(record.getTopRecord().hasField("abc")); |
| 80 | + Assert.assertEquals(record.getCulledFields().size(), 1); |
| 81 | + Assert.assertTrue((record.getCulledFields().contains("abc"))); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void testTypedGet() { |
| 86 | + record.getBaseRecord().setString("abc", "def"); |
| 87 | + record.getTopRecord().setString("foo", "bar"); |
| 88 | + |
| 89 | + Assert.assertEquals(record.typedGet("abc").getValue(), "def"); |
| 90 | + Assert.assertEquals(record.typedGet("foo").getValue(), "bar"); |
| 91 | + Assert.assertNull(record.typedGet("123").getValue()); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testTypedGetShadowedFieldAndCulledField() { |
| 96 | + record.getBaseRecord().setString("abc", "def"); |
| 97 | + record.getTopRecord().setString("abc", "bar"); |
| 98 | + |
| 99 | + Assert.assertEquals(record.typedGet("abc").getValue(), "bar"); |
| 100 | + |
| 101 | + record.remove("abc"); |
| 102 | + |
| 103 | + Assert.assertNull(record.typedGet("abc").getValue()); |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + public void testTypedSet() { |
| 108 | + record.getBaseRecord().setString("abc", "def"); |
| 109 | + |
| 110 | + Assert.assertTrue(record.getBaseRecord().hasField("abc")); |
| 111 | + Assert.assertFalse(record.getTopRecord().hasField("abc")); |
| 112 | + |
| 113 | + record.typedSet("abc", TypedObject.valueOf("def")); |
| 114 | + |
| 115 | + Assert.assertTrue(record.getBaseRecord().hasField("abc")); |
| 116 | + Assert.assertTrue(record.getTopRecord().hasField("abc")); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void testTypedGetAndTypedSetCulledField() { |
| 121 | + record.getBaseRecord().setString("abc", "def"); |
| 122 | + record.getTopRecord().setString("abc", "bar"); |
| 123 | + record.remove("abc"); |
| 124 | + |
| 125 | + Assert.assertNull(record.typedGet("abc").getValue()); |
| 126 | + Assert.assertEquals(record.getCulledFields().size(), 1); |
| 127 | + Assert.assertTrue(record.getCulledFields().contains("abc")); |
| 128 | + |
| 129 | + record.typedSet("abc", TypedObject.valueOf("bar")); |
| 130 | + |
| 131 | + Assert.assertEquals(record.typedGet("abc").getValue(), "bar"); |
| 132 | + Assert.assertEquals(record.getCulledFields().size(), 0); |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + public void testCopy() { |
| 137 | + Assert.assertSame(record, record.copy()); |
50 | 138 | }
|
51 | 139 |
|
52 | 140 | @Test(expectedExceptions = UnsupportedOperationException.class)
|
@@ -79,11 +167,6 @@ public void testGetAndRemove() {
|
79 | 167 | record.getAndRemove(null);
|
80 | 168 | }
|
81 | 169 |
|
82 |
| - @Test |
83 |
| - public void testCopy() { |
84 |
| - Assert.assertSame(record, record.copy()); |
85 |
| - } |
86 |
| - |
87 | 170 | @Test(expectedExceptions = UnsupportedOperationException.class)
|
88 | 171 | public void testIterator() {
|
89 | 172 | record.iterator();
|
|
0 commit comments