Search in sources :

Example 21 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertToEntityWhenHasConverter.

@Test
public void shouldConvertToEntityWhenHasConverter() {
    Worker worker = new Worker();
    Job job = new Job();
    job.setCity("Sao Paulo");
    job.setDescription("Java Developer");
    worker.setName("Bob");
    worker.setSalary(new Money("BRL", BigDecimal.TEN));
    worker.setJob(job);
    ColumnEntity entity = converter.toColumn(worker);
    Worker worker1 = converter.toEntity(entity);
    assertEquals(worker.getSalary(), worker1.getSalary());
    assertEquals(job.getCity(), worker1.getJob().getCity());
    assertEquals(job.getDescription(), worker1.getJob().getDescription());
}
Also used : Money(org.jnosql.artemis.model.Money) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Worker(org.jnosql.artemis.model.Worker) Job(org.jnosql.artemis.model.Job) Test(org.junit.jupiter.api.Test)

Example 22 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertToEmbeddedClassWhenHasSubColumn2.

@Test
public void shouldConvertToEmbeddedClassWhenHasSubColumn2() {
    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");
    entity.add(Column.of("title", "Matrix"));
    entity.add(Column.of("year", 2012));
    entity.add(Column.of("actors", singleton("Actor")));
    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 23 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertFromListEmbeddable.

@Test
public void shouldConvertFromListEmbeddable() {
    ColumnEntity entity = ColumnEntity.of("AppointmentBook");
    entity.add(Column.of("_id", "ids"));
    List<List<Column>> columns = new ArrayList<>();
    columns.add(asList(Column.of("name", "Ada"), Column.of("type", ContactType.EMAIL), Column.of("information", "ada@lovelace.com")));
    columns.add(asList(Column.of("name", "Ada"), Column.of("type", ContactType.MOBILE), Column.of("information", "11 1231231 123")));
    columns.add(asList(Column.of("name", "Ada"), Column.of("type", ContactType.PHONE), Column.of("information", "phone")));
    entity.add(Column.of("contacts", columns));
    AppointmentBook appointmentBook = converter.toEntity(entity);
    List<Contact> contacts = appointmentBook.getContacts();
    assertEquals("ids", appointmentBook.getId());
    assertEquals("Ada", contacts.stream().map(Contact::getName).distinct().findFirst().get());
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AppointmentBook(org.jnosql.artemis.model.AppointmentBook) Contact(org.jnosql.artemis.model.Contact) Test(org.junit.jupiter.api.Test)

Example 24 with ColumnEntity

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

the class DefaultColumnEventPersistManagerTest method shouldFirePostColumn.

@Test
public void shouldFirePostColumn() {
    ColumnEntity entity = ColumnEntity.of("columnFamily");
    subject.firePostColumn(entity);
    ArgumentCaptor<ColumnEntityPostPersist> captor = ArgumentCaptor.forClass(ColumnEntityPostPersist.class);
    verify(columnEntityPostPersistEvent).fire(captor.capture());
    ColumnEntityPostPersist captorValue = captor.getValue();
    assertEquals(entity, captorValue.getEntity());
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 25 with ColumnEntity

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

the class MockProducer method getColumnFamilyManager.

@Produces
public ColumnFamilyManager getColumnFamilyManager() {
    ColumnEntity entity = ColumnEntity.of("Person");
    entity.add(org.jnosql.diana.api.column.Column.of("name", "Default"));
    entity.add(org.jnosql.diana.api.column.Column.of("age", 10));
    ColumnFamilyManager manager = mock(ColumnFamilyManager.class);
    when(manager.insert(Mockito.any(ColumnEntity.class))).thenReturn(entity);
    return manager;
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) ColumnFamilyManager(org.jnosql.diana.api.column.ColumnFamilyManager) Produces(javax.enterprise.inject.Produces)

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