KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > notgeronimo > itests > naming > common > Test


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

17 package org.apache.notgeronimo.itests.naming.common;
18
19 import java.sql.Connection JavaDoc;
20 import javax.naming.InitialContext JavaDoc;
21 import javax.sql.DataSource JavaDoc;
22 import javax.jms.Topic JavaDoc;
23 import javax.jms.Queue JavaDoc;
24 import javax.jms.ConnectionFactory JavaDoc;
25 import javax.management.j2ee.Management JavaDoc;
26 import javax.management.j2ee.ManagementHome JavaDoc;
27
28 import org.apache.notgeronimo.itests.naming.common.webservice.interop.InteropLab;
29 import org.apache.notgeronimo.itests.naming.common.webservice.interop.InteropTestPortType;
30
31 /**
32  * @version $Rev: $ $Date: $
33  */

34 public class Test {
35
36     public void testWebServiceLookup() throws Exception JavaDoc {
37         InteropLab interopLab = (InteropLab) new InitialContext JavaDoc().lookup("java:comp/env/service/InteropLab");
38         InteropTestPortType interopTestPortType = interopLab.getinteropTestPort();
39         int result = interopTestPortType.echoInteger(1);
40         if (result != 1) {
41             throw new Exception JavaDoc("Result was not 1 but " + result);
42         }
43     }
44
45     public void testResourceRefLookup() throws Exception JavaDoc {
46          InitialContext JavaDoc initialContext = new InitialContext JavaDoc();
47          Object JavaDoc o = initialContext.lookup("java:comp/env/jdbc/DefaultDatasource");
48          DataSource JavaDoc ds = (DataSource JavaDoc) o;
49          Connection JavaDoc jdbcConnection = ds.getConnection();
50          jdbcConnection.close();
51
52          o = initialContext.lookup("java:comp/env/jms/JMSConnectionFactory");
53          ConnectionFactory JavaDoc connectionFactory = (ConnectionFactory JavaDoc) o;
54          javax.jms.Connection JavaDoc jmsConnection = connectionFactory.createConnection();
55          jmsConnection.close();
56
57          o = initialContext.lookup("java:comp/env/jms/Queue");
58          Queue JavaDoc jmsQueue = (Queue JavaDoc) o;
59
60          o = initialContext.lookup("java:comp/env/jms/Topic");
61          Topic JavaDoc jmsTopic = (Topic JavaDoc) o;
62      }
63
64     public void testMEJBLookup() throws Exception JavaDoc {
65         InitialContext JavaDoc initialContext = new InitialContext JavaDoc();
66         Object JavaDoc o = initialContext.lookup("java:comp/env/ejb/mgmt/MEJB");
67         ManagementHome JavaDoc home = (ManagementHome JavaDoc)o;
68         Management JavaDoc mejb = home.create();
69         mejb.getMBeanCount();
70     }
71
72 }
73
Popular Tags