Search in sources :

Example 96 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class EjbEnvEntryValue method check.

/**
 *If the Bean Provider provides a value for an environment entry using the
 * env-entry-value element, the value can be changed later by the Application
 * Assembler or Deployer. The value must be a string that is valid for the
 * constructor of the specified type that takes a single String parameter.
 *
 * @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.getEnvironmentProperties().isEmpty()) {
        // constructor of the specified type that takes a single String parameter
        for (Iterator itr = descriptor.getEnvironmentProperties().iterator(); itr.hasNext(); ) {
            EnvironmentProperty nextEnvironmentProperty = (EnvironmentProperty) itr.next();
            if ((nextEnvironmentProperty.getValue() != null) && (nextEnvironmentProperty.getValue().length() > 0)) {
                if (!validEnvType(nextEnvironmentProperty)) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Environment entry name [ {0} ] does not have" + " valid value [ {1} ] for constructor of the specified type" + " [ {2} ] that takes a single String parameter within bean [ {3} ]", new Object[] { nextEnvironmentProperty.getName(), nextEnvironmentProperty.getValue(), nextEnvironmentProperty.getType(), descriptor.getName() }));
                }
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Environment entry name has valid value"));
    }
    return result;
}
Also used : EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 97 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class EjbClientJarManifestClassPath method check.

/**
 * The EJB specification does not specify whether the ejb-jar file should
 * include the classes that are in the ejb-client JAR by copy or by reference.
 * If the by-copy approach is used, the producer simply includes all the class
 * files in the ejb-client JAR file also in the ejb-jar file. If the
 * by-reference approach is used, the ejb-jar file producer does not duplicate
 * the content of the ejb-client JAR file in the ejb-jar file, but instead uses
 * a Manifest Class-Path entry in the ejb-jar file to specify that the ejb-jar
 * file depends on the ejb-client JAR at runtime.
 *
 * @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();
    // Stub test class placeholder
    // fill in guts/logic - pass/fail accordingly in future
    // once DOL returns proper value
    result.setStatus(Result.NOT_IMPLEMENTED);
    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
    result.addNaDetails(smh.getLocalString(getClass().getName() + ".notImplemented", "No static testing done - yet."));
    return result;
}
Also used : ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 98 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class EjbEnvEntryValueType method check.

/**
 * The environment entry value type must be one of the following Java types:
 * String, Integer, Boolean, Double, Byte, Short, Long, and Float.
 *
 * @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.getEnvironmentProperties().isEmpty()) {
        // String, Integer, Boolean, Double, Byte, Short, Long, and Float.
        for (Iterator itr = descriptor.getEnvironmentProperties().iterator(); itr.hasNext(); ) {
            EnvironmentProperty nextEnvironmentProperty = (EnvironmentProperty) itr.next();
            String envType = nextEnvironmentProperty.getType();
            if (!((envType.equals("java.lang.String")) || (envType.equals("java.lang.Integer")) || (envType.equals("java.lang.Boolean")) || (envType.equals("java.lang.Double")) || (envType.equals("java.lang.Byte")) || (envType.equals("java.lang.Short")) || (envType.equals("java.lang.Long")) || (envType.equals("java.lang.Character")) || (envType.equals("java.lang.Float")))) {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Environment entry value [ {0} ] does not have" + " valid value type [ {1} ] within bean [ {2} ]", new Object[] { nextEnvironmentProperty.getName(), envType, descriptor.getName() }));
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Environment entry value has valid value type"));
    }
    return result;
}
Also used : EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 99 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class EjbNameUnique method check.

/**
 * The ejb-name must be unique amoung the names of the enterprise beans within
 * the same ejb-jar file.
 *
 * @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();
    String ejbName = descriptor.getName();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // initialize needed by ejb loop
    int found = 0;
    // no duplicates.
    for (Iterator itr = descriptor.getEjbBundleDescriptor().getEjbs().iterator(); itr.hasNext(); ) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
        if (ejbDescriptor.getName().equals(ejbName)) {
            found++;
            if (found > 1) {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] has found [ {1} ] duplicate ejb name(s) within the same jar.", new Object[] { ejbName, new Integer((found - 1)) }));
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid: [ {0} ] was found once within jar, ejb-name is unique.", new Object[] { ejbName }));
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 100 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class LocalInterfaceExposed method check.

/**
 * Bean interface type test.
 * The bean provider must provide either Local or Remote or Both 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 EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    EjbBundleDescriptorImpl bundle = descriptor.getEjbBundleDescriptor();
    Iterator<EjbDescriptor> iterator = (bundle.getEjbs()).iterator();
    Set<String> localInterfaces = new HashSet<String>();
    while (iterator.hasNext()) {
        EjbDescriptor entity = iterator.next();
        if (entity.getLocalClassName() != null)
            localInterfaces.add(entity.getLocalClassName());
        localInterfaces.addAll(entity.getLocalBusinessClassNames());
    }
    ClassLoader jcl = getVerifierContext().getClassLoader();
    try {
        Set<String> remoteInterfaces = new HashSet<String>();
        if (descriptor.getRemoteClassName() != null)
            remoteInterfaces.add(descriptor.getRemoteClassName());
        remoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
        for (String intf : remoteInterfaces) {
            Class c = Class.forName(intf, false, getVerifierContext().getClassLoader());
            Method[] methods = c.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                // check all the local interfaces in the ejb bundle
                for (Iterator itr = localInterfaces.iterator(); itr.hasNext(); ) {
                    String localIntf = (String) itr.next();
                    Class returnType = methods[i].getReturnType();
                    if ((getBaseComponentType(returnType).getName()).equals(localIntf) || (contains(methods[i].getParameterTypes(), localIntf))) {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error : Local Interface [ {0} ] has been " + "exposed in remote interface [ {1} ]", new Object[] { localIntf, c.getName() }));
                        return result;
                    }
                }
            }
        }
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Remote interface."));
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getRemoteClassName() }));
    }
    return result;
}
Also used : Method(java.lang.reflect.Method) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Iterator(java.util.Iterator) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl) HashSet(java.util.HashSet)

Aggregations

ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)237 Result (com.sun.enterprise.tools.verifier.Result)212 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)87 Method (java.lang.reflect.Method)70 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)66 Iterator (java.util.Iterator)40 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)28 Set (java.util.Set)19 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)16 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)14 Field (java.lang.reflect.Field)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)12 Enumeration (java.util.Enumeration)11 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)11 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)7 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)6 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)6 Vector (java.util.Vector)6