Package com.volantis.xml.expression

Examples of com.volantis.xml.expression.Function


   
    /**
     * Tests if 0 is returned for empty sequence
     */
    public void testEmptySequence() throws ExpressionException {
        final Function function = new CountFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createSequence(new Item[]{})});
        assertTrue(result instanceof IntValue);
        assertEquals(0, ((IntValue) result).asJavaInt());
    }
View Full Code Here


   
    /**
     * Tests if 1 is returned for integer
     */
    public void testIntValue() throws ExpressionException {
        final Function function = new CountFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createIntValue(3)});
        assertTrue(result instanceof IntValue);
        assertEquals(1, ((IntValue) result).asJavaInt());
    }
View Full Code Here

   
    /**
     * Tests if 1 is returned for string
     */
    public void testStringValue() throws ExpressionException {
        final Function function = new CountFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createStringValue("abc")});
        assertTrue(result instanceof IntValue);
        assertEquals(1, ((IntValue) result).asJavaInt());
    }
View Full Code Here

   
    /**
     * Tests if function works correctly for sequences
     */
    public void testSequence() throws ExpressionException {
        final Function function = new CountFunction();
        Value result = function.invoke(expressionContextMock, new Value[]{
                factory.createSequence(new Item[]{
                        factory.createBooleanValue(true),
                        factory.createStringValue("abc"),
                        DoubleValue.NOT_A_NUMBER,
                        factory.createDurationValue(true, 2, 2, 3, 1, 0, 6, 100)
View Full Code Here

    /**
     * Tests if {@link ExpressionException} is thrown when function is called without
     * arguments
     */
    public void testNoArguments() {
        final Function function = new NormalizeSpaceFunction();
        try {
            function.invoke(expressionContextMock, new Value[]{});
            fail("Exception wasn't thrown when normalize-space was invoked with 0 arguments");
        } catch (ExpressionException e) {
            //do nothing, expected situation
        }
    }
View Full Code Here

    public void registerFunctions(ExpressionContext context) {
        // Register the functions.
        for (Iterator i = functions.entrySet().iterator(); i.hasNext();) {
            Map.Entry entry = (Map.Entry) i.next();
            ImmutableExpandedName name = (ImmutableExpandedName) entry.getKey();
            Function function = (Function) entry.getValue();
            context.registerFunction(name, function);
        }

        // Register the default prefixes.
        NamespacePrefixTracker tracker = context.getNamespacePrefixTracker();
View Full Code Here

    /**
     * Tests if {@link ExpressionException} is thrown when function is called
     * with two arguments
     */
    public void testTwoArguments() {
        final Function function = new NormalizeSpaceFunction();
        try {
            function.invoke(expressionContextMock, new Value[]{
                    factory.createStringValue("arg1"),
                    factory.createStringValue("arg2")});
            fail("Exception wasn't thrown when normalize-space was invoked with 2 arguments");
        } catch (ExpressionException e) {
            //do nothing, expected situation
View Full Code Here

     * Test for xs:months-from-duration() function.
     *
     * @throws Exception thrown by tested function
     */
    public void testMonthsFromDuration() throws Exception {
        final Function function = new MonthsFromDurationFunction();
        DurationValue duration;
        Value result;

        duration =
                factory.createDurationValue(true, 20, 15, 0, 0, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(3));

        duration =
                factory.createDurationValue(false, 20, 18, 0, 0, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(-6));

        duration =
                factory.createDurationValue(false, 0, 0, 2, 15, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(0));
    }
View Full Code Here

     * Test for xs:days-from-duration() function.
     *
     * @throws Exception thrown by tested function
     */
    public void testDaysFromDuration() throws Exception {
        final Function function = new DaysFromDurationFunction();
        DurationValue duration;
        Value result;

        duration =
                factory.createDurationValue(true, 0, 0, 3, 10, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(3));

        duration =
                factory.createDurationValue(true, 0, 0, 3, 55, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(5));

        duration =
                factory.createDurationValue(false, 3, 5, 0, 0, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(0));
    }
View Full Code Here

     * Test for xs:hours-from-duration() function.
     *
     * @throws Exception thrown by tested function
     */
    public void testHoursFromDuration() throws Exception {
        final Function function = new HoursFromDurationFunction();
        DurationValue duration;
        Value result;

        duration =
                factory.createDurationValue(true, 0, 0, 3, 10, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(10));

        duration =
                factory.createDurationValue(true, 0, 0, 3, 12, 32, 12, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(12));

        duration =
                factory.createDurationValue(true, 0, 0, 0, 123, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(3));

        duration =
                factory.createDurationValue(false, 0, 0, 3, 10, 0, 0, 0);
        result = function.invoke(
                expressionContextMock,
                new Value[] { duration });
        assertEquals(result, factory.createIntValue(-10));
    }
View Full Code Here

TOP

Related Classes of com.volantis.xml.expression.Function

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.