use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestClientBuilders method testBatchGetCompoundKeyRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchGetWithEncoding")
public void testBatchGetCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
BatchGetRequestBuilder<CompoundKey, TestRecord> builder = new BatchGetRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
CompoundKey key1 = new CompoundKey();
key1.append("equals", "=");
key1.append("ampersand", "&");
CompoundKey key2 = new CompoundKey();
key2.append("equals", "==");
key2.append("ampersand", "&&");
BatchGetKVRequest<CompoundKey, TestRecord> request = builder.ids(key1, key2).fields(TestRecord.fields().id(), TestRecord.fields().message()).buildKV();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
// Compare key sets. Note that have to convert keys to Strings as the request internally converts them to string
HashSet<CompoundKey> expectedIds = new HashSet<CompoundKey>(Arrays.asList(key1, key2));
Assert.assertEquals(request.getObjectIds(), expectedIds);
Assert.assertEquals(request.getFields(), new HashSet<PathSpec>(Arrays.asList(TestRecord.fields().id(), TestRecord.fields().message())));
Assert.assertEquals(request.isSafe(), true);
Assert.assertEquals(request.isIdempotent(), true);
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_GET, null, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestClientBuilders method checkRequestIsReadOnly.
@SuppressWarnings("unchecked")
private void checkRequestIsReadOnly(final Request<?> request) {
final Set<PathSpec> fields = request.getFields();
if (fields != null) {
checkReadOnlyOperation(new Runnable() {
@Override
public void run() {
fields.add(new PathSpec("abc"));
}
});
}
checkReadOnlyOperation(new Runnable() {
@Override
public void run() {
request.getHeaders().put("abc", "abc");
}
});
final RecordTemplate input = request.getInputRecord();
if (input != null) {
checkReadOnlyOperation(new Runnable() {
@Override
public void run() {
input.data().put("abc", "abc");
}
});
}
final Map<String, Object> pathKeys = request.getPathKeys();
if (pathKeys != null) {
checkReadOnlyOperation(new Runnable() {
@Override
public void run() {
pathKeys.put("abc", "abc");
}
});
final List<Object> keysToEdit = new ArrayList<Object>();
for (Object key : pathKeys.values()) {
if (key instanceof CompoundKey || key instanceof ComplexResourceKey) {
keysToEdit.add(key);
} else {
Assert.assertTrue(isPrimitiveOrEnum(key));
}
}
for (final Object keytoEdit : keysToEdit) {
checkReadOnlyOperation(new Runnable() {
@Override
public void run() {
if (keytoEdit instanceof ComplexResourceKey) {
((ComplexResourceKey) keytoEdit).getKey().data().put("abc", "abc");
} else if (keytoEdit instanceof CompoundKey) {
((CompoundKey) keytoEdit).append("abc", "abc");
}
}
});
}
Collection<Object> queryParamObjects = request.getQueryParamsObjects().values();
List<Object> readOnlyTargets = new ArrayList<Object>();
for (Object queryParamObject : queryParamObjects) {
collectReadOnlyQueryParamObjectTargets(queryParamObject, readOnlyTargets);
}
for (final Object readOnlyTarget : readOnlyTargets) {
checkReadOnlyOperation(new Runnable() {
@Override
public void run() {
if (readOnlyTarget instanceof DataTemplate) {
Object data = ((DataTemplate) readOnlyTarget).data();
if (data instanceof DataMap) {
((DataMap) data).put("abc", "abc");
} else if (data instanceof DataList) {
((DataList) data).add("abc");
}
} else if (readOnlyTarget instanceof CompoundKey) {
((CompoundKey) readOnlyTarget).append("abc", "abc");
} else if (readOnlyTarget instanceof ComplexResourceKey) {
((ComplexResourceKey) readOnlyTarget).getKey().data().put("abc", "abc");
} else if (readOnlyTarget instanceof List) {
((List<Object>) readOnlyTarget).add("abc");
}
}
});
}
}
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPathSpec method testUnionPathSpec.
@Test
public void testUnionPathSpec() {
PathSpec p = UnionTest.fields().unionWithInline().RecordInUnion().a();
Assert.assertEquals(p.toString(), "/unionWithInline/com.linkedin.pegasus.generator.test.RecordInUnion/a");
p = UnionTest.fields().unionWithoutNull().RecordBar().location();
Assert.assertEquals(p.toString(), "/unionWithoutNull/com.linkedin.pegasus.generator.test.RecordBar/location");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPathSpec method testSelfReferencePathSpec.
@Test
public void testSelfReferencePathSpec() {
PathSpec p = AliasTest.fields().a1().a1().a1().a1();
Assert.assertEquals(p.toString(), "/a1/a1/a1/a1");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPathSpec method testTyperefPathSpec.
@Test
public void testTyperefPathSpec() {
PathSpec p = TyperefTest.fields().bar1().location();
Assert.assertEquals(p.toString(), "/bar1/location");
p = TyperefTest.fields().barRefMap().values().location();
Assert.assertEquals(p.toString(), "/barRefMap/*/location");
}
Aggregations