KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > management > TestConnectors


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.management;
16
17 import java.io.InputStream JavaDoc;
18 import java.net.HttpURLConnection JavaDoc;
19 import java.net.URL JavaDoc;
20
21 import javax.management.remote.JMXConnectorServerMBean JavaDoc;
22
23 import mx4j.tools.adaptor.http.HttpAdaptorMBean;
24
25 import org.apache.hivemind.Registry;
26 import org.apache.hivemind.xml.XmlTestCase;
27
28 /**
29  * Test of MX4j http adaptor and jsr160 connectors
30  *
31  * @author Achim Huegen
32  * @since 1.1
33  */

34 public class TestConnectors extends XmlTestCase
35 {
36     /**
37      * Tests the mx4j HttpAdaptor connector, that is predefined
38      */

39     public void testMx4jHttpAdaptor() throws Exception JavaDoc
40     {
41         Registry registry = buildFrameworkRegistry("testConnectors.xml");
42         Object JavaDoc service = registry.getService(HttpAdaptorMBean.class);
43         assertNotNull(service);
44
45         // try a http connection
46
URL JavaDoc url = new URL JavaDoc("http://localhost:9000");
47         HttpURLConnection JavaDoc connection = (HttpURLConnection JavaDoc) url.openConnection();
48         connection.setDoOutput(true);
49         connection.connect();
50         InputStream JavaDoc inputStream = connection.getInputStream();
51         assertTrue(inputStream.read() != 0);
52
53         registry.shutdown();
54     }
55
56     public void testJsr160Connector() throws Exception JavaDoc
57     {
58         Registry registry = buildFrameworkRegistry("testConnectors.xml");
59         Object JavaDoc service = registry.getService(JMXConnectorServerMBean JavaDoc.class);
60         assertNotNull(service);
61     }
62
63 }
Popular Tags