View Javadoc
1   /*
2    * Copyright 2018 the original author or authors.
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package org.openehealth.ipf.commons.ihe.hl7v2.audit.iti31;
18  
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.audit.codes.EventActionCode;
21  import org.openehealth.ipf.commons.audit.codes.EventIdCode;
22  import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
23  import org.openehealth.ipf.commons.audit.model.AuditMessage;
24  import org.openehealth.ipf.commons.ihe.hl7v2.audit.FeedAuditDataset;
25  import org.openehealth.ipf.commons.ihe.hl7v2.audit.Hl7v2AuditorTestBase;
26  
27  import static org.junit.Assert.assertNotNull;
28  
29  /**
30   * @author Christian Ohr
31   */
32  public class Iti31AuditStrategyTest extends Hl7v2AuditorTestBase {
33  
34      @Test
35      public void testCreateServerSide() {
36          testRequest(true, EventActionCode.Create);
37      }
38  
39      @Test
40      public void testCreateClientSide() {
41          testRequest(false, EventActionCode.Create);
42      }
43  
44      @Test
45      public void testUpdateServerSide() {
46          testRequest(true, EventActionCode.Update);
47      }
48  
49      @Test
50      public void testUpdateClientSide() {
51          testRequest(false, EventActionCode.Update);
52      }
53  
54      @Test
55      public void testDeleteServerSide() {
56          testRequest(true, EventActionCode.Delete);
57      }
58  
59      @Test
60      public void testDeleteClientSide() {
61          testRequest(false, EventActionCode.Delete);
62      }
63  
64      private void testRequest(boolean serverSide, EventActionCode eventActionCode) {
65          Iti31AuditStrategy strategy = new Iti31AuditStrategy(serverSide);
66          FeedAuditDataset auditDataset = getHl7v2AuditDataset(strategy, eventActionCode);
67          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
68  
69          assertNotNull(auditMessage);
70          auditMessage.validate();
71          assertCommonV2AuditAttributes(auditMessage,
72                  EventOutcomeIndicator.Success,
73                  EventIdCode.PatientRecord,
74                  eventActionCode,
75                  serverSide,
76                  true);
77      }
78  
79      private FeedAuditDataset getHl7v2AuditDataset(Iti31AuditStrategy strategy, EventActionCode eventActionCode) {
80          FeedAuditDataset auditDataset = strategy.createAuditDataset();
81          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
82          // auditDataset.setLocalAddress(SERVER_URI);
83          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
84          auditDataset.setMessageControlId(MESSAGE_ID);
85          auditDataset.setPatientId(PATIENT_IDS[0]);
86          switch (eventActionCode) {
87              case Create: auditDataset.setMessageType("A01"); break;
88              case Update: auditDataset.setMessageType("A08"); break;
89              case Delete: auditDataset.setMessageType("A41"); break;
90          }
91          auditDataset.setSendingFacility(SENDING_FACILITY);
92          auditDataset.setSendingApplication(SENDING_APPLICATION);
93          auditDataset.setReceivingFacility(RECEIVING_FACILITY);
94          auditDataset.setReceivingApplication(RECEIVING_APPLICATION);
95          return auditDataset;
96      }
97  }