Search in sources :

Example 26 with DocumentEntity

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

the class InsertQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert 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).insert(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 27 with DocumentEntity

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

the class InsertQueryParserTest method shouldReturnParserQuery4.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 minute" })
public void shouldReturnParserQuery4(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.ofMinutes(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 28 with DocumentEntity

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

the class InsertQueryParserTest method shouldReturnParserQuery5.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 second" })
public void shouldReturnParserQuery5(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.ofSeconds(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 29 with DocumentEntity

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

the class InsertQueryParserTest method shouldReturnParserQuery8.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert Person {\"name\":\"Ada Lovelace\"}" })
public void shouldReturnParserQuery8(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("Person", entity.getName());
    assertEquals(Document.of("name", "Ada Lovelace"), entity.find("name").get());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with DocumentEntity

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

the class InsertQueryParserTest method shouldReturnParserQuery3.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = \"Diana\") 10 hour" })
public void shouldReturnParserQuery3(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.ofHours(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)

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