Search in sources :

Example 26 with TypeReference

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

the class DocumentEntityTest method shouldFindTypeSupplier.

@Test
public void shouldFindTypeSupplier() {
    Document document = Document.of("name", "name");
    DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
    List<String> names = entity.find("name", new TypeReference<List<String>>() {
    }).orElse(Collections.emptyList());
    Assertions.assertNotNull(names);
    Assertions.assertFalse(names.isEmpty());
    MatcherAssert.assertThat(names, Matchers.contains("name"));
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 27 with TypeReference

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameBetween.

@Test
public void shouldSelectWhereNameBetween() {
    String columnFamily = "columnFamily";
    Number valueA = 10;
    Number valueB = 20;
    ColumnDeleteQuery query = delete().from(columnFamily).where("name").between(valueA, valueB).build();
    ColumnCondition condition = query.getCondition().get();
    Column column = condition.getColumn();
    assertTrue(query.getColumns().isEmpty());
    assertEquals(columnFamily, query.getColumnFamily());
    assertEquals(Condition.BETWEEN, condition.getCondition());
    assertEquals("name", column.getName());
    assertThat(column.get(new TypeReference<List<Number>>() {
    }), Matchers.contains(10, 20));
}
Also used : Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 28 with TypeReference

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

the class DefaultValueTest method shouldConvertToSingletonSet.

@Test
public void shouldConvertToSingletonSet() {
    Long number = 10L;
    Value value = Value.of(number);
    assertThat(value.get(new TypeReference<Set<String>>() {
    }), containsInAnyOrder("10"));
    assertThat(value.get(new TypeReference<List<Long>>() {
    }), containsInAnyOrder(10L));
}
Also used : Value(jakarta.nosql.Value) TypeReference(jakarta.nosql.TypeReference) Test(org.junit.jupiter.api.Test)

Example 29 with TypeReference

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

the class DefaultValueTest method shouldConvertToSet.

@Test
public void shouldConvertToSet() {
    Value value = Value.of(Arrays.asList(10, 20, 30));
    assertThat(value.get(new TypeReference<Set<String>>() {
    }), containsInAnyOrder("10", "20", "30"));
    assertThat(value.get(new TypeReference<List<BigInteger>>() {
    }), containsInAnyOrder(BigInteger.TEN, BigInteger.valueOf(20L), BigInteger.valueOf(30L)));
}
Also used : Value(jakarta.nosql.Value) BigInteger(java.math.BigInteger) TypeReference(jakarta.nosql.TypeReference) Test(org.junit.jupiter.api.Test)

Example 30 with TypeReference

use of jakarta.nosql.TypeReference in project jnosql-diana 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(4, columns.size());
    List<Column> zip = columnEntity.find("zipCode").map(d -> d.get(new TypeReference<List<Column>>() {
    })).orElse(Collections.emptyList());
    assertEquals("Rua Engenheiro Jose Anasoh", getValue(columnEntity.find("street")));
    assertEquals("Salvador", getValue(columnEntity.find("city")));
    assertEquals("Bahia", getValue(columnEntity.find("state")));
    assertEquals("12321", getValue(zip.stream().filter(d -> d.getName().equals("zip")).findFirst()));
    assertEquals("1234", getValue(zip.stream().filter(d -> d.getName().equals("plusFour")).findFirst()));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AppointmentBook(jakarta.nosql.tck.entities.AppointmentBook) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Citizen(org.eclipse.jnosql.mapping.column.entities.Citizen) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Person(jakarta.nosql.tck.entities.Person) HashMap(java.util.HashMap) ContactType(jakarta.nosql.tck.entities.ContactType) ZipCode(jakarta.nosql.tck.entities.ZipCode) ArrayList(java.util.ArrayList) Address(jakarta.nosql.tck.entities.Address) Inject(javax.inject.Inject) Actor(jakarta.nosql.tck.entities.Actor) BigDecimal(java.math.BigDecimal) Vendor(jakarta.nosql.tck.entities.Vendor) TypeReference(jakarta.nosql.TypeReference) CDIExtension(jakarta.nosql.tck.test.CDIExtension) Collections.singleton(java.util.Collections.singleton) Money(jakarta.nosql.tck.entities.Money) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Download(jakarta.nosql.tck.entities.Download) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ColumnEntity(jakarta.nosql.column.ColumnEntity) Worker(jakarta.nosql.tck.entities.Worker) Director(jakarta.nosql.tck.entities.Director) Movie(jakarta.nosql.tck.entities.Movie) Contact(jakarta.nosql.tck.entities.Contact) Collection(java.util.Collection) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Value(jakarta.nosql.Value) List(java.util.List) Column(jakarta.nosql.column.Column) Stream(java.util.stream.Stream) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions(org.junit.jupiter.api.Assertions) Job(jakarta.nosql.tck.entities.Job) Optional(java.util.Optional) Collections(java.util.Collections) ColumnEntity(jakarta.nosql.column.ColumnEntity) Address(jakarta.nosql.tck.entities.Address) Column(jakarta.nosql.column.Column) ZipCode(jakarta.nosql.tck.entities.ZipCode) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

TypeReference (jakarta.nosql.TypeReference)30 Test (org.junit.jupiter.api.Test)28 Value (jakarta.nosql.Value)10 Document (jakarta.nosql.document.Document)10 Column (jakarta.nosql.column.Column)9 List (java.util.List)9 DocumentCondition (jakarta.nosql.document.DocumentCondition)7 ColumnCondition (jakarta.nosql.column.ColumnCondition)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)4 KeyValueEntity (jakarta.nosql.keyvalue.KeyValueEntity)3 Actor (jakarta.nosql.tck.entities.Actor)3 Address (jakarta.nosql.tck.entities.Address)3 AppointmentBook (jakarta.nosql.tck.entities.AppointmentBook)3 Contact (jakarta.nosql.tck.entities.Contact)3 ContactType (jakarta.nosql.tck.entities.ContactType)3 Director (jakarta.nosql.tck.entities.Director)3 Download (jakarta.nosql.tck.entities.Download)3 Job (jakarta.nosql.tck.entities.Job)3 Money (jakarta.nosql.tck.entities.Money)3 Movie (jakarta.nosql.tck.entities.Movie)3