vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should not validate an invalid model.
   *
   * @param resultHandler handler to manage the HTTP result.
   * @param success       function to call when the validation success.
   *
   * @see ModelResources#validate( ModelContext, ServiceContext, Runnable)
   */
Should not validate an invalid model.
@param resultHandler handler to manage the HTTP result.
@param success       function to call when the validation success.


Should not validate an invalid model . @param resultHandler handler to manage the HTTP result . @param success function to call when the validation success .
@Test
  public void shouldNotValidateIfModelIsNotValid(@Mock final Handler<AsyncResult<ServiceResponse>> resultHandler,
      @Mock final Runnable success) {
    final var model = this.createModelContext();
    model.source = new DummyComplexModelTest().createModelExample(2);
    model.source.siblings = new ArrayList<>();
    model.source.siblings.add(new DummyComplexModel());
    model.source.siblings.get(0).id = "0";
    model.source.siblings.add(new DummyComplexModel());
    model.source.siblings.get(1).id = "0";
    final var context = this.createServiceContext(resultHandler);
    ModelResources.validate(model, context, success);
    @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 shouldNotValidateIfModelIsNotValid ( @ Mock final Handler < AsyncResult < ServiceResponse > > resultHandler , @ Mock final Runnable success ) { final var model = this . createModelContext ( ) ; model . source = new DummyComplexModelTest ( ) . createModelExample ( 2 ) ; model . source . siblings = new ArrayList < > ( ) ; model . source . siblings . add ( new DummyComplexModel ( ) ) ; model . source . siblings . get ( 0 ) . id = "0" ; model . source . siblings . add ( new DummyComplexModel ( ) ) ; model . source . siblings . get ( 1 ) . id = "0" ; final var context = this . createServiceContext ( resultHandler ) ; ModelResources . validate ( model , context , success ) ; @ 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 validate an invalid model.
Should not validate an invalid model .