Search in sources :

Example 1 with ValidationException

use of javax.validation.ValidationException in project jersey by jersey.

the class ValidateOnExecutionHandler method processAnnotation.

/**
     * Process {@link ValidateOnExecution} annotation for given method on a class hierarchy.
     *
     * @param method method to be examined.
     * @param hierarchy class hierarchy to be examined.
     * @param checkOverrides flag whether a overriding/implementing methods should also be checked.
     * @return {@code true} if the method should be validated, {@code false} if not, {@code null} if the flag cannot be
     * determined (no annotation present).
     */
private Boolean processAnnotation(final Method method, final Deque<Class<?>> hierarchy, final boolean checkOverrides) {
    // Overridden methods.
    while (!hierarchy.isEmpty()) {
        final Class<?> overriddenClass = hierarchy.removeFirst();
        final Method overriddenMethod = AccessController.doPrivileged(ReflectionHelper.findMethodOnClassPA(overriddenClass, method));
        if (overriddenMethod != null) {
            // Method.
            Set<ExecutableType> executableTypes = getExecutableTypes(overriddenMethod);
            if (!executableTypes.isEmpty()) {
                // If an overriding/implementing method is annotated with @ValidateOnExecution, throw an exception.
                if (checkOverrides && processAnnotation(method, hierarchy, false) != null) {
                    final String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
                    throw new ValidationException(LocalizationMessages.OVERRIDE_CHECK_ERROR(methodName));
                }
                return validateMethod(overriddenMethod, true, executableTypes);
            }
            // Class.
            executableTypes = getExecutableTypes(overriddenClass);
            if (!executableTypes.isEmpty() && // ExecutableType#IMPLICIT on class itself does nothing.
            !(executableTypes.size() == 1 && executableTypes.contains(ExecutableType.IMPLICIT))) {
                return validateMethod(overriddenMethod, false, executableTypes);
            }
        }
    }
    return null;
}
Also used : ExecutableType(javax.validation.executable.ExecutableType) ValidationException(javax.validation.ValidationException) Method(java.lang.reflect.Method)

Example 2 with ValidationException

use of javax.validation.ValidationException in project apex-core by apache.

the class OiOStreamTest method validateNegativeOiOiOExtendeddiamond.

@Test
public void validateNegativeOiOiOExtendeddiamond() {
    logger.info("Checking the logic for sanity checking of OiO");
    LogicalPlan plan = new LogicalPlan();
    ThreadIdValidatingInputOperator inputOperator = plan.addOperator("inputOperator", new ThreadIdValidatingInputOperator());
    ThreadIdValidatingGenericIntermediateOperator intermediateOperator1 = plan.addOperator("intermediateOperator1", new ThreadIdValidatingGenericIntermediateOperator());
    ThreadIdValidatingGenericIntermediateOperator intermediateOperator2 = plan.addOperator("intermediateOperator2", new ThreadIdValidatingGenericIntermediateOperator());
    ThreadIdValidatingGenericIntermediateOperator intermediateOperator3 = plan.addOperator("intermediateOperator3", new ThreadIdValidatingGenericIntermediateOperator());
    ThreadIdValidatingGenericIntermediateOperator intermediateOperator4 = plan.addOperator("intermediateOperator4", new ThreadIdValidatingGenericIntermediateOperator());
    ThreadIdValidatingGenericOperatorWithTwoInputPorts outputOperator = plan.addOperator("outputOperator", new ThreadIdValidatingGenericOperatorWithTwoInputPorts());
    plan.addStream("OiOin", inputOperator.output, intermediateOperator1.input, intermediateOperator3.input).setLocality(Locality.THREAD_LOCAL);
    plan.addStream("OiOIntermediate1", intermediateOperator1.output, intermediateOperator2.input).setLocality(Locality.THREAD_LOCAL);
    plan.addStream("nonOiOIntermediate2", intermediateOperator3.output, intermediateOperator4.input).setLocality(null);
    plan.addStream("OiOout1", intermediateOperator2.output, outputOperator.input).setLocality(Locality.THREAD_LOCAL);
    plan.addStream("OiOout2", intermediateOperator4.output, outputOperator.input2).setLocality(Locality.THREAD_LOCAL);
    try {
        plan.validate();
        Assert.fail("OiOiO extended diamond validation");
    } catch (ConstraintViolationException ex) {
        Assert.assertTrue("OiOiO extended diamond validation", true);
    } catch (ValidationException ex) {
        Assert.assertTrue("OiOiO extended diamond validation", true);
    }
}
Also used : ValidationException(javax.validation.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) Test(org.junit.Test)

Example 3 with ValidationException

use of javax.validation.ValidationException in project apex-core by apache.

the class OiOStreamTest method validateNegativeOiO.

@Test
public void validateNegativeOiO() {
    LogicalPlan plan = new LogicalPlan();
    RecoverableInputOperator inputOp1 = plan.addOperator("InputOperator1", new RecoverableInputOperator());
    RecoverableInputOperator inputOp2 = plan.addOperator("InputOperator2", new RecoverableInputOperator());
    GenericOperator genOp = plan.addOperator("GenericOperator", new GenericOperator());
    StreamMeta oio1 = plan.addStream("OiO1", inputOp1.output, genOp.ip1).setLocality(Locality.THREAD_LOCAL);
    StreamMeta oio2 = plan.addStream("OiO2", inputOp2.output, genOp.ip2).setLocality(Locality.THREAD_LOCAL);
    try {
        plan.validate();
        Assert.fail("OIO Both InputPorts");
    } catch (ConstraintViolationException ex) {
        Assert.assertTrue("OiO validation passed", true);
    } catch (ValidationException ex) {
        Assert.assertTrue("OiO validation passed", true);
    }
    oio1.setLocality(null);
    try {
        plan.validate();
        Assert.fail("OIO First InputPort");
    } catch (ConstraintViolationException ex) {
        Assert.assertTrue("OiO validation passed", true);
    } catch (ValidationException ex) {
        Assert.assertTrue("OiO validation passed", true);
    }
    oio1.setLocality(Locality.THREAD_LOCAL);
    oio2.setLocality(null);
    try {
        plan.validate();
        Assert.fail("OIO Second InputPort");
    } catch (ConstraintViolationException ex) {
        Assert.assertTrue("OiO validation passed", true);
    } catch (ValidationException ex) {
        Assert.assertTrue("OiO validation passed", true);
    }
}
Also used : RecoverableInputOperator(com.datatorrent.stram.engine.RecoverableInputOperator) StreamMeta(com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta) ValidationException(javax.validation.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) GenericOperator(com.datatorrent.stram.engine.GenericNodeTest.GenericOperator) Test(org.junit.Test)

Example 4 with ValidationException

use of javax.validation.ValidationException in project apex-core by apache.

the class OiOStreamTest method validateNegativeOiOiOdiamond.

@Test
public void validateNegativeOiOiOdiamond() {
    logger.info("Checking the logic for sanity checking of OiO");
    LogicalPlan plan = new LogicalPlan();
    ThreadIdValidatingInputOperator inputOperator = plan.addOperator("inputOperator", new ThreadIdValidatingInputOperator());
    ThreadIdValidatingGenericIntermediateOperator intermediateOperator1 = plan.addOperator("intermediateOperator1", new ThreadIdValidatingGenericIntermediateOperator());
    ThreadIdValidatingGenericIntermediateOperator intermediateOperator2 = plan.addOperator("intermediateOperator2", new ThreadIdValidatingGenericIntermediateOperator());
    ThreadIdValidatingGenericOperatorWithTwoInputPorts outputOperator = plan.addOperator("outputOperator", new ThreadIdValidatingGenericOperatorWithTwoInputPorts());
    plan.addStream("OiOin", inputOperator.output, intermediateOperator1.input, intermediateOperator2.input).setLocality(Locality.THREAD_LOCAL);
    plan.addStream("OiOout1", intermediateOperator1.output, outputOperator.input).setLocality(Locality.THREAD_LOCAL);
    plan.addStream("nonOiOout2", intermediateOperator2.output, outputOperator.input2).setLocality(null);
    try {
        plan.validate();
        Assert.fail("OIOIO negative diamond");
    } catch (ConstraintViolationException ex) {
        Assert.assertTrue("OIOIO negative diamond", true);
    } catch (ValidationException ex) {
        Assert.assertTrue("OIOIO negative diamond", true);
    }
}
Also used : ValidationException(javax.validation.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) Test(org.junit.Test)

Example 5 with ValidationException

use of javax.validation.ValidationException in project apex-core by apache.

the class LogicalPlan method checkAttributeValueSerializable.

private void checkAttributeValueSerializable(AttributeMap attributes, String context) {
    StringBuilder sb = new StringBuilder();
    String delim = "";
    // Check all attributes got operator are serializable
    for (Entry<Attribute<?>, Object> entry : attributes.entrySet()) {
        if (entry.getValue() != null && !(entry.getValue() instanceof Serializable)) {
            sb.append(delim).append(entry.getKey().getSimpleName());
            delim = ", ";
        }
    }
    if (sb.length() > 0) {
        throw new ValidationException("Attribute value(s) for " + sb.toString() + " in " + context + " are not serializable");
    }
}
Also used : Serializable(java.io.Serializable) ValidationException(javax.validation.ValidationException) ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) Attribute(com.datatorrent.api.Attribute)

Aggregations

ValidationException (javax.validation.ValidationException)34 Test (org.junit.Test)17 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)10 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)8 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)6 StreamMeta (com.datatorrent.stram.plan.logical.LogicalPlan.StreamMeta)5 HashMap (java.util.HashMap)5 ConstraintViolationException (javax.validation.ConstraintViolationException)5 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 IOException (java.io.IOException)3 Properties (java.util.Properties)3 ValidatorFactory (javax.validation.ValidatorFactory)3 AffinityRule (com.datatorrent.api.AffinityRule)2 AffinityRulesSet (com.datatorrent.api.AffinityRulesSet)2 Attribute (com.datatorrent.api.Attribute)2 InputOperator (com.datatorrent.api.InputOperator)2 Operator (com.datatorrent.api.Operator)2