Search in sources :

Example 6 with TypeReference

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

the class DefaultKeyValueEntityTest method shouldAliasOnValue.

@Test
public void shouldAliasOnValue() {
    String value = "10";
    KeyValueEntity entity = KeyValueEntity.of("key", value);
    assertEquals(value, entity.getValue());
    assertEquals(Integer.valueOf(10), entity.getValue(Integer.class));
    assertThat(singletonList(10), Matchers.contains(entity.getValue(new TypeReference<List<Integer>>() {
    }).get(0)));
}
Also used : TypeReference(jakarta.nosql.TypeReference) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 7 with TypeReference

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

the class DefaultKeyValueEntityTest method shouldReturnErrorWhenGetKeySupplierIsNull.

@Test
public void shouldReturnErrorWhenGetKeySupplierIsNull() {
    Value value = Value.of("value");
    KeyValueEntity entity = KeyValueEntity.of("10", value);
    assertNotNull(entity);
    Assertions.assertThrows(NullPointerException.class, () -> entity.getKey((TypeReference<Object>) null));
}
Also used : Value(jakarta.nosql.Value) TypeReference(jakarta.nosql.TypeReference) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) Test(org.junit.jupiter.api.Test)

Example 8 with TypeReference

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

the class DefaultDocumentEntityConverterTest method shouldConvertEntityFromDocumentEntity2.

@Test
public void shouldConvertEntityFromDocumentEntity2() {
    Movie movie = new Movie("Matrix", 2012, singleton("Actor"));
    Director director = Director.builderDirector().withAge(12).withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).withMovie(movie).build();
    DocumentEntity entity = converter.toDocument(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());
    Document subdocument = entity.find("movie").get();
    List<Document> documents = subdocument.get(new TypeReference<List<Document>>() {
    });
    assertEquals(3, documents.size());
    assertEquals("movie", subdocument.getName());
    assertEquals(movie.getTitle(), getValue(documents.stream().filter(d -> "title".equals(d.getName())).findFirst()));
    assertEquals(movie.getYear(), getValue(documents.stream().filter(d -> "year".equals(d.getName())).findFirst()));
    assertEquals(movie.getActors(), getValue(documents.stream().filter(d -> "actors".equals(d.getName())).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) 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) Citizen(org.eclipse.jnosql.mapping.document.entities.Citizen) 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) 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) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) DisplayName(org.junit.jupiter.api.DisplayName) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Value(jakarta.nosql.Value) List(java.util.List) 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) Movie(jakarta.nosql.tck.entities.Movie) DocumentEntity(jakarta.nosql.document.DocumentEntity) Director(jakarta.nosql.tck.entities.Director) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 9 with TypeReference

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

the class DefaultDocumentEntityConverterTest 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);
    DocumentEntity documentEntity = converter.toDocument(address);
    List<Document> documents = documentEntity.getDocuments();
    assertEquals("Address", documentEntity.getName());
    assertEquals(4, documents.size());
    List<Document> zip = documentEntity.find("zipCode").map(d -> d.get(new TypeReference<List<Document>>() {
    })).orElse(Collections.emptyList());
    assertEquals("Rua Engenheiro Jose Anasoh", getValue(documentEntity.find("street")));
    assertEquals("Salvador", getValue(documentEntity.find("city")));
    assertEquals("Bahia", getValue(documentEntity.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) 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) Citizen(org.eclipse.jnosql.mapping.document.entities.Citizen) 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) 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) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) DisplayName(org.junit.jupiter.api.DisplayName) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Value(jakarta.nosql.Value) List(java.util.List) 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) DocumentEntity(jakarta.nosql.document.DocumentEntity) Address(jakarta.nosql.tck.entities.Address) ZipCode(jakarta.nosql.tck.entities.ZipCode) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 10 with TypeReference

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

the class DefaultValueTest method shouldConvertToSingletonList.

@Test
public void shouldConvertToSingletonList() {
    Long number = 10L;
    Value value = Value.of(number);
    assertThat(value.get(new TypeReference<List<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)

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