Search in sources :

Example 1 with Simple

use of com.linkedin.pegasus.generator.test.idl.records.Simple in project rest.li by linkedin.

the class ArrayGeneratorTest method testWithCustomTypesArray.

@Test
public void testWithCustomTypesArray() throws Throwable {
    String json = load("WithCustomTypesArray.json");
    WithCustomTypesArray original = new WithCustomTypesArray();
    CustomIntArray ints = new CustomIntArray();
    ints.add(new CustomInt(1));
    ints.add(new CustomInt(2));
    ints.add(new CustomInt(3));
    original.setInts(ints);
    SimpleArrayArray arrays = new SimpleArrayArray();
    SimpleArray simpleArray = new SimpleArray();
    Simple simple = new Simple();
    simple.setMessage("a1");
    simpleArray.add(simple);
    arrays.add(simpleArray);
    original.setArrays(arrays);
    SimpleMapArray maps = new SimpleMapArray();
    SimpleMap map = new SimpleMap();
    Simple simplem1 = new Simple();
    simplem1.setMessage("m1");
    map.put("a", simplem1);
    maps.add(map);
    original.setMaps(maps);
    Simple simpleu1 = new Simple();
    simpleu1.setMessage("u1");
    WithCustomTypesArrayUnionArray unions = new WithCustomTypesArrayUnionArray();
    unions.add(WithCustomTypesArrayUnion.create(1));
    unions.add(WithCustomTypesArrayUnion.create("str"));
    unions.add(WithCustomTypesArrayUnion.create(simpleu1));
    original.setUnions(unions);
    Fixed8 fixed8 = new Fixed8(SchemaFixtures.bytesFixed8);
    Fixed8Array fixed8Array = new Fixed8Array();
    fixed8Array.add(fixed8);
    original.setFixed(fixed8Array);
    assertJson(original, json);
    WithCustomTypesArray roundTripped = new WithCustomTypesArray(roundTrip(original.data()));
    assertJson(roundTripped, json);
}
Also used : Fixed8(com.linkedin.pegasus.generator.test.idl.fixed.Fixed8) SimpleArray(com.linkedin.pegasus.generator.test.idl.records.SimpleArray) SimpleMap(com.linkedin.pegasus.generator.test.idl.records.SimpleMap) WithCustomTypesArrayUnionArray(com.linkedin.pegasus.generator.test.idl.arrays.WithCustomTypesArrayUnionArray) WithCustomTypesArray(com.linkedin.pegasus.generator.test.idl.arrays.WithCustomTypesArray) CustomIntArray(com.linkedin.pegasus.generator.test.idl.customtypes.CustomIntArray) SimpleMapArray(com.linkedin.pegasus.generator.test.idl.records.SimpleMapArray) CustomInt(com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt) SimpleArrayArray(com.linkedin.pegasus.generator.test.idl.records.SimpleArrayArray) Fixed8Array(com.linkedin.pegasus.generator.test.idl.fixed.Fixed8Array) Simple(com.linkedin.pegasus.generator.test.idl.records.Simple) Test(org.testng.annotations.Test)

Example 2 with Simple

use of com.linkedin.pegasus.generator.test.idl.records.Simple in project rest.li by linkedin.

the class RecordGeneratorTest method testWithComplexTypes.

@Test
public void testWithComplexTypes() throws Throwable {
    WithComplexTypes original = new WithComplexTypes();
    Simple simple = new Simple();
    simple.setMessage("message");
    original.setRecord(simple);
    original.setEnum(Fruits.APPLE);
    original.setUnion(WithComplexTypes.Union.create(1));
    IntegerArray intArray = new IntegerArray();
    intArray.add(1);
    original.setArray(intArray);
    IntegerMap intMap = new IntegerMap();
    intMap.put("a", 1);
    original.setMap(intMap);
    SimpleMap simpleMap = new SimpleMap();
    simpleMap.put("a", simple);
    original.setComplexMap(simpleMap);
    original.setCustom(new CustomInt(1));
    WithComplexTypes roundTripped = new WithComplexTypes(roundTrip(original.data()));
    assertEquals(roundTripped.getRecord(), simple);
    assertEquals(roundTripped.getEnum(), Fruits.APPLE);
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) WithComplexTypes(com.linkedin.pegasus.generator.test.idl.records.WithComplexTypes) SimpleMap(com.linkedin.pegasus.generator.test.idl.records.SimpleMap) CustomInt(com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt) Simple(com.linkedin.pegasus.generator.test.idl.records.Simple) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Example 3 with Simple

use of com.linkedin.pegasus.generator.test.idl.records.Simple in project rest.li by linkedin.

the class UnionGeneratorTest method testWithComplexTypesUnion.

@Test
public void testWithComplexTypesUnion() throws Throwable {
    WithComplexTypesUnion.Union recordMember = WithComplexTypesUnion.Union.create(new Empty());
    WithComplexTypesUnion.Union enumMember = WithComplexTypesUnion.Union.create(Fruits.APPLE);
    SimpleMap simpleMap = new SimpleMap();
    Simple m1 = new Simple();
    m1.setMessage("m1");
    simpleMap.put("a", m1);
    WithComplexTypesUnion.Union mapMember = WithComplexTypesUnion.Union.create(simpleMap);
    SimpleArray simpleArray = new SimpleArray();
    Simple a1 = new Simple();
    a1.setMessage("a1");
    simpleArray.add(a1);
    WithComplexTypesUnion.Union arrayMember = WithComplexTypesUnion.Union.create(simpleArray);
    WithComplexTypesUnion withRecord = new WithComplexTypesUnion();
    withRecord.setUnion(recordMember);
    assertJson(withRecord, load("WithComplexTypesUnion_Empty.json"));
    WithComplexTypesUnion withEnum = new WithComplexTypesUnion();
    withEnum.setUnion(enumMember);
    assertJson(withEnum, load("WithComplexTypesUnion_Enum.json"));
    WithComplexTypesUnion withArray = new WithComplexTypesUnion();
    withArray.setUnion(arrayMember);
    assertJson(withArray, load("WithComplexTypesUnion_Array.json"));
    WithComplexTypesUnion withMap = new WithComplexTypesUnion();
    withMap.setUnion(mapMember);
    assertJson(withMap, load("WithComplexTypesUnion_Map.json"));
}
Also used : Empty(com.linkedin.pegasus.generator.test.idl.records.Empty) WithComplexTypesUnion(com.linkedin.pegasus.generator.test.idl.unions.WithComplexTypesUnion) SimpleArray(com.linkedin.pegasus.generator.test.idl.records.SimpleArray) SimpleMap(com.linkedin.pegasus.generator.test.idl.records.SimpleMap) Simple(com.linkedin.pegasus.generator.test.idl.records.Simple) Test(org.testng.annotations.Test)

Example 4 with Simple

use of com.linkedin.pegasus.generator.test.idl.records.Simple in project rest.li by linkedin.

the class MapGeneratorTest method testWithComplexTypesMap.

@Test
public void testWithComplexTypesMap() throws Throwable {
    String json = load("WithComplexTypesMap.json");
    WithComplexTypesMap original = new WithComplexTypesMap();
    EmptyMap empties = new EmptyMap();
    empties.put("a", new Empty());
    empties.put("b", new Empty());
    empties.put("c", new Empty());
    original.setEmpties(empties);
    FruitsMap fruits = new FruitsMap();
    fruits.put("a", Fruits.APPLE);
    fruits.put("b", Fruits.BANANA);
    fruits.put("c", Fruits.ORANGE);
    original.setFruits(fruits);
    SimpleArrayMap simpleArrays = new SimpleArrayMap();
    Simple simplev1 = new Simple();
    simplev1.setMessage("v1");
    Simple simplev2 = new Simple();
    simplev2.setMessage("v2");
    SimpleArray simpleArray = new SimpleArray();
    simpleArray.add(simplev1);
    simpleArray.add(simplev2);
    simpleArrays.put("a", simpleArray);
    original.setArrays(simpleArrays);
    SimpleMap simpleMapi1 = new SimpleMap();
    Simple simpleo1i1 = new Simple();
    simpleo1i1.setMessage("o1i1");
    simpleMapi1.put("i1", simpleo1i1);
    Simple simpleo1i2 = new Simple();
    simpleo1i2.setMessage("o1i2");
    simpleMapi1.put("i2", simpleo1i2);
    SimpleMapMap maps = new SimpleMapMap();
    maps.put("o1", simpleMapi1);
    original.setMaps(maps);
    WithComplexTypesMapUnionMap unions = new WithComplexTypesMapUnionMap();
    unions.put("a", WithComplexTypesMapUnion.create(1));
    unions.put("b", WithComplexTypesMapUnion.create("u1"));
    original.setUnions(unions);
    Fixed8Map fixed = new Fixed8Map();
    fixed.put("a", new Fixed8(SchemaFixtures.bytesFixed8));
    original.setFixed(fixed);
    assertJson(original, json);
    WithComplexTypesMap roundTripped = new WithComplexTypesMap(roundTrip(original.data()));
    assertJson(roundTripped, json);
}
Also used : WithComplexTypesMapUnionMap(com.linkedin.pegasus.generator.test.idl.maps.WithComplexTypesMapUnionMap) FruitsMap(com.linkedin.pegasus.generator.test.idl.enums.FruitsMap) SimpleArrayMap(com.linkedin.pegasus.generator.test.idl.records.SimpleArrayMap) Fixed8Map(com.linkedin.pegasus.generator.test.idl.fixed.Fixed8Map) Simple(com.linkedin.pegasus.generator.test.idl.records.Simple) Empty(com.linkedin.pegasus.generator.test.idl.records.Empty) SimpleMapMap(com.linkedin.pegasus.generator.test.idl.records.SimpleMapMap) Fixed8(com.linkedin.pegasus.generator.test.idl.fixed.Fixed8) SimpleArray(com.linkedin.pegasus.generator.test.idl.records.SimpleArray) SimpleMap(com.linkedin.pegasus.generator.test.idl.records.SimpleMap) EmptyMap(com.linkedin.pegasus.generator.test.idl.records.EmptyMap) WithComplexTypesMap(com.linkedin.pegasus.generator.test.idl.maps.WithComplexTypesMap) Test(org.testng.annotations.Test)

Example 5 with Simple

use of com.linkedin.pegasus.generator.test.idl.records.Simple in project rest.li by linkedin.

the class RecordGeneratorTest method testWithOptionalComplexTypesDefaults.

@Test
public void testWithOptionalComplexTypesDefaults() {
    WithOptionalComplexTypeDefaults withDefaults = new WithOptionalComplexTypeDefaults();
    Simple simple = new Simple();
    simple.setMessage("defaults!");
    assertEquals(withDefaults.getRecord(), simple);
    assertEquals(withDefaults.getEnum(), Fruits.APPLE);
    assertEquals(withDefaults.getUnion(), WithComplexTypeDefaults.Union.create(1));
    IntegerArray intArray = new IntegerArray();
    intArray.add(1);
    assertEquals(withDefaults.getArray(), intArray);
    IntegerMap intMap = new IntegerMap();
    intMap.put("a", 1);
    assertEquals(withDefaults.getMap(), intMap);
    assertEquals(withDefaults.getCustom(), new CustomInt(1));
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) WithOptionalComplexTypeDefaults(com.linkedin.pegasus.generator.test.idl.records.WithOptionalComplexTypeDefaults) CustomInt(com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt) Simple(com.linkedin.pegasus.generator.test.idl.records.Simple) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Aggregations

Simple (com.linkedin.pegasus.generator.test.idl.records.Simple)6 Test (org.testng.annotations.Test)6 SimpleMap (com.linkedin.pegasus.generator.test.idl.records.SimpleMap)4 CustomInt (com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt)4 IntegerArray (com.linkedin.data.template.IntegerArray)3 IntegerMap (com.linkedin.data.template.IntegerMap)3 SimpleArray (com.linkedin.pegasus.generator.test.idl.records.SimpleArray)3 Fixed8 (com.linkedin.pegasus.generator.test.idl.fixed.Fixed8)2 Empty (com.linkedin.pegasus.generator.test.idl.records.Empty)2 WithCustomTypesArray (com.linkedin.pegasus.generator.test.idl.arrays.WithCustomTypesArray)1 WithCustomTypesArrayUnionArray (com.linkedin.pegasus.generator.test.idl.arrays.WithCustomTypesArrayUnionArray)1 CustomIntArray (com.linkedin.pegasus.generator.test.idl.customtypes.CustomIntArray)1 FruitsMap (com.linkedin.pegasus.generator.test.idl.enums.FruitsMap)1 Fixed8Array (com.linkedin.pegasus.generator.test.idl.fixed.Fixed8Array)1 Fixed8Map (com.linkedin.pegasus.generator.test.idl.fixed.Fixed8Map)1 WithComplexTypesMap (com.linkedin.pegasus.generator.test.idl.maps.WithComplexTypesMap)1 WithComplexTypesMapUnionMap (com.linkedin.pegasus.generator.test.idl.maps.WithComplexTypesMapUnionMap)1 EmptyMap (com.linkedin.pegasus.generator.test.idl.records.EmptyMap)1 SimpleArrayArray (com.linkedin.pegasus.generator.test.idl.records.SimpleArrayArray)1 SimpleArrayMap (com.linkedin.pegasus.generator.test.idl.records.SimpleArrayMap)1