Search in sources :

Example 1 with RecordTemplateWithPrimitiveKey

use of com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey in project rest.li by linkedin.

the class TestKeyValueRecord method testComplex.

@Test
@SuppressWarnings("rawtypes")
public void testComplex() {
    KeyValueRecordFactory<ComplexResourceKey, RecordTemplateWithPrimitiveKey> factory = new KeyValueRecordFactory<>(ComplexResourceKey.class, MyComplexKey.class, MyComplexKey.class, null, RecordTemplateWithPrimitiveKey.class);
    MyComplexKey key = new MyComplexKey().setA("key").setB(1L);
    MyComplexKey params = new MyComplexKey().setA("params").setB(2L);
    ComplexResourceKey<MyComplexKey, MyComplexKey> complexKey = new ComplexResourceKey<>(key, params);
    RecordTemplateWithPrimitiveKey mockRecord = new RecordTemplateWithPrimitiveKey().setId(1L).setBody("foo");
    KeyValueRecord<ComplexResourceKey, RecordTemplateWithPrimitiveKey> keyValueRecord = factory.create(complexKey, mockRecord);
    Assert.assertEquals(keyValueRecord.getComplexKey(MyComplexKey.class, MyComplexKey.class), complexKey);
    Assert.assertEquals(keyValueRecord.getValue(RecordTemplateWithPrimitiveKey.class), mockRecord);
}
Also used : RecordTemplateWithPrimitiveKey(com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) Test(org.testng.annotations.Test)

Example 2 with RecordTemplateWithPrimitiveKey

use of com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey in project rest.li by linkedin.

the class TestKeyValueRecord method testCompoundKey.

private void testCompoundKey(CompoundKey compoundKey, Map<String, CompoundKey.TypeInfo> fieldTypes) {
    RecordTemplateWithPrimitiveKey mockRecord = new RecordTemplateWithPrimitiveKey().setId(7L).setBody("foo");
    KeyValueRecordFactory<CompoundKey, RecordTemplateWithPrimitiveKey> factory = new KeyValueRecordFactory<>(CompoundKey.class, null, null, fieldTypes, RecordTemplateWithPrimitiveKey.class);
    KeyValueRecord<CompoundKey, RecordTemplateWithPrimitiveKey> keyValueRecord = factory.create(compoundKey, mockRecord);
    Assert.assertEquals(keyValueRecord.getCompoundKey(fieldTypes), compoundKey);
    Assert.assertEquals(keyValueRecord.getValue(RecordTemplateWithPrimitiveKey.class), mockRecord);
}
Also used : RecordTemplateWithPrimitiveKey(com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey)

Example 3 with RecordTemplateWithPrimitiveKey

use of com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey in project rest.li by linkedin.

the class TestKeyValueRecord method testPrimitive.

@Test
public void testPrimitive() {
    KeyValueRecordFactory<Long, RecordTemplateWithPrimitiveKey> factory = new KeyValueRecordFactory<>(Long.class, null, null, null, RecordTemplateWithPrimitiveKey.class);
    Long id = 1L;
    RecordTemplateWithPrimitiveKey mockRecordTemplate = new RecordTemplateWithPrimitiveKey();
    mockRecordTemplate.setId(id).setBody("foo");
    KeyValueRecord<Long, RecordTemplateWithPrimitiveKey> keyValueRecord = factory.create(id, mockRecordTemplate);
    Assert.assertEquals(keyValueRecord.getPrimitiveKey(Long.class), id);
    Assert.assertEquals(keyValueRecord.getValue(RecordTemplateWithPrimitiveKey.class), mockRecordTemplate);
}
Also used : RecordTemplateWithPrimitiveKey(com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey) Test(org.testng.annotations.Test)

Example 4 with RecordTemplateWithPrimitiveKey

use of com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey in project rest.li by linkedin.

the class TestKeyValueRecord method testTyperefToCustomType.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTyperefToCustomType() {
    KeyValueRecordFactory factory = new KeyValueRecordFactory(MyCustomStringRef.class, null, null, null, RecordTemplateWithPrimitiveKey.class);
    MyCustomString id = new MyCustomString("1");
    RecordTemplateWithPrimitiveKey mockRecord = new RecordTemplateWithPrimitiveKey().setId(1L).setBody("foo");
    KeyValueRecord keyValueRecord = factory.create(id, mockRecord);
    Assert.assertEquals(keyValueRecord.getPrimitiveKey(MyCustomStringRef.class), id);
    Assert.assertEquals(keyValueRecord.getValue(RecordTemplateWithPrimitiveKey.class), mockRecord);
}
Also used : RecordTemplateWithPrimitiveKey(com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey) MyCustomStringRef(com.linkedin.restli.common.test.MyCustomStringRef) Test(org.testng.annotations.Test)

Example 5 with RecordTemplateWithPrimitiveKey

use of com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey in project rest.li by linkedin.

the class TestKeyValueRecord method testEnum.

@Test
public void testEnum() {
    KeyValueRecordFactory<SimpleEnum, RecordTemplateWithPrimitiveKey> factory = new KeyValueRecordFactory<>(SimpleEnum.class, null, null, null, RecordTemplateWithPrimitiveKey.class);
    SimpleEnum id = SimpleEnum.A;
    RecordTemplateWithPrimitiveKey mockRecordTemplate = new RecordTemplateWithPrimitiveKey();
    mockRecordTemplate.setId(1L).setBody("foo");
    KeyValueRecord<SimpleEnum, RecordTemplateWithPrimitiveKey> keyValueRecord = factory.create(id, mockRecordTemplate);
    Assert.assertEquals(keyValueRecord.getPrimitiveKey(SimpleEnum.class), id);
    Assert.assertEquals(keyValueRecord.getValue(RecordTemplateWithPrimitiveKey.class), mockRecordTemplate);
}
Also used : RecordTemplateWithPrimitiveKey(com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey) SimpleEnum(com.linkedin.restli.common.test.SimpleEnum) Test(org.testng.annotations.Test)

Aggregations

RecordTemplateWithPrimitiveKey (com.linkedin.restli.common.test.RecordTemplateWithPrimitiveKey)5 Test (org.testng.annotations.Test)4 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)1 MyCustomStringRef (com.linkedin.restli.common.test.MyCustomStringRef)1 SimpleEnum (com.linkedin.restli.common.test.SimpleEnum)1