vertx/src/test/java/eu/internetofus/common/vertx/ModelResourcesTest.java
/**
   * Should create model setting timestamps.
   *
   * @param resultHandler handler to manage the HTTP result.
   * @param success       function to call when the validation success.
   * @param storer        the function used to store a model.
   *
   * @see ModelResources#createModelChain
   */
Should create model setting timestamps.
@param resultHandler handler to manage the HTTP result.
@param success       function to call when the validation success.
@param storer        the function used to store a model.


Should create model setting timestamps . @param resultHandler handler to manage the HTTP result . @param success function to call when the validation success . @param storer the function used to store a model .
@Test
  @SuppressWarnings("unchecked")
  public void shouldSetTimeStampWhenCreateModel(
      @Mock final BiConsumer<DummyTsModel, Handler<AsyncResult<DummyTsModel>>> storer,
      @Mock final Handler<AsyncResult<ServiceResponse>> resultHandler, @Mock final Runnable success) {
    final var context = this.createServiceContext(resultHandler);
    final var modelContext = this.createModelContextForDummyTsModel();
    final var newElement = new DummyTsModel();
    newElement._creationTs = 2;
    newElement._lastUpdateTs = 3;
    newElement.value = "ElementToCreate";
    final var start = TimeManager.now();
    ModelResources.createModelChain(newElement.toJsonObject(), modelContext, storer, context, success);
    final ArgumentCaptor<DummyTsModel> modelToStore = ArgumentCaptor.forClass(DummyTsModel.class);
    final ArgumentCaptor<Handler<AsyncResult<DummyTsModel>>> storerHandler = ArgumentCaptor.forClass(Handler.class);
    verify(storer, timeout(30000).times(1)).accept(modelToStore.capture(), storerHandler.capture());
    final var storedElement = modelToStore.getValue();
    storedElement._id = "1";
    storerHandler.getValue().handle(Future.succeededFuture(storedElement));
    verify(success, timeout(30000).times(1)).run();
    final var end = TimeManager.now();
    assertThat(storedElement._creationTs).isBetween(start, end);
    assertThat(storedElement._lastUpdateTs).isEqualTo(storedElement._creationTs);
  }
@ Test @ SuppressWarnings ( "unchecked" ) public void shouldSetTimeStampWhenCreateModel ( @ Mock final BiConsumer < DummyTsModel , Handler < AsyncResult < DummyTsModel > > > storer , @ Mock final Handler < AsyncResult < ServiceResponse > > resultHandler , @ Mock final Runnable success ) { final var context = this . createServiceContext ( resultHandler ) ; final var modelContext = this . createModelContextForDummyTsModel ( ) ; final var newElement = new DummyTsModel ( ) ; newElement . _creationTs = 2 ; newElement . _lastUpdateTs = 3 ; newElement . value = "ElementToCreate" ; final var start = TimeManager . now ( ) ; ModelResources . createModelChain ( newElement . toJsonObject ( ) , modelContext , storer , context , success ) ; final ArgumentCaptor < DummyTsModel > modelToStore = ArgumentCaptor . forClass ( DummyTsModel . class ) ; final ArgumentCaptor < Handler < AsyncResult < DummyTsModel > > > storerHandler = ArgumentCaptor . forClass ( Handler . class ) ; verify ( storer , timeout ( 30000 ) . times ( 1 ) ) . accept ( modelToStore . capture ( ) , storerHandler . capture ( ) ) ; final var storedElement = modelToStore . getValue ( ) ; storedElement . _id = "1" ; storerHandler . getValue ( ) . handle ( Future . succeededFuture ( storedElement ) ) ; verify ( success , timeout ( 30000 ) . times ( 1 ) ) . run ( ) ; final var end = TimeManager . now ( ) ; assertThat ( storedElement . _creationTs ) . isBetween ( start , end ) ; assertThat ( storedElement . _lastUpdateTs ) . isEqualTo ( storedElement . _creationTs ) ; }
Should create model setting timestamps.
Should create model setting timestamps .