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.xds.iti63;
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.codes.ParticipantObjectTypeCode;
24  import org.openehealth.ipf.commons.audit.model.AuditMessage;
25  import org.openehealth.ipf.commons.ihe.core.atna.AuditDataset.HumanUser;
26  import org.openehealth.ipf.commons.ihe.xds.atna.XdsAuditorTestBase;
27  import org.openehealth.ipf.commons.ihe.xds.core.audit.XdsQueryAuditDataset;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertNotNull;
31  
32  /**
33   * @author Christian Ohr
34   */
35  public class Iti63AuditStrategyTest extends XdsAuditorTestBase {
36  
37      @Test
38      public void testServerSide() {
39          testRequest(true);
40      }
41  
42      @Test
43      public void testClientSide() {
44          testRequest(false);
45      }
46  
47      private void testRequest(boolean serverSide) {
48          Iti63AuditStrategy strategy = new Iti63AuditStrategy(serverSide);
49          XdsQueryAuditDataset auditDataset = getXdsAuditDataset(strategy);
50          AuditMessage auditMessage = makeAuditMessage(strategy, auditContext, auditDataset);
51  
52          assertNotNull(auditMessage);
53          auditMessage.validate();
54  
55          // System.out.println(printAuditMessage(auditMessage));
56  
57          assertCommonXdsAuditAttributes(auditMessage,
58                  EventOutcomeIndicator.Success,
59                  EventIdCode.Query,
60                  EventActionCode.Execute,
61                  serverSide,
62                  true);
63  
64          assertEquals(2, auditMessage.findParticipantObjectIdentifications(
65                  poit -> poit.getParticipantObjectTypeCode() == ParticipantObjectTypeCode.System)
66                  .get(0)
67                  .getParticipantObjectDetails().size());
68      }
69  
70      private XdsQueryAuditDataset getXdsAuditDataset(Iti63AuditStrategy strategy) {
71          XdsQueryAuditDataset auditDataset = strategy.createAuditDataset();
72          auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success);
73          // auditDataset.setLocalAddress(SERVER_URI);
74          auditDataset.setRemoteAddress(CLIENT_IP_ADDRESS);
75          auditDataset.setSourceUserId(REPLY_TO_URI);
76          auditDataset.setDestinationUserId(SERVER_URI);
77          auditDataset.setRequestPayload(QUERY_PAYLOAD);
78          auditDataset.setPurposesOfUse(PURPOSES_OF_USE);
79          auditDataset.getPatientIds().add(PATIENT_IDS[0]);
80          auditDataset.setQueryUuid(QUERY_ID);
81          auditDataset.setHomeCommunityId(HOME_COMMUNITY_ID);
82          auditDataset.getHumanUsers().add(new HumanUser(USER_ID, USER_NAME, USER_ROLES));
83  
84          return auditDataset;
85      }
86  }