use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class EjbPostCreateMethodStatic method check.
/**
* Entity Bean's ejbPostCreate(...) methods test.
* Each entity Bean class may define zero or more ejbPostCreate(...) methods.
* The number and signatures of a entity Bean's create methods are specific
* to each EJB class. The method signatures must follow these rules:
*
* The method name must be ejbPostCreate.
*
* The method must not be declared as static.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor instanceof EjbEntityDescriptor) {
boolean oneFailed = false;
int foundAtLeastOne = 0;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
boolean ejbPostCreateFound = false;
boolean isStatic = false;
// start do while loop here....
do {
Method[] methods = c.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
// reset flags from last time thru loop
ejbPostCreateFound = false;
isStatic = false;
// The method name must be ejbPostCreate.
if (methods[i].getName().startsWith("ejbPostCreate")) {
foundAtLeastOne++;
ejbPostCreateFound = true;
// The method must not be declared as final or static.
int modifiers = methods[i].getModifiers();
if (Modifier.isStatic(modifiers)) {
isStatic = true;
}
// ejbPostCreate method
if (ejbPostCreateFound && (!isStatic)) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares non-static [ {1} ] method.", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
} else if (ejbPostCreateFound && isStatic) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] ejbPostCreate(...) Method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", new Object[] { methods[i].getName(), methods[i].getName() }));
}
}
}
} while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
if (foundAtLeastOne == 0) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbPostCreate(...) methods.", new Object[] { descriptor.getEjbClassName() }));
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
oneFailed = true;
}
if (oneFailed) {
result.setStatus(result.FAILED);
} else if (foundAtLeastOne == 0) {
result.setStatus(result.NOT_APPLICABLE);
} else {
result.setStatus(result.PASSED);
}
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Entity", "Session" }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceFindByPrimaryKeyReturn method commonToBothInterfaces.
/**
* This method is responsible for the logic of the test. It is called for both local and remote interfaces.
* @param descriptor the Enterprise Java Bean deployment descriptor
* @param home for the Home interface of the Ejb.
* @param remote for Remote/Local interface
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String home, String remote, EjbDescriptor descriptor) {
boolean findByPrimaryKeyMethodFound = false;
boolean oneFailed = false;
boolean returnValueValid = false;
try {
// retrieve the home interface methods
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class homeInterfaceClass = Class.forName(home, false, getVerifierContext().getClassLoader());
Method[] ejbFinderMethods = homeInterfaceClass.getDeclaredMethods();
Class rc = Class.forName(remote, false, getVerifierContext().getClassLoader());
for (int j = 0; j < ejbFinderMethods.length; ++j) {
// reset all booleans for next method within the loop
returnValueValid = false;
if (ejbFinderMethods[j].getName().equals("findByPrimaryKey")) {
// must be a single-object finder).
if (!findByPrimaryKeyMethodFound) {
findByPrimaryKeyMethodFound = true;
}
Class returnByPrimaryKeyValue = ejbFinderMethods[j].getReturnType();
// is valid
if (((returnByPrimaryKeyValue.getName().equals(rc.getName())) && (!((returnByPrimaryKeyValue.getName().equals("java.util.Collection")) || (returnByPrimaryKeyValue.getName().equals("java.util.Enumeration")))))) {
returnValueValid = true;
}
// report for this particular findByPrimaryKey(...)
if (findByPrimaryKeyMethodFound && returnValueValid) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home interface [ {0} ] Finder Method [ {1} ]", new Object[] { homeInterfaceClass.getName(), ejbFinderMethods[j].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A findByPrimaryKey method was found with valid return type."));
} else if (findByPrimaryKeyMethodFound && !returnValueValid) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home interface [ {0} ] Finder Method [ {1} ]", new Object[] { homeInterfaceClass.getName(), ejbFinderMethods[j].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A findByPrimaryKey method was found, but with invalid return type."));
}
// found findByPrimaryKey, so break out of loop
break;
}
}
if (!findByPrimaryKeyMethodFound) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug3", "For Home interface [ {0} ] ", new Object[] { homeInterfaceClass.getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: No findByPrimaryKey method was found in home interface class [ {0} ].", new Object[] { homeInterfaceClass.getName() }));
}
return oneFailed;
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable.", new Object[] { home }));
oneFailed = true;
return oneFailed;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceFindMethodExceptionMatch method commonToBothInterfaces.
/**
* This method is responsible for the logic of the test. It is called for both local and remote interfaces.
* @param descriptor the Enterprise Java Bean deployment descriptor
* @param home for the Home interface of the Ejb.
* @param interfaceType determines the type of interface (remote/local)
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor) {
boolean oneFailed = false;
int ejbFinderMethodLoopCounter = 0;
// methods which match ejbfind<METHOD>, and exceptions match Bean's
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
Class methodReturnType;
Class[] methodParameterTypes;
Class[] methodExceptionTypes;
Class[] ejbFinderMethodExceptionTypes;
Class[] ejbFinderMethodParameterTypes;
boolean ejbFinderFound = false;
boolean signaturesMatch = false;
boolean exceptionsMatch = false;
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("find")) {
// clear these from last time thru loop
ejbFinderFound = false;
signaturesMatch = false;
exceptionsMatch = false;
// retrieve the EJB Class Methods
Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// start do while loop here....
do {
Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
// find matching "ejbFind<METHOD>" in bean class
for (int z = 0; z < ejbFinderMethods.length; z++) {
if (ejbFinderMethods[z].getName().startsWith("ejbFind")) {
// ejbFindAccount
if (methods[i].getName().toUpperCase().equals(ejbFinderMethods[z].getName().toUpperCase().substring(3))) {
// found one, see if it matches same number and types
// of arguments, exceptions too,
ejbFinderFound = true;
methodParameterTypes = methods[i].getParameterTypes();
ejbFinderMethodParameterTypes = ejbFinderMethods[z].getParameterTypes();
if (Arrays.equals(methodParameterTypes, ejbFinderMethodParameterTypes)) {
signaturesMatch = true;
methodExceptionTypes = methods[i].getExceptionTypes();
ejbFinderMethodExceptionTypes = ejbFinderMethods[z].getExceptionTypes();
if (RmiIIOPUtils.isEjbFindMethodExceptionsSubsetOfFindMethodExceptions(ejbFinderMethodExceptionTypes, methodExceptionTypes)) {
exceptionsMatch = true;
// used to display output below
ejbFinderMethodLoopCounter = z;
break;
}
}
// method params match
}
// check rest of string to see if findAccount
// matches ejbFindAccount
}
// found ejbFind<METHOD>
}
// method
if (ejbFinderFound && signaturesMatch && exceptionsMatch) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The corresponding [ {0} ] method with matching exceptions was found.", new Object[] { ejbFinderMethods[ejbFinderMethodLoopCounter].getName() }));
} else if (ejbFinderFound && signaturesMatch && !exceptionsMatch) {
logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { c.getName(), methods[i].getName() });
logger.log(Level.FINE, getClass().getName() + ".debug3", new Object[] { "ejb" + methods[i].getName().toUpperCase().substring(0, 1) + methods[i].getName().substring(1) });
logger.log(Level.FINE, getClass().getName() + ".debug2");
} else if (ejbFinderFound && !signaturesMatch) {
logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { c.getName(), methods[i].getName() });
logger.log(Level.FINE, getClass().getName() + ".debug4", new Object[] { "ejb" + methods[i].getName().toUpperCase().substring(0, 1) + methods[i].getName().substring(1) });
logger.log(Level.FINE, getClass().getName() + ".debug2");
}
} while (((EJBClass = EJBClass.getSuperclass()) != null) && (!(ejbFinderFound && signaturesMatch && exceptionsMatch)));
if (!ejbFinderFound && !signaturesMatch && !exceptionsMatch) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No corresponding [ {0} ] method with matching signatures was found.", new Object[] { "ejb" + methods[i].getName().toUpperCase().substring(0, 1) + methods[i].getName().substring(1) }));
}
// end of reporting for this particular 'find' method
}
// if the home interface found a "find" method
}
// for all the methods within the home interface class, loop
return oneFailed;
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] or EJB class [ {1} ] does not exist or is not loadable within bean [ {2} ]", new Object[] { home, descriptor.getEjbClassName(), descriptor.getName() }));
return oneFailed;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceFindMethodExceptionRemote method check.
/**
* Entity beans home interface find<METHOD> method throws
* java.rmi.RemoteException test.
*
* The following are the requirements for the enterprise Bean's home interface
* find<METHOD> signature:
*
* An Entity Bean's home interface defines one or more find<METHOD>(...)
* methods.
*
* The throws clause must include java.rmi.RemoteException.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor instanceof EjbEntityDescriptor) {
String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
boolean oneFailed = false;
// methods which must throw java.rmi.RemoteException
if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "No Remote Interface for this Ejb", new Object[] {}));
return result;
}
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
Class[] methodExceptionTypes;
boolean throwsRemoteException = false;
for (int i = 0; i < methods.length; i++) {
// clear these from last time thru loop
throwsRemoteException = false;
if (methods[i].getName().startsWith("find")) {
methodExceptionTypes = methods[i].getExceptionTypes();
// methods must throw java.rmi.RemoteException
if (EjbUtils.isValidRemoteException(methodExceptionTypes)) {
throwsRemoteException = true;
break;
}
// particular find<METHOD> method
if (throwsRemoteException) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The find<METHOD> method which must throw java.rmi.RemoteException was found."));
} else if (!throwsRemoteException) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A find<METHOD> method was found, but did not throw java.rmi.RemoteException."));
}
// end of reporting for this particular 'find' method
}
// if the home interface found a "find" method
}
// for all the methods within the home interface class, loop
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { descriptor.getHomeClassName(), descriptor.getName() }));
}
if (oneFailed) {
result.setStatus(result.FAILED);
} else {
result.setStatus(result.PASSED);
}
return result;
} else {
// if (CONTAINER_PERSISTENCE.equals(persistence))
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
return result;
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean, but called with {2} bean", new Object[] { getClass(), "Entity", "Session" }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceFindMethodHasQuery method commonToBothInterfaces.
/**
* This method is responsible for the logic of the test. It is called for both local and remote interfaces.
* @param descriptor the Enterprise Java Bean deployment descriptor
* @param home for the Home interface of the Ejb.
* @param methodIntf is the interface type
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor, String methodIntf) {
boolean oneFailed = false;
// methods which must throw javax.ejb.FinderException
try {
PersistenceDescriptor pers = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor();
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("find") && !(methods[i].getName()).equals(FINDBYPRIMARYKEY)) {
QueryDescriptor query = pers.getQueryFor(new MethodDescriptor(methods[i], methodIntf));
if (query != null) {
if (query.getQuery() != null && !"".equals(query.getQuery())) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The [ {0} ] method has a query assigned to it", new Object[] { methods[i].getName() }));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A [ {0} ] method was found, but did not have a query element assigned", new Object[] { methods[i].getName() }));
}
// end of reporting for this particular 'find' method
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A [ {0} ] method was found, but did not have a query element assigned", new Object[] { methods[i].getName() }));
}
}
// if the home interface found a "find" method
}
// for all the methods within the home interface class, loop
return oneFailed;
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { home, descriptor.getName() }));
return oneFailed;
}
}
Aggregations