vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should not delete the model field element because it can not stored deleted
   * model.
   *
   * @param resultHandler     handler to manage the HTTP result.
   * @param searcher          the function used to search a model.
   * @param storerDeleteModel the function to delete the model.
   *
   * @see ModelResources#deleteModelFieldElement( ModelFieldContext, BiConsumer,
   *      java.util.function.Function, java.util.function.BiFunction, BiConsumer,
   *      ServiceContext)
   */
Should not delete the model field element because it can not stored deleted
model.

@param resultHandler     handler to manage the HTTP result.
@param searcher          the function used to search a model.
@param storerDeleteModel the function to delete the model.


Should not delete the model field element because it can not stored deleted model . @param resultHandler handler to manage the HTTP result . @param searcher the function used to search a model . @param storerDeleteModel the function to delete the model .
@Test
  public void shouldNotDeleteModelFieldElementBecauseCanNotStoreDeleted(
      @Mock final Handler<AsyncResult<ServiceResponse>> resultHandler,
      @Mock final BiConsumer<String, Handler<AsyncResult<DummyComplexModel>>> searcher,
      @Mock final BiConsumer<DummyComplexModel, Handler<AsyncResult<Void>>> storerDeleteModel) {
    final var element = this.createModelFieldContextById();
    final var target = new DummyComplexModelTest().createModelExample(2);
    element.id = target.siblings.get(0).id;
    final var context = this.createServiceContext(resultHandler);
    ModelResources.deleteModelFieldElement(element, searcher, dummy -> dummy.siblings,
        ModelResources.searchElementById((dummy, id) -> id != null && id.equals(dummy.id)), storerDeleteModel, context);
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<Handler<AsyncResult<DummyComplexModel>>> searchHandler = ArgumentCaptor
        .forClass(Handler.class);
    verify(searcher, timeout(30000).times(1)).accept(any(), searchHandler.capture());
    searchHandler.getValue().handle(Future.succeededFuture(target));
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<Handler<AsyncResult<Void>>> storerHandler = ArgumentCaptor.forClass(Handler.class);
    verify(storerDeleteModel, timeout(30000).times(1)).accept(any(), storerHandler.capture());
    storerHandler.getValue().handle(Future.failedFuture("Can not store"));
    @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).isNotEqualTo(error.message);
    assertThat(error.message).isEqualTo("Can not store");
  }
@ Test public void shouldNotDeleteModelFieldElementBecauseCanNotStoreDeleted ( @ Mock final Handler < AsyncResult < ServiceResponse > > resultHandler , @ Mock final BiConsumer < String , Handler < AsyncResult < DummyComplexModel > > > searcher , @ Mock final BiConsumer < DummyComplexModel , Handler < AsyncResult < Void > > > storerDeleteModel ) { final var element = this . createModelFieldContextById ( ) ; final var target = new DummyComplexModelTest ( ) . createModelExample ( 2 ) ; element . id = target . siblings . get ( 0 ) . id ; final var context = this . createServiceContext ( resultHandler ) ; ModelResources . deleteModelFieldElement ( element , searcher , dummy -> dummy . siblings , ModelResources . searchElementById ( ( dummy , id ) -> id != null && id . equals ( dummy . id ) ) , storerDeleteModel , context ) ; @ SuppressWarnings ( "unchecked" ) final ArgumentCaptor < Handler < AsyncResult < DummyComplexModel > > > searchHandler = ArgumentCaptor . forClass ( Handler . class ) ; verify ( searcher , timeout ( 30000 ) . times ( 1 ) ) . accept ( any ( ) , searchHandler . capture ( ) ) ; searchHandler . getValue ( ) . handle ( Future . succeededFuture ( target ) ) ; @ SuppressWarnings ( "unchecked" ) final ArgumentCaptor < Handler < AsyncResult < Void > > > storerHandler = ArgumentCaptor . forClass ( Handler . class ) ; verify ( storerDeleteModel , timeout ( 30000 ) . times ( 1 ) ) . accept ( any ( ) , storerHandler . capture ( ) ) ; storerHandler . getValue ( ) . handle ( Future . failedFuture ( "Can not store" ) ) ; @ 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 ) . isNotEqualTo ( error . message ) ; assertThat ( error . message ) . isEqualTo ( "Can not store" ) ; }
Should not delete the model field element because it can not stored deleted
 model.
Should not delete the model field element because it can not stored deleted model .