KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > cmp2 > FindMethodHasDescriptors


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 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2;
24
25 import java.util.*;
26 import java.lang.reflect.Method JavaDoc;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.deployment.QueryDescriptor;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * Find Methods should have deployment descriptors associated with them
34  *
35  * @author Jerome Dochez
36  * @version
37  */

38 public class FindMethodHasDescriptors extends QueryMethodTest {
39
40     /**
41      * <p>
42      * Run an individual test against a finder method (single or multi)
43      * </p>
44      *
45      * @param method is the finder method reference
46      * @param descriptor is the entity bean descriptor
47      * @param targetClass is the class to apply to tests to
48      * @param result is where to place the result
49      *
50      * @return true if the test passes
51      */

52     protected boolean runIndividualQueryTest(Method JavaDoc method, EjbCMPEntityDescriptor descriptor, Class JavaDoc targetClass, Result result) {
53     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54         if (method.getName().equals("findByPrimaryKey")) {
55         result.addGoodDetails(smh.getLocalString
56                        ("tests.componentNameConstructor",
57                     "For [ {0} ]",
58                     new Object JavaDoc[] {compName.toString()}));
59         result.addGoodDetails(smh.getLocalString
60                   ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.passed1",
61                    "Passed: Found method findByPrimaryKey",
62                    new Object JavaDoc[] {}));
63             return true;
64     }
65         
66         // We don't use getQueryFor to free ourselfves from classloader issues.
67
Set set = descriptor.getPersistenceDescriptor().getQueriedMethods();
68         Iterator iterator = set.iterator();
69     if (iterator.hasNext()) {
70         while(iterator.hasNext()) {
71         MethodDescriptor queryMethod = (MethodDescriptor) iterator.next();
72         if (queryMethod.getName().equals(method.getName())) {
73             Class JavaDoc mParms[] = method.getParameterTypes();
74             String JavaDoc queryParms[] = queryMethod.getParameterClassNames();
75             int queryParamsLen;
76             if(queryParms == null)
77               queryParamsLen = 0;
78             else
79               queryParamsLen = queryParms.length;
80             if (queryParamsLen == mParms.length) {
81             boolean same = true;
82             if(queryParamsLen > 0)
83             {
84             for (int i=0;i<mParms.length;i++) {
85                 if (!mParms[i].getName().equals(queryParms[i]))
86                 same=false;
87             }
88             }
89             if (same) {
90                 result.addGoodDetails(smh.getLocalString
91                        ("tests.componentNameConstructor",
92                     "For [ {0} ]",
93                     new Object JavaDoc[] {compName.toString()}));
94                 result.addGoodDetails(smh.getLocalString
95                 ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.passed",
96                  "[ {0} ] has a query element associated with it",
97                  new Object JavaDoc[] {method}));
98                 return true;
99             }
100             }
101         }
102         }
103         result.addErrorDetails(smh.getLocalString
104                        ("tests.componentNameConstructor",
105                     "For [ {0} ]",
106                     new Object JavaDoc[] {compName.toString()}));
107         result.addErrorDetails(smh.getLocalString
108                 ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.failed",
109                  "Error : [ {0} ] seems to be a finder method but has no query element associated with it",
110                  new Object JavaDoc[] {method}));
111         return false;
112     }
113     else {
114         result.addGoodDetails(smh.getLocalString
115                        ("tests.componentNameConstructor",
116                     "For [ {0} ]",
117                     new Object JavaDoc[] {compName.toString()}));
118         result.addGoodDetails(smh.getLocalString
119         ("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.notApplicable",
120          "NotApplicable : No Query methods found",
121          new Object JavaDoc[] {}));
122         return true;
123     }
124        
125     }
126 }
127
Popular Tags