use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceCreateMethodExceptionCreate 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.
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String home, EjbSessionDescriptor descriptor) {
boolean oneFailed = false;
// remote interface.
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
Class[] methodExceptionTypes;
boolean throwsCreateException = false;
for (int i = 0; i < methods.length; i++) {
// clear these from last time thru loop
throwsCreateException = false;
if (methods[i].getName().startsWith("create")) {
methodExceptionTypes = methods[i].getExceptionTypes();
// methods must also throw javax.ejb.CreateException
if (EjbUtils.isValidCreateException(methodExceptionTypes)) {
throwsCreateException = true;
}
// method
if (throwsCreateException) {
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 create method which must throw javax.ejb.CreateException was found.."));
} else if (!throwsCreateException) {
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 create method was found, but did not throw javax.ejb.CreateException."));
}
// end of reporting for this particular 'create' method
}
// if the home interface found a "create" method
}
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;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceCreateMethodExceptionRemote method check.
/**
* Session beans home interface create method throws RemoteException test.
*
* The following are the requirements for the enterprise Bean's home interface
* signature:
*
* An Session Bean's home interface defines zero or more create(...) 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 EjbSessionDescriptor) {
boolean oneFailed = false;
boolean foundAtLeastOneRemote = 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 Home 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("create")) {
// is failed
if (!foundAtLeastOneRemote) {
foundAtLeastOneRemote = true;
}
methodExceptionTypes = methods[i].getExceptionTypes();
// methods must also throw java.rmi.RemoteException
if (EjbUtils.isValidRemoteException(methodExceptionTypes)) {
throwsRemoteException = true;
}
// 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 create 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 create method was found, but did not throw java.rmi.RemoteException."));
}
// end of reporting for this particular 'create' method
}
// if the home interface found a "create" 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 (!foundAtLeastOneRemote) {
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[] { descriptor.getHomeClassName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "No create method was found in [ {0} ]", new Object[] { descriptor.getHomeClassName() }));
result.setStatus(result.FAILED);
} else {
if (oneFailed) {
result.setStatus(result.FAILED);
} else {
result.setStatus(result.PASSED);
}
}
return result;
} else {
result.addErrorDetails(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(), "Session", "Entity" }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class EjbCreateMatchesCreate 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.
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String remote, String local, EjbDescriptor descriptor) {
boolean oneFailed = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class[] methodParameterTypes;
Class[] businessMethodParameterTypes;
boolean signaturesMatch = false;
boolean found = false;
Vector<Method> createMethodSuffix = new Vector<Method>();
if (local != null) {
Class localhome = Class.forName(local, false, getVerifierContext().getClassLoader());
Method[] localhomeMethods = localhome.getDeclaredMethods();
for (int i = 0; i < localhomeMethods.length; i++) {
// The method name must start with create.
if (localhomeMethods[i].getName().startsWith("create")) {
createMethodSuffix.addElement((Method) localhomeMethods[i]);
foundAtLeastOneCreate = true;
}
}
}
if (remote != null) {
Class home = Class.forName(remote, false, getVerifierContext().getClassLoader());
Method[] homeMethods = home.getDeclaredMethods();
for (int i = 0; i < homeMethods.length; i++) {
// The method name must start with create.
if (homeMethods[i].getName().startsWith("create")) {
createMethodSuffix.addElement((Method) homeMethods[i]);
foundAtLeastOneCreate = true;
}
}
}
if (foundAtLeastOneCreate == false) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: no create<Method> method exists!", new Object[] {}));
return true;
}
Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// start do while loop here....
Method[] methods = EJBClass.getMethods();
// find matching "ejbCreate" in bean class
for (int k = 0; k < createMethodSuffix.size(); k++) {
for (int j = 0; j < methods.length; j++) {
found = false;
if (methods[j].getName().startsWith("ejbCreate")) {
found = true;
String matchSuffix = methods[j].getName().substring(9);
signaturesMatch = false;
if (matchSuffix.equals(((Method) (createMethodSuffix.elementAt(k))).getName().substring(6))) {
methodParameterTypes = ((Method) (createMethodSuffix.elementAt(k))).getParameterTypes();
businessMethodParameterTypes = methods[j].getParameterTypes();
if (Arrays.equals(methodParameterTypes, businessMethodParameterTypes)) {
signaturesMatch = true;
// now display the appropriate results for this particular ejbCreate
// method
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface Method [ {0} ]", new Object[] { ((Method) (createMethodSuffix.elementAt(k))).getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The corresponding ejbCreate method with matching parameters was found."));
break;
}
}
}
}
if (signaturesMatch == false) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug3", "For Home Interface", new Object[] {}));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No corresponding ejbCreate<Method> method with matching parameters was found."));
}
}
if (found == false && foundAtLeastOneCreate == true) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: ejbCreate<Method> method corresponding to the create<Method> method does not exist!", new Object[] {}));
}
if (found == false && foundAtLeastOneCreate == false) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: no create<Method> method exists!", new Object[] {}));
}
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 (Local/Remote) interface or bean class [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
oneFailed = true;
return oneFailed;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class EjbCreateMethodArgs method check.
/**
* Session Bean's ejbCreate(...) methods arguments test.
* Each session Bean class must define one or more ejbCreate(...) methods.
* The number and signatures of a session Bean's create methods are specific
* to each EJB class. The method signatures must follow these rules:
*
* The method name must be ejbCreate.
*
* The methods arguments must be legal types for RMI-IIOP.
*
* @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();
boolean remote_exists = false;
if (descriptor instanceof EjbSessionDescriptor) {
boolean oneFailed = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
Class[] ejbCreateMethodParameterTypes;
boolean ejbCreateFound = false;
boolean isLegalRMIIIOP = false;
int foundAtLeastOne = 0;
// bug fix for 4699227
if (descriptor.getHomeClassName() == null || descriptor.getHomeClassName().equals("")) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp", "Not Applicable because, EJB [ {0} ] has Local Interfaces only.", new Object[] { descriptor.getEjbClassName() }));
return result;
}
if (descriptor.getRemoteClassName() != null && !descriptor.getRemoteClassName().equals(""))
remote_exists = true;
// 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
ejbCreateFound = false;
isLegalRMIIIOP = false;
// The method name must be ejbCreate.
if (methods[i].getName().startsWith("ejbCreate")) {
foundAtLeastOne++;
ejbCreateFound = true;
if (remote_exists == true) {
// The methods arguments types must be legal types for RMI-IIOP.
ejbCreateMethodParameterTypes = methods[i].getParameterTypes();
if (RmiIIOPUtils.isValidRmiIIOPParameters(ejbCreateMethodParameterTypes)) {
// these method parameters are valid, continue
isLegalRMIIIOP = true;
}
} else
// if the ejb has only a local interface
isLegalRMIIIOP = true;
// method
if (ejbCreateFound && isLegalRMIIIOP) {
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 [ {1} ] method with valid RMI-IIOP argument types.", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
} else if (ejbCreateFound && (!isLegalRMIIIOP)) {
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} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An [ {0} ] method was found, but [ {1} ] method has illegal parameter values. [ {2} ] methods arguments types must be legal types for RMI-IIOP.", new Object[] { methods[i].getName(), methods[i].getName(), methods[i].getName() }));
}
}
}
} while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
if (foundAtLeastOne == 0) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: [ {0} ] does not properly declare at least one ejbCreate(...) method. [ {1} ] is not a valid bean.", new Object[] { descriptor.getEjbClassName(), descriptor.getEjbClassName() }));
oneFailed = true;
}
} 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 {
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(), "Session", "Entity" }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class EjbCreateMethodFinal method check.
/**
* Session Bean's ejbCreate(...) methods final test.
* Each session Bean class must define one or more ejbCreate(...) methods.
* The number and signatures of a session Bean's create methods are specific
* to each EJB class. The method signatures must follow these rules:
*
* The method name must be ejbCreate.
*
* The method must not be declared as final.
*
* @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 EjbSessionDescriptor) {
boolean oneFailed = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
int foundAtLeastOne = 0;
boolean ejbCreateFound = false;
boolean isFinal = 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
ejbCreateFound = false;
isFinal = false;
// The method name must be ejbCreate.
if (methods[i].getName().startsWith("ejbCreate")) {
foundAtLeastOne++;
ejbCreateFound = true;
// The method must not be declared as final or static.
int modifiers = methods[i].getModifiers();
if (Modifier.isFinal(modifiers)) {
isFinal = true;
}
// method
if (ejbCreateFound && (!isFinal)) {
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-final [ {1} ] method.", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
} else if (ejbCreateFound && isFinal) {
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} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A final [ {0} ] method was found, but [ {1} ] cannot be declared as final.", new Object[] { methods[i].getName(), methods[i].getName() }));
}
}
}
} while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
if (foundAtLeastOne == 0) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: [ {0} ] does not properly declare at least one ejbCreate(...) method. [ {1} ] is not a valid bean.", new Object[] { descriptor.getEjbClassName(), descriptor.getEjbClassName() }));
oneFailed = true;
}
} 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 {
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(), "Session", "Entity" }));
return result;
}
}
Aggregations