Search in sources :

Example 1 with IntegerArray

use of com.linkedin.data.template.IntegerArray in project rest.li by linkedin.

the class ArrayGeneratorTest method testWithPrimitivesArray.

@Test
public void testWithPrimitivesArray() throws Throwable {
    String json = load("WithPrimitivesArray.json");
    WithPrimitivesArray original = new WithPrimitivesArray().setInts(new IntegerArray(Arrays.asList(1, 2, 3))).setLongs(new LongArray(10L, 20L, 30L)).setFloats(new FloatArray(1.1f, 2.2f, 3.3f)).setDoubles(new DoubleArray(11.1d, 22.2d, 33.3d)).setBooleans(new BooleanArray(false, true)).setStrings(new StringArray("a", "b", "c")).setBytes(new BytesArray(SchemaFixtures.bytes1, SchemaFixtures.bytes2));
    assertJson(original, json);
    WithPrimitivesArray roundTripped = new WithPrimitivesArray(roundTrip(original.data()));
    assertJson(roundTripped, json);
}
Also used : LongArray(com.linkedin.data.template.LongArray) BytesArray(com.linkedin.data.template.BytesArray) FloatArray(com.linkedin.data.template.FloatArray) StringArray(com.linkedin.data.template.StringArray) WithPrimitivesArray(com.linkedin.pegasus.generator.test.idl.arrays.WithPrimitivesArray) DoubleArray(com.linkedin.data.template.DoubleArray) IntegerArray(com.linkedin.data.template.IntegerArray) BooleanArray(com.linkedin.data.template.BooleanArray) Test(org.testng.annotations.Test)

Example 2 with IntegerArray

use of com.linkedin.data.template.IntegerArray in project rest.li by linkedin.

the class RecordGeneratorTest method testWithComplexTypes.

@Test
public void testWithComplexTypes() throws Throwable {
    Simple simple = new Simple();
    simple.setMessage("message");
    IntegerMap intMap = new IntegerMap();
    intMap.put("a", 1);
    SimpleMap simpleMap = new SimpleMap();
    simpleMap.put("a", simple);
    WithComplexTypes original = new WithComplexTypes().setRecord(simple).setEnum(Fruits.APPLE).setUnion(WithComplexTypes.Union.create(1)).setArray(new IntegerArray(Collections.singletonList(1))).setMap(intMap).setComplexMap(simpleMap).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 IntegerArray

use of com.linkedin.data.template.IntegerArray in project rest.li by linkedin.

the class TestClientBuilders method testBuilderParam.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "builderParam")
public void testBuilderParam(URIDetails expectedURIDetails) {
    final GetRequestBuilder<Long, TestRecord> builder = new GetRequestBuilder<>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    final Collection<Integer> coll = Arrays.asList(3, 4, 5);
    final IntegerArray array = new IntegerArray(coll);
    final GetRequest<TestRecord> request = builder.id(1L).setReqParam("simpleKey", 2).setParam("arrayKey1", coll).setParam("arrayKey2", array).build();
    URIDetails.testUriGeneration(request, expectedURIDetails);
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Example 4 with IntegerArray

use of com.linkedin.data.template.IntegerArray in project rest.li by linkedin.

the class TestGroupsClient method testSimpleArrayParameter.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProvider")
public void testSimpleArrayParameter(RootBuilderWrapper<Integer, Group> groupBuilders) throws RemoteInvocationException {
    final Collection<Integer> coll = Arrays.asList(1, 2, 3);
    final IntegerArray array = new IntegerArray(coll);
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").setQueryParam("coercedArray", coll).build()).getResponse();
    getClient().sendRequest(groupBuilders.findBy("ComplexCircuit").setQueryParam("coercedArray", array).build()).getResponse();
}
Also used : IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Example 5 with IntegerArray

use of com.linkedin.data.template.IntegerArray 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("Hello", "World"));
    Assert.assertSame(result.getClass(), StringArray.class);
    result = test("[false, true]", BooleanArray.class);
    Assert.assertEquals(result, new BooleanArray(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(2L, 3L, 4L));
    Assert.assertSame(result.getClass(), LongArray.class);
    result = test("[1.1, 2.2, 3.3]", FloatArray.class);
    Assert.assertEquals(result, new FloatArray(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(2.2D, 3.3D, 4.4D));
    Assert.assertSame(result.getClass(), DoubleArray.class);
    result = test("[\"APPLE\", \"BANANA\"]", EnumFruitsArray.class);
    Assert.assertEquals(result, new EnumFruitsArray(EnumFruits.APPLE, EnumFruits.BANANA));
    Assert.assertSame(result.getClass(), EnumFruitsArray.class);
    result = test("[" + _bytes16Quoted + ", " + _bytes16Quoted + "]", BytesArray.class);
    Assert.assertEquals(result, new BytesArray(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(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 = ArrayTest.UnionArray.create("String in union");
    final ArrayTest.UnionArray fixture2 = ArrayTest.UnionArray.create(1);
    Assert.assertEquals(result, new ArrayTest.UnionArrayArray(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(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)

Aggregations

IntegerArray (com.linkedin.data.template.IntegerArray)11 Test (org.testng.annotations.Test)10 DoubleArray (com.linkedin.data.template.DoubleArray)3 IntegerMap (com.linkedin.data.template.IntegerMap)3 Simple (com.linkedin.pegasus.generator.test.idl.records.Simple)3 CustomInt (com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt)3 BooleanArray (com.linkedin.data.template.BooleanArray)2 BytesArray (com.linkedin.data.template.BytesArray)2 FloatArray (com.linkedin.data.template.FloatArray)2 LongArray (com.linkedin.data.template.LongArray)2 StringArray (com.linkedin.data.template.StringArray)2 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)1 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 StringMap (com.linkedin.data.template.StringMap)1 TestDataTemplateUtil (com.linkedin.data.template.TestDataTemplateUtil)1 ArrayTest (com.linkedin.pegasus.generator.test.ArrayTest)1 EnumFruitsArray (com.linkedin.pegasus.generator.test.EnumFruitsArray)1 FixedMD5 (com.linkedin.pegasus.generator.test.FixedMD5)1