use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class PersistenceFieldsElement method check.
/**
* Container-managed fields test.
* If the enterprise bean is a Entity Bean w/Container managed persistence
* the Bean provider must specify container managed fields in the
* "persistent-fields" element.
*
* @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 persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
// this test apply only to 1.x cmp beans, in 2.x fields are virtual fields only
if (EjbCMPEntityDescriptor.CMP_1_1 != ((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.notApplicable3", "Test do not apply to this cmp-version of container managed persistence EJBs"));
return result;
}
logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { persistentType });
// RULE: Entity w/Container managed persistence bean provider must
// specify container managed fields in the persistent-fields
// element
Set persistentFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields();
Iterator iterator = persistentFields.iterator();
// check class to see if fields actually exist
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
Descriptor persistentField;
Field field;
boolean oneFailed = false;
while (iterator.hasNext()) {
persistentField = (Descriptor) iterator.next();
try {
field = c.getField(persistentField.getName());
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] field found in [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), descriptor.getEjbClassName() }));
} catch (NoSuchFieldException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: NoSuchFieldException: [ {0} ] not found in [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), descriptor.getEjbClassName() }));
if (!oneFailed) {
oneFailed = true;
}
} catch (SecurityException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: SecurityException: [ {0} ] not found in [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), descriptor.getEjbClassName() }));
if (!oneFailed) {
oneFailed = true;
}
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException3", "Error: Fields don't exist or are not loadable within bean [ {0} ]", new Object[] { descriptor.getName() }));
}
} else if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Expected persistence type [ {0} ], but [ {1} ] bean has persistence type [ {2} ]", new Object[] { EjbEntityDescriptor.CONTAINER_PERSISTENCE, descriptor.getName(), persistentType }));
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] is not valid persistentType within bean [ {1} ]", new Object[] { persistentType, descriptor.getName() }));
}
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 CmpEjbCreateMethod method check.
/**
* Entity Bean's with container managed persistence ejbCreate(...) and
* ejbPostCrete(...) methods must be defined to return the primary key class
* type. The implementation of the ejbCreate(...) methods should be coded to
* return a null. The returned value is ignored by the Container.
*
* The method signatures must follow these rules:
*
* The return type must be defined to return the primary key class type.
*
* @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.CONTAINER_PERSISTENCE.equals(persistence)) {
boolean oneFailed = false;
int foundAtLeastOne = 0;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
Method[] methods1 = c.getDeclaredMethods();
int loopCounter = 0;
boolean ejbCreateFound = false;
boolean returnsPrimaryKeyClassType = false;
// start do while loop here....
do {
Method[] methods = c.getDeclaredMethods();
methods1 = null;
methods1 = methods;
for (int i = 0; i < methods.length; i++) {
// reset flags from last time thru loop
ejbCreateFound = false;
loopCounter++;
returnsPrimaryKeyClassType = false;
// The method name must be ejbCreate.
if (methods[i].getName().startsWith("ejbCreate")) {
foundAtLeastOne++;
ejbCreateFound = true;
// The return type must be be defined to
// return the primary key class type
Class rt = methods[i].getReturnType();
Class str = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName());
do {
if (rt.getName().equals(str.getName())) {
returnsPrimaryKeyClassType = true;
}
str = str.getSuperclass();
} while (str != null && returnsPrimaryKeyClassType != true);
// method
if (ejbCreateFound && returnsPrimaryKeyClassType) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] ejbCreate(...) Method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly returns the primary key class type.", new Object[] { descriptor.getEjbClassName() }));
} else if (ejbCreateFound && !returnsPrimaryKeyClassType) {
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} ] ejbCreate(...) Method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods1[loopCounter].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An ejbCreate(...) method was found, but did not properly return the primary key class type."));
}
}
}
} while (((c = c.getSuperclass()) != null) && (!(ejbCreateFound && returnsPrimaryKeyClassType)));
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 ejbCreate(...) 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() }));
}
if (oneFailed) {
result.setStatus(result.FAILED);
} else if (foundAtLeastOne == 0) {
result.setStatus(result.NOT_APPLICABLE);
} else {
result.setStatus(result.PASSED);
}
return result;
} else {
// if (BEAN_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.CONTAINER_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 QueryMethodTest 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 ejbHome for the Home interface of the Ejb.
* @param result Result of the test
* @param remote Remote/Local interface
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String ejbHome, String remote, EjbDescriptor descriptor, Result result) {
boolean allIsWell = true;
boolean found = false;
String ejbClassName = descriptor.getEjbClassName();
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
try {
Class ejbClass = Class.forName(ejbClassName, false, getVerifierContext().getClassLoader());
Method[] methods = Class.forName(ejbHome, false, getVerifierContext().getClassLoader()).getMethods();
for (int i = 0; i < methods.length; i++) {
String methodName = methods[i].getName();
// get the expected return type
String methodReturnType = methods[i].getReturnType().getName();
if (methodName.startsWith("find")) {
found = true;
if (methodReturnType.equals(remote) || isSubclassOf(Class.forName(methodReturnType, false, getVerifierContext().getClassLoader()), "java.util.Collection") || isImplementorOf(Class.forName(methodReturnType, false, getVerifierContext().getClassLoader()), "java.util.Collection")) {
if (!runIndividualQueryTest(methods[i], (EjbCMPEntityDescriptor) descriptor, ejbClass, result))
allIsWell = false;
}
}
}
if (found == false) {
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.EjbTest.passed", "Not Applicable : No find methods found", new Object[] {}));
}
return allIsWell;
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.EjbTest.failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
allIsWell = false;
return allIsWell;
}
}
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, EjbDescriptor descriptor) {
boolean oneFailed = false;
// methods which must throw javax.ejb.CreateException
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")) {
// is N/A
if (!foundAtLeastOneCreate) {
foundAtLeastOneCreate = true;
}
methodExceptionTypes = methods[i].getExceptionTypes();
// methods must also throw javax.ejb.CreateException
for (int kk = 0; kk < methodExceptionTypes.length; ++kk) {
if (methodExceptionTypes[kk].getName().equals("javax.ejb.CreateException")) {
throwsCreateException = true;
break;
}
}
// 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[] { home, methods[i].getName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A create method was found, but did not throw javax.ejb.CreateException."));
break;
}
// 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 HomeInterfaceCreateMethodMatchArgs 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 component, String local, EjbDescriptor descriptor) {
boolean oneFailed = false;
boolean found = false;
foundAtLeastOneCreate = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class[] methodParameterTypes;
Class[] businessMethodParameterTypes;
boolean signaturesMatch = false;
Vector<Method> createMethodSuffix = new Vector<Method>();
if (component != null) {
Class home = Class.forName(component, 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")) {
foundAtLeastOneCreate = true;
createMethodSuffix.addElement((Method) homeMethods[i]);
}
}
}
if (local != null) {
Class home = Class.forName(local, 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")) {
foundAtLeastOneCreate = true;
createMethodSuffix.addElement((Method) homeMethods[i]);
}
}
}
if (foundAtLeastOneCreate == false)
return false;
Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// start do while loop here....
do {
Method[] methods = EJBClass.getDeclaredMethods();
// find matching "ejbCreate" in bean class
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);
for (int k = 0; k < createMethodSuffix.size(); k++) {
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."));
break;
}
// for all the business methods within the bean class, loop
}
}
if (oneFailed == true)
break;
} while (((EJBClass = EJBClass.getSuperclass()) != null) && (!signaturesMatch));
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: ejbPostCreate<Method> method corresponding to the ejbCreate<Method> method does not exist!", new Object[] {}));
}
if (found == false && foundAtLeastOneCreate == false) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "No create method was found, test not applicable."));
}
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 (Remote/Local) or bean class [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
return oneFailed;
}
}
Aggregations