vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should not obtain page because the search has failed.
   *
   * @param resultHandler handler to manage the HTTP result.
   * @param searcher      the function to obtain the page.
   *
   * @see ModelResources#toModel(JsonObject, ModelContext, ServiceContext,
   *      Runnable)
   */
Should not obtain page because the search has failed.
@param resultHandler handler to manage the HTTP result.
@param searcher      the function to obtain the page.


Should not obtain page because the search has failed . @param resultHandler handler to manage the HTTP result . @param searcher the function to obtain the page .
@Test
  public void shouldNotRetrieveModelsPageWhenSearchFailed(
      @Mock final Handler<AsyncResult<ServiceResponse>> resultHandler,
      @Mock final BiConsumer<ModelsPageContext, Promise<JsonObject>> searcher) {
    final var context = this.createServiceContext(resultHandler);
    ModelResources.retrieveModelsPage(0, 100, searcher, context);
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<Promise<JsonObject>> searchHandler = ArgumentCaptor.forClass(Promise.class);
    verify(searcher, timeout(30000).times(1)).accept(any(), searchHandler.capture());
    searchHandler.getValue().fail("Not found");
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<AsyncResult<ServiceResponse>> resultCaptor = ArgumentCaptor.forClass(AsyncResult.class);
    verify(resultHandler, timeout(30000).times(1)).handle(resultCaptor.capture());
    final var asyncResult = resultCaptor.getValue();
    assertThat(asyncResult.failed()).isFalse();
    final var result = asyncResult.result();
    assertThat(result.getStatusCode()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
    final var error = Model.fromBuffer(result.getPayload(), ErrorMessage.class);
    assertThat(error).isNotNull();
    assertThat(error.code).isNotNull().isNotEqualTo(error.message);
    assertThat(error.message).isNotNull();
  }
@ Test public void shouldNotRetrieveModelsPageWhenSearchFailed ( @ Mock final Handler < AsyncResult < ServiceResponse > > resultHandler , @ Mock final BiConsumer < ModelsPageContext , Promise < JsonObject > > searcher ) { final var context = this . createServiceContext ( resultHandler ) ; ModelResources . retrieveModelsPage ( 0 , 100 , searcher , context ) ; @ SuppressWarnings ( "unchecked" ) final ArgumentCaptor < Promise < JsonObject > > searchHandler = ArgumentCaptor . forClass ( Promise . class ) ; verify ( searcher , timeout ( 30000 ) . times ( 1 ) ) . accept ( any ( ) , searchHandler . capture ( ) ) ; searchHandler . getValue ( ) . fail ( "Not found" ) ; @ SuppressWarnings ( "unchecked" ) final ArgumentCaptor < AsyncResult < ServiceResponse > > resultCaptor = ArgumentCaptor . forClass ( AsyncResult . class ) ; verify ( resultHandler , timeout ( 30000 ) . times ( 1 ) ) . handle ( resultCaptor . capture ( ) ) ; final var asyncResult = resultCaptor . getValue ( ) ; assertThat ( asyncResult . failed ( ) ) . isFalse ( ) ; final var result = asyncResult . result ( ) ; assertThat ( result . getStatusCode ( ) ) . isEqualTo ( Status . BAD_REQUEST . getStatusCode ( ) ) ; final var error = Model . fromBuffer ( result . getPayload ( ) , ErrorMessage . class ) ; assertThat ( error ) . isNotNull ( ) ; assertThat ( error . code ) . isNotNull ( ) . isNotEqualTo ( error . message ) ; assertThat ( error . message ) . isNotNull ( ) ; }
Should not obtain page because the search has failed.
Should not obtain page because the search has failed .