Package com.volantis.xml.expression

Examples of com.volantis.xml.expression.Function


   
    /**
     * Tests if function works correctly for positive infinity
     */
    public void testPositiveInfinity() throws ExpressionException {
        final Function function = new CeilingFunction();
        Value result = function.invoke(expressionContextMock, new Value[]{
                DoubleValue.POSITIVE_INFINITY});
        assertTrue(result instanceof DoubleValue);
        assertTrue(Double.POSITIVE_INFINITY == (((DoubleValue) result).asJavaDouble()));
    }
View Full Code Here


   
    /**
     * Tests if function works correctly for negative infinity
     */
    public void testNegativeInfinity() throws ExpressionException {
        final Function function = new CeilingFunction();
        Value result = function.invoke(expressionContextMock, new Value[]{
                DoubleValue.NEGATIVE_INFINITY});
        assertTrue(result instanceof DoubleValue);
        assertTrue(Double.NEGATIVE_INFINITY == (((DoubleValue) result).asJavaDouble()));
    }
View Full Code Here

    // javadoc inherited
    protected void registerExpressionFunctions(ExpressionContext context) {
        //add a new function capable of returning an empty sequence.
        context.registerFunction(
            new ImmutableExpandedName("", "empty-sequence"),
            new Function() {
                public Value invoke(ExpressionContext context, Value[] args) {
                    return Sequence.EMPTY;
                }
            });
View Full Code Here

     * Testing the except function.
     *
     * @throws Exception
     */
    public void testFunction() throws Exception {
        final Function exceptFunction = new ExceptFunction();
        try {
            exceptFunction.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,
                exceptFunction.invoke(expressionContextMock, new Value[] {
                        Sequence.EMPTY, Sequence.EMPTY
                }));
        final Sequence firstSequence =
                expressionContextMock.getFactory().createSequence(
                        new Item[] {
                                expressionContextMock.getFactory()
                                        .createStringValue("value0"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value0"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(true)});
        final Sequence secondSequence =
                expressionContextMock.getFactory().createSequence(
                        new Item[] {
                                expressionContextMock.getFactory()
                                        .createStringValue("value2"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value3"),
                                expressionContextMock.getFactory()
                                        .createStringValue("value3"),
                                expressionContextMock.getFactory()
                                        .createBooleanValue(false)});
        final Sequence result = (Sequence) exceptFunction.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 that the search string is found where expected.
     */
    public void testSearchPresent() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory,
                new String[]{"a", "dog", "and", "a", "duck"});
        Value search = factory.createStringValue("a");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned (1, 4)
        assertTrue(retSeq.getLength() == 2);
View Full Code Here

     * Tests that the search string is not found.
     */
    public void testSearchNotPresent() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory,
                new String[]{"a", "dog", "and", "a", "duck"});
        Value search = factory.createStringValue("cat");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned ()
        assertSame(retSeq, Sequence.EMPTY);
View Full Code Here

     * Tests that the search string is found at all positions.
     */
    public void testAllItemsMatch() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory,
                new String[]{"abc", "abc", "abc", "abc", "abc"});
        Value search = factory.createStringValue("abc");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned (1, 2, 3, 4, 5)
        assertTrue(retSeq.getLength() == 5);
View Full Code Here

     * returned.
     */
    public void testEmptySearch() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory,
                new String[]{"abc", "abc", "abc", "abc", "abc"});
        Value search = factory.createStringValue("");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned ()
        assertSame(retSeq, Sequence.EMPTY);
View Full Code Here

     * returned.
     */
    public void testEmptySequence() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory, null);
        Value search = factory.createStringValue("peter");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned ()
        assertSame(retSeq, Sequence.EMPTY);
View Full Code Here

     * sequence to be returned.
     */
    public void testEmptySequenceEmptySearch() throws Exception {
        ExpressionContext context = createExpressionContext();
        ExpressionFactory factory = context.getFactory();
        Function indexOf = new IndexOfFunction();
        Sequence sequence = createStringSequence(factory, null);
        Value search = factory.createStringValue("");
        Value retVal = indexOf.invoke(context, new Value[]{sequence, search});

        final Sequence retSeq = retVal.getSequence();

        // Should have returned ()
        assertSame(retSeq, Sequence.EMPTY);
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.