~ubuntu-branches/ubuntu/precise/tomcat7/precise-proposed

« back to all changes in this revision

Viewing changes to test/org/apache/catalina/mbeans/TestRegistration.java

  • Committer: Package Import Robot
  • Author(s): tony mancill, Jakub Adam, tony mancill
  • Date: 2012-03-01 21:22:50 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120301212250-yrkv3u4y9mbg4a1o
Tags: 7.0.26-1
[ Jakub Adam ]
* New upstream release.
* Add Jakub Adam to Uploaders.
* Bump Standards-Version to 3.9.3.
* Don't Depend libservlet3.0-java-doc on package it documents, relax
  to Suggests.

[ tony mancill ]
* Add Polish debconf translation. (Closes: #661644)
  - Thanks to Michał Kułach.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
package org.apache.catalina.mbeans;
18
18
 
19
19
import java.io.File;
 
20
import java.net.InetAddress;
 
21
import java.net.UnknownHostException;
20
22
import java.util.ArrayList;
21
23
import java.util.Arrays;
22
24
import java.util.List;
45
47
 
46
48
    private static final String contextName = "/foo";
47
49
 
 
50
    private static final String ADDRESS;
 
51
 
 
52
    static {
 
53
        String address;
 
54
        try {
 
55
            address = InetAddress.getByName("localhost").getHostAddress();
 
56
        } catch (UnknownHostException e) {
 
57
            address = "INIT_FAILED";
 
58
        }
 
59
        ADDRESS = address;
 
60
    }
 
61
 
 
62
 
48
63
    private static String[] basicMBeanNames() {
49
64
        return new String[] {
50
65
            "Tomcat:type=Engine",
 
66
            "Tomcat:type=Realm,realmPath=/realm0",
51
67
            "Tomcat:type=MBeanFactory",
52
68
            "Tomcat:type=NamingResources",
53
69
            "Tomcat:type=Server",
95
111
 
96
112
    private static String[] connectorMBeanNames(String port, String type) {
97
113
        return new String[] {
98
 
        "Tomcat:type=Connector,port=" + port,
99
 
        "Tomcat:type=GlobalRequestProcessor,name=\"http-" + type + "-" + port + "\"",
100
 
        "Tomcat:type=Mapper,port=" + port,
101
 
        "Tomcat:type=ProtocolHandler,port=" + port,
102
 
        "Tomcat:type=ThreadPool,name=\"http-" + type + "-" + port + "\"",
 
114
        "Tomcat:type=Connector,port=" + port + ",address="
 
115
                + ObjectName.quote(ADDRESS),
 
116
        "Tomcat:type=GlobalRequestProcessor,name="
 
117
                + ObjectName.quote("http-" + type + "-" + ADDRESS + "-" + port),
 
118
        "Tomcat:type=Mapper,port=" + port + ",address="
 
119
                + ObjectName.quote(ADDRESS),
 
120
        "Tomcat:type=ProtocolHandler,port=" + port + ",address="
 
121
                + ObjectName.quote(ADDRESS),
 
122
        "Tomcat:type=ThreadPool,name="
 
123
                + ObjectName.quote("http-" + type + "-" + ADDRESS + "-" + port),
103
124
        };
104
125
    }
105
126
 
111
132
    @Test
112
133
    public void testMBeanDeregistration() throws Exception {
113
134
        final MBeanServer mbeanServer = Registry.getRegistry(null, null).getMBeanServer();
 
135
        // Verify there are no Catalina or Tomcat MBeans
114
136
        Set<ObjectName> onames = mbeanServer.queryNames(new ObjectName("Catalina:*"), null);
115
 
        assertEquals("Remaining: " + onames, 0, onames.size());
 
137
        log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
 
138
        assertEquals("Unexpected: " + onames, 0, onames.size());
 
139
        onames = mbeanServer.queryNames(new ObjectName("Tomcat:*"), null);
 
140
        log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
 
141
        assertEquals("Unexpected: " + onames, 0, onames.size());
116
142
 
117
143
        final Tomcat tomcat = getTomcatInstance();
118
144
        final File contextDir = new File(getTemporaryDirectory(), "webappFoo");
125
151
 
126
152
        // Verify there are no Catalina MBeans
127
153
        onames = mbeanServer.queryNames(new ObjectName("Catalina:*"), null);
 
154
        log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
128
155
        assertEquals("Found: " + onames, 0, onames.size());
129
156
 
130
157
        // Verify there are the correct Tomcat MBeans
147
174
        ArrayList<String> expected = new ArrayList<String>(Arrays.asList(basicMBeanNames()));
148
175
        expected.addAll(Arrays.asList(hostMBeanNames("localhost")));
149
176
        expected.addAll(Arrays.asList(contextMBeanNames("localhost", contextName)));
150
 
        expected.addAll(Arrays.asList(connectorMBeanNames(Integer.toString(getPort()), protocol)));
 
177
        expected.addAll(Arrays.asList(connectorMBeanNames("auto-1", protocol)));
151
178
        expected.addAll(Arrays.asList(optionalMBeanNames("localhost")));
152
179
 
153
180
        // Did we find all expected MBeans?
184
211
 
185
212
        // There should be no Catalina MBeans and no Tomcat MBeans
186
213
        onames = mbeanServer.queryNames(new ObjectName("Catalina:*"), null);
 
214
        log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
187
215
        assertEquals("Remaining: " + onames, 0, onames.size());
188
216
        onames = mbeanServer.queryNames(new ObjectName("Tomcat:*"), null);
 
217
        log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
189
218
        assertEquals("Remaining: " + onames, 0, onames.size());
190
219
    }
191
220