source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Common/NhincLib/test/gov/hhs/fha/nhinc/connectmgr/data/CMInternalConnectionInfosXMLTest.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 8.3 KB
Line 
1package gov.hhs.fha.nhinc.connectmgr.data;
2
3import org.junit.After;
4import org.junit.AfterClass;
5import org.junit.Before;
6import org.junit.BeforeClass;
7import org.junit.Test;
8import static org.junit.Assert.*;
9
10/**
11 * Tests the serialization and deserialization of the InternalConnectionInfos object.
12 *
13 * @author Les Westberg
14 */
15public class CMInternalConnectionInfosXMLTest
16{
17 public CMInternalConnectionInfosXMLTest()
18 {
19 }
20
21 @BeforeClass
22 public static void setUpClass() throws Exception
23 {
24 }
25
26 @AfterClass
27 public static void tearDownClass() throws Exception
28 {
29 }
30
31 @Before
32 public void setUp()
33 {
34 }
35
36 @After
37 public void tearDown()
38 {
39 }
40
41 /**
42 * Test of serialize method, of class CMInternalConnectionInfosXML.
43 */
44 @Test
45 public void testSerializeAndDeserialize()
46 {
47 System.out.println("serializeAndDeserialize");
48
49 CMInternalConnectionInfos oConnInfos = new CMInternalConnectionInfos();
50 CMInternalConnectionInfo oConnInfo = new CMInternalConnectionInfo();
51 oConnInfos.getInternalConnectionInfo().add(oConnInfo);
52 oConnInfo.setDescription("Home1 Description");
53 oConnInfo.setHomeCommunityId("1111.1111.1111.1111");
54 oConnInfo.setName("Home1");
55 CMInternalConnInfoServices oServices = new CMInternalConnInfoServices();
56 oConnInfo.setServices(oServices);
57 CMInternalConnInfoService oService = new CMInternalConnInfoService();
58 oServices.getService().add(oService);
59 oService.setDescription("Service 1 Description");
60 oService.setName("Service 1 Name");
61 oService.setEndpointURL("http://www.service1.com");
62 oService.setExternalService(true);
63 oService = new CMInternalConnInfoService();
64 oServices.getService().add(oService);
65 oService.setDescription("Service 2 Description");
66 oService.setName("Service 2 Name");
67 oService.setEndpointURL("http://www.service2.com");
68 oService.setExternalService(false);
69
70 oConnInfo = new CMInternalConnectionInfo();
71 oConnInfos.getInternalConnectionInfo().add(oConnInfo);
72 oConnInfo.setDescription("Home2 Description");
73 oConnInfo.setHomeCommunityId("2222.2222.2222.2222");
74 oConnInfo.setName("Home2");
75 oServices = new CMInternalConnInfoServices();
76 oConnInfo.setServices(oServices);
77 oService = new CMInternalConnInfoService();
78 oServices.getService().add(oService);
79 oService.setDescription("Service 3 Description");
80 oService.setName("Service 3 Name");
81 oService.setEndpointURL("http://www.service3.com");
82 oService.setExternalService(true);
83 oService = new CMInternalConnInfoService();
84 oServices.getService().add(oService);
85 oService.setDescription("Service 4 Description");
86 oService.setName("Service 4 Name");
87 oService.setEndpointURL("http://www.service4.com");
88 oService.setExternalService(false);
89
90 String sXML = CMInternalConnectionInfosXML.serialize(oConnInfos);
91 assertNotNull(sXML);
92 System.out.println(sXML);
93
94 // Now deserialize and see if we got back what we expected.
95 //---------------------------------------------------------
96 CMInternalConnectionInfos oResult = CMInternalConnectionInfosXML.deserialize(sXML);
97 assertNotNull(oResult);
98 assertNotNull(oResult.getInternalConnectionInfo());
99 assertEquals(2, oResult.getInternalConnectionInfo().size());
100 boolean baFoundConn[] = {false, false};
101 for (CMInternalConnectionInfo oResultConnInfo : oResult.getInternalConnectionInfo())
102 {
103 if (oResultConnInfo.getName().equals("Home1"))
104 {
105 baFoundConn[0] = true;
106 assertEquals("Home1 Description", oResultConnInfo.getDescription());
107 assertEquals("1111.1111.1111.1111", oResultConnInfo.getHomeCommunityId());
108 assertNotNull(oResultConnInfo.getServices());
109 assertNotNull(oResultConnInfo.getServices().getService());
110 assertEquals(2, oResultConnInfo.getServices().getService().size());
111 boolean baFoundService[] = {false, false};
112 for (CMInternalConnInfoService oResultService : oResultConnInfo.getServices().getService())
113 {
114 if (oResultService.getName().equals("Service 1 Name"))
115 {
116 baFoundService[0] = true;
117 assertEquals("Service 1 Description", oResultService.getDescription());
118 assertEquals("http://www.service1.com", oResultService.getEndpointURL());
119 assertEquals(true, oResultService.isExternalService());
120 }
121 else if (oResultService.getName().equals("Service 2 Name"))
122 {
123 baFoundService[1] = true;
124 assertEquals("Service 2 Description", oResultService.getDescription());
125 assertEquals("http://www.service2.com", oResultService.getEndpointURL());
126 assertEquals(false, oResultService.isExternalService());
127 }
128 else
129 {
130 fail("Found an unexpected service.");
131 }
132 } // for (CMInternalConnInfoService oResultService : oResultConnInfo.getServices().getService())
133 assertTrue(baFoundService[0]);
134 assertTrue(baFoundService[1]);
135 } // if (oResultConnInfo.getName().equals("Home1"))
136 else if (oResultConnInfo.getName().equals("Home2"))
137 {
138 baFoundConn[1] = true;
139 assertEquals("Home2 Description", oResultConnInfo.getDescription());
140 assertEquals("2222.2222.2222.2222", oResultConnInfo.getHomeCommunityId());
141 assertNotNull(oResultConnInfo.getServices());
142 assertNotNull(oResultConnInfo.getServices().getService());
143 assertEquals(2, oResultConnInfo.getServices().getService().size());
144 boolean baFoundService[] = {false, false};
145 for (CMInternalConnInfoService oResultService : oResultConnInfo.getServices().getService())
146 {
147 if (oResultService.getName().equals("Service 3 Name"))
148 {
149 baFoundService[0] = true;
150 assertEquals("Service 3 Description", oResultService.getDescription());
151 assertEquals("http://www.service3.com", oResultService.getEndpointURL());
152 assertEquals(true, oResultService.isExternalService());
153 }
154 else if (oResultService.getName().equals("Service 4 Name"))
155 {
156 baFoundService[1] = true;
157 assertEquals("Service 4 Description", oResultService.getDescription());
158 assertEquals("http://www.service4.com", oResultService.getEndpointURL());
159 assertEquals(false, oResultService.isExternalService());
160 }
161 else
162 {
163 fail("Found an unexpected service.");
164 }
165 } // for (CMInternalConnInfoService oResultService : oResultConnInfo.getServices().getService())
166 assertTrue(baFoundService[0]);
167 assertTrue(baFoundService[1]);
168 }
169 else
170 {
171 fail("Found an unexpected CMInternalConnectionInfo object");
172 }
173 }
174 assertTrue(baFoundConn[0]);
175 assertTrue(baFoundConn[1]);
176
177
178
179
180
181 }
182
183 /**
184 * Test of deserialize method, of class CMInternalConnectionInfosXML.
185 */
186// @Test
187// public void testDeserialize()
188// {
189// System.out.println("deserialize");
190// String sXML = "";
191// CMInternalConnectionInfos expResult = null;
192// CMInternalConnectionInfos result = CMInternalConnectionInfosXML.deserialize(sXML);
193// assertEquals(expResult, result);
194// // TODO review the generated test code and remove the default call to fail.
195// fail("The test case is a prototype.");
196// }
197}
Note: See TracBrowser for help on using the repository browser.