vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should update a model.
   *
   * @param resultHandler handler to manage the HTTP result.
   * @param searcher      the function used to search a model.
   * @param updater       the function used to update a model.
   *
   * @see ModelResources#updateModel( JsonObject, ModelContext, BiConsumer,
   *      BiConsumer, ServiceContext)
   */
Should update a model.
@param resultHandler handler to manage the HTTP result.
@param searcher      the function used to search a model.
@param updater       the function used to update a model.


Should update a model . @param resultHandler handler to manage the HTTP result . @param searcher the function used to search a model . @param updater the function used to update a model .
@Test
  public void shouldUpdateModel(@Mock final Handler<AsyncResult<ServiceResponse>> resultHandler,
      @Mock final BiConsumer<String, Handler<AsyncResult<DummyComplexModel>>> searcher,
      @Mock final BiConsumer<DummyComplexModel, Handler<AsyncResult<Void>>> updater) {
    final var model = this.createModelContext();
    final var context = this.createServiceContext(resultHandler);
    final var source = new DummyComplexModelTest().createModelExample(2);
    final var value = source.toJsonObject();
    ModelResources.updateModel(value, model, searcher, updater, context);
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<Handler<AsyncResult<DummyComplexModel>>> storeCaptor = ArgumentCaptor.forClass(Handler.class);
    verify(searcher, timeout(30000).times(1)).accept(any(), storeCaptor.capture());
    final var target = new DummyComplexModelTest().createModelExample(1);
    storeCaptor.getValue().handle(Future.succeededFuture(target));
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<Handler<AsyncResult<Void>>> updateCaptor = ArgumentCaptor.forClass(Handler.class);
    verify(updater, timeout(30000).times(1)).accept(any(), updateCaptor.capture());
    updateCaptor.getValue().handle(Future.succeededFuture());
    @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.OK.getStatusCode());
    final var updated = Model.fromBuffer(result.getPayload(), DummyComplexModel.class);
    assertThat(updated).isNotNull().isNotEqualTo(source).isNotEqualTo(target);
    target.index = source.index;
    target.siblings = source.siblings;
    assertThat(updated).isEqualTo(target);
  }
@ Test public void shouldUpdateModel ( @ Mock final Handler < AsyncResult < ServiceResponse > > resultHandler , @ Mock final BiConsumer < String , Handler < AsyncResult < DummyComplexModel > > > searcher , @ Mock final BiConsumer < DummyComplexModel , Handler < AsyncResult < Void > > > updater ) { final var model = this . createModelContext ( ) ; final var context = this . createServiceContext ( resultHandler ) ; final var source = new DummyComplexModelTest ( ) . createModelExample ( 2 ) ; final var value = source . toJsonObject ( ) ; ModelResources . updateModel ( value , model , searcher , updater , context ) ; @ SuppressWarnings ( "unchecked" ) final ArgumentCaptor < Handler < AsyncResult < DummyComplexModel > > > storeCaptor = ArgumentCaptor . forClass ( Handler . class ) ; verify ( searcher , timeout ( 30000 ) . times ( 1 ) ) . accept ( any ( ) , storeCaptor . capture ( ) ) ; final var target = new DummyComplexModelTest ( ) . createModelExample ( 1 ) ; storeCaptor . getValue ( ) . handle ( Future . succeededFuture ( target ) ) ; @ SuppressWarnings ( "unchecked" ) final ArgumentCaptor < Handler < AsyncResult < Void > > > updateCaptor = ArgumentCaptor . forClass ( Handler . class ) ; verify ( updater , timeout ( 30000 ) . times ( 1 ) ) . accept ( any ( ) , updateCaptor . capture ( ) ) ; updateCaptor . getValue ( ) . handle ( Future . succeededFuture ( ) ) ; @ 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 . OK . getStatusCode ( ) ) ; final var updated = Model . fromBuffer ( result . getPayload ( ) , DummyComplexModel . class ) ; assertThat ( updated ) . isNotNull ( ) . isNotEqualTo ( source ) . isNotEqualTo ( target ) ; target . index = source . index ; target . siblings = source . siblings ; assertThat ( updated ) . isEqualTo ( target ) ; }
Should update a model.
Should update a model .