View Javadoc
1   /*
2    * Copyright 2009 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  package org.openehealth.ipf.platform.camel.ihe.atna.util;
17  
18  import org.apache.camel.EndpointInject;
19  import org.apache.camel.Message;
20  import org.apache.camel.component.mock.MockEndpoint;
21  import org.junit.After;
22  import org.junit.Test;
23  import org.junit.runner.RunWith;
24  import org.openehealth.ipf.commons.audit.AuditContext;
25  import org.openehealth.ipf.commons.audit.codes.EventIdCode;
26  import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
27  import org.openehealth.ipf.commons.audit.event.ApplicationActivityBuilder;
28  import org.openehealth.ipf.commons.audit.model.AuditMessage;
29  import org.springframework.beans.factory.annotation.Autowired;
30  import org.springframework.test.context.ContextConfiguration;
31  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
32  
33  import static org.junit.Assert.assertEquals;
34  
35  /**
36   * @author Martin Krasser
37   */
38  @RunWith(SpringJUnit4ClassRunner.class)
39  @ContextConfiguration(locations = {"/context.xml"})
40  public class CamelAuditMessageQueueTest {
41  
42      @Autowired
43      private AuditContext auditContext;
44  
45      @EndpointInject(uri = "mock:mock")
46      private MockEndpoint mock;
47  
48      @After
49      public void tearDown() {
50          mock.reset();
51      }
52  
53      @Test
54      public void testCamelEndpointAudit() {
55          AuditMessage auditMessage = new ApplicationActivityBuilder.ApplicationStart(EventOutcomeIndicator.Success, null).getMessage();
56          auditContext.audit(auditMessage);
57  
58          Message message = mock.assertExchangeReceived(0).getIn();
59          AuditMessage body = message.getBody(AuditMessage.class);
60          Object header1 = message.getHeader(CamelAuditMessageQueue.HEADER_NAMESPACE + ".destination.address");
61          Object header2 = message.getHeader(CamelAuditMessageQueue.HEADER_NAMESPACE + ".destination.port");
62  
63          assertEquals(EventIdCode.ApplicationActivity, body.getEventIdentification().getEventID());
64          assertEquals("0.0.0.0", header1);
65          assertEquals(-1, header2);
66      }
67  
68  }