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.iti10;
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.Hl7v2AuditorTestBase;
25  import org.openehealth.ipf.commons.ihe.hl7v2.audit.QueryAuditDataset;
26  
27  import static org.junit.Assert.assertNotNull;
28  
29  /**
30   * @author Christian Ohr
31   */
32  public class Iti10AuditStrategyTest extends Hl7v2AuditorTestBase {
33  
34      @Test
35      public void testServerSide() {
36          testRequest(true);
37      }
38  
39      @Test
40      public void testClientSide() {
41          testRequest(false);
42      }
43  
44      private void testRequest(boolean serverSide) {
45          Iti10AuditStrategy strategy = new Iti10AuditStrategy(serverSide);
46          QueryAuditDataset auditDataset = getHl7v2AuditDataset(strategy);
47          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
48  
49          assertNotNull(auditMessage);
50          auditMessage.validate();
51          assertCommonV2AuditAttributes(auditMessage,
52                  EventOutcomeIndicator.Success,
53                  EventIdCode.PatientRecord,
54                  serverSide ? EventActionCode.Update : EventActionCode.Read,
55                  serverSide,
56                  true);
57      }
58  
59      private QueryAuditDataset getHl7v2AuditDataset(Iti10AuditStrategy strategy) {
60          QueryAuditDataset auditDataset = strategy.createAuditDataset();
61          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
62          // auditDataset.setLocalAddress(SERVER_URI);
63          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
64          auditDataset.setMessageControlId(MESSAGE_ID);
65          auditDataset.setPatientIds(PATIENT_IDS);
66          auditDataset.setSendingFacility(SENDING_FACILITY);
67          auditDataset.setSendingApplication(SENDING_APPLICATION);
68          auditDataset.setReceivingFacility(RECEIVING_FACILITY);
69          auditDataset.setReceivingApplication(RECEIVING_APPLICATION);
70          auditDataset.setPayload(QUERY_PAYLOAD);
71          return auditDataset;
72      }
73  }