Ejemplo n.º 1
0
  @Test(dataProvider = "annotatedRequestHandlerData")
  public void testReadCollectionItemAnnotatedRequestHandler(
      Class<?> requestHandler,
      boolean collection,
      boolean create,
      boolean read,
      boolean update,
      boolean delete,
      boolean patch,
      boolean resourceAction,
      boolean collectionAction,
      boolean query)
      throws Exception {

    // Given
    Object provider = requestHandler.newInstance();
    Connection connection = Resources.newInternalConnection(createHandler(collection, provider));
    ReadRequest req = Requests.newReadRequest("/test/fred");

    // When
    Promise<Resource, ResourceException> promise = connection.readAsync(new RootContext(), req);

    // Then
    if (read && collection) {
      assertThat(promise).succeeded().withId().isEqualTo("read-fred");
    } else if (collection) {
      assertThat(promise).failedWithException().isInstanceOf(NotSupportedException.class);
    } else {
      assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
    }
  }
Ejemplo n.º 2
0
 @SuppressWarnings("unchecked")
 @Test(dataProvider = "testCollectionResourceProviderData")
 public void testCollectionResourceProvider(String resourcePath, String expectedId)
     throws Exception {
   CollectionResourceProvider collection = mock(CollectionResourceProvider.class);
   RequestHandler handler = Resources.newCollection(collection);
   Connection connection = Resources.newInternalConnection(handler);
   ReadRequest read = Requests.newReadRequest(resourcePath);
   connection.readAsync(new RootContext(), read);
   ArgumentCaptor<ReadRequest> captor = ArgumentCaptor.forClass(ReadRequest.class);
   verify(collection).readInstance(any(ServerContext.class), eq(expectedId), captor.capture());
   Assertions.assertThat(captor.getValue().getResourcePath()).isEqualTo("");
 }