Examples of MutableNumberType


Examples of com.volantis.shared.metadata.type.mutable.MutableNumberType

        return new ImmutableNumberTypeImpl();
    }

    // Javadoc inherited.
    public void testEqualsAndHashcodeImplementedCorrectly() {
        MutableNumberType numberType1 = createNumberTypeForTestingEquals();
        MutableNumberType numberType2 = createNumberTypeForTestingEquals();

        // test that both the values are equal and they have the same hash codes
        assertEquals("Object 1 should be equal to object 2", numberType1, numberType2);
        MetaDataTestCaseHelper.ensureHashcodesEqual(numberType1, numberType2);

        // change a property in one of the objects and ensure they are not equal and
        // ideally have different hashcodes
        // todo add test for enumerated constraint - should actually go into superclass

        numberType2.setNumberSubTypeConstraint(null);
        assertNotEquals(numberType1, numberType2);

        MetaDataTestCaseHelper.ensureHashcodesNotEqual(numberType1, numberType2);

        // Reset the object
        numberType2 = createNumberTypeForTestingEquals();

        // Now test changing the number sub type constraint make the objects and their
        // hashcodes not equal
        NumberSubTypeConstraint numberSubTypeConstraint = MetaDataFactory.
                getDefaultInstance().
                getTypeFactory().getConstraintFactory().
                getNumberSubTypeConstraint(Integer.class);

        numberType2.setNumberSubTypeConstraint(numberSubTypeConstraint);

        assertNotEquals(numberType1, numberType2);
        MetaDataTestCaseHelper.ensureHashcodesNotEqual(numberType1, numberType2);

        // Reset the object
        numberType2 = createNumberTypeForTestingEquals();

        // Now test changing the minimum value constraint makes the objects and their
        // hashcodes not equal
        numberType2.setMinimumValueConstraint(null);

        assertNotEquals(numberType1, numberType2);
        MetaDataTestCaseHelper.ensureHashcodesNotEqual(numberType1, numberType2);

        // Reset the object
        numberType2 = createNumberTypeForTestingEquals();

        // Now test changing the maximum value constraint makes the objects and their
        // hashcodes not equal
        numberType2.setMaximumValueConstraint(null);

        assertNotEquals(numberType1, numberType2);
        MetaDataTestCaseHelper.ensureHashcodesNotEqual(numberType1, numberType2);
    }
View Full Code Here

Examples of com.volantis.shared.metadata.type.mutable.MutableNumberType

        return mutableNumberType;
    }

    public void testVerify() {
        final MutableNumberType numberType = TYPE_FACTORY.createNumberType();

        // normal case
        MutableNumberValue numberValue = VALUE_FACTORY.createNumberValue();
        numberValue.setValue(new Integer(5));
        Collection errors = numberType.verify(numberValue);
        assertEquals(0, errors.size());

        // 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

Examples of com.volantis.shared.metadata.type.mutable.MutableNumberType

    public void testVerify() {
        // create the test type
        final MutableQuantityType quantityType =
            TYPE_FACTORY.createQuantityType();

        final MutableNumberType numberType = TYPE_FACTORY.createNumberType();
        final ImmutableNumberSubTypeConstraint subTypeConstraint =
            CONSTRAINT_FACTORY.getNumberSubTypeConstraint(Integer.class);
        numberType.setNumberSubTypeConstraint(subTypeConstraint);
        quantityType.setMagnitudeType(numberType);

        final MutableUnitType unitType = TYPE_FACTORY.createUnitType();
        final MutableEnumeratedConstraint enumeratedConstraint =
            CONSTRAINT_FACTORY.createEnumeratedConstraint();
View Full Code Here

Examples of com.volantis.shared.metadata.type.mutable.MutableNumberType

            TYPE_FACTORY.createFieldDefinition("child");
        final MutableStructureType childStructureType =
            TYPE_FACTORY.createStructureType();

        fieldDefinition = TYPE_FACTORY.createFieldDefinition("baz");
        final MutableNumberType numberType =
            TYPE_FACTORY.createNumberType();
        fieldDefinition.setType(numberType);
        childStructureType.getMutableFields().add(fieldDefinition);

        childDefinition.setType(childStructureType);
View Full Code Here

Examples of com.volantis.shared.metadata.type.mutable.MutableNumberType

            TYPE_FACTORY.createFieldDefinition("child");
        final MutableStructureType childStructureType =
            TYPE_FACTORY.createStructureType();

        fieldDefinition = TYPE_FACTORY.createFieldDefinition("baz");
        final MutableNumberType numberType =
            TYPE_FACTORY.createNumberType();
        fieldDefinition.setType(numberType);
        childStructureType.getMutableFields().add(fieldDefinition);

        childDefinition.setType(childStructureType);
View Full Code Here

Examples of com.volantis.shared.metadata.type.mutable.MutableNumberType

        return maxInclusive;
    }

    // Javadoc inherited.
    public ImmutableMetaDataType createMetaDataType() {
        MutableNumberType numberType = TYPE_FACTORY.createNumberType();

        Integer min = new Integer(minInclusive);
        Integer max = new Integer(maxInclusive);

        MutableMaximumValueConstraint maxConstraint
                = CONSTRAINT_FACTORY.createMaximumValueConstraint();
        maxConstraint.setLimit(max);
        maxConstraint.setInclusive(true);

        MutableMinimumValueConstraint minConstraint
                = CONSTRAINT_FACTORY.createMinimumValueConstraint();
        minConstraint.setLimit(min);
        minConstraint.setInclusive(true);

        numberType.setMinimumValueConstraint(minConstraint);
        numberType.setMaximumValueConstraint(maxConstraint);

        return (ImmutableMetaDataType) numberType.createImmutable();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.