use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class CmpFields method check.
/**
* Container-managed fields valid type test.
*
* The Bean Provider must ensure that the Java types assigned to the
* container-managed fields are one of the following: Java primitive types,
* Java serializable types, or references to enterprise beans' remote or home
* interfaces.
*
* @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;
}
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
// RULE: container-managed fields are one of the following:
// Java primitive types, Java serializable types, or references
// to enterprise beans' remote or home interfaces.
Set persistentFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields();
Iterator iterator = persistentFields.iterator();
Descriptor persistentField;
Field field;
boolean oneFailed = false;
while (iterator.hasNext()) {
persistentField = (Descriptor) iterator.next();
boolean foundField = false;
try {
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// start do while loop here....
do {
try {
Field f = c.getDeclaredField(persistentField.getName());
foundField = true;
Class persistentFieldClassType = f.getType();
if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()) && descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) {
if (RmiIIOPUtils.isPersistentFieldTypeValid(persistentFieldClassType, descriptor.getHomeClassName(), descriptor.getRemoteClassName())) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
}
}
if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName()) && descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) {
if (RmiIIOPUtils.isPersistentFieldTypeValid(persistentFieldClassType, descriptor.getLocalHomeClassName(), descriptor.getLocalClassName())) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
}
}
} catch (NoSuchFieldException e) {
foundField = false;
}
} while (((c = c.getSuperclass()) != null) && (!foundField));
if (!foundField) {
if (!oneFailed) {
oneFailed = true;
}
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException1", "Error: field [ {0} ] not found in class [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), 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 {
result.setStatus(Result.PASSED);
}
} else {
// if (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 }));
}
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 SelectMethodExposition 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
* @param m Method
* @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, Result result, Method m) {
try {
// we must not find this method exposed in the home or remote interface
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Method m1 = getMethod(Class.forName(home, false, getVerifierContext().getClassLoader()), m.getName(), m.getParameterTypes());
Method m2 = getMethod(Class.forName(remote, false, getVerifierContext().getClassLoader()), m.getName(), m.getParameterTypes());
if (m1 == null && m2 == null) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodExposition.passed", "[ {0} ] is not declared in the home or remote interface", new Object[] { m.getName() }));
return true;
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodExposition.failed", "Error : [ {0} ] is declared in the home or remote interface", new Object[] { m.getName() }));
return false;
}
} catch (ClassNotFoundException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodExposition.failedException", "Error: home or remote interface not found.", new Object[] {}));
Verifier.debug(e);
return false;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceCreateMethodReturn 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 Remote/Local interface
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String remote, String home, String local, String localHome, EjbEntityDescriptor descriptor) {
boolean oneFailed = false;
Class c, rc, lc, hc;
Method[] localMethods, methods;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
if (remote_exists) {
c = Class.forName(home, false, getVerifierContext().getClassLoader());
rc = Class.forName(remote, false, getVerifierContext().getClassLoader());
methods = c.getDeclaredMethods();
oneFailed = findReturnType(methods, home, local, remote);
}
if (oneFailed == false) {
if (local_exists) {
hc = Class.forName(localHome, false, getVerifierContext().getClassLoader());
lc = Class.forName(local, false, getVerifierContext().getClassLoader());
localMethods = hc.getDeclaredMethods();
oneFailed = findReturnType(localMethods, localHome, local, remote);
}
}
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 [ {1} ]or Component interface [ {2} ] or [ {3} ] does not exist or is not loadable within bean [ {4} ]", new Object[] { home, localHome, remote, local, descriptor.getName() }));
return false;
}
}
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.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ]`s home/localhome does not declare any create<Method> methods.", new Object[] { descriptor.getEjbClassName() }));
return false;
}
Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// start do while loop here....
do {
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."));
break;
}
}
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: 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.
/**
* Entity Bean's ejbCreate(...) methods arguments test.
* Each entity Bean class may define zero or more ejbCreate(...) 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 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();
if (descriptor instanceof EjbEntityDescriptor) {
boolean oneFailed = false;
int foundAtLeastOne = 0;
boolean remote_exists = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// bug fix for 4699227
if (descriptor.getRemoteClassName() == null || descriptor.getRemoteClassName().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;
Class[] ejbCreateMethodParameterTypes;
boolean ejbCreateFound = false;
boolean isLegalRMIIIOP = 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;
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;
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() }));
break;
}
}
}
if (oneFailed == true)
break;
} 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 ejbCreate(...) methods.", new Object[] { descriptor.getEjbClassName() }));
}
if (oneFailed == false && foundAtLeastOne > 0) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ]", new Object[] { descriptor.getEjbClassName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares ejbCreate<method> method with arguments that are legal types for RMI-IIOP.", 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;
}
}
Aggregations