public SchemaRegistry getSchemaRegistry() { if (schemaRegistry == null) { schemaRegistry = SchemaRegistry.createDefault(); } return schemaRegistry; }
@Test public void testAutoSchemaProvider() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); assertEquals(EMPTY_SCHEMA, registry.getSchema(TestSchemaClass.class)); }
@Test public void testDefaultSchemaProvider() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); assertEquals(EMPTY_SCHEMA, registry.getSchema(TestDefaultSchemaClass.class)); }
@Test public void testSchema() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Schema schema = registry.getSchema(SimplePOJO.class); SchemaTestUtils.assertSchemaEquivalent(SIMPLE_POJO_SCHEMA, schema); }
@Test public void testSchema() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Schema schema = registry.getSchema(SimpleBean.class); SchemaTestUtils.assertSchemaEquivalent(SIMPLE_BEAN_SCHEMA, schema); }
@Test public void testRegisterProvider() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); registry.registerSchemaProvider(new Provider()); tryGetters(registry); }
@Test public void testRegisterJavaBean() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); registry.registerJavaBean(SimpleBean.class); Schema schema = registry.getSchema(SimpleBean.class); assertTrue(SIMPLE_BEAN_SCHEMA.equivalent(schema)); } }
@Test public void testRegisterPojo() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); registry.registerPOJO(SimplePOJO.class); Schema schema = registry.getSchema(SimplePOJO.class); assertTrue(SIMPLE_POJO_SCHEMA.equivalent(schema)); }
@Test public void testNestedNullValuesGetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Row row = registry .getToRowFunction(POJOWithNestedNullable.class) .apply(new POJOWithNestedNullable(null)); assertNull(row.getValue("nested")); }
@Test public void testFromRowWithGetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); SimpleBean bean = createSimple("string"); Row row = registry.getToRowFunction(SimpleBean.class).apply(bean); // Test that the fromRowFunction simply returns the original object back. SimpleBean extracted = registry.getFromRowFunction(SimpleBean.class).apply(row); assertSame(bean, extracted); }
@Test public void testFromRowWithGetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); SimplePOJO pojo = createSimple("string"); Row row = registry.getToRowFunction(SimplePOJO.class).apply(pojo); // Test that the fromRowFunction simply returns the original object back. SimplePOJO extracted = registry.getFromRowFunction(SimplePOJO.class).apply(row); assertSame(pojo, extracted); }
@Test public void testNNestedullValuesSetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Row row = Row.withSchema(NESTED_NULLABLE_SCHEMA).addValue(null).build(); POJOWithNestedNullable pojo = registry.getFromRowFunction(POJOWithNestedNullable.class).apply(row); assertNull(pojo.nested); } }
@Test public void testNullValuesGetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Row row = registry.getToRowFunction(POJOWithNullables.class).apply(new POJOWithNullables(null, 42)); assertNull(row.getString("str")); assertEquals(42, (Object) row.getInt32("anInt")); }
@Test public void testNullValuesSetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Row row = Row.withSchema(NULLABLES_SCHEMA).addValues(null, 42).build(); POJOWithNullables pojo = registry.getFromRowFunction(POJOWithNullables.class).apply(row); assertNull(pojo.str); assertEquals(42, pojo.anInt); }
@Test public void testNestedArraysSetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); List<List<String>> listOfLists = Lists.newArrayList( Lists.newArrayList("a", "b", "c"), Lists.newArrayList("d", "e", "f"), Lists.newArrayList("g", "h", "i")); Row row = Row.withSchema(NESTED_ARRAYS_POJO_SCHEMA).addArray(listOfLists).build(); NestedArraysPOJO pojo = registry.getFromRowFunction(NestedArraysPOJO.class).apply(row); assertEquals(listOfLists, pojo.lists); }
@Test public void testNestedArraysSetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); List<List<String>> listOfLists = Lists.newArrayList( Lists.newArrayList("a", "b", "c"), Lists.newArrayList("d", "e", "f"), Lists.newArrayList("g", "h", "i")); Row row = Row.withSchema(NESTED_ARRAYS_BEAM_SCHEMA).addArray(listOfLists).build(); NestedArraysBean bean = registry.getFromRowFunction(NestedArraysBean.class).apply(row); assertEquals(listOfLists, bean.getLists()); }
@Test public void testNestedArraysGetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); SchemaTestUtils.assertSchemaEquivalent( NESTED_ARRAYS_POJO_SCHEMA, registry.getSchema(NestedArraysPOJO.class)); List<List<String>> listOfLists = Lists.newArrayList( Lists.newArrayList("a", "b", "c"), Lists.newArrayList("d", "e", "f"), Lists.newArrayList("g", "h", "i")); NestedArraysPOJO pojo = new NestedArraysPOJO(listOfLists); Row row = registry.getToRowFunction(NestedArraysPOJO.class).apply(pojo); assertEquals(listOfLists, row.getArray("lists")); }
@Test public void testNestedArraysGetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); SchemaTestUtils.assertSchemaEquivalent( NESTED_ARRAYS_BEAM_SCHEMA, registry.getSchema(NestedArraysBean.class)); List<List<String>> listOfLists = Lists.newArrayList( Lists.newArrayList("a", "b", "c"), Lists.newArrayList("d", "e", "f"), Lists.newArrayList("g", "h", "i")); NestedArraysBean bean = new NestedArraysBean(listOfLists); Row row = registry.getToRowFunction(NestedArraysBean.class).apply(bean); assertEquals(listOfLists, row.getArray("lists")); }
@Test public void testRecursiveArraySetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Row row1 = createSimpleRow("string1"); Row row2 = createSimpleRow("string2"); Row row3 = createSimpleRow("string3"); ; Row row = Row.withSchema(NESTED_ARRAY_POJO_SCHEMA).addArray(row1, row2, row3).build(); NestedArrayPOJO pojo = registry.getFromRowFunction(NestedArrayPOJO.class).apply(row); assertEquals(3, pojo.pojos.length); assertEquals("string1", pojo.pojos[0].str); assertEquals("string2", pojo.pojos[1].str); assertEquals("string3", pojo.pojos[2].str); }
@Test public void testRecursiveArraySetters() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); Row row1 = createSimpleRow("string1"); Row row2 = createSimpleRow("string2"); Row row3 = createSimpleRow("string3"); ; Row row = Row.withSchema(NESTED_ARRAY_BEAN_SCHEMA).addArray(row1, row2, row3).build(); NestedArrayBean bean = registry.getFromRowFunction(NestedArrayBean.class).apply(row); assertEquals(3, bean.getBeans().length); assertEquals("string1", bean.getBeans()[0].getStr()); assertEquals("string2", bean.getBeans()[1].getStr()); assertEquals("string3", bean.getBeans()[2].getStr()); }