Package com.volantis.xml.expression

Examples of com.volantis.xml.expression.Function


    /**
     * Tests if substring start and length are correctly rounded when
     * specified as doubles
     */
    public void testBoundariesAsDoubles() throws ExpressionException {
        final Function function = new SubstringFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createStringValue("123456"),
                factory.createDoubleValue(3.5), factory.createDoubleValue(2.2)});
        assertTrue(result instanceof StringValue);
        assertEquals("45", ((StringValue) result).asJavaString());
    }
View Full Code Here


     * Tests if exception is not thrown and correct string is returned
     * when specified substring length is greater than length of original
     * string
     */
    public void testLengthGreaterThanStringLength() throws ExpressionException {
        final Function function = new SubstringFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createStringValue("123456"),
                factory.createIntValue(2), factory.createIntValue(100)});
        assertTrue(result instanceof StringValue);
        assertEquals("23456", ((StringValue) result).asJavaString());
    }
View Full Code Here

    /**
     * Tests if correct string is returned when specified substring
     * length is a positive infinity.
     */
    public void testLengthPositiveInfinity() throws ExpressionException {
        final Function function = new SubstringFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createStringValue("123456"),
                factory.createIntValue(2), DoubleValue.POSITIVE_INFINITY});
        assertTrue(result instanceof StringValue);
        assertEquals("23456", ((StringValue) result).asJavaString());
    }
View Full Code Here

    /**
     * Tests if empty string is returned when specified substring
     * start is not a number
     */
    public void testStartIsNotANumber() throws ExpressionException {
        final Function function = new SubstringFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createStringValue("123456"),
                DoubleValue.NOT_A_NUMBER, factory.createDoubleValue(2)});
        assertTrue(result instanceof StringValue);
        assertEquals("", ((StringValue) result).asJavaString());
    }
View Full Code Here

    /**
     * Tests if substring is created when specified substring
     * start is a string that can be converted to number
     */
    public void testStartAsString() throws ExpressionException {
        final Function function = new SubstringFunction();
        Value result = function.invoke(expressionContextMock,
                new Value[]{factory.createStringValue("123456"),
                factory.createStringValue("2"), factory.createDoubleValue(2.2)});
        assertTrue(result instanceof StringValue);
        assertEquals("23", ((StringValue) result).asJavaString());
    }
View Full Code Here

    /**
     * Tests if {@link ExpressionException} is thrown when specified substring
     * start is a string that can't be converted to number
     */
    public void testStartAsNotNumericString() {
        final Function function = new SubstringFunction();
        try {
            function.invoke(expressionContextMock,
                    new Value[]{factory.createStringValue("123456"),
                    factory.createStringValue("abc"), factory.createDoubleValue(2.2)});
            fail("substring should fail when start position is a string");
        } catch (ExpressionException e) {
            //ignore, expected situation
View Full Code Here

    /**
     * Tests if {@link ExpressionException} is thrown when specified substring
     * length is a string that can't be converted to number
     */
    public void testLengthAsNotNumericString() {
        final Function function = new SubstringFunction();
        try {
            function.invoke(expressionContextMock,
                    new Value[]{factory.createStringValue("123456"),
                    factory.createDoubleValue(2.2), factory.createStringValue("abc"), });
            fail("substring should fail when length is a string");
        } catch (ExpressionException e) {
            //ignore, expected situation
View Full Code Here

     * Testing the intersect function.
     *
     * @throws Exception
     */
    public void testFunction() throws Exception {
        final Function intersectFunction = new IntersectFunction();
        try {
            intersectFunction.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,
                intersectFunction.invoke(expressionContextMock, new Value[] {
                        Sequence.EMPTY, Sequence.EMPTY
                }));
        final Sequence firstSequence =
                expressionContextMock.getFactory().createSequence(
                        new Item[] {
                                expressionContextMock.getFactory()
                                        .createStringValue("value0"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value1"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(true)});
        final Sequence secondSequence =
                expressionContextMock.getFactory().createSequence(
                        new Item[] {
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value3"),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(false),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(true)});
        final Sequence result = (Sequence) intersectFunction.invoke(
                expressionContextMock, new Value[] {firstSequence,
                        secondSequence});
        assertEquals("number of elements in returned sequence is incorrect",
                2, 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 CountFunction();
        try {
            function.invoke(expressionContextMock, new Value[]{});
            fail("Exception wasn't thrown when count 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 CountFunction();
        try {
            function.invoke(expressionContextMock, new Value[]{
                    factory.createStringValue("arg1"),
                    factory.createStringValue("arg2")});
            fail("Exception wasn't thrown when count was invoked with 2 arguments");
        } catch (ExpressionException e) {
            //do nothing, expected situation
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.