use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class HomeInterfaceExtendsRightInterface method check.
/**
* Extends the EJBHome Interface test.
* All enterprise beans home interface's must extend the EJBHome interface.
*
* @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();
String str = null;
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;
}
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(getClassName(descriptor), false, jcl);
str = getSuperInterface();
if (isImplementorOf(c, str)) {
// it extends the proper EJBHome
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly extends the " + str + "interface.", 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: [ {0} ] does not properly extend the " + str + " interface. All enterprise beans home interfaces must extend the " + str + " interface. [ {1} ] is not a valid home interface.", new Object[] { getClassName(descriptor), 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() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { getClassName(descriptor) }));
}
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 or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class MessageBeanTest method loadMessageBeanClass.
/**
* <p>
* load the declared message bean class from the archive
* </p>
*
* @param descriptor deployment descriptor for the message bean
* @param result result to use if failure
* @return the message bean class
*/
protected Class loadMessageBeanClass(EjbMessageBeanDescriptor descriptor, Result result) {
try {
compName = getVerifierContext().getComponentNameConstructor();
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
return Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
} 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.messagebean.classnotfoundexception", "Cannot load declared message-driven bean component [ {0} ]"));
return null;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class TransactionDemarcationHomeInterface method check.
/**
* Session Bean transaction demarcation type home interface methods test.
* Transaction attributes must not be specified for the methods of a session
* bean's home interface.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
// <ejb-class>verifier.ejb.hello.BogusEJB...
try {
// bean's home interface.
if (descriptor instanceof EjbSessionDescriptor) {
String transactionType = descriptor.getTransactionType();
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
boolean oneFailed = false;
if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) {
Class superclass = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
do {
oneFailed = commonToBothInterfaces(superclass.getName(), (EjbSessionDescriptor) descriptor, MethodDescriptor.EJB_HOME);
if (oneFailed == true) {
break;
}
superclass = superclass.getSuperclass();
} while (superclass != null);
}
if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) {
Class superclass = Class.forName(descriptor.getLocalHomeClassName(), false, getVerifierContext().getClassLoader());
do {
oneFailed = commonToBothInterfaces(superclass.getName(), (EjbSessionDescriptor) descriptor, MethodDescriptor.EJB_LOCALHOME);
if (oneFailed == true) {
break;
}
superclass = superclass.getSuperclass();
} while (superclass != null);
}
if ((oneFailed == false) && (implementsEndpoints(descriptor))) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", new Object[] { compName.toString() }));
result.setStatus(Result.NOT_APPLICABLE);
return result;
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
return result;
} else {
// not container managed, but is a session bean
addNaDetails(result, compName);
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 {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Session", "Entity" }));
return result;
}
} catch (Throwable t) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ].", new Object[] { t.getMessage(), descriptor.getName() }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.VerifierTestContext in project Payara by payara.
the class TransactionDemarcationHomeInterface 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 for the interface type
* @return boolean the results for this assertion i.e if a test has failed or not
*/
private boolean commonToBothInterfaces(String home, EjbSessionDescriptor descriptor, String methodIntf) {
boolean oneFailed = false;
try {
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
boolean lookForIt = false;
for (int i = 0; i < methods.length; i++) {
try {
ContainerTransaction containerTransaction = null;
boolean resolved = true;
if (!descriptor.getMethodContainerTransactions().isEmpty()) {
for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
lookForIt = false;
MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
// style 1)
if (methodDescriptor.getName().equals(MethodDescriptor.ALL_METHODS)) {
// if Home - PASS
if (methodDescriptor.getEjbClassSymbol() == null) {
lookForIt = true;
} else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) {
lookForIt = true;
// if empty String PASS
} else if (methodDescriptor.getEjbClassSymbol().equals("")) {
lookForIt = true;
} else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) {
lookForIt = false;
// else (Bogus)
} else {
// carry on & don't look for
// container transaction
lookForIt = false;
}
} else if (methodDescriptor.getParameterClassNames() == null) {
// if (getEjbClassSybol() is Home or is the empty String AND if methods[i].getName().equals(methodDescriptor.getName())
if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && (methods[i].getName().equals(methodDescriptor.getName()))) {
// PASS
lookForIt = true;
} else {
// carry on
lookForIt = false;
}
} else {
// the parameters of the method[i] are the same as the parameters of the method descriptor )
if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && (methods[i].getName().equals(methodDescriptor.getName())) && (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(methods[i], methodIntf)).getParameterClassNames()))) {
// PASS
lookForIt = true;
} else {
// CARRY ON
lookForIt = false;
}
}
if (lookForIt) {
containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
if (containerTransaction != null) {
String transactionAttribute = containerTransaction.getTransactionAttribute();
// don't need this check here
if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute) || (!transactionAttribute.equals(""))) {
// if "*" ignore, test N/A
if (!methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) && !methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) {
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for home interface [ {2} ]", new Object[] { transactionAttribute, methods[i].getName(), home }));
} else {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid. Transaction attributes must not be specified for all methods of session bean home interface [ {2} ].", new Object[] { transactionAttribute, methods[i].getName(), home }));
resolved = false;
}
} else {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for home interface [ {2} ]", new Object[] { transactionAttribute, methods[i].getName(), home }));
}
} else {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedException", "Valid: TransactionAttribute is null for method [ {0} ]", new Object[] { methodDescriptor.getName() }));
}
}
}
// did you resolve the last one okay?
if (!resolved) {
/*
// This if-stmt code is a workaround introduced by Harminder
// because currently methodDescriptor.getEjbClassSymbol() is
// returning NULL
//if (allMethods){
if (!wildCardWasPresent) {
*/
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: Transaction attributes must not be specified for the methods defined in the session bean home interface [ {0} ]. Method [ {1} ] has transaction attribute defined within this bean [ {2} ].", new Object[] { home, methods[i].getName(), descriptor.getName() }));
/*
}
else {
result.addGoodDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".passed",
"Valid: TransactionAttribute [ {0} ] for method [ {1} ] is defined for remote interface [ {2} ]", new Object[] {"*", "*",home}));
}
// End of workaround code. Note : this else also has to be removed once
// the original bug of methodDesc.getEjbClassSymbol() is fixed
*/
} else {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed2", "Valid: Transaction attributes must not be specified for the methods defined in the session bean home interface [ {0} ]. Method [ {1} ] has no transaction attribute defined within this bean [ {2} ].", new Object[] { home, methods[i].getName(), descriptor.getName() }));
}
} else {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Valid: There are no method permissions within this bean [ {0} ]. Transaction attributes must not be specified for the methods defined in the session bean home interface [ {1} ]. Method [ {2} ] has no transaction attribute defined.", new Object[] { descriptor.getName(), home, methods[i].getName() }));
}
if (oneFailed == true)
return oneFailed;
} catch (Exception e) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: Home interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { home, e.getMessage(), descriptor.getName() }));
return oneFailed;
}
}
// for all the methods within the home interface class, loop
return oneFailed;
} catch (ClassNotFoundException e) {
Verifier.debug(e);
addErrorDetails(result, compName);
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 JarFileContainsProperEJBClasses method check.
/**
* ejb-jar file must contain the java class file of the enterprise bean
* implementation class, and any of the classes that it depends on.
*
* @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();
try {
VerifierTestContext context = getVerifierContext();
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// if we are dealing with a CMP2 entity bean, the class is abstract..
if (descriptor instanceof EjbEntityDescriptor) {
String persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
if (EjbCMPEntityDescriptor.CMP_1_1 != ((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Bean class [ {0} ] exists and it's supporting classes exist.", new Object[] { descriptor.getEjbClassName() }));
return result;
}
}
}
try {
c.newInstance();
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Bean class [ {0} ] exists and it's supporting classes exist.", new Object[] { descriptor.getEjbClassName() }));
} catch (InstantiationException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Could not instantiate [ {0} ] within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
} catch (IllegalAccessException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: Illegal Access while trying to instantiate [ {0} ] within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), 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() + ".failedException2", "Error: Can't find class [ {0} ] within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
} catch (Throwable t) {
Verifier.debug(t);
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Not Applicable: [ {0} ] class encountered [ {1} ]. Cannot create instance of class [ {2} ] becuase [ {3} ] is not accessible within [ {4} ].", new Object[] { (descriptor).getEjbClassName(), t.toString(), descriptor.getEjbClassName(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() }));
}
return result;
}
Aggregations