Package com.volantis.shared.metadata.type.mutable

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


        return new ImmutableQuantityTypeImpl();
    }

    // Javadoc inherited.
    public void testEqualsAndHashcodeImplementedCorrectly() {
        MutableQuantityType fieldDefinition1 = createMutableUnitTypeForTestingEquals();
        MutableQuantityType fieldDefinition2 = createMutableUnitTypeForTestingEquals();

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

        // change the magnitude
        fieldDefinition2.setMagnitudeType(null);
        MetaDataTestCaseHelper.assertNotEquals(fieldDefinition1, fieldDefinition2);
        MetaDataTestCaseHelper.ensureHashcodesNotEqual(fieldDefinition1, fieldDefinition2);

        // now reset
        fieldDefinition2 = createMutableUnitTypeForTestingEquals();

        // change the type
        fieldDefinition2.setUnitType(null);
        MetaDataTestCaseHelper.assertNotEquals(fieldDefinition1, fieldDefinition2);
        MetaDataTestCaseHelper.ensureHashcodesNotEqual(fieldDefinition1, fieldDefinition2);
    }
View Full Code Here


     * Helper method which creates a <code>MutableUnitType</code> which can be used for
     * testing.
     * @return a mutable unit type.
     */
    private MutableQuantityType createMutableUnitTypeForTestingEquals() {
        MutableQuantityType mutableQuantityType = new MutableQuantityTypeImpl();

        MetaDataTypeFactory factory = MetaDataFactory.getDefaultInstance().
                getTypeFactory();

        NumberType numberType = factory.createNumberType();
        mutableQuantityType.setMagnitudeType( numberType );

        UnitType unitType = factory.createUnitType();
        mutableQuantityType.setUnitType(unitType);

        return mutableQuantityType;
    }
View Full Code Here

    }


    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();
        final List enumeratedValues =
            enumeratedConstraint.getMutableEnumeratedValues();
        enumeratedValues.add(QuantityUnits.MILLIMETERS);
        enumeratedValues.add(QuantityUnits.CENTIMETERS);
        enumeratedValues.add(QuantityUnits.INCHES);
        unitType.setEnumeratedConstraint(enumeratedConstraint);
        quantityType.setUnitType(unitType);

        // normal case
        MutableQuantityValue quantityValue = VALUE_FACTORY.createQuantityValue();
        final MutableNumberValue magnitudeValue =
            VALUE_FACTORY.createNumberValue();
        magnitudeValue.setValue(new Integer(123));
        quantityValue.setMagnitudeValue(magnitudeValue);
        quantityValue.setUnitValue(QuantityUnits.CENTIMETERS);
        Collection errors = quantityType.verify(quantityValue);
        assertEquals(0, errors.size());

        // 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());
View Full Code Here

TOP

Related Classes of com.volantis.shared.metadata.type.mutable.MutableQuantityType

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.