[507] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | package gov.hhs.fha.nhinc.connectmgr.data;
|
---|
| 7 |
|
---|
| 8 | import org.junit.After;
|
---|
| 9 | import org.junit.AfterClass;
|
---|
| 10 | import org.junit.Before;
|
---|
| 11 | import org.junit.BeforeClass;
|
---|
| 12 | import org.junit.Test;
|
---|
| 13 | import static org.junit.Assert.*;
|
---|
| 14 |
|
---|
| 15 | /**
|
---|
| 16 | *
|
---|
| 17 | * @author westbergl
|
---|
| 18 | */
|
---|
| 19 | public class CMUDDIConnectionInfoXMLTest {
|
---|
| 20 |
|
---|
| 21 | public CMUDDIConnectionInfoXMLTest() {
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | @BeforeClass
|
---|
| 25 | public static void setUpClass() throws Exception
|
---|
| 26 | {
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | @AfterClass
|
---|
| 30 | public static void tearDownClass() throws Exception
|
---|
| 31 | {
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | @Before
|
---|
| 35 | public void setUp() {
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | @After
|
---|
| 39 | public void tearDown() {
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | /**
|
---|
| 43 | * Create a set of binding names.
|
---|
| 44 | *
|
---|
| 45 | * @param sTag The tag to append to the data.
|
---|
| 46 | * @return The BindingNames object.
|
---|
| 47 | */
|
---|
| 48 | private CMBindingNames createBindingNames(String sTag)
|
---|
| 49 | {
|
---|
| 50 | CMBindingNames oBindingNames = new CMBindingNames();
|
---|
| 51 | oBindingNames.getName().add("BindingName" + sTag + ".1");
|
---|
| 52 | oBindingNames.getName().add("BindingName" + sTag + ".2");
|
---|
| 53 |
|
---|
| 54 | return oBindingNames;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
| 58 | * Create a set of binding descriptions.
|
---|
| 59 | *
|
---|
| 60 | * @param sTag The tag to append to the data.
|
---|
| 61 | * @return The BindingDescriptions
|
---|
| 62 | */
|
---|
| 63 | private CMBindingDescriptions createBindingDescriptions(String sTag)
|
---|
| 64 | {
|
---|
| 65 | CMBindingDescriptions oDescriptions = new CMBindingDescriptions();
|
---|
| 66 | oDescriptions.getDescription().add("BindingDescription" + sTag + ".1");
|
---|
| 67 | oDescriptions.getDescription().add("BindingDescription" + sTag + ".2");
|
---|
| 68 |
|
---|
| 69 | return oDescriptions;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
| 73 | * Create a single binding template with the data appended with the tag.
|
---|
| 74 | *
|
---|
| 75 | * @param sTag The tag to append to the data.
|
---|
| 76 | * @return The new CMBindingTemplate.
|
---|
| 77 | */
|
---|
| 78 | private CMBindingTemplate createBindingTemplate(String sTag)
|
---|
| 79 | {
|
---|
| 80 | CMBindingTemplate oTemplate = new CMBindingTemplate();
|
---|
| 81 |
|
---|
| 82 | oTemplate.setBindingKey("BindingKey" + sTag);
|
---|
| 83 | oTemplate.setEndpointURL("EndpointURL" + sTag);
|
---|
| 84 | oTemplate.setWsdlURL("WSDLURL" + sTag);
|
---|
| 85 |
|
---|
| 86 | return oTemplate;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
| 90 | * This method creates the binding templates.
|
---|
| 91 | *
|
---|
| 92 | * @param sTag The tag to append to the data.
|
---|
| 93 | * @return The new binding templates.
|
---|
| 94 | */
|
---|
| 95 | private CMBindingTemplates createBindingTemplates(String sTag)
|
---|
| 96 | {
|
---|
| 97 | CMBindingTemplates oBindingTemplates = new CMBindingTemplates();
|
---|
| 98 |
|
---|
| 99 | oBindingTemplates.getBindingTemplate().add(createBindingTemplate(sTag + ".1"));
|
---|
| 100 | oBindingTemplates.getBindingTemplate().add(createBindingTemplate(sTag + ".2"));
|
---|
| 101 |
|
---|
| 102 | return oBindingTemplates;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /**
|
---|
| 106 | * Create a single business service with the data containing the given tag.
|
---|
| 107 | *
|
---|
| 108 | * @param sTag The tag to append to the data.
|
---|
| 109 | * @return The new business service.
|
---|
| 110 | */
|
---|
| 111 | private CMBusinessService createBusinessService(String sTag)
|
---|
| 112 | {
|
---|
| 113 | CMBusinessService oService = new CMBusinessService();
|
---|
| 114 |
|
---|
| 115 | oService.setInternalWebService(true);
|
---|
| 116 | oService.setServiceKey("ServiceKey" + sTag);
|
---|
| 117 | oService.setServiceVersion("1.0");
|
---|
| 118 | oService.setUniformServiceName("ServiceName" + sTag);
|
---|
| 119 | oService.setBindingTemplates(createBindingTemplates(sTag));
|
---|
| 120 | oService.setNames(createBindingNames(sTag));
|
---|
| 121 | oService.setDescriptions(createBindingDescriptions(sTag));
|
---|
| 122 |
|
---|
| 123 | return oService;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /**
|
---|
| 127 | * This method loads up a business services.
|
---|
| 128 | *
|
---|
| 129 | * @param idx1 The first index to use in the data.
|
---|
| 130 | * @return The new BusinessServices
|
---|
| 131 | */
|
---|
| 132 | private CMBusinessServices createBusinessServices(String sTag)
|
---|
| 133 | {
|
---|
| 134 | CMBusinessServices oServices = new CMBusinessServices();
|
---|
| 135 | oServices.getBusinessService().add(createBusinessService(sTag + ".1"));
|
---|
| 136 | oServices.getBusinessService().add(createBusinessService(sTag + ".2"));
|
---|
| 137 |
|
---|
| 138 | return oServices;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | /**
|
---|
| 142 | * Creates the descriptions for a contact.
|
---|
| 143 | *
|
---|
| 144 | * @param sTag The data to append to the data.
|
---|
| 145 | * @return The contact descriptions that were created.
|
---|
| 146 | */
|
---|
| 147 | private CMContactDescriptions createContactDescriptions(String sTag)
|
---|
| 148 | {
|
---|
| 149 | CMContactDescriptions oDescriptions = new CMContactDescriptions();
|
---|
| 150 | oDescriptions.getDescription().add("ContactDescription" + sTag + ".1");
|
---|
| 151 | oDescriptions.getDescription().add("ContactDescription" + sTag + ".2");
|
---|
| 152 | return oDescriptions;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | /**
|
---|
| 156 | * Creates the names for a contact.
|
---|
| 157 | *
|
---|
| 158 | * @param sTag The data to append to the data.
|
---|
| 159 | * @return The contact names that were created.
|
---|
| 160 | */
|
---|
| 161 | private CMPersonNames createContactPersonNames(String sTag)
|
---|
| 162 | {
|
---|
| 163 | CMPersonNames oNames = new CMPersonNames();
|
---|
| 164 | oNames.getPersonName().add("ContactPersonName" + sTag + ".1");
|
---|
| 165 | oNames.getPersonName().add("ContactPersonName" + sTag + ".2");
|
---|
| 166 | return oNames;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | * Creates the phone numbers for a contact.
|
---|
| 171 | *
|
---|
| 172 | * @param sTag The tag to append to the data.
|
---|
| 173 | * @return The phone numbers.
|
---|
| 174 | */
|
---|
| 175 | private CMPhones createContactPhones(String sTag)
|
---|
| 176 | {
|
---|
| 177 | CMPhones oPhones = new CMPhones();
|
---|
| 178 |
|
---|
| 179 | oPhones.getPhone().add("ContactPhone" + sTag + ".1");
|
---|
| 180 | oPhones.getPhone().add("ContactPhone" + sTag + ".2");
|
---|
| 181 |
|
---|
| 182 | return oPhones;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | /**
|
---|
| 186 | * Create the email addresses for a contact.
|
---|
| 187 | *
|
---|
| 188 | * @param sTag the tag to append to the data.
|
---|
| 189 | * @return The email addresses.
|
---|
| 190 | */
|
---|
| 191 | private CMEmails createContactEmails(String sTag)
|
---|
| 192 | {
|
---|
| 193 | CMEmails oEmails = new CMEmails();
|
---|
| 194 | oEmails.getEmail().add("Email" + sTag + ".1");
|
---|
| 195 | oEmails.getEmail().add("Email" + sTag + ".2");
|
---|
| 196 |
|
---|
| 197 | return oEmails;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | /**
|
---|
| 202 | * Create a single address for a contact.
|
---|
| 203 | * @param sTag the tag to append to the data.
|
---|
| 204 | * @return The address that was created.
|
---|
| 205 | */
|
---|
| 206 | private CMAddress createContactAddress(String sTag)
|
---|
| 207 | {
|
---|
| 208 | CMAddress oAddr = new CMAddress();
|
---|
| 209 | oAddr.getAddressLine().add("AddressLine" + sTag + ".1");
|
---|
| 210 | oAddr.getAddressLine().add("AddressLine" + sTag + ".2");
|
---|
| 211 | return oAddr;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | /**
|
---|
| 215 | * Creates addresses for a contact.
|
---|
| 216 | *
|
---|
| 217 | * @param sTag The tag to append to the data.
|
---|
| 218 | * @return The contacts addresses.
|
---|
| 219 | */
|
---|
| 220 | private CMAddresses createContactAddresses(String sTag)
|
---|
| 221 | {
|
---|
| 222 | CMAddresses oAddrs = new CMAddresses();
|
---|
| 223 | oAddrs.getAddress().add(createContactAddress(sTag + ".1"));
|
---|
| 224 | oAddrs.getAddress().add(createContactAddress(sTag + ".2"));
|
---|
| 225 | return oAddrs;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | /**
|
---|
| 229 | * Create a single contact.
|
---|
| 230 | *
|
---|
| 231 | * @param sTag Append this to the end of the data fields.
|
---|
| 232 | * @return The contact that was created.
|
---|
| 233 | */
|
---|
| 234 | private CMContact createContact(String sTag)
|
---|
| 235 | {
|
---|
| 236 | CMContact oContact = new CMContact();
|
---|
| 237 |
|
---|
| 238 | oContact.setDescriptions(createContactDescriptions(sTag));
|
---|
| 239 | oContact.setPersonNames(createContactPersonNames(sTag));
|
---|
| 240 | oContact.setPhones(createContactPhones(sTag));
|
---|
| 241 | oContact.setEmails(createContactEmails(sTag));
|
---|
| 242 | oContact.setAddresses(createContactAddresses(sTag));
|
---|
| 243 |
|
---|
| 244 | return oContact;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | /**
|
---|
| 248 | * Create a set of contacts.
|
---|
| 249 | *
|
---|
| 250 | * @param sTag The tag to append to the data.
|
---|
| 251 | * @return The Contacts that were created.
|
---|
| 252 | */
|
---|
| 253 | private CMContacts createContacts(String sTag)
|
---|
| 254 | {
|
---|
| 255 | CMContacts oContacts = new CMContacts();
|
---|
| 256 | oContacts.getContact().add(createContact(sTag + ".1"));
|
---|
| 257 | oContacts.getContact().add(createContact(sTag + ".2"));
|
---|
| 258 |
|
---|
| 259 | return oContacts;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | /**
|
---|
| 263 | * Create the business descriptions for this business entity.
|
---|
| 264 | *
|
---|
| 265 | * @param sTag The tag to append to the data.
|
---|
| 266 | * @return The BusinessDescriptions that were added.
|
---|
| 267 | */
|
---|
| 268 | private CMBusinessDescriptions createBusinessDescriptions(String sTag)
|
---|
| 269 | {
|
---|
| 270 | CMBusinessDescriptions oDescriptions = new CMBusinessDescriptions();
|
---|
| 271 | oDescriptions.getBusinessDescription().add("BusinessDescription" + sTag + ".1");
|
---|
| 272 | oDescriptions.getBusinessDescription().add("BusinessDescription" + sTag + ".2");
|
---|
| 273 | return oDescriptions;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | /**
|
---|
| 277 | * Create the discovery URLs for the business entity.
|
---|
| 278 | *
|
---|
| 279 | * @param sTag The tag to append to the data.
|
---|
| 280 | * @return The URLs
|
---|
| 281 | */
|
---|
| 282 | private CMDiscoveryURLs createDiscoveryURLs(String sTag)
|
---|
| 283 | {
|
---|
| 284 | CMDiscoveryURLs oURLs = new CMDiscoveryURLs();
|
---|
| 285 | oURLs.getDiscoveryURL().add("URL" + sTag + ".1");
|
---|
| 286 | oURLs.getDiscoveryURL().add("URL" + sTag + ".2");
|
---|
| 287 | return oURLs;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | /**
|
---|
| 291 | * Creates a set of business names.
|
---|
| 292 | *
|
---|
| 293 | * @param sTag the tag to append to the data.
|
---|
| 294 | * @return The busines names.
|
---|
| 295 | */
|
---|
| 296 | private CMBusinessNames createBusinessNames(String sTag)
|
---|
| 297 | {
|
---|
| 298 | CMBusinessNames oNames = new CMBusinessNames();
|
---|
| 299 | oNames.getBusinessName().add("BusinessName" + sTag + ".1");
|
---|
| 300 | oNames.getBusinessName().add("BusinessName" + sTag + ".2");
|
---|
| 301 | return oNames;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | /**
|
---|
| 305 | * Create the states associated with the business entity.
|
---|
| 306 | *
|
---|
| 307 | * @param sTag The tag to append to the data.
|
---|
| 308 | * @return The states that were created.
|
---|
| 309 | */
|
---|
| 310 | private CMStates createBusinessStates(String sTag)
|
---|
| 311 | {
|
---|
| 312 | CMStates oStates = new CMStates();
|
---|
| 313 | oStates.getState().add("State" + sTag + ".1");
|
---|
| 314 | oStates.getState().add("State" + sTag + ".2");
|
---|
| 315 | return oStates;
|
---|
| 316 |
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | /**
|
---|
| 320 | * This method loads up a business entity with some test data.
|
---|
| 321 | *
|
---|
| 322 | * @param index The index to add to the end of the values.
|
---|
| 323 | * @return The CMBusinessEntity that was created.
|
---|
| 324 | */
|
---|
| 325 | private CMBusinessEntity createBusinessEntity(String sTag)
|
---|
| 326 | {
|
---|
| 327 | CMBusinessEntity oEntity = new CMBusinessEntity();
|
---|
| 328 |
|
---|
| 329 | oEntity.setBusinessKey("BusinessKey" + sTag);
|
---|
| 330 | oEntity.setFederalHIE(true);
|
---|
| 331 | oEntity.setHomeCommunityId("1111.1111.1111.1111." + sTag);
|
---|
| 332 | oEntity.setPublicKeyURI("http://www.thekey.com" + sTag);
|
---|
| 333 | oEntity.setBusinessServices(createBusinessServices(sTag));
|
---|
| 334 | oEntity.setContacts(createContacts(sTag));
|
---|
| 335 | oEntity.setDescriptions(createBusinessDescriptions(sTag));
|
---|
| 336 | oEntity.setDiscoveryURLs(createDiscoveryURLs(sTag));
|
---|
| 337 | oEntity.setNames(createBusinessNames(sTag));
|
---|
| 338 | oEntity.setStates(createBusinessStates(sTag));
|
---|
| 339 |
|
---|
| 340 | byte baPublicKey[] = {100, 100, 100, 100, 100, 100};
|
---|
| 341 | oEntity.setPublicKey(baPublicKey);
|
---|
| 342 |
|
---|
| 343 |
|
---|
| 344 | return oEntity;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | /**
|
---|
| 348 | * Test of serialize method, of class CMUDDIConnectionInfoXML.
|
---|
| 349 | */
|
---|
| 350 | @Test
|
---|
| 351 | public void testSerializeAndDeserialize()
|
---|
| 352 | {
|
---|
| 353 | try
|
---|
| 354 | {
|
---|
| 355 | System.out.println("serializeAndDeserialize");
|
---|
| 356 | System.out.println("");
|
---|
| 357 |
|
---|
| 358 |
|
---|
| 359 | CMUDDIConnectionInfo oConnInfo = new CMUDDIConnectionInfo();
|
---|
| 360 | CMBusinessEntities oEntities = new CMBusinessEntities();
|
---|
| 361 | oConnInfo.setBusinessEntities(oEntities);
|
---|
| 362 | oEntities.getBusinessEntity().add(createBusinessEntity(".1"));
|
---|
| 363 | oEntities.getBusinessEntity().add(createBusinessEntity(".2"));
|
---|
| 364 |
|
---|
| 365 | String sXML = CMUDDIConnectionInfoXML.serialize(oConnInfo);
|
---|
| 366 | System.out.print(sXML);
|
---|
| 367 | assertNotNull(sXML);
|
---|
| 368 |
|
---|
| 369 | CMUDDIConnectionInfo oResultConnInfo = CMUDDIConnectionInfoXML.deserialize(sXML);
|
---|
| 370 |
|
---|
| 371 | assertTrue(oResultConnInfo.equals(oConnInfo));
|
---|
| 372 | }
|
---|
| 373 | catch (Exception e)
|
---|
| 374 | {
|
---|
| 375 | fail("Unexpected exception occurred. Error: " + e.getMessage());
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | }
|
---|