Search in sources :

Example 6 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testSelfInspectableInspector.

@Test
public void testSelfInspectableInspector() throws Exception {
    final Inspector value = getData();
    final Inspector self = value.inspect();
    assertThat(self, is(value));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Example 7 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testInvalidValue.

@Test
public void testInvalidValue() throws Exception {
    final Inspector value = getData().entry(10).field("bogus").entry(0);
    assertThat(value.valid(), is(false));
    assertThat(value.type(), is(Type.EMPTY));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(0));
    assertThat(new Try() {

        void f() {
            value.asBool();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asLong();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asDouble();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asString();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asUtf8();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asData();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asBool(true), is(true));
    assertThat(value.asLong(50), is(50L));
    assertThat(value.asDouble(20.25), is(20.25));
    assertThat(value.asString("default"), is("default"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("utf8".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is("data".getBytes("UTF-8")));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields.size(), is(0));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("foo").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields.size(), is(0));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Example 8 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testStringValue.

@Test
public void testStringValue() throws Exception {
    final Inspector value = getData().entry(4).field("foo");
    assertThat(value.valid(), is(true));
    assertThat(value.type(), is(Type.STRING));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(0));
    assertThat(new Try() {

        void f() {
            value.asBool();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asLong();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asDouble();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asString(), is("foo_value"));
    assertThat(value.asUtf8(), is("foo_value".getBytes("UTF-8")));
    assertThat(new Try() {

        void f() {
            value.asData();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asBool(true), is(true));
    assertThat(value.asLong(50), is(50L));
    assertThat(value.asDouble(20.25), is(20.25));
    assertThat(value.asString("default"), is("foo_value"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("foo_value".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is("data".getBytes("UTF-8")));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields.size(), is(0));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("foo").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields.size(), is(0));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Example 9 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testObjectValue.

@Test
public void testObjectValue() throws Exception {
    final Inspector value = getData().entry(4);
    Map<String, Inspector> expected_fields = new Fields().add("foo", value.field("foo")).add("bar", value.field("bar")).add("nested", value.field("nested")).fields;
    assertThat(value.valid(), is(true));
    assertThat(value.type(), is(Type.OBJECT));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(expected_fields.size()));
    assertThat(new Try() {

        void f() {
            value.asBool();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asLong();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asDouble();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asString();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asUtf8();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asData();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asBool(true), is(true));
    assertThat(value.asLong(50), is(50L));
    assertThat(value.asDouble(20.25), is(20.25));
    assertThat(value.asString("default"), is("default"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("utf8".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is("data".getBytes("UTF-8")));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields, is(expected_fields));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("bogus").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields, is(expected_fields));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Example 10 with Inspector

use of com.yahoo.data.access.Inspector in project vespa by vespa-engine.

the class InspectorConformanceTestBase method testBoolValue.

@Test
public void testBoolValue() throws Exception {
    final Inspector value = getData().entry(1);
    assertThat(value.valid(), is(true));
    assertThat(value.type(), is(Type.BOOL));
    assertThat(value.entryCount(), is(0));
    assertThat(value.fieldCount(), is(0));
    assertThat(value.asBool(), is(true));
    assertThat(new Try() {

        void f() {
            value.asLong();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asDouble();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asString();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asUtf8();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(new Try() {

        void f() {
            value.asData();
        }
    }.call(), instanceOf(IllegalStateException.class));
    assertThat(value.asBool(false), is(true));
    assertThat(value.asLong(50), is(50L));
    assertThat(value.asDouble(20.25), is(20.25));
    assertThat(value.asString("default"), is("default"));
    assertThat(value.asUtf8("utf8".getBytes("UTF-8")), is("utf8".getBytes("UTF-8")));
    assertThat(value.asData("data".getBytes("UTF-8")), is("data".getBytes("UTF-8")));
    assertThat(new Entries().traverse(value).entries.size(), is(0));
    assertThat(new Fields().traverse(value).fields.size(), is(0));
    assertThat(value.entry(0).valid(), is(false));
    assertThat(value.field("foo").valid(), is(false));
    assertThat(new Entries().iterate(value).entries.size(), is(0));
    assertThat(new Fields().iterate(value).fields.size(), is(0));
}
Also used : Inspector(com.yahoo.data.access.Inspector) Test(org.junit.Test)

Aggregations

Inspector (com.yahoo.data.access.Inspector)21 Test (org.junit.Test)19 JSONString (com.yahoo.prelude.hitfield.JSONString)8 Value (com.yahoo.data.access.simple.Value)6 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)1 Slime (com.yahoo.slime.Slime)1 ByteBuffer (java.nio.ByteBuffer)1