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.iti30;
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 Iti30AuditStrategyTest 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  
55      private void testRequest(boolean serverSide, EventActionCode eventActionCode) {
56          Iti30AuditStrategy strategy = new Iti30AuditStrategy(serverSide);
57          FeedAuditDataset auditDataset = getHl7v2AuditDataset(strategy, eventActionCode);
58          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
59  
60          assertNotNull(auditMessage);
61          auditMessage.validate();
62          assertCommonV2AuditAttributes(auditMessage,
63                  EventOutcomeIndicator.Success,
64                  EventIdCode.PatientRecord,
65                  eventActionCode,
66                  serverSide,
67                  true);
68      }
69  
70      private FeedAuditDataset getHl7v2AuditDataset(Iti30AuditStrategy strategy, EventActionCode eventActionCode) {
71          FeedAuditDataset auditDataset = strategy.createAuditDataset();
72          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
73          // auditDataset.setLocalAddress(SERVER_URI);
74          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
75          auditDataset.setMessageControlId(MESSAGE_ID);
76          auditDataset.setPatientId(PATIENT_IDS[0]);
77          switch (eventActionCode) {
78              case Create: auditDataset.setMessageType("A28"); break;
79              case Update: auditDataset.setMessageType("A31"); break;
80          }
81          auditDataset.setSendingFacility(SENDING_FACILITY);
82          auditDataset.setSendingApplication(SENDING_APPLICATION);
83          auditDataset.setReceivingFacility(RECEIVING_FACILITY);
84          auditDataset.setReceivingApplication(RECEIVING_APPLICATION);
85          return auditDataset;
86      }
87  }