vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should create model field element when field is {@code null}.
   *
   * @param resultHandler     handler to manage the HTTP result.
   * @param searcher          the function used to search a model.
   * @param storerCreateModel the function to create the model.
   *
   * @see ModelResources#createModelFieldElement( JsonObject, ModelFieldContext,
   *      BiConsumer, java.util.function.Function, BiConsumer, BiConsumer,
   *      ServiceContext)
   */
Should create model field element when field is  null.
@param resultHandler     handler to manage the HTTP result.
@param searcher          the function used to search a model.
@param storerCreateModel the function to create the model.


Should create model field element when field is null . @param resultHandler handler to manage the HTTP result . @param searcher the function used to search a model . @param storerCreateModel the function to create the model .
@Test
  public void shouldCreateModelFieldElementWhenFieldIsNull(
      @Mock final Handler<AsyncResult<ServiceResponse>> resultHandler,
      @Mock final BiConsumer<String, Handler<AsyncResult<DummyComplexModel>>> searcher,
      @Mock final BiConsumer<DummyComplexModel, Handler<AsyncResult<Void>>> storerCreateModel) {
    final var element = this.createModelFieldContextById();
    final var target = new DummyComplexModelTest().createModelExample(1);
    element.model.id = target.id;
    final var context = this.createServiceContext(resultHandler);
    final var source = new DummyComplexModel();
    final var valueToCreate = source.toJsonObject();
    ModelResources.createModelFieldElement(valueToCreate, element, searcher, dummy -> dummy.siblings,
        (dummy, siblings) -> dummy.siblings = siblings, storerCreateModel, 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(storerCreateModel, timeout(30000).times(1)).accept(any(), storerHandler.capture());
    storerHandler.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 retrieveModel = Model.fromBuffer(result.getPayload(), DummyComplexModel.class);
    assertThat(retrieveModel).isNotNull().isNotEqualTo(source);
    source.id = retrieveModel.id;
    assertThat(retrieveModel).isEqualTo(source);
    target.siblings = new ArrayList<>();
    target.siblings.add(source);
    assertThat(element.model.value).isEqualTo(target);
  }
@ Test public void shouldCreateModelFieldElementWhenFieldIsNull ( @ Mock final Handler < AsyncResult < ServiceResponse > > resultHandler , @ Mock final BiConsumer < String , Handler < AsyncResult < DummyComplexModel > > > searcher , @ Mock final BiConsumer < DummyComplexModel , Handler < AsyncResult < Void > > > storerCreateModel ) { final var element = this . createModelFieldContextById ( ) ; final var target = new DummyComplexModelTest ( ) . createModelExample ( 1 ) ; element . model . id = target . id ; final var context = this . createServiceContext ( resultHandler ) ; final var source = new DummyComplexModel ( ) ; final var valueToCreate = source . toJsonObject ( ) ; ModelResources . createModelFieldElement ( valueToCreate , element , searcher , dummy -> dummy . siblings , ( dummy , siblings ) -> dummy . siblings = siblings , storerCreateModel , 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 ( storerCreateModel , timeout ( 30000 ) . times ( 1 ) ) . accept ( any ( ) , storerHandler . capture ( ) ) ; storerHandler . 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 retrieveModel = Model . fromBuffer ( result . getPayload ( ) , DummyComplexModel . class ) ; assertThat ( retrieveModel ) . isNotNull ( ) . isNotEqualTo ( source ) ; source . id = retrieveModel . id ; assertThat ( retrieveModel ) . isEqualTo ( source ) ; target . siblings = new ArrayList < > ( ) ; target . siblings . add ( source ) ; assertThat ( element . model . value ) . isEqualTo ( target ) ; }
Should create model field element when field is {@code null}.
Should create model field element when field is { @code null } .