use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceFindMethodReturn 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 oneFailed = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
Class rc = Class.forName(remote, false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
Class methodReturnType;
boolean validReturn = false;
for (int i = 0; i < methods.length; i++) {
// clear these from last time thru loop
validReturn = false;
if (methods[i].getName().startsWith("find")) {
// return type must be the remote interface
// or collection thereof
methodReturnType = methods[i].getReturnType();
if ((methodReturnType.getName().equals(rc.getName())) || (methodReturnType.getName().equals("java.util.Collection")) || (methodReturnType.getName().equals("java.util.Enumeration"))) {
// this is the right return type for find method
validReturn = true;
} else {
validReturn = false;
}
// method
if (validReturn) {
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> which returns remote interface or a collection there of was found."));
} else if (!validReturn) {
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> was found, but the return type [ {0} ] was not the Remote interface [ {1} ] or a collection there of.", new Object[] { methodReturnType.getName(), rc.getName() }));
}
// 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 Remote interface [ {1} ] does not exist or is not loadable within bean [ {2} ]", new Object[] { home, remote, descriptor.getName() }));
return oneFailed;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class PrimaryKeyClassFieldsCmp method check.
/**
* Enterprise Java Bean primary key class fields subset of the names of
* the container-managed fields test.
*
* The names of the fields in the primary key class must be a subset of the
* names of the container-managed fields. (This allows the container to
* extract the primary key fields from an instance's container-managed fields,
* and vice versa.)
*
* @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)) {
// field in entity bean class and this test in notApplicable
try {
FieldDescriptor fd = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
if (fd != null) {
String pkf = fd.getName();
if (pkf.length() > 0) {
// N/A case
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", new Object[] { descriptor.getEjbClassName() }));
}
} else {
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
boolean oneFailed = false;
boolean badField = false;
Field[] fields = c.getDeclaredFields();
Set persistentFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields();
for (int i = 0; i < fields.length; i++) {
badField = false;
if (EjbUtils.isFieldSubsetOfCMP(fields[i], persistentFields)) {
continue;
} else {
if (!oneFailed) {
oneFailed = true;
}
badField = true;
}
if (badField) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Field [ {0} ] defined within primary key class [ {1} ] is not defined within container managed fields.", new Object[] { fields[i].getName(), ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
}
}
if (!oneFailed) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "This primary key class [ {0} ] has defined all fields which are defined within container managed fields.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
}
} 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[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
} catch (Throwable t) {
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.warning(smh.getLocalString(getClass().getName() + ".warningException", "Warning: [ {0} ] class encountered [ {1} ]. Cannot access fields of class [ {2} ] which is external to [ {3} ].", new Object[] { (descriptor).getEjbClassName(), t.toString(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() }));
}
}
} catch (NullPointerException e) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Primkey field not defined within [ {0} ] bean.", new Object[] { descriptor.getName() }));
}
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() + ".notApplicable1", "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}.", new Object[] { getClass(), "Entity", "Session" }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class PrimekeyFieldPrimaryKeyType method check.
/**
* The type of the primkey-field must be the same as the primary key 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();
// The type of the primkey-field must be the same as the primary key type.
if (descriptor instanceof EjbEntityDescriptor) {
String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
try {
if (((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc() != null) {
Field pkf = c.getDeclaredField(((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc().getName());
Class pkfType = pkf.getType();
try {
String primkey = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
boolean foundMatch = false;
if (primkey.equals(pkfType.getName())) {
foundMatch = true;
} else {
foundMatch = false;
}
if (foundMatch) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "The type of the primkey-field [ {0} ] is the same as the primary key type [ {1} ] for bean [ {2} ]", new Object[] { ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc().getName(), primkey, descriptor.getName() }));
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "The type of the primkey-field [ {0} ] is not the same as the primary key type [ {1} ] for bean [ {2} ]", new Object[] { ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc().getName(), primkey, descriptor.getName() }));
}
} catch (NullPointerException e) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field not defined for [ {0} ] bean.", new Object[] { descriptor.getName() }));
}
} catch (NullPointerException e) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable3", "Primkey field not defined within [ {0} ] bean.", new Object[] { descriptor.getName() }));
} catch (NoSuchFieldException e) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Primkey field [ {0} ] not defined within [ {1} ] bean.", new Object[] { ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc().getName(), descriptor.getName() }));
}
} 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: EJB class [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", new Object[] { EjbEntityDescriptor.CONTAINER_PERSISTENCE, descriptor.getName(), persistence }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected \n {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 PrimaryKeyClassMethodHashCode method check.
/**
* Primary key class provide implementation of hashCode() methods test.
*
* Enterprise Bean's primary key class
* The class must provide suitable implementation of the hashCode()
* method to simplify the management of the primary keys by client code.
*
* @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 transactionType = descriptor.getTransactionType();
if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
boolean hasDefinedHashCodeMethod = false;
boolean oneFailed = false;
int lc = 0;
// RULE: Primary key class must defined HashCode() method
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
// retrieve the EJB primary key class
Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals("hashCode")) {
// this is the right primary key class method hashCode()
hasDefinedHashCodeMethod = true;
// used in output below
lc = i;
break;
}
}
if (hasDefinedHashCodeMethod) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB primary key class [ {0} ]", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Primary key class method [ {0} ] was defined in the primary key class.", new Object[] { methods[lc].getName() }));
} else if (!hasDefinedHashCodeMethod) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB primary key class [ {0} ]", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Primary key class method hashCode() was not defined in the primary key class."));
}
} 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: Class [ {0} ] not found within bean [ {1} ]", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), descriptor.getName() }));
}
if (oneFailed)
result.setStatus(result.FAILED);
else
result.setStatus(result.PASSED);
} else {
// not container managed, but is a entity bean
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Bean [ {0} ] is not {1} managed, it is [ {2} ] managed.", new Object[] { descriptor.getName(), EjbDescriptor.CONTAINER_TRANSACTION_TYPE, transactionType }));
}
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 HomeInterfaceClassExist method check.
/**
* Home Interface test.
* Verify that the bean home interface class exist and is loadable.
*
* @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) && !(descriptor instanceof EjbEntityDescriptor)) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
return result;
}
if (getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))) {
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;
}
// verify that the home interface class exist and is loadable
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(getClassName(descriptor), false, jcl);
if (c != null) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Home interface [ {0} ] exist and is loadable.", new Object[] { getClassName(descriptor) }));
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Home interface [ {0} ] does not exist or is not loadable.", new Object[] { getClassName(descriptor) }));
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Home interface [ {0} ] does not exist or is not loadable.", new Object[] { getClassName(descriptor) }));
}
return result;
}
Aggregations