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.core.management;
17  
18  import static org.junit.Assert.assertNotNull;
19  
20  import java.util.Set;
21  
22  import javax.management.MBeanServer;
23  import javax.management.ObjectInstance;
24  import javax.management.ObjectName;
25  
26  import org.apache.camel.CamelContext;
27  import org.junit.AfterClass;
28  import org.junit.BeforeClass;
29  import org.junit.Test;
30  import org.springframework.context.support.ClassPathXmlApplicationContext;
31  
32  /**
33   * @author Reinhard Luft
34   */
35  public class ProcessorManagementNamingStrategyTest {
36  
37      private static final String CONTEXT = "context-core-management.xml";
38  
39      private static CamelContext camelContext;
40  
41      private static ClassPathXmlApplicationContext appContext;
42  
43      @BeforeClass
44      public static void setUpContext() {
45  
46          appContext = new ClassPathXmlApplicationContext(CONTEXT);
47          camelContext = appContext.getBean("camelContext", CamelContext.class);
48      }
49  
50      @Test
51      public void testProcessorManagementNamingStrategy() throws Exception {
52  
53          ObjectName on = queryForNamedObjects("org.apache.camel:context=camelContext,type=processors,name=\"namingStrategyProcessor\"");
54  
55          ObjectInstance oi = getMBeanServer().getObjectInstance(on);
56          assertNotNull(oi);
57      }
58  
59      @AfterClass
60      public static void tearDownAfterClass() {
61  
62          appContext.destroy();
63      }
64  
65      private ObjectName queryForNamedObjects(String query) throws Exception {
66  
67          MBeanServer mbeanServer = getMBeanServer();
68          Set<ObjectName> s = mbeanServer.queryNames(new ObjectName(query), null);
69          return (ObjectName) s.toArray()[0];
70      }
71  
72      private MBeanServer getMBeanServer() {
73  
74          return camelContext.getManagementStrategy().getManagementAgent().getMBeanServer();
75      }
76  }