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);
}
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());
}
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());
}
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));
}
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());
}
Aggregations