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.hl7v3.iti46;
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.core.atna.AuditDataset.HumanUser;
25  import org.openehealth.ipf.commons.ihe.hl7v3.atna.HL7v3AuditorTestBase;
26  import org.openehealth.ipf.commons.ihe.hl7v3.audit.Hl7v3AuditDataset;
27  
28  import static org.junit.Assert.assertNotNull;
29  
30  /**
31   * @author Christian Ohr
32   */
33  public class Iti46AuditStrategyTest extends HL7v3AuditorTestBase {
34  
35      @Test
36      public void testServerSide() {
37          testRequest(true);
38      }
39  
40      @Test
41      public void testClientSide() {
42          testRequest(false);
43      }
44  
45      private void testRequest(boolean serverSide) {
46          Iti46AuditStrategy strategy = new Iti46AuditStrategy(serverSide);
47          Hl7v3AuditDataset auditDataset = getHl7v3AuditDataset(strategy);
48          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
49  
50          assertNotNull(auditMessage);
51          auditMessage.validate();
52          assertCommonV3AuditAttributes(auditMessage,
53                  EventOutcomeIndicator.Success,
54                  EventIdCode.PatientRecord,
55                  serverSide ? EventActionCode.Update : EventActionCode.Read,
56                  serverSide,
57                  true);
58      }
59  
60      private Hl7v3AuditDataset getHl7v3AuditDataset(Iti46AuditStrategy strategy) {
61          Hl7v3AuditDataset auditDataset = strategy.createAuditDataset();
62          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
63          // auditDataset.setLocalAddress(SERVER_URI);
64          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
65          auditDataset.setMessageId(MESSAGE_ID);
66          auditDataset.setPatientIds(PATIENT_IDS);
67          auditDataset.setSourceUserId(REPLY_TO_URI);
68          auditDataset.setDestinationUserId(SERVER_URI);
69          auditDataset.setPurposesOfUse(PURPOSES_OF_USE);
70          auditDataset.getHumanUsers().add(new HumanUser(USER_ID, USER_NAME, USER_ROLES));
71          return auditDataset;
72      }
73  }