Search in sources :

Example 41 with Document

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

the class SelectQueryParserTest method shouldReturnParserQuery24.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = \"Ada\" or age = 20" })
public void shouldReturnParserQuery24(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).select(captor.capture());
    DocumentQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery, 0L, 0L);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.OR, condition.getCondition());
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertThat(conditions, contains(eq(Document.of("name", "Ada")), eq(Document.of("age", 20L))));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with Document

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

the class SelectQueryParserTest method shouldReturnParserQuery26.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = \"Ada\" and age = 20 or" + " siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"} and birthday =" + " convert(\"2007-12-03\", java.time.LocalDate)" })
public void shouldReturnParserQuery26(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).select(captor.capture());
    DocumentQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery, 0L, 0L);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.EQUALS, conditions.get(0).getCondition());
    assertEquals(Condition.EQUALS, conditions.get(1).getCondition());
    assertEquals(Condition.OR, conditions.get(2).getCondition());
    assertEquals(Condition.EQUALS, conditions.get(3).getCondition());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with Document

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

the class DeleteQueryParserTest method shouldReturnParserQuery23.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name = \"Ada\" and age = 20" })
public void shouldReturnParserQuery23(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertThat(conditions, contains(eq(Document.of("name", "Ada")), eq(Document.of("age", 20L))));
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with Document

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

the class DefaultDocumentEntityConverterTest method shouldConvertEntityFromDocumentEntity2.

@Test
public void shouldConvertEntityFromDocumentEntity2() {
    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);
    assertEquals(5, entity.size());
    assertEquals(getValue(entity.find("name")), director.getName());
    assertEquals(getValue(entity.find("age")), director.getAge());
    assertEquals(getValue(entity.find("_id")), director.getId());
    assertEquals(getValue(entity.find("phones")), director.getPhones());
    Document subdocument = entity.find("movie").get();
    List<Document> documents = subdocument.get(new TypeReference<List<Document>>() {
    });
    assertEquals(3, documents.size());
    assertEquals("movie", subdocument.getName());
    assertEquals(movie.getTitle(), getValue(documents.stream().filter(d -> "title".equals(d.getName())).findFirst()));
    assertEquals(movie.getYear(), getValue(documents.stream().filter(d -> "year".equals(d.getName())).findFirst()));
    assertEquals(movie.getActors(), getValue(documents.stream().filter(d -> "actors".equals(d.getName())).findFirst()));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AppointmentBook(jakarta.nosql.tck.entities.AppointmentBook) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Person(jakarta.nosql.tck.entities.Person) HashMap(java.util.HashMap) ContactType(jakarta.nosql.tck.entities.ContactType) ZipCode(jakarta.nosql.tck.entities.ZipCode) ArrayList(java.util.ArrayList) Address(jakarta.nosql.tck.entities.Address) Inject(javax.inject.Inject) Actor(jakarta.nosql.tck.entities.Actor) BigDecimal(java.math.BigDecimal) Vendor(jakarta.nosql.tck.entities.Vendor) TypeReference(jakarta.nosql.TypeReference) CDIExtension(jakarta.nosql.tck.test.CDIExtension) Citizen(org.eclipse.jnosql.mapping.document.entities.Citizen) Collections.singleton(java.util.Collections.singleton) Money(jakarta.nosql.tck.entities.Money) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Download(jakarta.nosql.tck.entities.Download) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Worker(jakarta.nosql.tck.entities.Worker) Director(jakarta.nosql.tck.entities.Director) Movie(jakarta.nosql.tck.entities.Movie) Contact(jakarta.nosql.tck.entities.Contact) Collection(java.util.Collection) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) DisplayName(org.junit.jupiter.api.DisplayName) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Value(jakarta.nosql.Value) List(java.util.List) Stream(java.util.stream.Stream) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions(org.junit.jupiter.api.Assertions) Job(jakarta.nosql.tck.entities.Job) Optional(java.util.Optional) Collections(java.util.Collections) Movie(jakarta.nosql.tck.entities.Movie) DocumentEntity(jakarta.nosql.document.DocumentEntity) Director(jakarta.nosql.tck.entities.Director) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 45 with Document

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

the class DefaultDocumentEntityConverterTest method shouldConvertToListEmbeddable.

@Test
public void shouldConvertToListEmbeddable() {
    AppointmentBook appointmentBook = new AppointmentBook("ids");
    appointmentBook.add(Contact.builder().withType(ContactType.EMAIL).withName("Ada").withInformation("ada@lovelace.com").build());
    appointmentBook.add(Contact.builder().withType(ContactType.MOBILE).withName("Ada").withInformation("11 1231231 123").build());
    appointmentBook.add(Contact.builder().withType(ContactType.PHONE).withName("Ada").withInformation("12 123 1231 123123").build());
    DocumentEntity entity = converter.toDocument(appointmentBook);
    Document contacts = entity.find("contacts").get();
    assertEquals("ids", appointmentBook.getId());
    List<List<Document>> documents = (List<List<Document>>) contacts.get();
    assertEquals(3L, documents.stream().flatMap(Collection::stream).filter(c -> c.getName().equals("contact_name")).count());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) AppointmentBook(jakarta.nosql.tck.entities.AppointmentBook) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (jakarta.nosql.document.Document)196 Test (org.junit.jupiter.api.Test)140 DocumentEntity (jakarta.nosql.document.DocumentEntity)115 DocumentQuery (jakarta.nosql.document.DocumentQuery)93 DocumentCondition (jakarta.nosql.document.DocumentCondition)60 List (java.util.List)60 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)44 Arrays.asList (java.util.Arrays.asList)33 ArrayList (java.util.ArrayList)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 TypeReference (jakarta.nosql.TypeReference)21 HashMap (java.util.HashMap)20 Map (java.util.Map)17 Collectors (java.util.stream.Collectors)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)14 Matchers.contains (org.hamcrest.Matchers.contains)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14