Package com.linkedin.restli.examples.greetings.api

Examples of com.linkedin.restli.examples.greetings.api.Greeting


    Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = batchGetBuilder.ids(1L).build();
    ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future = REST_CLIENT.sendRequest(request);
    Response<BatchKVResponse<Long, EntityResponse<Greeting>>> greetingResponse = future.getResponse();

    // PUT
    Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get(1L).getEntity().data().copy());
    greeting.setMessage("This is a new message!");

    Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
    REST_CLIENT.sendRequest(writeRequest).getResponse();

    // GET again, to verify that our POST worked.
    Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request2 = batchGetBuilder.ids(1L).build();
    ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future2 = REST_CLIENT.sendRequest(request2);
    greetingResponse = future2.get();

    Greeting repeatedGreeting = new Greeting();
    repeatedGreeting.setMessage("Hello Hello");
    repeatedGreeting.setTone(Tone.SINCERE);
    List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);

    Request<BatchCreateIdResponse<Long>> request3 = builders.batchCreate().inputs(entities).build();
    BatchCreateIdResponse<Long> statuses = REST_CLIENT.sendRequest(request3).getResponse().getEntity();
    for (CreateIdStatus<Long> status : statuses.getElements())
View Full Code Here


   *
   * @return the newly generated Greeting
   */
  private Greeting generateTestGreeting(String message, Tone tone)
  {
    return new Greeting().setMessage(message).setTone(tone);
  }
View Full Code Here

        Long id = idsToGet.get(i);
        Request<Greeting> request = builders.get().id(id).build();
        ResponseFuture<Greeting> future = REST_CLIENT.sendRequest(request);
        Response<Greeting> greetingResponse = future.getResponse();

        Greeting fetchedGreeting = greetingResponse.getEntity();

        fetchedGreetings.add(fetchedGreeting);
      }
      catch (RestLiResponseException ex)
      {
View Full Code Here

  {
    List<Greeting> fetchedGreetings = getBatchTestDataSerially(builders, idsToGet);
    Assert.assertEquals(fetchedGreetings.size(), expectedGreetings.size());
    for (int i = 0; i < fetchedGreetings.size(); i++)
    {
      Greeting fetchedGreeting = fetchedGreetings.get(i);
      Greeting expectedGreeting = expectedGreetings.get(i);

      // Make sure the types of the fetched Greeting match the types in the schema. This happens as a side effect of the
      // validate method
      ValidateDataAgainstSchema.validate(fetchedGreeting.data(), fetchedGreeting.schema(), new ValidationOptions());

      if (fieldsToIgnore == null || fieldsToIgnore.isEmpty())
      {
        Assert.assertEquals(fetchedGreeting, expectedGreeting);
      }
      else
      {
        DataMap fetchedDataMap = fetchedGreeting.data();
        DataMap expectedDataMap = expectedGreeting.data();
        for (String field: fetchedDataMap.keySet())
        {
          if (!fieldsToIgnore.contains(field))
          {
            Assert.assertEquals(fetchedDataMap.get(field), expectedDataMap.get(field));
View Full Code Here

    List<Greeting> updatedGreetings = new ArrayList<Greeting>();
    Map<Long, Greeting> updateGreetingsRequestMap = new HashMap<Long, Greeting>();

    for (Greeting greeting: greetings)
    {
      Greeting updatedGreeting = new Greeting(greeting.data().copy());
      updatedGreeting.setMessage(updatedGreeting.getMessage().toUpperCase());
      updatedGreeting.setTone(Tone.SINCERE);
      updatedGreetings.add(updatedGreeting);
      updateGreetingsRequestMap.put(updatedGreeting.getId(), updatedGreeting);
    }

    // Batch update
    Request<BatchKVResponse<Long, UpdateStatus>> batchUpdateRequest =
        builders.batchUpdate().inputs(updateGreetingsRequestMap).build();
View Full Code Here

    Map<Long, PatchRequest<Greeting>> patchedGreetingsDiffs = new HashMap<Long, PatchRequest<Greeting>>();
    List<Greeting> patchedGreetings = new ArrayList<Greeting>();

    for (Greeting greeting: greetings)
    {
      Greeting patchedGreeting = new Greeting(greeting.data().copy());
      patchedGreeting.setMessage(patchedGreeting.getMessage().toUpperCase());

      PatchRequest<Greeting> patchRequest = PatchGenerator.diff(greeting, patchedGreeting);
      patchedGreetingsDiffs.put(patchedGreeting.getId(), patchRequest);
      patchedGreetings.add(patchedGreeting);
    }

    // Batch patch
    Request<BatchKVResponse<Long, UpdateStatus>> batchUpdateRequest =
View Full Code Here

        .pagingFields(CollectionMetadata.fields().total(), CollectionMetadata.fields().count(),
                      CollectionMetadata.fields().links())
        .build();

    final Response<CollectionResponse<Greeting>> response = REST_CLIENT.sendRequest(request).getResponse();
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    assertGreeting(metadataGreeting, false /*hasTone*/, true /*hasMessage*/, true /*hasID*/);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertPaging(response.getEntity().getPaging(), true /*hasTotal*/, false /*hasStart*/, true /*hasCount*/, true /*hasLinks*/);
    final int totalCount = response.getEntity().getPaging().getTotal();
    Assert.assertEquals(totalCount, 2, "We must have 2 in our count");
View Full Code Here

    return new CollectionResult<Greeting, Greeting>(LIST, 2, null);
  }

  private List<Greeting> applyRootObjectProjection(final MaskTree rootObjectProjection) throws CloneNotSupportedException
  {
    final Greeting clonedGreetingOne = GREETING_ONE.clone();
    final Greeting clonedGreetingTwo = GREETING_TWO.clone();
    if (rootObjectProjection != null && rootObjectProjection.getOperations().size() == 1 &&
        rootObjectProjection.getOperations().get(Greeting.fields().message()) == MaskOperation.POSITIVE_MASK_OP)
    {
      clonedGreetingOne.removeId();
      clonedGreetingTwo.removeId();
      //Note that technically the correct behavior here would be to remove not only the ID, but also the tone.
      //However since we are testing to make sure that manual root object projection works as intended, we will
      //intentionally apply an incorrect projection by hand to verify restli doesn't interfere with it.
    }
    return ImmutableList.of(clonedGreetingOne, clonedGreetingTwo);
View Full Code Here

    return ImmutableList.of(clonedGreetingOne, clonedGreetingTwo);
  }

  private Greeting applyMetadataProjection(final MaskTree metadataProjection) throws CloneNotSupportedException
  {
    final Greeting clonedGreeting = CUSTOM_METADATA_GREETING.clone();
    if (metadataProjection != null && metadataProjection.getOperations().size() == 1 &&
        metadataProjection.getOperations().get(Greeting.fields().message()) == MaskOperation.POSITIVE_MASK_OP)
    {
      clonedGreeting.removeId();
      //Note that technically the correct behavior here would be to remove not only the ID, but also the tone.
      //However since we are testing to make sure that manual custom metadata projection works as intended, we will
      //intentionally apply an incorrect projection by hand to verify restli doesn't interfere with it.
    }
    return clonedGreeting;
View Full Code Here

{

  @Override
  public Greeting get(CustomLong lo)
  {
    return new Greeting().setId(lo.toLong());
  }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.examples.greetings.api.Greeting

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.