vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should not create a model if it is not valid.
   *
   * @param resultHandler handler to manage the HTTP result.
   * @param storer        the function used to store the model.
   *
   * @see ModelResources#createModel( JsonObject, ModelContext, BiConsumer,
   *      ServiceContext)
   */
Should not create a model if it is not valid.
@param resultHandler handler to manage the HTTP result.
@param storer        the function used to store the model.


Should not create a model if it is not valid . @param resultHandler handler to manage the HTTP result . @param storer the function used to store the model .
@Test
  public void shouldNotCreateModelBecauseCanNotBeStored(@Mock final Handler<AsyncResult<ServiceResponse>> resultHandler,
      @Mock final BiConsumer<DummyComplexModel, Handler<AsyncResult<DummyComplexModel>>> storer) {
    final var model = this.createModelContext();
    final var expected = new DummyComplexModelTest().createModelExample(2);
    final var context = this.createServiceContext(resultHandler);
    ModelResources.createModel(expected.toJsonObject(), model, storer, context);
    final var cause = new Throwable("Can not store the model");
    @SuppressWarnings("unchecked")
    final ArgumentCaptor<Handler<AsyncResult<DummyComplexModel>>> storeCaptor = ArgumentCaptor.forClass(Handler.class);
    verify(storer, timeout(30000).times(1)).accept(any(), storeCaptor.capture());
    storeCaptor.getValue().handle(Future.failedFuture(cause));
    @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.message).contains(cause.getMessage());
  }
@ Test public void shouldNotCreateModelBecauseCanNotBeStored ( @ Mock final Handler < AsyncResult < ServiceResponse > > resultHandler , @ Mock final BiConsumer < DummyComplexModel , Handler < AsyncResult < DummyComplexModel > > > storer ) { final var model = this . createModelContext ( ) ; final var expected = new DummyComplexModelTest ( ) . createModelExample ( 2 ) ; final var context = this . createServiceContext ( resultHandler ) ; ModelResources . createModel ( expected . toJsonObject ( ) , model , storer , context ) ; final var cause = new Throwable ( "Can not store the model" ) ; @ SuppressWarnings ( "unchecked" ) final ArgumentCaptor < Handler < AsyncResult < DummyComplexModel > > > storeCaptor = ArgumentCaptor . forClass ( Handler . class ) ; verify ( storer , timeout ( 30000 ) . times ( 1 ) ) . accept ( any ( ) , storeCaptor . capture ( ) ) ; storeCaptor . getValue ( ) . handle ( Future . failedFuture ( cause ) ) ; @ 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 . message ) . contains ( cause . getMessage ( ) ) ; }
Should not create a model if it is not valid.
Should not create a model if it is not valid .