Clover Coverage Report - jmxmonitor 1.0.2
Coverage timestamp: Wed Feb 10 2010 07:36:51 GMT
21   123   10   2.62
4   76   0.48   2.67
8     1.25  
3    
 
  MultiNamedMBeanTest       Line # 41 17 0% 6 0 100% 1.0
  MultiNamedMBeanTest.PingMBean       Line # 92 0 - 0 0 - -1.0
  MultiNamedMBeanTest.Ping       Line # 101 4 0% 4 2 75% 0.75
 
  (1)
 
1    /*
2    * Copyright 2009 Ben Gidley
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 uk.co.gidley.jmxmonitor.monitoring;
18   
19    import ch.qos.logback.classic.spi.ILoggingEvent;
20    import org.testng.annotations.AfterMethod;
21    import org.testng.annotations.BeforeTest;
22    import org.testng.annotations.Test;
23    import uk.co.gidley.jmxmonitor.uk.co.gidley.testAppender.TestAppender;
24   
25    import javax.management.InstanceAlreadyExistsException;
26    import javax.management.MBeanRegistrationException;
27    import javax.management.MBeanServer;
28    import javax.management.MalformedObjectNameException;
29    import javax.management.NotCompliantMBeanException;
30    import javax.management.ObjectInstance;
31    import javax.management.ObjectName;
32    import java.lang.management.ManagementFactory;
33    import java.util.List;
34   
35    import static org.hamcrest.Matchers.equalTo;
36    import static org.hamcrest.MatcherAssert.assertThat;
37   
38    /**
39    * Created by IntelliJ IDEA. User: ben Date: Jan 8, 2010 Time: 4:38:11 PM
40    */
 
41    public class MultiNamedMBeanTest extends BaseMonitoringTest {
42    private ObjectInstance ping1;
43    private ObjectInstance ping2;
44   
45    /**
46    * This test tests handling MBeans like C3PO's they are called things like com.mchange.v2.c3p0:type=PooledDataSource[2rvxty863z22nb16dadw4|62a34b91]
47    * AND the bit in [] changes every JVM restart.
48    * <p/>
49    * You therefore have to use a wildcard in the objectname to find them.
50    */
 
51  1 toggle @Test
52    public void TestMultiNamedMBean() throws InterruptedException {
53   
54  1 List<ILoggingEvent> events = TestAppender.getEvents();
55    // Find "Heap Used" message
56  1 boolean ping1Found = false;
57  1 boolean ping2Found = false;
58   
59  1 for (ILoggingEvent event : events) {
60  2 if (event.getFormattedMessage().startsWith("Ping 1")) {
61  1 ping1Found = true;
62    }
63  2 if (event.getFormattedMessage().startsWith("Ping 2")) {
64  1 ping2Found = true;
65    }
66    }
67   
68  1 assertThat(ping1Found, equalTo(true));
69  1 assertThat(ping2Found, equalTo(true));
70    }
71   
 
72  1 toggle @Override
73    public String getConfiguration() {
74  1 return "src/test/resources/monitoring/MultiNamedMBeanConfiguration.properties";
75    }
76   
 
77  548 toggle @Override
78    public int waitForEvents() {
79  548 return 2;
80    }
81   
 
82  1 toggle @Override
83    public void registerTestMBeans() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException {
84  1 MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
85   
86  1 ObjectName bean1 = new ObjectName("uk.co.gidley.jmxmonitor:type=Bean1[guff]");
87  1 ObjectName bean2 = new ObjectName("uk.co.gidley.jmxmonitor:type=Bean1[guff2]");
88  1 ping1 = mBeanServer.registerMBean(new Ping("1"), bean1);
89  1 ping2 = mBeanServer.registerMBean(new Ping("2"), bean2);
90    }
91   
 
92    public interface PingMBean {
93   
94    public String getDiscriminator();
95   
96    public void setDiscriminator(String discriminator);
97   
98    public Boolean getPing();
99    }
100   
 
101    public class Ping implements PingMBean {
 
102  2 toggle private Ping(String discriminator) {
103  2 this.discriminator = discriminator;
104    }
105   
 
106  6 toggle @Override
107    public String getDiscriminator() {
108  6 return discriminator;
109    }
110   
 
111  0 toggle @Override
112    public void setDiscriminator(String discriminator) {
113  0 this.discriminator = discriminator;
114    }
115   
116    private String discriminator;
117   
 
118  6 toggle @Override
119    public Boolean getPing() {
120  6 return true;
121    }
122    }
123    }