vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should not merge a value because the merged value is not valid.
   *
   * @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#mergeModel( JsonObject, ModelContext, BiConsumer,
   *      BiConsumer, ServiceContext)
   */
Should not merge a value because the merged value is not valid.
@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 not merge a value because the merged value is not valid . @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 shouldNotMergeModelBecauseNotValid(@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(1);
    source.siblings = new ArrayList<>();
    source.siblings.add(new DummyComplexModel());
    source.siblings.get(0).id = "0";
    source.siblings.add(new DummyComplexModel());
    source.siblings.get(1).id = "0";
    final var value = source.toJsonObject();
    ModelResources.mergeModel(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<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).contains("modelName.siblings[1]");
    assertThat(error.message).contains("already defined");
  }
@ Test public void shouldNotMergeModelBecauseNotValid ( @ 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 ( 1 ) ; source . siblings = new ArrayList < > ( ) ; source . siblings . add ( new DummyComplexModel ( ) ) ; source . siblings . get ( 0 ) . id = "0" ; source . siblings . add ( new DummyComplexModel ( ) ) ; source . siblings . get ( 1 ) . id = "0" ; final var value = source . toJsonObject ( ) ; ModelResources . mergeModel ( 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 < 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 ) . contains ( "modelName.siblings[1]" ) ; assertThat ( error . message ) . contains ( "already defined" ) ; }
Should not merge a value because the merged value is not valid.
Should not merge a value because the merged value is not valid .