HomeInterfaceFindByPrimaryKeyNamepublic class HomeInterfaceFindByPrimaryKeyName extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheckDefine findByPrimaryKey method test.
Every entity enterprise Bean class must define the findByPrimaryKey
method. |
Fields Summary |
---|
Result | result | ComponentNameConstructor | compName |
Methods Summary |
---|
public Result | check(com.sun.enterprise.deployment.EjbDescriptor descriptor)Define findByPrimaryKey method test.
Every entity enterprise Bean class must define the findByPrimaryKey
method.
result = getInitializedResult();
boolean oneFailed = false;
compName = getVerifierContext().getComponentNameConstructor();
if (descriptor instanceof EjbEntityDescriptor) {
if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName()))
oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor);
if(oneFailed == false) {
if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()))
oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor);
}
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(),"Entity","Session"}));
return result;
}
| private boolean | commonToBothInterfaces(java.lang.String home, com.sun.enterprise.deployment.EjbDescriptor descriptor)This method is responsible for the logic of the test. It is called for both local and remote interfaces.
boolean findByPrimaryKeyMethodFound = false;
boolean oneFailed = false;
try {
// retrieve the home interface methods
Context context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
Class homeInterfaceClass = Class.forName(home, false, getVerifierContext().getClassLoader());
Method [] ejbFinderMethods = homeInterfaceClass.getDeclaredMethods();
for (int j = 0; j < ejbFinderMethods.length; j++) {
if (ejbFinderMethods[j].getName().equals("findByPrimaryKey")) {
// Every entity enterprise Bean class must define the
// findByPrimaryKey method.
findByPrimaryKeyMethodFound = true;
// report for this particular findByPrimaryKey(...)
result.addGoodDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".debug1",
"For Home interface [ {0} ] Finder Method [ {1} ]",
new Object[] {homeInterfaceClass.getName(),ejbFinderMethods[j].getName()}));
result.addGoodDetails(smh.getLocalString
(getClass().getName() + ".passed",
"A findByPrimaryKey method was found."));
return oneFailed;
}
}
if (!findByPrimaryKeyMethodFound) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString
("tests.componentNameConstructor",
"For [ {0} ]",
new Object[] {compName.toString()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".debug3",
"For Home interface [ {0} ] ",
new Object[] {homeInterfaceClass.getName()}));
result.addErrorDetails(smh.getLocalString
(getClass().getName() + ".failed",
"Error: No findByPrimaryKey method was found in home interface class [ {0} ].",
new Object[] {homeInterfaceClass.getName()}));
}
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.",
new Object[] {home}));
oneFailed = true;
return oneFailed;
}
|
|