[507] | 1 | package gov.hhs.fha.nhinc.subscription.repository.service.test;
|
---|
| 2 |
|
---|
| 3 | import org.junit.After;
|
---|
| 4 | import org.junit.Before;
|
---|
| 5 | import org.junit.Test;
|
---|
| 6 | import static org.junit.Assert.*;
|
---|
| 7 | import gov.hhs.fha.nhinc.subscription.repository.service.SubscriptionRepositoryFactory;
|
---|
| 8 | import gov.hhs.fha.nhinc.subscription.repository.service.SubscriptionRepositoryService;
|
---|
| 9 | import gov.hhs.fha.nhinc.subscription.repository.SubscriptionRepositoryException;
|
---|
| 10 | import gov.hhs.fha.nhinc.subscription.repository.data.*;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * Unit test for the SubscriptionRepository
|
---|
| 14 | *
|
---|
| 15 | * @author Neil Webb
|
---|
| 16 | */
|
---|
| 17 | public class SubscriptionRepositoryTest
|
---|
| 18 | {
|
---|
| 19 | private SubscriptionRepositoryService repositoryService = null;
|
---|
| 20 | private SubscriptionRecord rec = null;
|
---|
| 21 | private SubscriptionReference ref = null;
|
---|
| 22 |
|
---|
| 23 | private static final String CRITERION_KEY = "CriterionKey";
|
---|
| 24 | private static final String CRITERION_VALUE = "CriterionValue";
|
---|
| 25 |
|
---|
| 26 | @Before
|
---|
| 27 | public void setUp()
|
---|
| 28 | {
|
---|
| 29 | System.out.println("Begin setUp");
|
---|
| 30 | try
|
---|
| 31 | {
|
---|
| 32 | repositoryService = new SubscriptionRepositoryFactory().getSubscriptionRepositoryService();
|
---|
| 33 | assertNotNull("Subscription service was null", repositoryService);
|
---|
| 34 | rec = createSubscriptionRecord();
|
---|
| 35 | ref = repositoryService.storeSubscription(rec);
|
---|
| 36 | }
|
---|
| 37 | catch(Throwable t)
|
---|
| 38 | {
|
---|
| 39 | t.printStackTrace();
|
---|
| 40 | fail(t.getMessage());
|
---|
| 41 | }
|
---|
| 42 | System.out.println("End setUp");
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | @After
|
---|
| 46 | public void tearDown()
|
---|
| 47 | {
|
---|
| 48 | System.out.println("Begin tearDown");
|
---|
| 49 | try
|
---|
| 50 | {
|
---|
| 51 | repositoryService.deleteSubscription(rec);
|
---|
| 52 | }
|
---|
| 53 | catch(Throwable t)
|
---|
| 54 | {
|
---|
| 55 | t.printStackTrace();
|
---|
| 56 | fail(t.getMessage());
|
---|
| 57 | }
|
---|
| 58 | System.out.println("End tearDown");
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | @Test
|
---|
| 62 | public void testStore()
|
---|
| 63 | {
|
---|
| 64 | System.out.println("Begin testStore");
|
---|
| 65 | try
|
---|
| 66 | {
|
---|
| 67 | assertNotNull("SubscriptionReference was null", ref);
|
---|
| 68 | assertNotNull("SubscriptionManagerEndpointAddress was null", ref.getSubscriptionManagerEndpointAddress());
|
---|
| 69 | assertFalse("SubscriptionManagerEndpointAddress was empty", ref.getSubscriptionManagerEndpointAddress().trim().length() == 0);
|
---|
| 70 | System.out.println("SubscriptionManagerEndpointAddress: " + ref.getSubscriptionManagerEndpointAddress());
|
---|
| 71 | assertNotNull("ReferenceParameters list was null", ref.getReferenceParameters());
|
---|
| 72 | assertEquals("ReferenceParameters list did not contain 1 parameter", 1, ref.getReferenceParameters().size());
|
---|
| 73 | ReferenceParameter param = ref.getReferenceParameters().get(0);
|
---|
| 74 | assertNotNull("Reference parameter was null", param);
|
---|
| 75 | assertNotNull("Reference parameter namespace was null", param.getNamespace());
|
---|
| 76 | assertNotNull("Reference parameter namespace prefix was null", param.getNamespacePrefix());
|
---|
| 77 | assertNotNull("Reference parameter element name was null", param.getElementName());
|
---|
| 78 | assertNotNull("Reference parameter value was null", param.getValue());
|
---|
| 79 | System.out.println("Subscription ID: " + param.getValue());
|
---|
| 80 | }
|
---|
| 81 | catch (Throwable t)
|
---|
| 82 | {
|
---|
| 83 | t.printStackTrace();
|
---|
| 84 | fail(t.getMessage());
|
---|
| 85 | }
|
---|
| 86 | System.out.println("End testStore");
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | @Test
|
---|
| 90 | public void testRetriveByCriteria()
|
---|
| 91 | {
|
---|
| 92 | System.out.println("Begin testRetriveByCriteria");
|
---|
| 93 | try
|
---|
| 94 | {
|
---|
| 95 | // Create subscription criteria
|
---|
| 96 | SubscriptionCriteria subCriteria = new SubscriptionCriteria();
|
---|
| 97 |
|
---|
| 98 | Patient subscriberPatient = new Patient();
|
---|
| 99 | subscriberPatient.setPatientId("Subscriber patient id");
|
---|
| 100 | Community subscriberPatientAssnAuth = new Community();
|
---|
| 101 | subscriberPatientAssnAuth.setCommunityId("Subscriber patient assigning authority id");
|
---|
| 102 | subscriberPatientAssnAuth.setCommunityName("Subscriber patient assigning authority name");
|
---|
| 103 | subscriberPatient.setAssigningAuthority(subscriberPatientAssnAuth);
|
---|
| 104 | subCriteria.setSubscriberPatient(subscriberPatient);
|
---|
| 105 |
|
---|
| 106 | Patient subscribeePatient = new Patient();
|
---|
| 107 | subscribeePatient.setPatientId("Subscribee patient id");
|
---|
| 108 | Community subscribeePatientAssnAuth = new Community();
|
---|
| 109 | subscribeePatientAssnAuth.setCommunityId("Subscribee patient assigning authority id");
|
---|
| 110 | subscribeePatientAssnAuth.setCommunityName("Subscribee patient assigning authority name");
|
---|
| 111 | subscribeePatient.setAssigningAuthority(subscribeePatientAssnAuth);
|
---|
| 112 | subCriteria.setSubscribeePatient(subscribeePatient);
|
---|
| 113 |
|
---|
| 114 | Criterion crit = new Criterion();
|
---|
| 115 | crit.setKey(CRITERION_KEY);
|
---|
| 116 | crit.setValue(CRITERION_VALUE);
|
---|
| 117 | subCriteria.addCriterion(crit);
|
---|
| 118 |
|
---|
| 119 | SubscriptionRecordList subscriptions = repositoryService.retrieveByCriteria(subCriteria, SubscriptionType.SUBSCRIPTION);
|
---|
| 120 | assertNotNull("Subscription record list was null", subscriptions);
|
---|
| 121 | assertEquals("A single subscription was not returned", 1, subscriptions.size());
|
---|
| 122 | }
|
---|
| 123 | catch (Throwable t)
|
---|
| 124 | {
|
---|
| 125 | t.printStackTrace();
|
---|
| 126 | fail(t.getMessage());
|
---|
| 127 | }
|
---|
| 128 | System.out.println("End testRetriveByCriteria");
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | @Test
|
---|
| 132 | public void testRetriveByTopicExpression()
|
---|
| 133 | {
|
---|
| 134 | System.out.println("Begin testRetriveByTopicExpression");
|
---|
| 135 | try
|
---|
| 136 | {
|
---|
| 137 | // Create subscription criteria
|
---|
| 138 | SubscriptionCriteria subCriteria = new SubscriptionCriteria();
|
---|
| 139 |
|
---|
| 140 | TopicExpression topicExpression = new TopicExpression();
|
---|
| 141 | topicExpression.setTopicExpressionValue("TopicExpressionVal");
|
---|
| 142 | subCriteria.setTopicExpression(topicExpression);
|
---|
| 143 |
|
---|
| 144 | SubscriptionRecordList subscriptions = repositoryService.retrieveByCriteria(subCriteria, SubscriptionType.SUBSCRIPTION);
|
---|
| 145 | assertNotNull("Subscription record list by topic expression was null", subscriptions);
|
---|
| 146 | assertEquals("A single subscription by topic expression was not returned", 1, subscriptions.size());
|
---|
| 147 | }
|
---|
| 148 | catch (Throwable t)
|
---|
| 149 | {
|
---|
| 150 | t.printStackTrace();
|
---|
| 151 | fail(t.getMessage());
|
---|
| 152 | }
|
---|
| 153 | System.out.println("End testRetriveByTopicExpression");
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | @Test
|
---|
| 157 | public void testRetriveBySubscriptionReference()
|
---|
| 158 | {
|
---|
| 159 | System.out.println("Begin testRetriveBySubscriptionReference");
|
---|
| 160 | try
|
---|
| 161 | {
|
---|
| 162 | SubscriptionRecord record = repositoryService.retrieveBySubscriptionReference(ref, SubscriptionType.SUBSCRIPTION);
|
---|
| 163 | assertNotNull("Subscription record was null", record);
|
---|
| 164 | assertEquals("Subscription record was not equal to that stored", rec, record);
|
---|
| 165 | }
|
---|
| 166 | catch (Throwable t)
|
---|
| 167 | {
|
---|
| 168 | t.printStackTrace();
|
---|
| 169 | fail(t.getMessage());
|
---|
| 170 | }
|
---|
| 171 | System.out.println("End testRetriveBySubscriptionReference");
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | @Test
|
---|
| 175 | public void testRetriveByParentSubscriptionReference()
|
---|
| 176 | {
|
---|
| 177 | System.out.println("Begin testRetriveByParentSubscriptionReference");
|
---|
| 178 | try
|
---|
| 179 | {
|
---|
| 180 | // Parent subscription ref
|
---|
| 181 | String subMgrEndptAddr = "Submgredptaddr";
|
---|
| 182 | String namespace = "namespace";
|
---|
| 183 | String namespacePrefix = "prefix";
|
---|
| 184 | String elementName = "elementName";
|
---|
| 185 | String value = "elementValue";
|
---|
| 186 |
|
---|
| 187 | ReferenceParameter refParam = new ReferenceParameter();
|
---|
| 188 | refParam.setNamespace(namespace);
|
---|
| 189 | refParam.setNamespacePrefix(namespacePrefix);
|
---|
| 190 | refParam.setElementName(elementName);
|
---|
| 191 | refParam.setValue(value);
|
---|
| 192 |
|
---|
| 193 | SubscriptionReference subRef = new SubscriptionReference();
|
---|
| 194 | subRef.setSubscriptionManagerEndpointAddress(subMgrEndptAddr);
|
---|
| 195 | subRef.addReferenceParameter(refParam);
|
---|
| 196 |
|
---|
| 197 | SubscriptionRecordList subscriptions = repositoryService.retrieveByParentSubscriptionReference(subRef, SubscriptionType.SUBSCRIPTION);
|
---|
| 198 | assertNotNull("Subscriptoins list was null", subscriptions);
|
---|
| 199 | assertEquals("Subscriptoins list was not size of 1", 1, subscriptions.size());
|
---|
| 200 |
|
---|
| 201 | SubscriptionRecord record = subscriptions.get(0);
|
---|
| 202 | assertNotNull("Subscription record was null", record);
|
---|
| 203 | assertEquals("Subscription record was not equal to that stored", rec, record);
|
---|
| 204 | }
|
---|
| 205 | catch (Throwable t)
|
---|
| 206 | {
|
---|
| 207 | t.printStackTrace();
|
---|
| 208 | fail(t.getMessage());
|
---|
| 209 | }
|
---|
| 210 | System.out.println("End testRetriveByParentSubscriptionReference");
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | private SubscriptionRecord createSubscriptionRecord() throws SubscriptionRepositoryException
|
---|
| 214 | {
|
---|
| 215 | SubscriptionRecord rec = new SubscriptionRecord();
|
---|
| 216 | rec.setType(SubscriptionType.SUBSCRIPTION);
|
---|
| 217 | SubscriptionItem subItem = new SubscriptionItem();
|
---|
| 218 | rec.setSubscription(subItem);
|
---|
| 219 |
|
---|
| 220 | // Subscriber
|
---|
| 221 | SubscriptionParticipant subscriber = new SubscriptionParticipant();
|
---|
| 222 | subscriber.setNotificationEndpointAddress("Subscriber notification endpoint address");
|
---|
| 223 | subscriber.setUserAddress("Subscriber user address");
|
---|
| 224 | Community subscriberCommunity = new Community();
|
---|
| 225 | subscriberCommunity.setCommunityId("Subscriber community id");
|
---|
| 226 | subscriberCommunity.setCommunityName("Subscriber community name");
|
---|
| 227 | subscriber.setCommunity(subscriberCommunity);
|
---|
| 228 | subItem.setSubscriber(subscriber);
|
---|
| 229 |
|
---|
| 230 | // Subscribee
|
---|
| 231 | SubscriptionParticipant subscribee = new SubscriptionParticipant();
|
---|
| 232 | subscribee.setNotificationEndpointAddress("Subscribee notification endpoint address");
|
---|
| 233 | subscribee.setUserAddress("Subscribee user address");
|
---|
| 234 | Community subscribeeCommunity = new Community();
|
---|
| 235 | subscribeeCommunity.setCommunityId("Subscribee community id");
|
---|
| 236 | subscribeeCommunity.setCommunityName("Subscribee community name");
|
---|
| 237 | subscribee.setCommunity(subscribeeCommunity);
|
---|
| 238 | subItem.setSubscribee(subscribee);
|
---|
| 239 |
|
---|
| 240 | // Criteria
|
---|
| 241 | SubscriptionCriteria subCriteria = new SubscriptionCriteria();
|
---|
| 242 |
|
---|
| 243 | Patient subscriberPatient = new Patient();
|
---|
| 244 | subscriberPatient.setPatientId("Subscriber patient id");
|
---|
| 245 | Community subscriberPatientAssnAuth = new Community();
|
---|
| 246 | subscriberPatientAssnAuth.setCommunityId("Subscriber patient assigning authority id");
|
---|
| 247 | subscriberPatientAssnAuth.setCommunityName("Subscriber patient assigning authority name");
|
---|
| 248 | subscriberPatient.setAssigningAuthority(subscriberPatientAssnAuth);
|
---|
| 249 | subCriteria.setSubscriberPatient(subscriberPatient);
|
---|
| 250 |
|
---|
| 251 | Patient subscribeePatient = new Patient();
|
---|
| 252 | subscribeePatient.setPatientId("Subscribee patient id");
|
---|
| 253 | Community subscribeePatientAssnAuth = new Community();
|
---|
| 254 | subscribeePatientAssnAuth.setCommunityId("Subscribee patient assigning authority id");
|
---|
| 255 | subscribeePatientAssnAuth.setCommunityName("Subscribee patient assigning authority name");
|
---|
| 256 | subscribeePatient.setAssigningAuthority(subscribeePatientAssnAuth);
|
---|
| 257 | subCriteria.setSubscribeePatient(subscribeePatient);
|
---|
| 258 |
|
---|
| 259 | Criterion crit = new Criterion();
|
---|
| 260 | crit.setKey(CRITERION_KEY);
|
---|
| 261 | crit.setValue(CRITERION_VALUE);
|
---|
| 262 | subCriteria.addCriterion(crit);
|
---|
| 263 |
|
---|
| 264 | // Topic expression
|
---|
| 265 | TopicExpression topicExpression = new TopicExpression();
|
---|
| 266 | topicExpression.setDialect("YerBasicDialect");
|
---|
| 267 | topicExpression.setTopicExpressionValue("TopicExpressionVal");
|
---|
| 268 | subCriteria.setTopicExpression(topicExpression);
|
---|
| 269 |
|
---|
| 270 | subItem.setSubscriptionCriteria(subCriteria);
|
---|
| 271 |
|
---|
| 272 | // Parent subscription ref
|
---|
| 273 | String subMgrEndptAddr = "Submgredptaddr";
|
---|
| 274 | String namespace = "namespace";
|
---|
| 275 | String namespacePrefix = "prefix";
|
---|
| 276 | String elementName = "elementName";
|
---|
| 277 | String value = "elementValue";
|
---|
| 278 |
|
---|
| 279 | ReferenceParameter refParam = new ReferenceParameter();
|
---|
| 280 | refParam.setNamespace(namespace);
|
---|
| 281 | refParam.setNamespacePrefix(namespacePrefix);
|
---|
| 282 | refParam.setElementName(elementName);
|
---|
| 283 | refParam.setValue(value);
|
---|
| 284 |
|
---|
| 285 | SubscriptionReference subRef = new SubscriptionReference();
|
---|
| 286 | subRef.setSubscriptionManagerEndpointAddress(subMgrEndptAddr);
|
---|
| 287 | subRef.addReferenceParameter(refParam);
|
---|
| 288 | subItem.setParentSubscriptionReference(subRef);
|
---|
| 289 |
|
---|
| 290 | return rec;
|
---|
| 291 | }
|
---|
| 292 | }
|
---|