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.platform.camel.ihe.fhir.iti68;
18  
19  import org.junit.BeforeClass;
20  import org.junit.Test;
21  import org.openehealth.ipf.commons.audit.codes.*;
22  import org.openehealth.ipf.commons.audit.model.ActiveParticipantType;
23  import org.openehealth.ipf.commons.audit.model.AuditMessage;
24  import org.openehealth.ipf.commons.audit.model.AuditSourceIdentificationType;
25  import org.openehealth.ipf.commons.audit.model.ParticipantObjectIdentificationType;
26  import org.openehealth.ipf.commons.audit.queue.AbstractMockedAuditMessageQueue;
27  import org.openehealth.ipf.commons.audit.utils.AuditUtils;
28  import org.openehealth.ipf.commons.ihe.fhir.audit.codes.FhirEventTypeCode;
29  
30  import javax.servlet.ServletException;
31  
32  import static org.junit.Assert.*;
33  
34  /**
35   *
36   */
37  public class TestIti68Success extends AbstractTestIti68 {
38  
39      private static final String CONTEXT_DESCRIPTOR = "iti-68.xml";
40  
41      @BeforeClass
42      public static void setUpClass() {
43          startServer(CONTEXT_DESCRIPTOR);
44      }
45  
46  
47      @Test
48      public void testRetrieveDocument() {
49  
50          byte[] response = getProducerTemplate().requestBody("direct:input", null, byte[].class);
51          assertArrayEquals(Iti68TestRouteBuilder.DATA, response);
52  
53          // Check ATNA Audit
54  
55          AbstractMockedAuditMessageQueue sender = getAuditSender();
56          assertEquals(1, sender.getMessages().size());
57          AuditMessage event = sender.getMessages().get(0);
58  
59          // Event
60          assertEquals(
61                  EventOutcomeIndicator.Success,
62                  event.getEventIdentification().getEventOutcomeIndicator());
63          assertEquals(
64                  EventActionCode.Create,
65                  event.getEventIdentification().getEventActionCode());
66          assertEquals(EventIdCode.Export, event.getEventIdentification().getEventID());
67          assertEquals(FhirEventTypeCode.MobileDocumentRetrieval, event.getEventIdentification().getEventTypeCode().get(0));
68  
69  
70          // ActiveParticipant Source
71          ActiveParticipantType source = event.getActiveParticipants().get(0);
72          assertTrue(source.isUserIsRequestor());
73          assertEquals("127.0.0.1", source.getNetworkAccessPointID());
74          assertEquals(NetworkAccessPointTypeCode.IPAddress, source.getNetworkAccessPointTypeCode());
75  
76          // ActiveParticipant Destination
77          ActiveParticipantType destination = event.getActiveParticipants().get(1);
78          assertFalse(destination.isUserIsRequestor());
79          assertEquals(AuditUtils.getLocalIPAddress(), destination.getNetworkAccessPointID());
80          assertEquals("http://localhost:" + DEMO_APP_PORT + "/", destination.getUserID());
81  
82          // Audit Source
83          AuditSourceIdentificationType sourceIdentificationType = event.getAuditSourceIdentification();
84          assertEquals("IPF", sourceIdentificationType.getAuditSourceID());
85          assertEquals("IPF", sourceIdentificationType.getAuditEnterpriseSiteID());
86  
87          ParticipantObjectIdentificationType poit = event.findParticipantObjectIdentifications(p ->
88                  p.getParticipantObjectTypeCode() == ParticipantObjectTypeCode.System).get(0);
89          assertEquals(Iti68TestRouteBuilder.DOCUMENT_UNIQUE_ID, poit.getParticipantObjectID());
90          assertEquals(2, poit.getParticipantObjectDetails().size());
91  
92      }
93  
94  
95  }