Search in sources :

Example 11 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnTemplateTest method shouldInsertEntitiesTTL.

@Test
public void shouldInsertEntitiesTTL() {
    ColumnEntity columnEntity = ColumnEntity.of("Person");
    columnEntity.addAll(Stream.of(columns).collect(Collectors.toList()));
    Duration duration = Duration.ofHours(2);
    Mockito.when(managerMock.insert(any(ColumnEntity.class), Mockito.eq(duration))).thenReturn(columnEntity);
    subject.insert(Arrays.asList(person, person), duration);
    verify(managerMock, times(2)).insert(any(ColumnEntity.class), any(Duration.class));
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test)

Example 12 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn() {
    Movie movie = new Movie("Matrix", 2012, Collections.singleton("Actor"));
    Director director = Director.builderDiretor().withAge(12).withId(12).withName("Otavio").withPhones(asList("234", "2342")).withMovie(movie).build();
    ColumnEntity entity = converter.toColumn(director);
    Director director1 = converter.toEntity(entity);
    assertEquals(movie, director1.getMovie());
    assertEquals(director.getName(), director1.getName());
    assertEquals(director.getAge(), director1.getAge());
    assertEquals(director.getId(), director1.getId());
}
Also used : Movie(org.jnosql.artemis.model.Movie) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test)

Example 13 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertoListEmbeddable.

@Test
public void shouldConvertoListEmbeddable() {
    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());
    ColumnEntity entity = converter.toColumn(appointmentBook);
    Column contacts = entity.find("contacts").get();
    assertEquals("ids", appointmentBook.getId());
    List<List<Column>> columns = (List<List<Column>>) contacts.get();
    assertEquals(3L, columns.stream().flatMap(Collection::stream).filter(c -> c.getName().equals("name")).count());
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) AppointmentBook(org.jnosql.artemis.model.AppointmentBook) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 14 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn3.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn3() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDiretor().withAge(12).withId(12).withName("Otavio").withPhones(asList("234", "2342")).withMovie(movie).build();
    ColumnEntity entity = converter.toColumn(director);
    entity.remove("movie");
    Map<String, Object> map = new HashMap<>();
    map.put("title", "Matrix");
    map.put("year", 2012);
    map.put("actors", singleton("Actor"));
    entity.add(Column.of("movie", map));
    Director director1 = converter.toEntity(entity);
    assertEquals(movie, director1.getMovie());
    assertEquals(director.getName(), director1.getName());
    assertEquals(director.getAge(), director1.getAge());
    assertEquals(director.getId(), director1.getId());
}
Also used : Movie(org.jnosql.artemis.model.Movie) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) HashMap(java.util.HashMap) Director(org.jnosql.artemis.model.Director) Test(org.junit.jupiter.api.Test)

Example 15 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.

the class DefaultColumnEntityConverterTest method shouldReturnErrorWhenToEntityIsNull.

@Test
public void shouldReturnErrorWhenToEntityIsNull() {
    ColumnEntity entity = ColumnEntity.of("Actor");
    Stream.of(columns).forEach(entity::add);
    Actor actor = Actor.actorBuilder().build();
    assertThrows(NullPointerException.class, () -> {
        converter.toEntity(null, entity);
    });
    assertThrows(NullPointerException.class, () -> {
        converter.toEntity(actor, null);
    });
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Actor(org.jnosql.artemis.model.Actor) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)88 Test (org.junit.jupiter.api.Test)76 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)26 Column (org.jnosql.diana.api.column.Column)22 Arrays.asList (java.util.Arrays.asList)17 List (java.util.List)17 Consumer (java.util.function.Consumer)14 Collections.singletonList (java.util.Collections.singletonList)13 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)13 Person (org.jnosql.artemis.model.Person)12 Duration (java.time.Duration)11 Collections.emptyList (java.util.Collections.emptyList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)9 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)9 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8