use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.
the class EjbCreateMethodReturn method check.
/**
* Session Bean's ejbCreate(...) methods return test.
* Each session Bean class must define one or more ejbCreate(...) methods.
* The number and signature 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 return type must be void.
*
* @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());
Class[] ejbCreateMethodParameterTypes;
int foundAtLeastOne = 0;
boolean ejbCreateFound = false;
boolean returnsVoid = 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;
returnsVoid = false;
// The method name must be ejbCreate.
if (methods[i].getName().startsWith("ejbCreate")) {
ejbCreateFound = true;
// The return type must be void.
Class rt = methods[i].getReturnType();
if (rt.getName().equals("void")) {
returnsVoid = true;
foundAtLeastOne++;
}
// method
if (ejbCreateFound && returnsVoid) {
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 'void' return type.", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
} else if (ejbCreateFound && (!returnsVoid)) {
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() + ".notApplicable2", "An [ {0} ] method was found, but [ {1} ] method has a non 'void' return type value. [ {2} ] methods return types must define return 'void' type for at least one ejbCreate method.", new Object[] { methods[i].getName(), methods[i].getName(), methods[i].getName() }));
oneFailed = true;
}
}
}
} 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() + ".failed", "Error: [ {0} ] does not properly declare at least one ejbCreate(...) method with valid 'void' return type. [ {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.Result in project Payara by payara.
the class ClassNotFound method check.
public Result check(Descriptor descriptor) {
Result result = getInitializedResult();
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
result.setStatus(Result.PASSED);
final PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
for (String className : pu.getClasses()) {
try {
Class.forName(className, false, getVerifierContext().getClassLoader());
} catch (ClassNotFoundException e) {
result.failed(smh.getLocalString(getClass().getName() + "failed1", "Class [ {0} ] could not be loaded", new Object[] { className }));
} catch (NoClassDefFoundError e) {
result.failed(smh.getLocalString(getClass().getName() + "failed2", "Class [ {0} ] could not be loaded " + "because a dependent class could not be loaded. See reason:\n [ {1} ]", new Object[] { className, e.getMessage() }));
}
}
return result;
}
use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.
the class DefaultProviderVerification method check.
public Result check(Descriptor descriptor) {
PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
Result result = getInitializedResult();
result.setStatus(Result.PASSED);
PersistenceProvider provider;
final String appLocation = getVerifierContext().getAbstractArchive().getURI().getPath();
final InstrumentableClassLoader cl = InstrumentableClassLoader.class.cast(pu.getParent().getClassLoader());
PersistenceUnitInfo pi = new AVKPersistenceUnitInfoImpl(pu, appLocation, cl);
logger.fine("PersistenceInfo for PU is :\n" + pi);
Properties props = new Properties();
// This property is set to indicate that TopLink should only
// validate the descriptors etc. and not try to login to database.
props.put(PersistenceUnitProperties.VALIDATION_ONLY_PROPERTY, // NOI18N
"TRUE");
// This property is used so that TopLink throws validation exceptions
// as opposed to printing CONFIG level messages to console.
// e.g. if mapping file does not exist, we will get an exception.
props.put(PersistenceUnitProperties.THROW_EXCEPTIONS, // NOI18N
"TRUE");
// the following property is needed as it initializes the logger in TL
props.put(PersistenceUnitProperties.TARGET_SERVER, // NOI18N
"SunAS9");
// Turn off enhancement during verification. For details,
// refer to http://glassfish.dev.java.net/issues/show_bug.cgi?id=3295
props.put(PersistenceUnitProperties.WEAVING, "FALSE");
provider = new org.eclipse.persistence.jpa.PersistenceProvider();
EntityManagerFactory emf = null;
try {
emf = provider.createContainerEntityManagerFactory(pi, props);
logger.logp(Level.FINE, "DefaultProviderVerification", "check", "emf = {0}", emf);
} catch (IntegrityException ie) {
result.setStatus(Result.FAILED);
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
for (Object o : ie.getIntegrityChecker().getCaughtExceptions()) {
Exception e = Exception.class.cast(o);
result.addErrorDetails(e.getMessage());
}
} catch (ValidationException ve) {
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
result.failed(ve.getMessage());
logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", ve);
} catch (DatabaseException de) {
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
result.failed(de.getMessage());
logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", de);
} catch (PersistenceException pe) {
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
result.failed(pe.getMessage());
logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", pe);
} finally {
if (emf != null) {
emf.close();
}
}
return result;
}
use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.
the class DuplicatePUNameTest method check.
public Result check(Descriptor descriptor) {
PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
Result result = getInitializedResult();
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
// default status is PASSED
result.setStatus(Result.PASSED);
int count = 0;
for (PersistenceUnitDescriptor nextPU : getPUsInSameScope(pu)) {
result.addErrorDetails(smh.getLocalString(getClass().getName() + "puName", "Found a persistence unit by name [ {0} ] in persistence unit root [ {1} ]", new Object[] { nextPU.getName(), nextPU.getPuRoot() }));
if (nextPU.getName().equals(pu.getName()))
count++;
}
if (count != 1) {
result.failed(smh.getLocalString(getClass().getName() + "failed", "There are [ {0} ] number of persistence units by name [ {1} ]", new Object[] { count, pu.getName() }));
}
return result;
}
use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.
the class JarNotFound method check.
public Result check(Descriptor descriptor) {
Result result = getInitializedResult();
result.setStatus(Result.PASSED);
addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
File absolutePURootFile = getAbsolutePuRootFile(pu);
logger.fine("Absolute PU Root: " + absolutePURootFile);
String absolutePuRoot = absolutePURootFile.getAbsolutePath();
List<String> jarFileNames = new ArrayList<String>(pu.getJarFiles());
for (String jarFileName : jarFileNames) {
// ASSUMPTION:
// Because of the way deployment changes names of directories etc.
// it is very difficult to back calculate path names. So,
// the following code assumes user is specifying valid URIs.
// in the xml, names always use '/'
String nativeJarFileName = jarFileName.replace('/', File.separatorChar);
final File parentFile = new File(absolutePuRoot).getParentFile();
// only components are exploded, hence first look for original archives.
File jarFile = new File(parentFile, nativeJarFileName);
if (!jarFile.exists()) {
// if the referenced jar is itself a component, then
// it might have been exploded, hence let's see
// if that is the case.
// let's calculate the name component and path component from this URI
// e.g. if URI is ../../foo_bar/my-ejb.jar,
// name component is foo_bar/my-ejb.jar and
// path component is ../../
// These are my own notions used here.
String pathComponent = "";
String nameComponent = jarFileName;
if (jarFileName.lastIndexOf("../") != -1) {
final int separatorIndex = jarFileName.lastIndexOf("../") + 3;
pathComponent = jarFileName.substring(0, separatorIndex);
nameComponent = jarFileName.substring(separatorIndex);
}
logger.fine("For jar-file=" + jarFileName + ", " + "pathComponent=" + pathComponent + ", nameComponent=" + nameComponent);
File parentPath = new File(parentFile, pathComponent);
jarFile = new File(parentPath, DeploymentUtils.getRelativeEmbeddedModulePath(parentPath.getAbsolutePath(), nameComponent));
if (!jarFile.exists()) {
result.failed(smh.getLocalString(getClass().getName() + "failed", "[ {0} ] specified in persistence.xml does not exist in the application.", new Object[] { jarFileName }));
}
}
}
return result;
}
Aggregations