Package com.volantis.shared.metadata.type

Examples of com.volantis.shared.metadata.type.VerificationError


        // null value
        numberValue = VALUE_FACTORY.createNumberValue();
        errors = numberType.verify(numberValue);
        assertEquals(1, errors.size());
        VerificationError error =
            (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_NULL_VALUE,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(numberValue, error.getInvalidValue());
        assertNull(error.getConstraint());

        // invalid type
        BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
        errors = numberType.verify(booleanValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(booleanValue, error.getInvalidValue());
        assertNull(error.getConstraint());

        // enumerated constraint
        final MutableEnumeratedConstraint enumeratedConstraint =
            CONSTRAINT_FACTORY.createEnumeratedConstraint();
        final List enumeratedValues =
            enumeratedConstraint.getMutableEnumeratedValues();
        final MutableNumberValue constraintValue =
            VALUE_FACTORY.createNumberValue();
        constraintValue.setValue(new Integer(6));
        enumeratedValues.add(constraintValue.createImmutable());
        constraintValue.setValue(new Integer(7));
        enumeratedValues.add(constraintValue.createImmutable());
        numberType.setEnumeratedConstraint(enumeratedConstraint);
        // check constraint with right value
        numberValue.setValue(new Integer(6));
        errors = numberType.verify(numberValue);
        assertEquals(0, errors.size());
        // check constraint violation
        numberValue.setValue(new Integer(8));
        errors = numberType.verify(numberValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(numberValue, error.getInvalidValue());
        assertEquals(enumeratedConstraint, error.getConstraint());
        numberType.setEnumeratedConstraint(null);

        // sub type constraint
        final ImmutableNumberSubTypeConstraint subTypeConstraint =
            CONSTRAINT_FACTORY.getNumberSubTypeConstraint(Integer.class);
        numberType.setNumberSubTypeConstraint(subTypeConstraint);
        // check constraint with right value
        numberValue.setValue(new Integer(6));
        errors = numberType.verify(numberValue);
        assertEquals(0, errors.size());
        // check constraint violation
        numberValue.setValue(new Long(8));
        errors = numberType.verify(numberValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(numberValue, error.getInvalidValue());
        assertEquals(subTypeConstraint, error.getConstraint());
        numberType.setNumberSubTypeConstraint(null);

        // minimum value constraint with inclusive set to true
        final MutableMinimumValueConstraint minValueConstraint =
            CONSTRAINT_FACTORY.createMinimumValueConstraint();
        minValueConstraint.setLimit(new Integer(6));
        minValueConstraint.setInclusive(true);
        numberType.setMinimumValueConstraint(minValueConstraint);
        // check constraint with right value
        numberValue.setValue(new Integer(6));
        errors = numberType.verify(numberValue);
        assertEquals(0, errors.size());
        // check constraint violation
        numberValue.setValue(new Integer(5));
        errors = numberType.verify(numberValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(numberValue, error.getInvalidValue());
        assertEquals(minValueConstraint, error.getConstraint());
        numberType.setEnumeratedConstraint(null);

        // minimum value constraint with inclusive set to false
        minValueConstraint.setInclusive(false);
        numberType.setMinimumValueConstraint(minValueConstraint);
        // check constraint with right value
        numberValue.setValue(new Integer(7));
        errors = numberType.verify(numberValue);
        assertEquals(0, errors.size());
        // check constraint violation
        numberValue.setValue(new Integer(6));
        errors = numberType.verify(numberValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(numberValue, error.getInvalidValue());
        assertEquals(minValueConstraint, error.getConstraint());
        numberType.setMinimumValueConstraint(null);

        // maximum value constraint with inclusive set to true
        final MutableMaximumValueConstraint maxValueConstraint =
            CONSTRAINT_FACTORY.createMaximumValueConstraint();
        maxValueConstraint.setLimit(new Integer(6));
        maxValueConstraint.setInclusive(true);
        numberType.setMaximumValueConstraint(maxValueConstraint);
        // check constraint with right value
        numberValue.setValue(new Integer(6));
        errors = numberType.verify(numberValue);
        assertEquals(0, errors.size());
        // check constraint violation
        numberValue.setValue(new Integer(7));
        errors = numberType.verify(numberValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(numberValue, error.getInvalidValue());
        assertEquals(maxValueConstraint, error.getConstraint());
        numberType.setEnumeratedConstraint(null);

        // maximum value constraint with inclusive set to false
        maxValueConstraint.setInclusive(false);
        numberType.setMaximumValueConstraint(maxValueConstraint);
        // check constraint with right value
        numberValue.setValue(new Integer(5));
        errors = numberType.verify(numberValue);
        assertEquals(0, errors.size());
        // check constraint violation
        numberValue.setValue(new Integer(6));
        errors = numberType.verify(numberValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(numberValue, error.getInvalidValue());
        assertEquals(maxValueConstraint, error.getConstraint());
        numberType.setEnumeratedConstraint(null);
    }
View Full Code Here


        // invalid magnitude type
        magnitudeValue.setValue(new Byte((byte) 42));
        quantityValue.setMagnitudeValue(magnitudeValue);
        errors = quantityType.verify(quantityValue);
        assertEquals(1, errors.size());
        VerificationError error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("[@magnitude]", error.getLocation());
        assertEquals(magnitudeValue, error.getInvalidValue());
        assertEquals(subTypeConstraint, error.getConstraint());

        // invalid unit type
        magnitudeValue.setValue(new Integer(42));
        quantityValue.setMagnitudeValue(magnitudeValue);
        quantityValue.setUnitValue(QuantityUnits.PIXELS);
        errors = quantityType.verify(quantityValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("[@unit]", error.getLocation());
        assertEquals(QuantityUnits.PIXELS, error.getInvalidValue());
        assertEquals(enumeratedConstraint, error.getConstraint());

        // invalid type
        BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
        errors = quantityType.verify(booleanValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(booleanValue, error.getInvalidValue());
        assertNull(error.getConstraint());
    }
View Full Code Here

        // invalid type
        StringValue stringValue = VALUE_FACTORY.createStringValue();
        errors = booleanType.verify(stringValue);
        assertEquals(1, errors.size());
        VerificationError error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(stringValue, error.getInvalidValue());
        assertNull(error.getConstraint());

        // enumerated constraint
        final MutableEnumeratedConstraint enumeratedConstraint =
            CONSTRAINT_FACTORY.createEnumeratedConstraint();
        final List enumeratedValues =
            enumeratedConstraint.getMutableEnumeratedValues();
        final MutableBooleanValue constraintValue =
            VALUE_FACTORY.createBooleanValue();
        constraintValue.setValue(Boolean.FALSE);
        enumeratedValues.add(constraintValue);
        booleanType.setEnumeratedConstraint(enumeratedConstraint);
        // check constraint with right value
        booleanValue.setValue(Boolean.FALSE);
        errors = booleanType.verify(booleanValue);
        assertEquals(0, errors.size());
        // check constraint violation
        booleanValue.setValue(Boolean.TRUE);
        errors = booleanType.verify(booleanValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(booleanValue, error.getInvalidValue());
        assertEquals(enumeratedConstraint, error.getConstraint());
    }
View Full Code Here

        // invalid type
        final BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
        errors = structureType.verify(booleanValue);
        assertEquals(1, errors.size());
        VerificationError error =
            (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(booleanValue, error.getInvalidValue());
        assertNull(error.getConstraint());
    }
View Full Code Here

    private void checkError(final Collection errors,
                            final String path,
                            final VerificationError.ErrorType expectedType,
                            final MetaDataValue expectedInvalidValue,
                            final Constraint expectedConstraint) {
        VerificationError error = null;
        for (Iterator iter = errors.iterator();
                iter.hasNext() && error == null; ) {
            final VerificationError test = (VerificationError) iter.next();
            if (path.equals(test.getLocation())) {
                error = test;
            }
        }
        assertNotNull("Error with path '" + path + "' found.", error);
        assertEquals(expectedType, error.getType());
View Full Code Here

    private void checkError(final Collection errors,
                            final String path,
                            final VerificationError.ErrorType expectedType,
                            final MetaDataValue expectedInvalidValue,
                            final Constraint expectedConstraint) {
        VerificationError error = null;
        for (Iterator iter = errors.iterator();
                iter.hasNext() && error == null; ) {
            final VerificationError test = (VerificationError) iter.next();
            if (path.equals(test.getLocation())) {
                error = test;
            }
        }
        assertNotNull("Error with path '" + path + "' found.", error);
        assertEquals(expectedType, error.getType());
View Full Code Here

        // null value
        stringValue = VALUE_FACTORY.createStringValue();
        errors = stringType.verify(stringValue);
        assertEquals(1, errors.size());
        VerificationError error =
            (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_NULL_VALUE,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(stringValue, error.getInvalidValue());
        assertNull(error.getConstraint());

        // invalid type
        BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
        errors = stringType.verify(booleanValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(booleanValue, error.getInvalidValue());
        assertNull(error.getConstraint());

        // enumerated constraint
        final MutableEnumeratedConstraint enumeratedConstraint =
            CONSTRAINT_FACTORY.createEnumeratedConstraint();
        final List enumeratedValues =
            enumeratedConstraint.getMutableEnumeratedValues();
        final MutableStringValue constraintValue =
            VALUE_FACTORY.createStringValue();
        constraintValue.setValue("one");
        enumeratedValues.add(constraintValue.createImmutable());
        constraintValue.setValue("two");
        enumeratedValues.add(constraintValue.createImmutable());
        stringType.setEnumeratedConstraint(enumeratedConstraint);
        // check constraint with right value
        stringValue.setValue("two");
        errors = stringType.verify(stringValue);
        assertEquals(0, errors.size());
        // check constraint violation
        stringValue.setValue("three");
        errors = stringType.verify(stringValue);
        assertEquals(1, errors.size());
        error = (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(stringValue, error.getInvalidValue());
        assertEquals(enumeratedConstraint, error.getConstraint());
    }
View Full Code Here

        minimumLengthConstraint.setLimit(6);
        stringType.setMinimumLengthConstraint(minimumLengthConstraint);
        errors = stringType.verify(stringValue);
        assertEquals(1, errors.size());
        final Iterator iter = errors.iterator();
        VerificationError error = (VerificationError) iter.next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(stringValue, error.getInvalidValue());
        assertEquals(minimumLengthConstraint, error.getConstraint());
    }
View Full Code Here

        maximumLengthConstraint.setLimit(4);
        stringType.setMaximumLengthConstraint(maximumLengthConstraint);
        errors = stringType.verify(stringValue);
        assertEquals(1, errors.size());
        final Iterator iter = errors.iterator();
        VerificationError error = (VerificationError) iter.next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(stringValue, error.getInvalidValue());
        assertEquals(maximumLengthConstraint, error.getConstraint());
    }
View Full Code Here

        // invalid type
        BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
        errors = collectionType.verify(booleanValue);
        assertEquals(1, errors.size());
        VerificationError error =
            (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
            error.getType());
        assertEquals("", error.getLocation());
        assertEquals(booleanValue, error.getInvalidValue());
        assertNull(error.getConstraint());
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.metadata.type.VerificationError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.