KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > connector > managed > ManagedConnectionGetMetaData


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 /*
24  * ManagedConnectionGetMetaData.java
25  *
26  * Created on August 26, 2002
27  */

28
29 package com.sun.enterprise.tools.verifier.tests.connector.managed;
30
31 import java.io.File JavaDoc;
32 import java.lang.reflect.Method JavaDoc;
33 import com.sun.enterprise.tools.verifier.Result;
34 import com.sun.enterprise.tools.verifier.Verifier;
35 import com.sun.enterprise.deployment.ConnectorDescriptor;
36 import com.sun.enterprise.tools.verifier.tests.*;
37 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest;
38 import com.sun.enterprise.tools.verifier.tests.connector.ConnectorCheck;
39
40 /**
41  * Test that the return type of
42  * javax.resource.spi.ManagedConnection.getMetaData() implements
43  * the ManagedConnectionMetaData interface.
44  *
45  * @author Anisha Malhotra
46  * @version
47  */

48 public class ManagedConnectionGetMetaData
49     extends ConnectorTest
50     implements ConnectorCheck
51 {
52   /** <p>
53    * Test that the return type of
54    * javax.resource.spi.ManagedConnection.getMetaData() implements
55    * the ManagedConnectionMetaData interface.
56    * </p>
57    *
58    * @param descriptor deployment descriptor for the rar file
59    * @return result object containing the result of the individual test
60    * performed
61    */

62   public Result check(ConnectorDescriptor descriptor) {
63
64     Result result = getInitializedResult();
65     ComponentNameConstructor compName =
66       getVerifierContext().getComponentNameConstructor();
67     // test NA for inboundRA
68
if(!descriptor.getOutBoundDefined())
69     {
70       result.addNaDetails(smh.getLocalString
71           ("tests.componentNameConstructor",
72            "For [ {0} ]",
73            new Object JavaDoc[] {compName.toString()}));
74       result.notApplicable(smh.getLocalString
75           ("com.sun.enterprise.tools.verifier.tests.connector.managed.notApplicableForInboundRA",
76            "Resource Adapter does not provide outbound communication"));
77       return result;
78     }
79     //File jarFile = Verifier.getJarFile(descriptor.getModuleDescriptor().getArchiveUri());
80
// File f=Verifier.getArchiveFile(descriptor.getModuleDescriptor().getArchiveUri());
81
Class JavaDoc c = findImplementorOf(descriptor, "javax.resource.spi.ManagedConnection");
82     if(c == null)
83     {
84       result.addErrorDetails(smh.getLocalString
85           ("tests.componentNameConstructor",
86            "For [ {0} ]",
87            new Object JavaDoc[] {compName.toString()}));
88       result.failed(smh.getLocalString
89           ("com.sun.enterprise.tools.verifier.tests.connector.ConnectorTest.findImplementor.failed",
90            "Error: There is no implementation of the [ {0} ] provided",
91            new Object JavaDoc[] {"javax.resource.spi.ManagedConnection"}));
92       return result;
93     }
94     // get return type of getMetaData()
95
Method JavaDoc m = null;
96     do {
97       try {
98         m = c.getMethod("getMetaData", (Class JavaDoc[])null);
99       } catch(NoSuchMethodException JavaDoc nsme) {
100       } catch(SecurityException JavaDoc se) {
101       }
102       c = c.getSuperclass();
103     } while (m != null && c != Object JavaDoc.class);
104     if(m == null)
105     {
106       result.addErrorDetails(smh.getLocalString
107           ("tests.componentNameConstructor",
108            "For [ {0} ]",
109            new Object JavaDoc[] {compName.toString()}));
110       result.failed(smh.getLocalString
111           ("com.sun.enterprise.tools.verifier.tests.connector.managed.ManagedConnectionGetMetaData.failed",
112            "Error: There is no implementation of getMetaData() provided"));
113       return result;
114     }
115     Class JavaDoc returnType = m.getReturnType();
116     if(VerifierTest.isImplementorOf(returnType,
117           "javax.resource.spi.ManagedConnectionMetaData"))
118     {
119       result.addGoodDetails(smh.getLocalString
120           ("tests.componentNameConstructor",
121            "For [ {0} ]",
122            new Object JavaDoc[] {compName.toString()}));
123       result.passed(smh.getLocalString
124           ("com.sun.enterprise.tools.verifier.tests.connector.managed.ManagedConnectionGetMetaData.passed",
125            "ManagedConnection.getMetaData() returns an instance of the" +
126            "javax.resource.spi.ManagedConnectionMetaData interface"));
127     }
128     else
129     {
130       result.addErrorDetails(smh.getLocalString
131           ("tests.componentNameConstructor",
132            "For [ {0} ]",
133            new Object JavaDoc[] {compName.toString()}));
134       result.failed(smh.getLocalString
135           ("com.sun.enterprise.tools.verifier.tests.connector.managed.ManagedConnectionGetMetaData.failed1",
136            "Error: getMetaData() does not return an instance of the" +
137            "javax.resource.spi.ManagedConnectionMetaData interface"));
138     }
139     return result;
140   }
141 }
142
Popular Tags