1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.adapter.reidentification;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.adapter.reidentification.data.PseudonymMap;
|
---|
8 | import org.junit.After;
|
---|
9 | import org.junit.Before;
|
---|
10 | import org.junit.Test;
|
---|
11 | import static org.junit.Assert.*;
|
---|
12 | import org.apache.commons.logging.Log;
|
---|
13 | import org.apache.commons.logging.LogFactory;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Tester to validate the expected functionality of the Pseudonym management
|
---|
17 | */
|
---|
18 | public class PseudonymMapTest {
|
---|
19 | private static Log log = LogFactory.getLog(PseudonymMapTest.class);
|
---|
20 | private static final String pseudoPatientId_1 = "111";
|
---|
21 | private static final String pseudoAuthorityId_1 = "Auth.A.B.C";
|
---|
22 | private static final String realPatientId_1 = "999";
|
---|
23 | private static final String realAuthorityId_1 = "Auth.X.Y.Z";
|
---|
24 |
|
---|
25 | private static final String pseudoPatientId_2 = "222";
|
---|
26 | private static final String pseudoAuthorityId_2 = "Auth.A.B.C";
|
---|
27 | private static final String realPatientId_2 = "999";
|
---|
28 | private static final String realAuthorityId_2 = "Auth.X.Y.Z";
|
---|
29 |
|
---|
30 | private static final String pseudoPatientId_3 = "333";
|
---|
31 | private static final String pseudoAuthorityId_3 = "Auth.A.B.C";
|
---|
32 | private static final String realPatientId_3 = "888";
|
---|
33 | private static final String realAuthorityId_3 = "Auth.X.Y.Z";
|
---|
34 |
|
---|
35 | private PseudonymMap pseudonymMap_1;
|
---|
36 | private PseudonymMap pseudonymMap_2;
|
---|
37 | private PseudonymMap pseudonymMap_3;
|
---|
38 |
|
---|
39 | public PseudonymMapTest() {
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Before
|
---|
43 | public void setUp() {
|
---|
44 | //create first test PseudonymMap
|
---|
45 | pseudonymMap_1 = new PseudonymMap();
|
---|
46 | pseudonymMap_1.setPseudonymPatientId(pseudoPatientId_1);
|
---|
47 | pseudonymMap_1.setPseudonymPatientIdAssigningAuthority(pseudoAuthorityId_1);
|
---|
48 | pseudonymMap_1.setRealPatientId(realPatientId_1);
|
---|
49 | pseudonymMap_1.setRealPatientIdAssigningAuthority(realAuthorityId_1);
|
---|
50 |
|
---|
51 | //create second test PseudonymMap - only difference is pseudoPatientId
|
---|
52 | pseudonymMap_2 = new PseudonymMap();
|
---|
53 | pseudonymMap_2.setPseudonymPatientId(pseudoPatientId_2);
|
---|
54 | pseudonymMap_2.setPseudonymPatientIdAssigningAuthority(pseudoAuthorityId_2);
|
---|
55 | pseudonymMap_2.setRealPatientId(realPatientId_2);
|
---|
56 | pseudonymMap_2.setRealPatientIdAssigningAuthority(realAuthorityId_2);
|
---|
57 |
|
---|
58 | //create third test PseudonymMap - Ids are different
|
---|
59 | pseudonymMap_3 = new PseudonymMap();
|
---|
60 | pseudonymMap_3.setPseudonymPatientId(pseudoPatientId_3);
|
---|
61 | pseudonymMap_3.setPseudonymPatientIdAssigningAuthority(pseudoAuthorityId_3);
|
---|
62 | pseudonymMap_3.setRealPatientId(realPatientId_3);
|
---|
63 | pseudonymMap_3.setRealPatientIdAssigningAuthority(realAuthorityId_3);
|
---|
64 |
|
---|
65 | //initialize contents of internal memory
|
---|
66 | PseudonymMapManager.readMap();
|
---|
67 | }
|
---|
68 |
|
---|
69 | @After
|
---|
70 | public void tearDown() {
|
---|
71 | //reset external memory
|
---|
72 | PseudonymMapManager.writeMap();
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Test the creation of a Pseudonym Map XML file and the extraction of a stored map
|
---|
77 | */
|
---|
78 | @Test
|
---|
79 | public void testStoreRetrieve() {
|
---|
80 | log.debug("Entering PseudonymMapTest.testStoreRetrieve");
|
---|
81 | // pseudonymMap should not previously exist
|
---|
82 | assertNull(PseudonymMapManager.addPseudonymMap(pseudonymMap_1));
|
---|
83 | PseudonymMapManager.writeMap();
|
---|
84 | PseudonymMapManager.readMap();
|
---|
85 | PseudonymMap searchMap = PseudonymMapManager.findPseudonymMap(pseudoAuthorityId_1, pseudoPatientId_1);
|
---|
86 |
|
---|
87 | // pseudonymMap should be located
|
---|
88 | assertNotNull(searchMap);
|
---|
89 |
|
---|
90 | // and should be the same as what we created previously
|
---|
91 | assertEquals(pseudonymMap_1.toString(), searchMap.toString());
|
---|
92 | log.debug("Exiting PseudonymMapTest.testStoreRetrieve");
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Test the replacement of data given the same id
|
---|
97 | */
|
---|
98 | @Test
|
---|
99 | public void testIdReplacement() {
|
---|
100 | log.debug("Entering PseudonymMapTest.testIdReplacement");
|
---|
101 | // pseudonymMap for this Id should previously exist and return the old one
|
---|
102 | PseudonymMap prevMap = PseudonymMapManager.addPseudonymMap(pseudonymMap_2);
|
---|
103 | assertNotNull(prevMap);
|
---|
104 | // and should be the same as what we created previously
|
---|
105 | assertEquals(pseudonymMap_1.toString(), prevMap.toString());
|
---|
106 |
|
---|
107 | // pseudonymMap for this Id should not previously exist
|
---|
108 | PseudonymMap newMap = PseudonymMapManager.addPseudonymMap(pseudonymMap_3);
|
---|
109 | assertNull(newMap);
|
---|
110 |
|
---|
111 | PseudonymMapManager.writeMap();
|
---|
112 | PseudonymMapManager.readMap();
|
---|
113 |
|
---|
114 | PseudonymMap searchMap = PseudonymMapManager.findPseudonymMap(pseudoAuthorityId_2, pseudoPatientId_2);
|
---|
115 | // pseudonymMap should be located
|
---|
116 | assertNotNull(searchMap);
|
---|
117 | // and should be the same as what we created previously as 2
|
---|
118 | assertEquals(pseudonymMap_2.toString(), searchMap.toString());
|
---|
119 |
|
---|
120 | searchMap = PseudonymMapManager.findPseudonymMap(pseudoAuthorityId_3, pseudoPatientId_3);
|
---|
121 | // pseudonymMap should be located
|
---|
122 | assertNotNull(searchMap);
|
---|
123 | // and should be the same as what we created previously as 3
|
---|
124 | assertEquals(pseudonymMap_3.toString(), searchMap.toString());
|
---|
125 |
|
---|
126 | log.debug("Exiting PseudonymMapTest.testIdReplacement");
|
---|
127 | }
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Test the removal of maps
|
---|
131 | */
|
---|
132 | @Test
|
---|
133 | public void testRemoval() {
|
---|
134 | log.debug("Entering PseudonymMapTest.testRemoval");
|
---|
135 | // pseudonymMap_2 should exist and can be removed
|
---|
136 | assertTrue(PseudonymMapManager.removePseudonymMap(pseudonymMap_2));
|
---|
137 | // pseudonymMap_3 should exist and can be removed
|
---|
138 | assertTrue(PseudonymMapManager.removePseudonymMap(pseudonymMap_3));
|
---|
139 |
|
---|
140 | PseudonymMapManager.writeMap();
|
---|
141 | PseudonymMapManager.readMap();
|
---|
142 |
|
---|
143 | // neither 1, 2, or 3 should exist now
|
---|
144 | assertFalse(PseudonymMapManager.removePseudonymMap(pseudonymMap_1));
|
---|
145 | assertFalse(PseudonymMapManager.removePseudonymMap(pseudonymMap_2));
|
---|
146 | assertFalse(PseudonymMapManager.removePseudonymMap(pseudonymMap_3));
|
---|
147 | log.debug("Exiting PseudonymMapTest.testRemoval");
|
---|
148 | }
|
---|
149 | }
|
---|