aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/data/access/simple/SimpleConformanceTestCase.java
blob: 4fbc1542e723c37aeb7851ab5ed1d39f2e411ac7 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.data.access.simple;


import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;


public class SimpleConformanceTestCase extends com.yahoo.data.access.InspectorConformanceTestBase {

    // ARRAY {
    //   [0]: EMPTY
    //   [1]: BOOL: true
    //   [2]: LONG: 10
    //   [3]: DOUBLE: 5.75
    //   [4]: OBJECT {
    //     "foo": STRING: "foo_value"
    //     "bar": DATA: 0x04 0x02
    //     "nested": ARRAY {
    //       [0]: OBJECT {
    //         "hidden": STRING: "treasure"
    //       }
    //     }
    //   }
    // }
    public com.yahoo.data.access.Inspector getData() {
        return new Value.ArrayValue()
            .add(new Value.EmptyValue())
            .add(new Value.BoolValue(true))
            .add(new Value.LongValue(10L))
            .add(new Value.DoubleValue(5.75))
            .add(new Value.ObjectValue()
                 .put("foo", new Value.StringValue("foo_value"))
                 .put("bar", new Value.DataValue(new byte[] { (byte)4, (byte)2 }))
                 .put("nested", new Value.ArrayValue()
                      .add(new Value.ObjectValue()
                           .put("hidden", new Value.StringValue("treasure")))));
    }

    @Test
    public void testSingletons() {
        assertThat(Value.empty().valid(), is(true));
        assertThat(Value.empty().type(), is(com.yahoo.data.access.Type.EMPTY));
        assertThat(Value.invalid().valid(), is(false));
        assertThat(Value.invalid().type(), is(com.yahoo.data.access.Type.EMPTY));
    }

    @Test
    public void testToString() {
        String json = getData().toString();
        String correct = "[null,true,10,5.75,{\"foo\":\"foo_value\",\"bar\":\"0x0402\",\"nested\":[{\"hidden\":\"treasure\"}]}]";
        assertThat(json, is(correct));
    }
}