View Javadoc
1   /*
2    * Copyright 2011 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.ws.mbean;
17  
18  import java.util.Set;
19  
20  import javax.management.MBeanServer;
21  import javax.management.ObjectInstance;
22  import javax.management.ObjectName;
23  
24  import org.apache.camel.CamelContext;
25  import org.apache.camel.builder.RouteBuilder;
26  import org.apache.camel.management.DefaultManagementNamingStrategy;
27  import org.apache.camel.management.ManagementTestSupport;
28  import org.apache.camel.util.CastUtils;
29  
30  /**
31   * 
32   * @author Stefan Ivanov
33   * 
34   */
35  public class ManagedWsItiEndpointTest extends ManagementTestSupport {
36      
37      @Override
38      protected boolean useJmx() {
39          return true;
40      }
41      
42      protected CamelContext createCamelContext() throws Exception {
43          CamelContext context = super.createCamelContext();
44          context.addComponent("some-ws-iti", new SomeItiComponent());
45          DefaultManagementNamingStrategy naming = (DefaultManagementNamingStrategy) context
46              .getManagementStrategy().getManagementNamingStrategy();
47          naming.setHostName("localhost");
48          naming.setDomainName("org.apache.camel");
49          return context;
50      }
51      
52      public void testInit() throws Exception {
53          MBeanServer mbeanServer = getMBeanServer();
54          ObjectName on = ObjectName
55              .getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
56          ObjectInstance oi = mbeanServer.getObjectInstance(on);
57          assertNotNull(oi);
58      }
59  
60  
61      public void testEndpointAttributes() throws Exception {
62          MBeanServer mbeanServer = getMBeanServer();
63          
64          Set<ObjectName> s = CastUtils.cast(mbeanServer.queryNames(new ObjectName(
65              "org.apache.camel:*,type=endpoints,name=\"some-ws-iti://data*\""), null));
66          ObjectName on = (ObjectName) s.toArray()[0];
67          assertEquals(SomeItiComponent.WS_CONFIG.isAddressing(),
68              ((Boolean) mbeanServer.getAttribute(on, "Addressing")).booleanValue());
69          assertEquals(SomeItiComponent.WS_CONFIG.isMtom(),
70              ((Boolean) mbeanServer.getAttribute(on, "Mtom")).booleanValue());
71          assertEquals(SomeItiComponent.WS_CONFIG.isSwaOutSupport(),
72              ((Boolean) mbeanServer.getAttribute(on, "SwaOutSupport")).booleanValue());
73      }
74      
75      @Override
76      protected RouteBuilder createRouteBuilder() {
77          return new RouteBuilder() {
78              @Override
79              public void configure() {
80                  from("some-ws-iti:data?audit=false").to("mock:result");
81              }
82          };
83      }
84  
85  }