aboutsummaryrefslogtreecommitdiffstats
path: root/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SetValueTestCase.java
blob: 488a8c098fdd27fc31a46b7ffc35d3b020890043 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.expressions;

import com.yahoo.document.DataType;
import com.yahoo.document.datatypes.FieldValue;
import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter;
import org.junit.Test;

import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify;
import static org.junit.Assert.*;

/**
 * @author Simon Thoresen Hult
 */
public class SetValueTestCase {

    @Test
    public void requireThatAccessorsWork() {
        FieldValue foo = new StringFieldValue("foo");
        ConstantExpression exp = new ConstantExpression(foo);
        assertSame(foo, exp.getValue());
    }

    @Test
    public void requireThatHashCodeAndEqualsAreImplemented() {
        FieldValue foo = new StringFieldValue("foo");
        Expression exp = new ConstantExpression(foo);
        assertFalse(exp.equals(new Object()));
        assertFalse(exp.equals(new ConstantExpression(new StringFieldValue("bar"))));
        assertEquals(exp, new ConstantExpression(foo));
        assertEquals(exp.hashCode(), new ConstantExpression(foo).hashCode());
    }

    @Test
    public void requireThatExpressionCanBeVerified() {
        Expression exp = new ConstantExpression(new StringFieldValue("foo"));
        assertVerify(null, exp, DataType.STRING);
        assertVerify(DataType.INT, exp, DataType.STRING);
        assertVerify(DataType.STRING, exp, DataType.STRING);
    }

    @Test
    public void requireThatNullValueThrowsException() {
        try {
            new ConstantExpression(null);
            fail();
        } catch (NullPointerException e) {

        }
    }

    @Test
    public void requireThatValueIsSet() {
        ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
        new ConstantExpression(new StringFieldValue("69")).execute(ctx);
        assertEquals(new StringFieldValue("69"), ctx.getValue());
    }

    @Test
    public void requireThatLongFieldValueGetsATrailingL() {
        assertEquals("69L", new ConstantExpression(new LongFieldValue(69)).toString());
    }
}