1515 * Jason Koo, Chad Hartman, Karen Tamayo, Merritt Tidwell, Chris Anderberg
1616 */
1717public class DataManagerTests {
18-
1918 @ Test
2019 public void testInit () throws Exception {
2120 TestLibraryContext testCtx = TestLibraryContext .newInstance ();
@@ -49,6 +48,23 @@ public void testGetPersistentData() throws Exception {
4948
5049 LibraryContext ctx = TestLibraryContext .newInstance ();
5150
51+ Udo map = new Udo ();
52+ String key = "testKey" ;
53+ String value = "testValue" ;
54+ map .put (key , value );
55+
56+ DataManager data = new DataManager (ctx , TestUtils .dummyPersistentUdo (map ));
57+ Udo savedData = data .getPersistentData ();
58+
59+ assertTrue (savedData .containsKey (key ));
60+ assertTrue (savedData .containsValue (value ));
61+ }
62+
63+ @ Test
64+ public void testAddPersistentDataAddsDataToPersistentUdo () throws Exception {
65+
66+ LibraryContext ctx = TestLibraryContext .newInstance ();
67+
5268 DataManager data = new DataManager (ctx , TestUtils .dummyPersistentUdo ());
5369 Udo map = new Udo ();
5470
@@ -60,17 +76,30 @@ public void testGetPersistentData() throws Exception {
6076 // Write to disk first
6177 data .addPersistentData (map );
6278
63- Class <? extends DataManager > myclass = data .getClass ();
64- Method method = myclass .getDeclaredMethod ("getPersistentData" );
65- method .setAccessible (true );
66-
67- @ SuppressWarnings ("unchecked" )
68- Udo savedData = (Udo ) method .invoke (data );
79+ Udo savedData = data .getPersistentData ();
6980
7081 assertTrue (savedData .containsKey (key ));
7182 assertTrue (savedData .containsValue (value ));
7283 }
7384
85+ @ Test
86+ public void testDeletePersistentDataRemovesDataFromPersistentUdo () throws Exception {
87+
88+ LibraryContext ctx = TestLibraryContext .newInstance ();
89+
90+ Udo map = new Udo ();
91+ String key = "testKey" ;
92+ String value = "testValue" ;
93+ map .put (key , value );
94+
95+ DataManager data = new DataManager (ctx , TestUtils .dummyPersistentUdo (map ));
96+ data .deletePersistentData (Collections .singletonList ("testKey" ));
97+ Udo savedData = data .getPersistentData ();
98+
99+ assertFalse (savedData .containsKey (key ));
100+ assertFalse (savedData .containsValue (value ));
101+ }
102+
74103 /*
75104 * Test that new data doesn't contain visitor id or vid
76105 * Test that new data contains expected variables
0 commit comments