Search in sources :

Example 36 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class SelectQueryParserTest method shouldReturnParserQuery18.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"}" })
public void shouldReturnParserQuery18(String query) {
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).select(captor.capture());
    ColumnQuery columnQuery = captor.getValue();
    checkBaseQuery(columnQuery, 0L, 0L);
    assertTrue(columnQuery.getCondition().isPresent());
    ColumnCondition condition = columnQuery.getCondition().get();
    assertEquals(Condition.EQUALS, condition.getCondition());
    Column column = condition.getColumn();
    List<Column> columns = column.get(new TypeReference<List<Column>>() {
    });
    assertThat(columns, containsInAnyOrder(Column.of("apollo", "Brother"), Column.of("Zeus", "Father")));
    assertEquals("siblings", column.getName());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) List(java.util.List) ColumnCondition(jakarta.nosql.column.ColumnCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class InsertQueryParserTest method shouldReturnParserQuery10.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert Person {\"name\": \"Ada Lovelace\", \"age\": 12, \"sibling\":" + " [\"Ana\" ,\"Maria\"]," + " \"address\":{\"country\": \"United Kingdom\", \"city\": \"London\"}}" })
public void shouldReturnParserQuery10(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).insert(captor.capture());
    ColumnEntity entity = captor.getValue();
    List<String> siblings = entity.find("sibling").get().get(new TypeReference<List<String>>() {
    });
    List<Column> address = entity.find("address").get().get(new TypeReference<List<Column>>() {
    });
    assertEquals("Person", entity.getName());
    assertEquals(Column.of("name", "Ada Lovelace"), entity.find("name").get());
    assertEquals(Column.of("age", BigDecimal.valueOf(12)), entity.find("age").get());
    assertThat(siblings, contains("Ana", "Maria"));
    assertThat(address, containsInAnyOrder(Column.of("country", "United Kingdom"), Column.of("city", "London")));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) List(java.util.List) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class UpdateQueryParserTest method shouldReturnParserQuery4.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update Person {\"name\": \"Ada Lovelace\", \"age\": 12, \"sibling\":" + " [\"Ana\" ,\"Maria\"]," + " \"address\":{\"country\": \"United Kingdom\", \"city\": \"London\"}}" })
public void shouldReturnParserQuery4(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    parser.query(query, manager, observer);
    Mockito.verify(manager).update(captor.capture());
    ColumnEntity entity = captor.getValue();
    List<String> siblings = entity.find("sibling").get().get(new TypeReference<List<String>>() {
    });
    List<Column> address = entity.find("address").get().get(new TypeReference<List<Column>>() {
    });
    assertEquals("Person", entity.getName());
    assertEquals(Column.of("name", "Ada Lovelace"), entity.find("name").get());
    assertEquals(Column.of("age", BigDecimal.valueOf(12)), entity.find("age").get());
    assertThat(siblings, contains("Ana", "Maria"));
    assertThat(address, containsInAnyOrder(Column.of("country", "United Kingdom"), Column.of("city", "London")));
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) List(java.util.List) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with Column

use of jakarta.nosql.column.Column in project jnosql-diana by eclipse.

the class ColumnRepositoryProxyTest method shouldFindBySalary_CurrencyOrderByCurrency_Name.

@Test
public void shouldFindBySalary_CurrencyOrderByCurrency_Name() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
    personRepository.findBySalary_CurrencyOrderByCurrency_Name("USD");
    ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(template).select(captor.capture());
    ColumnQuery query = captor.getValue();
    ColumnCondition condition = query.getCondition().get();
    final Sort sort = query.getSorts().get(0);
    final Column document = condition.getColumn();
    assertEquals("Person", query.getColumnFamily());
    assertEquals("salary.currency", document.getName());
    assertEquals("currency.name", sort.getName());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) Sort(jakarta.nosql.Sort) Person(jakarta.nosql.tck.entities.Person) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 40 with Column

use of jakarta.nosql.column.Column in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldCreateUDTWithSet.

@Test
public void shouldCreateUDTWithSet() {
    ColumnEntity entity = createEntityWithIterableSet();
    entityManager.insert(entity);
    ColumnQuery query = ColumnQuery.select().from("agenda").build();
    final ColumnEntity result = entityManager.singleResult(query).get();
    Assert.assertEquals(Column.of("user", "otaviojava"), result.find("user").get());
    Assert.assertEquals(2, result.size());
    List<List<Column>> names = (List<List<Column>>) result.find("names").get().get();
    assertEquals(3, names.size());
    assertTrue(names.stream().allMatch(n -> n.size() == 2));
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ColumnDeleteQuery.delete(jakarta.nosql.column.ColumnDeleteQuery.delete) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) ConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel) Thread.sleep(java.lang.Thread.sleep) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Columns(jakarta.nosql.column.Columns) ColumnEntity(jakarta.nosql.column.ColumnEntity) Month(java.time.Month) Matchers(org.hamcrest.Matchers) ColumnQuery.select(jakarta.nosql.column.ColumnQuery.select) Instant(java.time.Instant) ZoneId(java.time.ZoneId) Test(org.junit.jupiter.api.Test) Value(jakarta.nosql.Value) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Column(jakarta.nosql.column.Column) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ColumnQuery(jakarta.nosql.column.ColumnQuery) Assert(org.junit.Assert) ColumnQuery(jakarta.nosql.column.ColumnQuery) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.jupiter.api.Test)

Aggregations

Column (jakarta.nosql.column.Column)113 Test (org.junit.jupiter.api.Test)72 ColumnCondition (jakarta.nosql.column.ColumnCondition)57 ColumnEntity (jakarta.nosql.column.ColumnEntity)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)35 List (java.util.List)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)24 ArrayList (java.util.ArrayList)13 Value (jakarta.nosql.Value)10 TypeReference (jakarta.nosql.TypeReference)9 Arrays.asList (java.util.Arrays.asList)9 Collections.singletonList (java.util.Collections.singletonList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 Optional (java.util.Optional)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)3