Examples of MutableQuantityValue


Examples of com.volantis.shared.metadata.value.mutable.MutableQuantityValue

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

Examples of com.volantis.shared.metadata.value.mutable.MutableQuantityValue

     * @throws Exception if an error occurs
     */
    public void testWhenCharacteristicIsQuantity() throws Exception {
        // add a policy/policy value pair to the request
        String charateristic = "quantity";
        MutableQuantityValue value =
                META_DATA_VALUE_FACTORY.createQuantityValue();

        ImmutableMetaDataValue quantityVal = (ImmutableMetaDataValue)
                                              value.createImmutable();

        serviceDefMock.expects.getCharacteristic(charateristic).returns(quantityVal);

        // invoke the function
        Expression expression = parser.parse(getFunctionQName() +
View Full Code Here

Examples of com.volantis.shared.metadata.value.mutable.MutableQuantityValue

    }

     // Javadoc inherited.
    public void testEqualsAndHashcodeImplementedCorrectly() {

        MutableQuantityValue quantityValue1 = createMutableUnitTypeForTestingEquals();
        MutableQuantityValue quantityValue2 = createMutableUnitTypeForTestingEquals();

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

        // change the magnitude
        final MutableNumberValueImpl magnitudeValue =
            new MutableNumberValueImpl();
        magnitudeValue.setValue(new Integer(123));
        quantityValue2.setMagnitudeValue(magnitudeValue);
        MetaDataTestCaseHelper.assertNotEquals(quantityValue1, quantityValue2);
        MetaDataTestCaseHelper.ensureHashcodesNotEqual(quantityValue1, quantityValue2);

        // now reset
        quantityValue2 = createMutableUnitTypeForTestingEquals();

        // change the type
        magnitudeValue.setValue(new Long(123));
        quantityValue2.setMagnitudeValue(magnitudeValue);
        MetaDataTestCaseHelper.assertNotEquals(quantityValue1, quantityValue2);
        MetaDataTestCaseHelper.ensureHashcodesNotEqual(quantityValue1, quantityValue2);

    }
View Full Code Here

Examples of com.volantis.shared.metadata.value.mutable.MutableQuantityValue

    /**
     * This tests the getMagnitudeValueAsNumber method.
     */
    public void testGetMagnitudeValueAsNumber() {
        MutableQuantityValue mutableQuantityValue = new MutableQuantityValueImpl();

        NumberValueImpl numberValue = new MutableNumberValueImpl();
        numberValue.setValue(new Double(10));
        mutableQuantityValue.setMagnitudeValue( numberValue );

        UnitValue unitValue = QuantityUnits.CENTIMETERS;
        mutableQuantityValue.setUnitValue(unitValue);

        Number expectedResultInMillimeters = new Double(100);
        Number result =
                mutableQuantityValue.getMagnitudeAsNumber(QuantityUnits.MILLIMETERS);

        assertEquals("CM to MM Conversion failure", expectedResultInMillimeters, result);

        // todo add tests for other conversions
    }
View Full Code Here

Examples of com.volantis.shared.metadata.value.mutable.MutableQuantityValue

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

        NumberValueImpl numberValue = new MutableNumberValueImpl();
        mutableQuantityValue.setMagnitudeValue( numberValue );

        UnitValueImpl unitValue = new ImmutableUnitValueImpl();
        mutableQuantityValue.setUnitValue(unitValue);

        return mutableQuantityValue;
    }
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.