use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestEscapeCharsInStringKeys method testFinderWithStringParam.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestStringKeysBuilderDataProvider")
public void testFinderWithStringParam(RootBuilderWrapper<String, Message> builders) throws Exception {
Request<CollectionResponse<Message>> request = builders.findBy("Search").setQueryParam("keyword", key1()).build();
CollectionResponse<Message> response = getClient().sendRequest(request).get().getEntity();
List<Message> hits = response.getElements();
Assert.assertEquals(hits.size(), 1);
Message hit = hits.get(0);
Assert.assertEquals(hit.getMessage(), key1(), "Message of matching result should be key1");
}
use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestEscapeCharsInStringKeys method testBatchGetEntityWithSimpleKey.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestStringKeysOptionsDataProvider")
public void testBatchGetEntityWithSimpleKey(RestliRequestOptions requestOptions) throws Exception {
Set<String> keys = new HashSet<String>();
keys.add(key1());
keys.add(key2());
Request<BatchKVResponse<String, EntityResponse<Message>>> req = new StringKeysRequestBuilders(requestOptions).batchGet().ids(keys).build();
BatchKVResponse<String, EntityResponse<Message>> response = getClient().sendRequest(req).get().getEntity();
Map<String, EntityResponse<Message>> results = response.getResults();
Assert.assertEquals(results.get(key1()).getEntity().getMessage(), key1(), "Message should match key for key1");
Assert.assertEquals(results.get(key2()).getEntity().getMessage(), key2(), "Message should match key for key2");
}
use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestTyperefCustomDoubleAssociationKeyResource method testGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
HashMap<String, CompoundKey.TypeInfo> keyParts = new HashMap<String, CompoundKey.TypeInfo>();
keyParts.put("src", new CompoundKey.TypeInfo(Double.class, Double.class));
keyParts.put("dest", new CompoundKey.TypeInfo(Double.class, Double.class));
GetRequestBuilder<CompoundKey, Message> getBuilder = new GetRequestBuilder<CompoundKey, Message>("typerefCustomDoubleAssociationKeyResource", Message.class, new ResourceSpecImpl(EnumSet.of(ResourceMethod.GET), new HashMap<String, DynamicRecordMetadata>(), new HashMap<String, DynamicRecordMetadata>(), CompoundKey.class, null, null, Message.class, keyParts), requestOptions);
final String[] stringArray = { "foo" };
GetRequest<Message> req = getBuilder.id(new CompoundKey().append("src", 100.0).append("dest", 200.0)).setReqParam("array", stringArray).build();
Response<Message> resp = REST_CLIENT.sendRequest(req).getResponse();
Message result = resp.getEntity();
Assert.assertEquals(result.getId(), "100.0->200.0");
Assert.assertEquals(result.getMessage(), String.format("I need some $20. Array contents %s.", Arrays.asList(stringArray)));
}
use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestActionsResource method testArrayTypesOnActions.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testArrayTypesOnActions(RootBuilderWrapper<?, ?> builders) throws RemoteInvocationException {
//Record template array
MessageArray inputMessageArray = new MessageArray();
inputMessageArray.add(new Message().setId("My Message Id").setMessage("My Message"));
inputMessageArray.add(new Message().setId("My Message Id 2").setMessage("My Message 2"));
Request<MessageArray> messageArrayRequest = builders.<MessageArray>action("EchoMessageArray").setActionParam("Messages", inputMessageArray).build();
MessageArray messageArray = getClient().sendRequest(messageArrayRequest).getResponse().getEntity();
Assert.assertEquals(messageArray.get(0).getId(), "My Message Id");
Assert.assertEquals(messageArray.get(0).getMessage(), "My Message");
Assert.assertEquals(messageArray.get(1).getId(), "My Message Id 2");
Assert.assertEquals(messageArray.get(1).getMessage(), "My Message 2");
//Primitive type array
StringArray inputStringArray = new StringArray();
inputStringArray.add("message1");
inputStringArray.add("message2");
Request<StringArray> stringArrayRequest = builders.<StringArray>action("EchoStringArray").setActionParam("Strings", inputStringArray).build();
StringArray stringArray = getClient().sendRequest(stringArrayRequest).getResponse().getEntity();
Assert.assertEquals(stringArray.get(0), "message1");
Assert.assertEquals(stringArray.get(1), "message2");
//Enum array
ToneArray inputTonesArray = new ToneArray();
inputTonesArray.add(Tone.SINCERE);
inputTonesArray.add(Tone.FRIENDLY);
Request<ToneArray> toneArrayRequest = builders.<ToneArray>action("EchoToneArray").setActionParam("Tones", inputTonesArray).build();
ToneArray tones = getClient().sendRequest(toneArrayRequest).getResponse().getEntity();
Assert.assertEquals(tones.get(0), Tone.SINCERE);
Assert.assertEquals(tones.get(1), Tone.FRIENDLY);
}
use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestAssociationsResource method testSubresourceFinder.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubresourceFinder(RootBuilderWrapper<String, Message> builders) throws RemoteInvocationException {
Request<CollectionResponse<Message>> request = builders.findBy("Tone").setPathKey("dest", "dest").setPathKey("src", "src").setQueryParam("tone", Tone.FRIENDLY).build();
List<Message> messages = getClient().sendRequest(request).getResponse().getEntity().getElements();
for (Message message : messages) {
Assert.assertEquals(message.getTone(), Tone.FRIENDLY);
}
}
Aggregations