source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Gateway/NhincAuditLogDteEJB/test/gov/hhs/fha/nhinc/transform/audit/UnsubscribeTransformsTest.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: 9.3 KB
Line 
1package gov.hhs.fha.nhinc.transform.audit;
2
3import com.services.nhinc.schema.auditmessage.AuditMessageType;
4import com.services.nhinc.schema.auditmessage.AuditSourceIdentificationType;
5import com.services.nhinc.schema.auditmessage.EventIdentificationType;
6import gov.hhs.fha.nhinc.common.auditlog.LogEventRequestType;
7import gov.hhs.fha.nhinc.common.auditlog.LogNhinUnsubscribeRequestType;
8import gov.hhs.fha.nhinc.common.auditlog.LogUnsubscribeResponseType;
9import gov.hhs.fha.nhinc.common.auditlog.UnsubscribeResponseMessageType;
10import gov.hhs.fha.nhinc.common.nhinccommon.AssertionType;
11import gov.hhs.fha.nhinc.common.nhinccommon.HomeCommunityType;
12import gov.hhs.fha.nhinc.common.nhinccommon.PersonNameType;
13import gov.hhs.fha.nhinc.common.nhinccommon.UserType;
14import gov.hhs.fha.nhinc.common.nhinccommoninternalorch.UnsubscribeRequestType;
15import gov.hhs.fha.nhinc.common.subscription.ReferenceParameterType;
16import gov.hhs.fha.nhinc.common.subscription.ReferenceParametersType;
17import gov.hhs.fha.nhinc.common.subscription.SubscriptionReferenceType;
18import gov.hhs.fha.nhinc.common.subscription.UnsubscribeType;
19import org.oasis_open.docs.wsn.b_2.UnsubscribeResponse;
20import org.apache.commons.logging.Log;
21import org.apache.commons.logging.LogFactory;
22import org.junit.Test;
23import static org.junit.Assert.*;
24
25/**
26 * Test for UnsubscribeTransforms class
27 *
28 * @author Neil Webb
29 */
30public class UnsubscribeTransformsTest
31{
32
33 private static Log log = LogFactory.getLog(UnsubscribeTransformsTest.class);
34
35 @Test
36 public void testUnsubscribeRequest()
37 {
38 log.debug("Start testUnsubscribeRequest");
39 try
40 {
41 LogNhinUnsubscribeRequestType message = new LogNhinUnsubscribeRequestType();
42 message.setDirection("Inbound");
43 message.setInterface("Nhin");
44
45 UnsubscribeRequestType unsubscribeRequest = new UnsubscribeRequestType();
46
47 // Assertion
48 HomeCommunityType home = new HomeCommunityType();
49 home.setHomeCommunityId("2.16.840.1.113883.3.200");
50 home.setName("Federal - VA");
51 UserType userInfo = new UserType();
52 userInfo.setOrg(home);
53 PersonNameType personName = new PersonNameType();
54 personName.setFamilyName("Smith");
55 personName.setGivenName("Mary");
56 userInfo.setPersonName(personName);
57 AssertionType assertion = new AssertionType();
58 assertion.setUserInfo(userInfo);
59 unsubscribeRequest.setAssertion(assertion);
60
61 // Unsubscribe
62 UnsubscribeType unsubscribe = new UnsubscribeType();
63 SubscriptionReferenceType subRef = new SubscriptionReferenceType();
64 ReferenceParametersType refParams = new ReferenceParametersType();
65 ReferenceParameterType refParam = new ReferenceParameterType();
66 refParam.setPrefix("nhin");
67 refParam.setNamespace("http://www.hhs.gov/healthid/nhin");
68 refParam.setElementName("SubscriptionId");
69 refParam.setValue("testval");
70 refParams.getReferenceParameter().add(refParam);
71 subRef.setSubscriptionManagerEndpointAddress("http://www.somewhere.com/SubscriptionManager");
72 subRef.setReferenceParameters(refParams);
73 unsubscribe.setSubscriptionReference(subRef);
74 unsubscribeRequest.setUnsubscribe(unsubscribe);
75
76 message.setMessage(unsubscribeRequest);
77
78 UnsubscribeTransforms transform = new UnsubscribeTransforms();
79 LogEventRequestType result = transform.transformNhinUnsubscribeRequestToAuditMessage(message);
80
81 // Expected log result
82 LogEventRequestType expResult = new LogEventRequestType();
83 AuditMessageType auditMsg = new AuditMessageType();
84 expResult.setAuditMessage(auditMsg);
85 AuditMessageType.ActiveParticipant participant = new AuditMessageType.ActiveParticipant();
86 participant.setUserName("Mary Smith");
87 expResult.getAuditMessage().getActiveParticipant().add(participant);
88 AuditSourceIdentificationType sourceId = new AuditSourceIdentificationType();
89 sourceId.setAuditEnterpriseSiteID(home.getName());
90 expResult.getAuditMessage().getAuditSourceIdentification().add(sourceId);
91 EventIdentificationType eventId = new EventIdentificationType();
92 eventId.setEventActionCode(AuditDataTransformConstants.EVENT_ACTION_CODE_CREATE);
93 expResult.getAuditMessage().setEventIdentification(eventId);
94
95 // Validate
96 assertNotNull("LogEventRequestType was null", result);
97 assertEquals(expResult.getAuditMessage().getActiveParticipant().get(0).getUserName(), result.getAuditMessage().getActiveParticipant().get(0).getUserName());
98 assertEquals(expResult.getAuditMessage().getAuditSourceIdentification().get(0).getAuditEnterpriseSiteID(),
99 result.getAuditMessage().getAuditSourceIdentification().get(0).getAuditEnterpriseSiteID());
100 assertEquals(expResult.getAuditMessage().getEventIdentification().getEventActionCode(), result.getAuditMessage().getEventIdentification().getEventActionCode());
101
102 } catch (Throwable t)
103 {
104 log.error("Error occured in testUnsubscribeRequest: " + t.getMessage(), t);
105 fail(t.getMessage());
106 }
107 log.debug("End testUnsubscribeRequest");
108 }
109
110 @Test
111 public void testUnsubscribeResponse()
112 {
113 log.debug("Begin testUnsubscribeResponse");
114 try
115 {
116 LogUnsubscribeResponseType message = new LogUnsubscribeResponseType();
117 message.setDirection("Inbound");
118 message.setInterface("Nhin");
119
120 UnsubscribeResponseMessageType unsubscribeResponseMessage = new UnsubscribeResponseMessageType();
121
122 // Assertion
123 HomeCommunityType home = new HomeCommunityType();
124 home.setHomeCommunityId("2.16.840.1.113883.3.200");
125 home.setName("Federal - VA");
126 UserType userInfo = new UserType();
127 userInfo.setOrg(home);
128 PersonNameType personName = new PersonNameType();
129 personName.setFamilyName("Smith");
130 personName.setGivenName("Mary");
131 userInfo.setPersonName(personName);
132 AssertionType assertion = new AssertionType();
133 assertion.setUserInfo(userInfo);
134 unsubscribeResponseMessage.setAssertion(assertion);
135
136 // Unsubscribe response
137 UnsubscribeResponse unsubscribeResponse = new UnsubscribeResponse();
138 SubscriptionReferenceType subRef = new SubscriptionReferenceType();
139 ReferenceParametersType refParams = new ReferenceParametersType();
140 ReferenceParameterType refParam = new ReferenceParameterType();
141 refParam.setPrefix("nhin");
142 refParam.setNamespace("http://www.hhs.gov/healthid/nhin");
143 refParam.setElementName("SubscriptionId");
144 refParam.setValue("testval");
145 refParams.getReferenceParameter().add(refParam);
146 subRef.setSubscriptionManagerEndpointAddress("http://www.somewhere.com/SubscriptionManager");
147 subRef.setReferenceParameters(refParams);
148 unsubscribeResponseMessage.setUnsubscribeResponse(unsubscribeResponse);
149
150 message.setMessage(unsubscribeResponseMessage);
151
152 UnsubscribeTransforms transform = new UnsubscribeTransforms();
153 LogEventRequestType result = transform.transformUnsubscribeResponseToGenericAudit(message);
154
155 // Expected log result
156 LogEventRequestType expResult = new LogEventRequestType();
157 AuditMessageType auditMsg = new AuditMessageType();
158 expResult.setAuditMessage(auditMsg);
159 AuditMessageType.ActiveParticipant participant = new AuditMessageType.ActiveParticipant();
160 participant.setUserName("Mary Smith");
161 expResult.getAuditMessage().getActiveParticipant().add(participant);
162 AuditSourceIdentificationType sourceId = new AuditSourceIdentificationType();
163 sourceId.setAuditEnterpriseSiteID(home.getName());
164 expResult.getAuditMessage().getAuditSourceIdentification().add(sourceId);
165 EventIdentificationType eventId = new EventIdentificationType();
166 eventId.setEventActionCode(AuditDataTransformConstants.EVENT_ACTION_CODE_CREATE);
167 expResult.getAuditMessage().setEventIdentification(eventId);
168
169 // Validate
170 assertNotNull("LogEventRequestType was null", result);
171 assertEquals(expResult.getAuditMessage().getActiveParticipant().get(0).getUserName(), result.getAuditMessage().getActiveParticipant().get(0).getUserName());
172 assertEquals(expResult.getAuditMessage().getAuditSourceIdentification().get(0).getAuditEnterpriseSiteID(),
173 result.getAuditMessage().getAuditSourceIdentification().get(0).getAuditEnterpriseSiteID());
174 assertEquals(expResult.getAuditMessage().getEventIdentification().getEventActionCode(), result.getAuditMessage().getEventIdentification().getEventActionCode());
175
176 } catch (Throwable t)
177 {
178 log.error("Error running testUnsubscribeResponse: " + t.getMessage(), t);
179 fail(t.getMessage());
180 }
181 log.debug("End testUnsubscribeResponse");
182 }
183}
Note: See TracBrowser for help on using the repository browser.