Search in sources :

Example 31 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class InsertQueryParserTest method shouldReturnParserQuery7.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 nanosecond" })
public void shouldReturnParserQuery7(String query) {
    ArgumentCaptor<DocumentEntity> captor = ArgumentCaptor.forClass(DocumentEntity.class);
    ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).insert(captor.capture(), durationCaptor.capture());
    DocumentEntity entity = captor.getValue();
    Duration duration = durationCaptor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Document.of("name", "Diana"), entity.find("name").get());
    assertEquals(Duration.ofNanos(10L), duration);
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Duration(java.time.Duration) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class InsertQueryParserTest method shouldReturnParserQuery1.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (age = 30, name = \"Artemis\")" })
public void shouldReturnParserQuery1(String query) {
    ArgumentCaptor<DocumentEntity> captor = ArgumentCaptor.forClass(DocumentEntity.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).insert(captor.capture());
    DocumentEntity entity = captor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Document.of("name", "Artemis"), entity.find("name").get());
    assertEquals(Document.of("age", 30L), entity.find("age").get());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class UpdateQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (name = @name)" })
public void shouldExecutePrepareStatement(String query) {
    ArgumentCaptor<DocumentEntity> captor = ArgumentCaptor.forClass(DocumentEntity.class);
    DocumentPreparedStatement prepare = parser.prepare(query, manager, observer);
    prepare.bind("name", "Diana");
    prepare.getResult();
    Mockito.verify(manager).update(captor.capture());
    DocumentEntity entity = captor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Document.of("name", "Diana"), entity.find("name").get());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldReturnErrorWhenToEntityIsNull.

@Test
public void shouldReturnErrorWhenToEntityIsNull() {
    DocumentEntity entity = DocumentEntity.of("Actor");
    Stream.of(documents).forEach(entity::add);
    Actor actor = Actor.actorBuilder().build();
    assertThrows(NullPointerException.class, () -> converter.toEntity(null, entity));
    assertThrows(NullPointerException.class, () -> converter.toEntity(actor, null));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Actor(jakarta.nosql.tck.entities.Actor) Test(org.junit.jupiter.api.Test)

Example 35 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubDocument2.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubDocument2() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDirector().withAge(12).withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).withMovie(movie).build();
    DocumentEntity entity = converter.toDocument(director);
    entity.remove("movie");
    entity.add(Document.of("movie", Arrays.asList(Document.of("title", "Matrix"), Document.of("year", 2012), Document.of("actors", singleton("Actor")))));
    Director director1 = converter.toEntity(entity);
    assertEquals(movie, director1.getMovie());
    assertEquals(director.getName(), director1.getName());
    assertEquals(director.getAge(), director1.getAge());
    assertEquals(director.getId(), director1.getId());
}
Also used : Movie(jakarta.nosql.tck.entities.Movie) DocumentEntity(jakarta.nosql.document.DocumentEntity) Director(jakarta.nosql.tck.entities.Director) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentEntity (jakarta.nosql.document.DocumentEntity)312 Test (org.junit.jupiter.api.Test)238 DocumentQuery (jakarta.nosql.document.DocumentQuery)131 Document (jakarta.nosql.document.Document)129 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)62 List (java.util.List)54 Arrays.asList (java.util.Arrays.asList)51 ArrayList (java.util.ArrayList)46 Duration (java.time.Duration)31 HashMap (java.util.HashMap)30 Map (java.util.Map)27 Collectors (java.util.stream.Collectors)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 TypeReference (jakarta.nosql.TypeReference)21 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)21 Matchers.contains (org.hamcrest.Matchers.contains)21 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)21