Search in sources :

Example 1 with RecordBar

use of com.linkedin.pegasus.generator.test.RecordBar in project rest.li by linkedin.

the class TestRestUtils method testRecord.

@Test
public void testRecord() throws CloneNotSupportedException {
    RecordBar bar = new RecordBar();
    bar.setLocation("mountain view");
    RecordBar expected = bar.copy();
    // Introduce bad elements
    bar.data().put("SF", "CA");
    Assert.assertEquals(bar.data().size(), 2);
    RestUtils.trimRecordTemplate(bar, false);
    Assert.assertEquals(bar, expected);
}
Also used : RecordBar(com.linkedin.pegasus.generator.test.RecordBar) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 2 with RecordBar

use of com.linkedin.pegasus.generator.test.RecordBar in project rest.li by linkedin.

the class TestParameterDefaultValue method testRecord.

@Test
public void testRecord() {
    final Map<String, Object> fixture;
    fixture = new HashMap<String, Object>();
    fixture.put("location", "LinkedIn");
    Assert.assertEquals(test("{\"location\": \"LinkedIn\"}", RecordBar.class), new RecordBar(new DataMap(fixture)));
}
Also used : RecordBar(com.linkedin.pegasus.generator.test.RecordBar) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest)

Example 3 with RecordBar

use of com.linkedin.pegasus.generator.test.RecordBar in project rest.li by linkedin.

the class TestParameterDefaultValue method testWrappedMap.

@Test
public void testWrappedMap() {
    Object result;
    result = test("{\"key1\": \"Hello\", \"key2\": \"World\"}", StringMap.class);
    final Map<String, String> stringFixture = new HashMap<String, String>();
    stringFixture.put("key1", "Hello");
    stringFixture.put("key2", "World");
    Assert.assertEquals(result, new StringMap(stringFixture));
    Assert.assertSame(result.getClass(), StringMap.class);
    result = test("{\"key1\": true, \"key2\": false}", BooleanMap.class);
    final Map<String, Boolean> booleanFixture = new HashMap<String, Boolean>();
    booleanFixture.put("key1", true);
    booleanFixture.put("key2", false);
    Assert.assertEquals(result, new BooleanMap(booleanFixture));
    Assert.assertSame(result.getClass(), BooleanMap.class);
    result = test("{\"key1\": 1, \"key2\": 2}", IntegerMap.class);
    final Map<String, Integer> integerFixture = new HashMap<String, Integer>();
    integerFixture.put("key1", 1);
    integerFixture.put("key2", 2);
    Assert.assertEquals(result, new IntegerMap(integerFixture));
    Assert.assertSame(result.getClass(), IntegerMap.class);
    result = test("{\"key1\": 2, \"key2\": 3}", LongMap.class);
    final Map<String, Long> longFixture = new HashMap<String, Long>();
    longFixture.put("key1", 2L);
    longFixture.put("key2", 3L);
    Assert.assertEquals(result, new LongMap(longFixture));
    Assert.assertSame(result.getClass(), LongMap.class);
    result = test("{\"key1\": 1.1, \"key2\": 2.2}", FloatMap.class);
    final Map<String, Float> floatFixture = new HashMap<String, Float>();
    floatFixture.put("key1", 1.1F);
    floatFixture.put("key2", 2.2F);
    Assert.assertEquals(result, new FloatMap(floatFixture));
    Assert.assertSame(result.getClass(), FloatMap.class);
    result = test("{\"key1\": 2.2, \"key2\": 3.3}", DoubleMap.class);
    final Map<String, Double> doubleFixture = new HashMap<String, Double>();
    doubleFixture.put("key1", 2.2D);
    doubleFixture.put("key2", 3.3D);
    Assert.assertEquals(result, new DoubleMap(doubleFixture));
    Assert.assertSame(result.getClass(), DoubleMap.class);
    result = test("{\"key1\": " + _bytes16Quoted + ", \"key2\": " + _bytes16Quoted + "}", BytesMap.class);
    final Map<String, ByteString> bytesFixture = new HashMap<String, ByteString>();
    bytesFixture.put("key1", ByteString.copyAvroString(_bytes16, true));
    bytesFixture.put("key2", ByteString.copyAvroString(_bytes16, true));
    Assert.assertEquals(result, new BytesMap(new DataMap(bytesFixture)));
    Assert.assertSame(result.getClass(), BytesMap.class);
    result = test("{\"key1\": {\"location\": \"Sunnyvale\"}, \"key2\": {\"location\": \"MTV\"}}", RecordBarMap.class);
    final DataMap dataFixture1 = new DataMap();
    final DataMap dataFixture2 = new DataMap();
    dataFixture1.put("location", "Sunnyvale");
    dataFixture2.put("location", "MTV");
    final RecordBar record1 = new RecordBar(dataFixture1);
    final RecordBar record2 = new RecordBar(dataFixture2);
    final Map<String, RecordBar> recordFixture = new HashMap<String, RecordBar>();
    recordFixture.put("key1", record1);
    recordFixture.put("key2", record2);
    Assert.assertEquals(result, new RecordBarMap(recordFixture));
    Assert.assertSame(result.getClass(), RecordBarMap.class);
}
Also used : StringMap(com.linkedin.data.template.StringMap) HashMap(java.util.HashMap) ByteString(com.linkedin.data.ByteString) BytesMap(com.linkedin.data.template.BytesMap) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) ByteString(com.linkedin.data.ByteString) DoubleMap(com.linkedin.data.template.DoubleMap) DataMap(com.linkedin.data.DataMap) RecordBarMap(com.linkedin.pegasus.generator.test.RecordBarMap) IntegerMap(com.linkedin.data.template.IntegerMap) LongMap(com.linkedin.data.template.LongMap) FloatMap(com.linkedin.data.template.FloatMap) BooleanMap(com.linkedin.data.template.BooleanMap) Test(org.testng.annotations.Test) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest)

Example 4 with RecordBar

use of com.linkedin.pegasus.generator.test.RecordBar in project rest.li by linkedin.

the class TestParameterDefaultValue method testWrappedArray.

@Test
public void testWrappedArray() {
    Object result;
    result = test("[\"Hello\", \"World\"]", StringArray.class);
    Assert.assertEquals(result, new StringArray(Arrays.asList("Hello", "World")));
    Assert.assertSame(result.getClass(), StringArray.class);
    result = test("[false, true]", BooleanArray.class);
    Assert.assertEquals(result, new BooleanArray(Arrays.asList(false, true)));
    Assert.assertSame(result.getClass(), BooleanArray.class);
    result = test("[1, 2, 3]", IntegerArray.class);
    Assert.assertEquals(result, new IntegerArray(Arrays.asList(1, 2, 3)));
    Assert.assertSame(result.getClass(), IntegerArray.class);
    result = test("[1.1, 2.2, 3.3]", IntegerArray.class);
    Assert.assertEquals(result, new IntegerArray(Arrays.asList(1, 2, 3)));
    Assert.assertSame(result.getClass(), IntegerArray.class);
    result = test("[2, 3, 4]", LongArray.class);
    Assert.assertEquals(result, new LongArray(Arrays.asList(2L, 3L, 4L)));
    Assert.assertSame(result.getClass(), LongArray.class);
    result = test("[1.1, 2.2, 3.3]", FloatArray.class);
    Assert.assertEquals(result, new FloatArray(Arrays.asList(1.1F, 2.2F, 3.3F)));
    Assert.assertSame(result.getClass(), FloatArray.class);
    result = test("[2.2, 3.3, 4.4]", DoubleArray.class);
    Assert.assertEquals(result, new DoubleArray(Arrays.asList(2.2D, 3.3D, 4.4D)));
    Assert.assertSame(result.getClass(), DoubleArray.class);
    result = test("[\"APPLE\", \"BANANA\"]", EnumFruitsArray.class);
    Assert.assertEquals(result, new EnumFruitsArray(Arrays.asList(EnumFruits.APPLE, EnumFruits.BANANA)));
    Assert.assertSame(result.getClass(), EnumFruitsArray.class);
    result = test("[" + _bytes16Quoted + ", " + _bytes16Quoted + "]", BytesArray.class);
    Assert.assertEquals(result, new BytesArray(Arrays.asList(ByteString.copyAvroString(_bytes16, true), ByteString.copyAvroString(_bytes16, true))));
    Assert.assertSame(result.getClass(), BytesArray.class);
    result = test("[" + _bytes16Quoted + ", " + _bytes16Quoted + "]", FixedMD5Array.class);
    Assert.assertEquals(result, new FixedMD5Array(Arrays.asList(new FixedMD5(_bytes16), new FixedMD5(_bytes16))));
    Assert.assertSame(result.getClass(), FixedMD5Array.class);
    result = test("[{\"string\": \"String in union\"}, {\"int\": 1}]", ArrayTest.UnionArrayArray.class);
    final ArrayTest.UnionArray fixture1 = new ArrayTest.UnionArray();
    fixture1.setString("String in union");
    final ArrayTest.UnionArray fixture2 = new ArrayTest.UnionArray();
    fixture2.setInt(1);
    Assert.assertEquals(result, new ArrayTest.UnionArrayArray(Arrays.asList(fixture1, fixture2)));
    Assert.assertSame(result.getClass(), ArrayTest.UnionArrayArray.class);
    result = test("[{\"location\": \"Sunnyvale\"}, {\"location\": \"Mountain View\"}]", RecordBarArray.class);
    final DataMap dataFixture1 = new DataMap();
    final DataMap dataFixture2 = new DataMap();
    dataFixture1.put("location", "Sunnyvale");
    dataFixture2.put("location", "Mountain View");
    Assert.assertEquals(result, new RecordBarArray(Arrays.asList(new RecordBar(dataFixture1), new RecordBar(dataFixture2))));
    Assert.assertSame(result.getClass(), RecordBarArray.class);
}
Also used : BytesArray(com.linkedin.data.template.BytesArray) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) FixedMD5(com.linkedin.pegasus.generator.test.FixedMD5) BooleanArray(com.linkedin.data.template.BooleanArray) IntegerArray(com.linkedin.data.template.IntegerArray) DataMap(com.linkedin.data.DataMap) LongArray(com.linkedin.data.template.LongArray) FloatArray(com.linkedin.data.template.FloatArray) RecordBarArray(com.linkedin.pegasus.generator.test.RecordBarArray) StringArray(com.linkedin.data.template.StringArray) EnumFruitsArray(com.linkedin.pegasus.generator.test.EnumFruitsArray) FixedMD5Array(com.linkedin.pegasus.generator.test.FixedMD5Array) DoubleArray(com.linkedin.data.template.DoubleArray) Test(org.testng.annotations.Test) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest)

Example 5 with RecordBar

use of com.linkedin.pegasus.generator.test.RecordBar in project rest.li by linkedin.

the class TestRestUtils method testOverrideMask.

@Test
public void testOverrideMask() throws CloneNotSupportedException {
    RecordBar bar = new RecordBar();
    bar.setLocation("mountain view");
    bar.data().put("SF", "CA");
    RecordBar expected = bar.clone();
    MaskTree maskTree = new MaskTree();
    maskTree.addOperation(new PathSpec("SF"), MaskOperation.POSITIVE_MASK_OP);
    RestUtils.trimRecordTemplate(bar, maskTree, false);
    Assert.assertEquals(bar, expected);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) PathSpec(com.linkedin.data.schema.PathSpec) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Aggregations

RecordBar (com.linkedin.pegasus.generator.test.RecordBar)11 Test (org.testng.annotations.Test)11 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)8 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)8 DataMap (com.linkedin.data.DataMap)4 ArrayTest (com.linkedin.pegasus.generator.test.ArrayTest)3 RecordBarMap (com.linkedin.pegasus.generator.test.RecordBarMap)3 ByteString (com.linkedin.data.ByteString)2 PathSpec (com.linkedin.data.schema.PathSpec)2 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)2 RecordBarArray (com.linkedin.pegasus.generator.test.RecordBarArray)2 DataList (com.linkedin.data.DataList)1 BooleanArray (com.linkedin.data.template.BooleanArray)1 BooleanMap (com.linkedin.data.template.BooleanMap)1 BytesArray (com.linkedin.data.template.BytesArray)1 BytesMap (com.linkedin.data.template.BytesMap)1 DoubleArray (com.linkedin.data.template.DoubleArray)1 DoubleMap (com.linkedin.data.template.DoubleMap)1 FloatArray (com.linkedin.data.template.FloatArray)1 FloatMap (com.linkedin.data.template.FloatMap)1