Package com.volantis.shared.metadata.type

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


        assertEquals(new Integer(expectedErrors.size()), new Integer(errors.size()));

        // iterate over the actual errors and compare to expected errors
        final Iterator iter = errors.iterator();
        while (iter.hasNext()) {
            VerificationError error = (VerificationError) iter.next();
            boolean finished = false;
            for (int i=0; i<expectedErrors.size() && !finished; i++) {
                ExpectedError expected = (ExpectedError) expectedErrors.get(i);
                if (expected.getErrorType().equals(error.getType())
                    && expected.getInvalidValue().equals(error.getInvalidValue())) {
                    if ( (null != expected.getConstraint() && expected.getConstraint().equals(error.getConstraint()))
                        || (null == expected.getConstraint() && null == error.getConstraint())) {
                        finished = true;
                        expectedErrors.remove(i);
                    }
                }
            }
View Full Code Here


        minimumLengthConstraint.setLimit(3);
        collectionType.setMinimumLengthConstraint(minimumLengthConstraint);
        errors = collectionType.verify(collectionValue);
        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(collectionValue, error.getInvalidValue());
        assertEquals(minimumLengthConstraint, error.getConstraint());
    }
View Full Code Here

        maximumLengthConstraint.setLimit(1);
        collectionType.setMaximumLengthConstraint(maximumLengthConstraint);
        errors = collectionType.verify(collectionValue);
        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(collectionValue, error.getInvalidValue());
        assertEquals(maximumLengthConstraint, error.getConstraint());
    }
View Full Code Here

                    final MetaDataValue child = (MetaDataValue) iter.next();
                    final String childPath = path + "[" + i + "]";
                    final Collection childErrors =
                        memberType.verify(child, childPath);
                    if (childErrors.size() > 0) {
                        errors.add(new VerificationError(
                            VerificationError.TYPE_CONSTRAINT_VIOLATION,
                            childPath, child, memberTypeConstraint,
                            "Member type constraint violation."));
                        errors.addAll(childErrors);
                    }
                }
            }
            // check minimum length constraint
            if (minimumLengthConstraint != null) {
                if (contents.size() < minimumLengthConstraint.getLimit()) {
                    errors.add(new VerificationError(
                        VerificationError.TYPE_CONSTRAINT_VIOLATION, path, value,
                        minimumLengthConstraint, "Minimum length constraint " +
                            "violation. Minimum length is " +
                            minimumLengthConstraint.getLimit() +
                            ", but this collection has only " + contents.size() +
                            " elements."));
                }
            }
            // check minimum length constraint
            if (maximumLengthConstraint != null) {
                if (contents.size() > maximumLengthConstraint.getLimit()) {
                    errors.add(new VerificationError(
                        VerificationError.TYPE_CONSTRAINT_VIOLATION, path, value,
                        maximumLengthConstraint, "Maximum length constraint " +
                            "violation. Maximum length is " +
                            maximumLengthConstraint.getLimit() +
                            ", but this collection has " + contents.size() +
View Full Code Here

            (MutableListValue) createCollectionValue(new String[]{"one", "one"});
        errors = listType.verify(listValue);
        assertEquals(1, errors.size());
        final MutableStringValue stringValue = VALUE_FACTORY.createStringValue();
        stringValue.setValue("one");
        final VerificationError error =
            (VerificationError) errors.iterator().next();
        assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
            error.getType());
        assertEquals("[2]", error.getLocation());
        assertEquals(stringValue, error.getInvalidValue());
        assertEquals(uniqueMemberConstraint, error.getConstraint());
    }
View Full Code Here

     * the value is correct
     */
    protected Collection verify(final MetaDataValue value, final String path) {
        final Collection errors = new LinkedHashSet();
        if (value == null) {
            errors.add(new VerificationError(VerificationError.TYPE_NULL_VALUE,
                path, value, null, "Value cannot be null."));
        } else {
            // check if the value has the expected type
            final Class expectedValueType = getExpectedValueType();
            if (!expectedValueType.isAssignableFrom(value.getClass())) {
                errors.add(new VerificationError(
                    VerificationError.TYPE_INVALID_IMPLEMENTATION, path, value, null,
                    "Invalid value type. Expected: " + expectedValueType +
                        ", received: " + value.getClass().getName()));
            }
        }
View Full Code Here

                final Set values = new HashSet();
                final Iterator iter = list.getContentsAsList().iterator();
                for (int i = 1; iter.hasNext(); i++) {
                    final MetaDataValue child = (MetaDataValue) iter.next();
                    if (!values.add(child)) {
                        errors.add(new VerificationError(
                            VerificationError.TYPE_CONSTRAINT_VIOLATION,
                            path + "[" + i + "]", child, uniqueMemberConstraint,
                            "Unique member constraint violation."));
                    }
                }
View Full Code Here

           
            final String choiceName = choiceValue.getChoiceName();
           
            if (choiceName == null) {
                if (!choiceDefinitions.isEmpty()) {
                    errors.add(new VerificationError(
                            VerificationError.CHOICE_NAME_NULL,
                            path,
                            value,
                            null,
                            "Null choice name."));
                }
            } else {
                final ChoiceDefinition choiceDefinition =
                    getChoiceDefinition(choiceName);
               
                if (choiceDefinition == null) {
                    // No choice definition for selected choice name is an error.
                    errors.add(new VerificationError(
                            VerificationError.TYPE_UNEXPECTED_VALUE,
                            path,
                            value,
                            null,
                            "Choice '" + choiceName + "' is not expected here."));
View Full Code Here

        final Collection errors = super.verify(value, path);
        if (value instanceof StringValue) {
            final StringValue stringValue = (StringValue) value;
            final String string = stringValue.getValueAsString();
            if (string == null) {
                errors.add(new VerificationError(
                    VerificationError.TYPE_NULL_VALUE, path, value, null,
                    "Value cannot be null."));
            } else {
                // check minimum length constraint
                if (minimumLengthConstraint != null) {
                    final int minimumLength = minimumLengthConstraint.getLimit();
                    if (minimumLength > string.length()) {
                        errors.add(new VerificationError(
                            VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
                            value, minimumLengthConstraint, "Minimum length " +
                                "constraint violation. Minimum length is " +
                                minimumLength + ", but the length of the " +
                                "string is " + string.length() + "."));
                    }
                }
                // check minimum length constraint
                if (maximumLengthConstraint != null) {
                    final int maximumLength = maximumLengthConstraint.getLimit();
                    if (string.length() > maximumLength) {
                        errors.add(new VerificationError(
                            VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
                            value, maximumLengthConstraint, "Maximum length " +
                                "constraint violation. Maximum length is " +
                                maximumLength + ", but the length of the " +
                                "string is " + string.length() + "."));
View Full Code Here

            if (number != null) {
                // check number sub-type constraint
                if (numberSubTypeConstraint != null) {
                    if (!numberSubTypeConstraint.getNumberSubType().equals(
                            number.getClass())) {
                        errors.add(new VerificationError(
                            VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
                            value, numberSubTypeConstraint,
                            "Invalid number type. Expected: " +
                                numberSubTypeConstraint.getNumberSubType() +
                                ", found: " + number.getClass()));
                    }
                }
                // check minimum value constraint
                if (minimumValueConstraint != null) {
                    final Number minimum =
                        minimumValueConstraint.getLimitAsNumber();
                    final boolean inclusive =
                        minimumValueConstraint.isInclusive();
                    final int compareResult =
                        NUMBER_COMPARATOR.compare(number, minimum);
                    if (compareResult < 0 || compareResult == 0 && !inclusive) {
                        errors.add(new VerificationError(
                            VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
                            value, minimumValueConstraint,
                            "Minimum value constraint violated. " +
                                "Minimum value: " + minimum +
                                (inclusive? " (inclusive)": " (exclusive)") +
                                ", received: " + number));
                    }
                }
                // check maximum value constraint
                if (maximumValueConstraint != null) {
                    final Number maximum =
                        maximumValueConstraint.getLimitAsNumber();
                    final boolean inclusive =
                        maximumValueConstraint.isInclusive();
                    final int compareResult =
                        NUMBER_COMPARATOR.compare(maximum, number);
                    if (compareResult < 0 || compareResult == 0 && !inclusive) {
                        errors.add(new VerificationError(
                            VerificationError.TYPE_CONSTRAINT_VIOLATION, path,
                            value, maximumValueConstraint,
                            "Maximum value constraint violated. " +
                                "Maximum value: " + maximum +
                                (inclusive? " (inclusive)": " (exclusive)") +
                                ", received: " + number));
                    }
                }
            } else {
                errors.add(new VerificationError(
                    VerificationError.TYPE_NULL_VALUE, path, value, null,
                    "Value cannot be null."));
            }
        }
        return errors;
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.