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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations