Search in sources :

Example 16 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertSubEntity.

@Test
public void shouldConvertSubEntity() {
    Zipcode zipcode = new Zipcode();
    zipcode.setZip("12321");
    zipcode.setPlusFour("1234");
    Address address = new Address();
    address.setCity("Salvador");
    address.setState("Bahia");
    address.setStreet("Rua Engenheiro Jose Anasoh");
    address.setZipcode(zipcode);
    ColumnEntity columnEntity = converter.toColumn(address);
    List<Column> columns = columnEntity.getColumns();
    assertEquals("Address", columnEntity.getName());
    assertEquals(5, columns.size());
    assertEquals("Rua Engenheiro Jose Anasoh", getValue(columnEntity.find("street")));
    assertEquals("Salvador", getValue(columnEntity.find("city")));
    assertEquals("Bahia", getValue(columnEntity.find("state")));
    assertEquals("12321", getValue(columnEntity.find("zip")));
    assertEquals("1234", getValue(columnEntity.find("plusFour")));
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Address(org.jnosql.artemis.model.Address) Column(org.jnosql.diana.api.column.Column) Zipcode(org.jnosql.artemis.model.Zipcode) Test(org.junit.jupiter.api.Test)

Example 17 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertEntityToColumnEntity2.

@Test
public void shouldConvertEntityToColumnEntity2() {
    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);
    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());
    Column subColumn = entity.find("movie").get();
    List<Column> columns = subColumn.get(new TypeReference<List<Column>>() {
    });
    assertEquals(3, columns.size());
    assertEquals("movie", subColumn.getName());
    assertEquals(movie.getTitle(), columns.stream().filter(c -> "title".equals(c.getName())).findFirst().get().get());
    assertEquals(movie.getYear(), columns.stream().filter(c -> "year".equals(c.getName())).findFirst().get().get());
    assertEquals(movie.getActors(), columns.stream().filter(c -> "actors".equals(c.getName())).findFirst().get().get());
}
Also used : Movie(org.jnosql.artemis.model.Movie) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) Director(org.jnosql.artemis.model.Director) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 18 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertToColumnWhenHaConverter.

@Test
public void shouldConvertToColumnWhenHaConverter() {
    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);
    assertEquals("Worker", entity.getName());
    assertEquals("Bob", entity.find("name").get().get());
    Column subColumn = entity.find("job").get();
    List<Column> columns = subColumn.get(new TypeReference<List<Column>>() {
    });
    assertThat(columns, Matchers.containsInAnyOrder(Column.of("city", "Sao Paulo"), Column.of("description", "Java Developer")));
    assertEquals("BRL 10", entity.find("money").get().get());
}
Also used : Money(org.jnosql.artemis.model.Money) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) Worker(org.jnosql.artemis.model.Worker) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Job(org.jnosql.artemis.model.Job) Test(org.junit.jupiter.api.Test)

Example 19 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertColumnInSubEntity.

@Test
public void shouldConvertColumnInSubEntity() {
    ColumnEntity entity = ColumnEntity.of("Address");
    entity.add(Column.of("street", "Rua Engenheiro Jose Anasoh"));
    entity.add(Column.of("city", "Salvador"));
    entity.add(Column.of("state", "Bahia"));
    entity.add(Column.of("zip", "12321"));
    entity.add(Column.of("plusFour", "1234"));
    Address address = converter.toEntity(entity);
    assertEquals("Rua Engenheiro Jose Anasoh", address.getStreet());
    assertEquals("Salvador", address.getCity());
    assertEquals("Bahia", address.getState());
    assertEquals("12321", address.getZipcode().getZip());
    assertEquals("1234", address.getZipcode().getPlusFour());
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Address(org.jnosql.artemis.model.Address) Test(org.junit.jupiter.api.Test)

Example 20 with ColumnEntity

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

the class DefaultColumnEntityConverterTest method shouldConvertColumnEntityToEntity2.

@Test
public void shouldConvertColumnEntityToEntity2() {
    ColumnEntity entity = ColumnEntity.of("Actor");
    Stream.of(columns).forEach(entity::add);
    Actor actor = converter.toEntity(entity);
    assertNotNull(actor);
    assertEquals(10, actor.getAge());
    assertEquals(12L, actor.getId());
    assertEquals(asList("234", "2342"), actor.getPhones());
    assertEquals(Collections.singletonMap("JavaZone", "Jedi"), actor.getMovieCharacter());
    assertEquals(Collections.singletonMap("JavaZone", 10), actor.getMovieRating());
}
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