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)));
}
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));
}
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()));
}
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()));
}
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));
}
Aggregations