View Javadoc
1   /*
2    * Copyright 2017 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.iti44;
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 Iti44AuditStrategyTest extends HL7v3AuditorTestBase {
34  
35      @Test
36      public void testCreateServerSide() {
37          testRequest(true, EventActionCode.Create);
38      }
39  
40      @Test
41      public void testCreateClientSide() {
42          testRequest(false, EventActionCode.Create);
43      }
44  
45      @Test
46      public void testUpdateServerSide() {
47          testRequest(true, EventActionCode.Update);
48      }
49  
50      @Test
51      public void testUpdateClientSide() {
52          testRequest(false, EventActionCode.Update);
53      }
54  
55  
56      private void testRequest(boolean serverSide, EventActionCode eventActionCode) {
57          Iti44AuditStrategy strategy = new Iti44AuditStrategy(serverSide);
58          Hl7v3AuditDataset auditDataset = getHl7v3AuditDataset(strategy, eventActionCode);
59          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
60  
61          assertNotNull(auditMessage);
62          auditMessage.validate();
63          assertCommonV3AuditAttributes(auditMessage,
64                  EventOutcomeIndicator.Success,
65                  EventIdCode.PatientRecord,
66                  eventActionCode,
67                  serverSide,
68                  true);
69      }
70  
71      private Hl7v3AuditDataset getHl7v3AuditDataset(Iti44AuditStrategy strategy, EventActionCode eventActionCode) {
72          Hl7v3AuditDataset auditDataset = strategy.createAuditDataset();
73          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
74          // auditDataset.setLocalAddress(SERVER_URI);
75          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
76          auditDataset.setMessageId(MESSAGE_ID);
77          auditDataset.setPatientIds(PATIENT_IDS);
78          switch (eventActionCode) {
79              case Create: auditDataset.setRequestType("PRPA_IN201301UV02"); break;
80              case Update: auditDataset.setRequestType("PRPA_IN201302UV02"); break;
81              case Delete: auditDataset.setRequestType("PRPA_IN201302UV03"); break;
82          }
83  
84          auditDataset.setSourceUserId(REPLY_TO_URI);
85          auditDataset.setDestinationUserId(SERVER_URI);
86          auditDataset.setPurposesOfUse(PURPOSES_OF_USE);
87          auditDataset.getHumanUsers().add(new HumanUser(USER_ID, USER_NAME, USER_ROLES));
88          return auditDataset;
89      }
90  }