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

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


  public GreetingsResourceImpl(String resourceName)
  {
    for (int i = 0; i < INITIAL_SIZE; i++)
    {
      Greeting g =
          new Greeting().setId(_idSeq.incrementAndGet())
                        .setMessage(INITIAL_MESSAGES[i])
                        .setTone(INITIAL_TONES[i]);
      _db.put(g.getId(), g);
    }
    _resourceName = resourceName;
  }
View Full Code Here


  {
    Map<Long, Greeting> batch = new HashMap<Long, Greeting>();
    Map<Long, RestLiServiceException> errors = new HashMap<Long, RestLiServiceException>();
    for (long id : ids)
    {
      Greeting g = _db.get(id);
      if (g != null)
      {
        batch.put(id, g);
      }
      else
View Full Code Here

  }

  @RestMethod.PartialUpdate
  public UpdateResponse update(Long key, PatchRequest<Greeting> patch)
  {
    Greeting g = _db.get(key);
    if (g == null)
    {
      return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request2BuilderDataProvider")
  public void testCollectionGet(RootBuilderWrapper<CustomLong, Greeting> builders) throws RemoteInvocationException
  {
    Long lo = 5L;
    Request<Greeting> request = builders.get().id(new CustomLong(lo)).build();
    Greeting result = REST_CLIENT.sendRequest(request).getResponse().getEntity();

    Assert.assertEquals(result.getId(), lo);
  }
View Full Code Here

  }

  @RestMethod.Update
  public UpdateResponse update(Long key, Greeting entity)
  {
    Greeting g = _db.get(key);
    if (g == null)
    {
      return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
View Full Code Here

  }

  private Greeting createGreeting()
  {
    return
      new Greeting().setId(_idSeq.incrementAndGet())
                    .setMessage("This is a newly created greeting")
                    .setTone(DEFAULT_TONE);
  }
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "request2BuilderDataProvider")
  public void testCollectionBatchUpdate(RootBuilderWrapper<CustomLong, Greeting> builders) throws RemoteInvocationException
  {
    RequestBuilder<? extends Request<BatchKVResponse<CustomLong, UpdateStatus>>> request =
      builders.batchUpdate().input(new CustomLong(1L), new Greeting().setId(1)).input(new CustomLong(2L), new Greeting().setId(2)).getBuilder();
    Map<CustomLong, UpdateStatus> statuses = REST_CLIENT.sendRequest(request).getResponse().getEntity().getResults();

    Assert.assertEquals(statuses.size(), 2);
    Assert.assertEquals(statuses.get(new CustomLong(1L)).getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
    Assert.assertEquals(statuses.get(new CustomLong(2L)).getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
View Full Code Here

  }

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
  public void testCollectionCreate(RestliRequestOptions requestOptions) throws RemoteInvocationException
  {
    CreateRequest<Greeting> request = new CustomTypes2Builders(requestOptions).create().input(new Greeting().setId(10)).build();
    Response<EmptyRecord> response = REST_CLIENT.sendRequest(request).getResponse();

    Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());

    @SuppressWarnings("unchecked")
View Full Code Here

                             @ActionParam("newTone") @Optional Tone newTone,
                             @ActionParam("delOld") @Optional("false") Boolean delOld)
  {
    // the way to get entity key in action
    Long key = resource.getContext().getPathKeys().get(_resourceName + "Id");
    Greeting g = _db.get(key);
    if (g == null)
    {
      // HTTP 404
      return g;
    }

    // delete existing Greeting and assign new key
    if (delOld)
    {
      _db.remove(key);
      key = _idSeq.incrementAndGet();
      g.setId(key);
    }

    Tone t;
    // newTone is an optional parameter
    // omitting it in request results a null value
    if (newTone == null)
    {
      t = DEFAULT_TONE;
    }
    else
    {
      t = newTone;
    }
    g.setTone(t);
    _db.put(key, g);

    return g;
  }
View Full Code Here

  }

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
  public void testCollectionCreateId(RestliRequestOptions requestOptions) throws RemoteInvocationException
  {
    CreateIdRequest<CustomLong, Greeting> request = new CustomTypes2RequestBuilders(requestOptions).create().input(new Greeting().setId(10)).build();
    Response<IdResponse<CustomLong>> response = REST_CLIENT.sendRequest(request).getResponse();

    Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
    Assert.assertEquals(response.getEntity().getId(), new CustomLong(10L));
  }
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.