Search in sources :

Example 1 with DerivedFoo

use of org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo in project pulsar by apache.

the class JSONSchemaTest method testAllowNullCorrectPolymorphism.

@Test
public void testAllowNullCorrectPolymorphism() {
    Bar bar = new Bar();
    bar.setField1(true);
    DerivedFoo derivedFoo = new DerivedFoo();
    derivedFoo.setField1("foo1");
    derivedFoo.setField2("bar2");
    derivedFoo.setField3(4);
    derivedFoo.setField4(bar);
    derivedFoo.setField5("derived1");
    derivedFoo.setField6(2);
    Foo foo = new Foo();
    foo.setField1("foo1");
    foo.setField2("bar2");
    foo.setField3(4);
    foo.setField4(bar);
    SchemaTestUtils.DerivedDerivedFoo derivedDerivedFoo = new SchemaTestUtils.DerivedDerivedFoo();
    derivedDerivedFoo.setField1("foo1");
    derivedDerivedFoo.setField2("bar2");
    derivedDerivedFoo.setField3(4);
    derivedDerivedFoo.setField4(bar);
    derivedDerivedFoo.setField5("derived1");
    derivedDerivedFoo.setField6(2);
    derivedDerivedFoo.setFoo2(foo);
    derivedDerivedFoo.setDerivedFoo(derivedFoo);
    // schema for base class
    JSONSchema<Foo> baseJsonSchema = JSONSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(foo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedFoo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedDerivedFoo)), foo);
    // schema for derived class
    JSONSchema<DerivedFoo> derivedJsonSchema = JSONSchema.of(SchemaDefinition.<DerivedFoo>builder().withPojo(DerivedFoo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedFoo)), derivedFoo);
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedDerivedFoo)), derivedFoo);
    // schema for derived derived class
    JSONSchema<SchemaTestUtils.DerivedDerivedFoo> derivedDerivedJsonSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.DerivedDerivedFoo>builder().withPojo(SchemaTestUtils.DerivedDerivedFoo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(derivedDerivedJsonSchema.decode(derivedDerivedJsonSchema.encode(derivedDerivedFoo)), derivedDerivedFoo);
}
Also used : NestedBar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBar) Bar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Bar) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) Foo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Foo) Test(org.testng.annotations.Test)

Example 2 with DerivedFoo

use of org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo in project pulsar by yahoo.

the class JSONSchemaTest method testAllowNullCorrectPolymorphism.

@Test
public void testAllowNullCorrectPolymorphism() {
    Bar bar = new Bar();
    bar.setField1(true);
    DerivedFoo derivedFoo = new DerivedFoo();
    derivedFoo.setField1("foo1");
    derivedFoo.setField2("bar2");
    derivedFoo.setField3(4);
    derivedFoo.setField4(bar);
    derivedFoo.setField5("derived1");
    derivedFoo.setField6(2);
    Foo foo = new Foo();
    foo.setField1("foo1");
    foo.setField2("bar2");
    foo.setField3(4);
    foo.setField4(bar);
    SchemaTestUtils.DerivedDerivedFoo derivedDerivedFoo = new SchemaTestUtils.DerivedDerivedFoo();
    derivedDerivedFoo.setField1("foo1");
    derivedDerivedFoo.setField2("bar2");
    derivedDerivedFoo.setField3(4);
    derivedDerivedFoo.setField4(bar);
    derivedDerivedFoo.setField5("derived1");
    derivedDerivedFoo.setField6(2);
    derivedDerivedFoo.setFoo2(foo);
    derivedDerivedFoo.setDerivedFoo(derivedFoo);
    // schema for base class
    JSONSchema<Foo> baseJsonSchema = JSONSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(foo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedFoo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedDerivedFoo)), foo);
    // schema for derived class
    JSONSchema<DerivedFoo> derivedJsonSchema = JSONSchema.of(SchemaDefinition.<DerivedFoo>builder().withPojo(DerivedFoo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedFoo)), derivedFoo);
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedDerivedFoo)), derivedFoo);
    // schema for derived derived class
    JSONSchema<SchemaTestUtils.DerivedDerivedFoo> derivedDerivedJsonSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.DerivedDerivedFoo>builder().withPojo(SchemaTestUtils.DerivedDerivedFoo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(derivedDerivedJsonSchema.decode(derivedDerivedJsonSchema.encode(derivedDerivedFoo)), derivedDerivedFoo);
}
Also used : NestedBar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBar) Bar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Bar) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) Foo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Foo) Test(org.testng.annotations.Test)

Example 3 with DerivedFoo

use of org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo in project pulsar by yahoo.

the class JSONSchemaTest method testNotAllowNullCorrectPolymorphism.

@Test
public void testNotAllowNullCorrectPolymorphism() {
    Bar bar = new Bar();
    bar.setField1(true);
    DerivedFoo derivedFoo = new DerivedFoo();
    derivedFoo.setField1("foo1");
    derivedFoo.setField2("bar2");
    derivedFoo.setField3(4);
    derivedFoo.setField4(bar);
    derivedFoo.setField5("derived1");
    derivedFoo.setField6(2);
    Foo foo = new Foo();
    foo.setField1("foo1");
    foo.setField2("bar2");
    foo.setField3(4);
    foo.setField4(bar);
    SchemaTestUtils.DerivedDerivedFoo derivedDerivedFoo = new SchemaTestUtils.DerivedDerivedFoo();
    derivedDerivedFoo.setField1("foo1");
    derivedDerivedFoo.setField2("bar2");
    derivedDerivedFoo.setField3(4);
    derivedDerivedFoo.setField4(bar);
    derivedDerivedFoo.setField5("derived1");
    derivedDerivedFoo.setField6(2);
    derivedDerivedFoo.setFoo2(foo);
    derivedDerivedFoo.setDerivedFoo(derivedFoo);
    // schema for base class
    JSONSchema<Foo> baseJsonSchema = JSONSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(foo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedFoo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedDerivedFoo)), foo);
    // schema for derived class
    JSONSchema<DerivedFoo> derivedJsonSchema = JSONSchema.of(SchemaDefinition.<DerivedFoo>builder().withPojo(DerivedFoo.class).build());
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedFoo)), derivedFoo);
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedDerivedFoo)), derivedFoo);
    // schema for derived derived class
    JSONSchema<SchemaTestUtils.DerivedDerivedFoo> derivedDerivedJsonSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.DerivedDerivedFoo>builder().withPojo(SchemaTestUtils.DerivedDerivedFoo.class).build());
    Assert.assertEquals(derivedDerivedJsonSchema.decode(derivedDerivedJsonSchema.encode(derivedDerivedFoo)), derivedDerivedFoo);
}
Also used : NestedBar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBar) Bar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Bar) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) Foo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Foo) Test(org.testng.annotations.Test)

Example 4 with DerivedFoo

use of org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo in project incubator-pulsar by apache.

the class JSONSchemaTest method testAllowNullCorrectPolymorphism.

@Test
public void testAllowNullCorrectPolymorphism() {
    Bar bar = new Bar();
    bar.setField1(true);
    DerivedFoo derivedFoo = new DerivedFoo();
    derivedFoo.setField1("foo1");
    derivedFoo.setField2("bar2");
    derivedFoo.setField3(4);
    derivedFoo.setField4(bar);
    derivedFoo.setField5("derived1");
    derivedFoo.setField6(2);
    Foo foo = new Foo();
    foo.setField1("foo1");
    foo.setField2("bar2");
    foo.setField3(4);
    foo.setField4(bar);
    SchemaTestUtils.DerivedDerivedFoo derivedDerivedFoo = new SchemaTestUtils.DerivedDerivedFoo();
    derivedDerivedFoo.setField1("foo1");
    derivedDerivedFoo.setField2("bar2");
    derivedDerivedFoo.setField3(4);
    derivedDerivedFoo.setField4(bar);
    derivedDerivedFoo.setField5("derived1");
    derivedDerivedFoo.setField6(2);
    derivedDerivedFoo.setFoo2(foo);
    derivedDerivedFoo.setDerivedFoo(derivedFoo);
    // schema for base class
    JSONSchema<Foo> baseJsonSchema = JSONSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(foo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedFoo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedDerivedFoo)), foo);
    // schema for derived class
    JSONSchema<DerivedFoo> derivedJsonSchema = JSONSchema.of(SchemaDefinition.<DerivedFoo>builder().withPojo(DerivedFoo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedFoo)), derivedFoo);
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedDerivedFoo)), derivedFoo);
    // schema for derived derived class
    JSONSchema<SchemaTestUtils.DerivedDerivedFoo> derivedDerivedJsonSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.DerivedDerivedFoo>builder().withPojo(SchemaTestUtils.DerivedDerivedFoo.class).withAlwaysAllowNull(false).build());
    Assert.assertEquals(derivedDerivedJsonSchema.decode(derivedDerivedJsonSchema.encode(derivedDerivedFoo)), derivedDerivedFoo);
}
Also used : NestedBar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBar) Bar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Bar) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) Foo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Foo) Test(org.testng.annotations.Test)

Example 5 with DerivedFoo

use of org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo in project incubator-pulsar by apache.

the class JSONSchemaTest method testNotAllowNullCorrectPolymorphism.

@Test
public void testNotAllowNullCorrectPolymorphism() {
    Bar bar = new Bar();
    bar.setField1(true);
    DerivedFoo derivedFoo = new DerivedFoo();
    derivedFoo.setField1("foo1");
    derivedFoo.setField2("bar2");
    derivedFoo.setField3(4);
    derivedFoo.setField4(bar);
    derivedFoo.setField5("derived1");
    derivedFoo.setField6(2);
    Foo foo = new Foo();
    foo.setField1("foo1");
    foo.setField2("bar2");
    foo.setField3(4);
    foo.setField4(bar);
    SchemaTestUtils.DerivedDerivedFoo derivedDerivedFoo = new SchemaTestUtils.DerivedDerivedFoo();
    derivedDerivedFoo.setField1("foo1");
    derivedDerivedFoo.setField2("bar2");
    derivedDerivedFoo.setField3(4);
    derivedDerivedFoo.setField4(bar);
    derivedDerivedFoo.setField5("derived1");
    derivedDerivedFoo.setField6(2);
    derivedDerivedFoo.setFoo2(foo);
    derivedDerivedFoo.setDerivedFoo(derivedFoo);
    // schema for base class
    JSONSchema<Foo> baseJsonSchema = JSONSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(foo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedFoo)), foo);
    Assert.assertEquals(baseJsonSchema.decode(baseJsonSchema.encode(derivedDerivedFoo)), foo);
    // schema for derived class
    JSONSchema<DerivedFoo> derivedJsonSchema = JSONSchema.of(SchemaDefinition.<DerivedFoo>builder().withPojo(DerivedFoo.class).build());
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedFoo)), derivedFoo);
    Assert.assertEquals(derivedJsonSchema.decode(derivedJsonSchema.encode(derivedDerivedFoo)), derivedFoo);
    // schema for derived derived class
    JSONSchema<SchemaTestUtils.DerivedDerivedFoo> derivedDerivedJsonSchema = JSONSchema.of(SchemaDefinition.<SchemaTestUtils.DerivedDerivedFoo>builder().withPojo(SchemaTestUtils.DerivedDerivedFoo.class).build());
    Assert.assertEquals(derivedDerivedJsonSchema.decode(derivedDerivedJsonSchema.encode(derivedDerivedFoo)), derivedDerivedFoo);
}
Also used : NestedBar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBar) Bar(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Bar) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) DerivedFoo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo) Foo(org.apache.pulsar.client.impl.schema.SchemaTestUtils.Foo) Test(org.testng.annotations.Test)

Aggregations

Bar (org.apache.pulsar.client.impl.schema.SchemaTestUtils.Bar)6 DerivedFoo (org.apache.pulsar.client.impl.schema.SchemaTestUtils.DerivedFoo)6 Foo (org.apache.pulsar.client.impl.schema.SchemaTestUtils.Foo)6 NestedBar (org.apache.pulsar.client.impl.schema.SchemaTestUtils.NestedBar)6 Test (org.testng.annotations.Test)6