Search in sources :

Example 26 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity 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<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    ColumnPreparedStatement prepare = parser.prepare(query, manager, observer);
    prepare.bind("name", "Diana");
    prepare.getResult();
    Mockito.verify(manager).insert(captor.capture());
    ColumnEntity entity = captor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Column.of("name", "Diana"), entity.find("name").get());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity 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<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    ColumnPreparedStatement prepare = parser.prepare(query, manager, observer);
    prepare.bind("name", "Diana");
    prepare.getResult();
    Mockito.verify(manager).update(captor.capture());
    ColumnEntity entity = captor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Column.of("name", "Diana"), entity.find("name").get());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with ColumnEntity

use of jakarta.nosql.column.ColumnEntity 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 29 with ColumnEntity

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

the class UpdateQueryParserTest method shouldReturnParserQuery.

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

Example 30 with ColumnEntity

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

the class DefaultColumnTemplateTest method shouldInsert.

@Test
public void shouldInsert() {
    ColumnEntity columnEntity = ColumnEntity.of("Person");
    columnEntity.addAll(Stream.of(columns).collect(Collectors.toList()));
    Mockito.when(managerMock.insert(any(ColumnEntity.class))).thenReturn(columnEntity);
    subject.insert(this.person);
    verify(managerMock).insert(captor.capture());
    verify(columnEventPersistManager).firePostEntity(any(Person.class));
    verify(columnEventPersistManager).firePreEntity(any(Person.class));
    verify(columnEventPersistManager).firePreColumn(any(ColumnEntity.class));
    verify(columnEventPersistManager).firePostColumn(any(ColumnEntity.class));
    ColumnEntity value = captor.getValue();
    assertEquals("Person", value.getName());
    assertEquals(4, value.getColumns().size());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnEntity (jakarta.nosql.column.ColumnEntity)146 Test (org.junit.jupiter.api.Test)103 Column (jakarta.nosql.column.Column)39 ColumnQuery (jakarta.nosql.column.ColumnQuery)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 Duration (java.time.Duration)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Arrays.asList (java.util.Arrays.asList)11 Person (jakarta.nosql.tck.entities.Person)9 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Value (jakarta.nosql.Value)6 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)6 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)5 Actor (jakarta.nosql.tck.entities.Actor)5 Director (jakarta.nosql.tck.entities.Director)5 Movie (jakarta.nosql.tck.entities.Movie)5