Package com.volantis.xml.expression

Examples of com.volantis.xml.expression.Function


     * Test for xs:minutes-from-duration() function.
     *
     * @throws Exception thrown by tested function
     */
    public void testMinutesFromDuration() throws Exception {
        final Function function = new MinutesFromDurationFunction();
        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(0));

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


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

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

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

                // do nothing
                return null;
            }
           
        };
        final Function stringFunction = new StringFunction();
        try {
            stringFunction.invoke(expressionContextMock, new Value[0]);
            fail("Exception wasn't thrown when empty arguments passed" +
                    " to function");
        } catch (Exception e) {
            // ignore it, expected situation
        }
        for (int i = 0; i < 10; i++) {
            final Value result = stringFunction.invoke(expressionContextMock,
                    new Value[] {testValue});
            assertTrue("Incorrect or null Value from StringFunction",
                    result != null && result instanceof StringValue);
            assertEquals(((StringValue) result).asJavaString(),
                    String.valueOf(i));
View Full Code Here

    public void testEmptySequence() throws Exception {

        // Create an empty sequence.
        Sequence sequence = Sequence.EMPTY;

        Function function = new ExistsFunction();
        Value result =
                function.invoke(expressionContextMock, new Value[] {sequence});
        assertSame(result, BooleanValue.FALSE);
    }
View Full Code Here

        // Create a non empty sequence.
        Sequence sequence = factory.createSequence(new Item[] {
            BooleanValue.TRUE
        });

        Function function = new ExistsFunction();
        Value result =
                function.invoke(expressionContextMock, new Value[] {sequence});
        assertSame(result, BooleanValue.TRUE);
    }
View Full Code Here

     * Testing the union function.
     *
     * @throws Exception
     */
    public void testFunction() throws Exception {
        final Function unionFunction = new UnionFunction();
        try {
            unionFunction.invoke(expressionContextMock, new Value[0]);
            fail("Exception wasn't thrown when empty arguments passed" +
                    " to function");
        } catch (Exception e) {
            // ignore it, expected situation
        }
        assertSame("Function invoked with the empty sequences didn't" +
                " return the empty sequence",
                Sequence.EMPTY,
                unionFunction.invoke(expressionContextMock, new Value[] {
                        Sequence.EMPTY, Sequence.EMPTY
                }));
        final Sequence firstSequence =
                expressionContextMock.getFactory().createSequence(
                        new Item[] {
                                expressionContextMock.getFactory()
                                        .createStringValue("value1"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(true)});
        final Sequence secondSequence =
            expressionContextMock.getFactory().createSequence(
                    new Item[] {
                            expressionContextMock.getFactory()
                                    .createStringValue("value0"),
                            expressionContextMock.getFactory()
                                    .createStringValue("value0"),
                            expressionContextMock.getFactory()
                                    .createStringValue("value1"),
                            expressionContextMock.getFactory()
                                    .createBooleanValue(false)});
        final Sequence result = (Sequence) unionFunction.invoke(
                expressionContextMock, new Value[] {firstSequence,
                        secondSequence});
        assertEquals("number of elements in returned sequence is incorrect",
                5, result.getLength());
        assertEquals("incorrect element in returned sequence",
View Full Code Here

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

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

   
    /**
     * Tests if function works correctly for string
     */
    public void testString() throws ExpressionException {
        final Function function = new StringLengthFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createStringValue("qwerty")});
        assertTrue(result instanceof IntValue);
        assertEquals(6, ((IntValue) result).asJavaInt());
    }
View Full Code Here

   
    /**
     * Tests if function returns 0 for empty sequence
     */
    public void testEmptySequence() throws ExpressionException {
        final Function function = new StringLengthFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createSequence(new Item[]{})});
        assertTrue(result instanceof IntValue);
        assertEquals(0, ((IntValue) result).asJavaInt());
    }
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.