1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2; 24 25 import java.lang.reflect.Method ; 26 import com.sun.enterprise.deployment.*; 27 import com.sun.enterprise.tools.verifier.Result; 28 import com.sun.enterprise.tools.verifier.*; 29 import java.lang.ClassLoader ; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 32 38 abstract public class QueryMethodTest extends CMPTest { 39 ComponentNameConstructor compName = null; 40 52 protected abstract boolean runIndividualQueryTest(Method method, EjbCMPEntityDescriptor descriptor, Class targetClass, Result result); 53 54 61 public Result check(EjbCMPEntityDescriptor descriptor) { 62 63 boolean allIsWell = true; 64 Result result = getInitializedResult(); 65 compName = getVerifierContext().getComponentNameConstructor(); 66 67 if (descriptor.getHomeClassName() != null && !((descriptor.getHomeClassName()).equals("")) && 68 descriptor.getRemoteClassName() != null && !((descriptor.getRemoteClassName()).equals(""))) { 69 allIsWell = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor.getRemoteClassName(),descriptor, result); 70 } 71 if(allIsWell == true) { 72 if (descriptor.getLocalHomeClassName() != null && !((descriptor.getLocalHomeClassName()).equals("")) && 73 descriptor.getLocalClassName() != null && !((descriptor.getLocalClassName()).equals(""))) { 74 allIsWell = commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor.getLocalClassName(),descriptor, result); 75 } 76 } 77 78 if (allIsWell) 79 result.setStatus(Result.PASSED); 80 else 81 result.setStatus(Result.FAILED); 82 83 return result; 84 } 85 93 94 95 private boolean commonToBothInterfaces(String ejbHome, String remote, EjbDescriptor descriptor, Result result) { 96 boolean allIsWell = true; 97 boolean found = false; 98 String ejbClassName = descriptor.getEjbClassName(); 99 Context context = getVerifierContext(); 100 ClassLoader jcl = context.getClassLoader(); 101 try { 102 Class ejbClass = Class.forName(ejbClassName, false, 103 getVerifierContext().getClassLoader()); 104 Method [] methods = Class.forName(ejbHome, false, 105 getVerifierContext().getClassLoader()).getMethods(); 106 for (int i=0;i<methods.length;i++) { 107 String methodName = methods[i].getName(); 108 String methodReturnType = methods[i].getReturnType().getName(); 110 if (methodName.startsWith("find")) { 111 found = true; 112 if (methodReturnType.equals(remote) || 113 isSubclassOf(Class.forName(methodReturnType, false, 114 getVerifierContext().getClassLoader()), "java.util.Collection") || 115 isImplementorOf(Class.forName(methodReturnType, false, 116 getVerifierContext().getClassLoader()), "java.util.Collection")) { 117 118 if (!runIndividualQueryTest(methods[i], (EjbCMPEntityDescriptor) descriptor, ejbClass, result)) 119 allIsWell=false; 120 } 121 } 122 } 123 if (found == false) { 124 result.addGoodDetails(smh.getLocalString 125 ("com.sun.enterprise.tools.verifier.tests.ejb.EjbTest.passed", 126 "Not Applicable : No find methods found", 127 new Object [] {})); 128 } 129 130 return allIsWell; 131 } catch (ClassNotFoundException e) { 132 Verifier.debug(e); 133 result.addErrorDetails(smh.getLocalString 134 ("tests.componentNameConstructor", 135 "For [ {0} ]", 136 new Object [] {compName.toString()})); 137 result.failed(smh.getLocalString 138 ("com.sun.enterprise.tools.verifier.tests.ejb.EjbTest.failedException", 139 "Error: [ {0} ] class not found.", 140 new Object [] {descriptor.getEjbClassName()})); 141 allIsWell= false; 142 return allIsWell; 143 } 144 } 145 } 146 | Popular Tags |