Search in sources :

Example 1 with TypeReference

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

the class ColumnEntityTest method shouldFindTypeSupplier.

@Test
public void shouldFindTypeSupplier() {
    Column column = Column.of("name", "name");
    ColumnEntity entity = ColumnEntity.of("entity", singletonList(column));
    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 : ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) Test(org.junit.jupiter.api.Test)

Example 2 with TypeReference

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameBetween.

@Test
public void shouldSelectWhereNameBetween() {
    String columnFamily = "columnFamily";
    Number valueA = 10;
    Number valueB = 20;
    ColumnQuery query = select().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 : ColumnQuery(jakarta.nosql.column.ColumnQuery) Column(jakarta.nosql.column.Column) TypeReference(jakarta.nosql.TypeReference) ColumnCondition(jakarta.nosql.column.ColumnCondition) Test(org.junit.jupiter.api.Test)

Example 3 with TypeReference

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

the class ColumnTest method shouldReturnGetType.

@Test
public void shouldReturnGetType() {
    Value value = Value.of("text");
    Column column = Column.of("name", value);
    TypeReference<List<String>> typeReference = new TypeReference<List<String>>() {
    };
    assertEquals(value.get(typeReference), column.get(typeReference));
}
Also used : Column(jakarta.nosql.column.Column) Value(jakarta.nosql.Value) List(java.util.List) TypeReference(jakarta.nosql.TypeReference) Test(org.junit.jupiter.api.Test)

Example 4 with TypeReference

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

the class DefaultDocumentConditionTest method shouldCreateOrCondition.

@Test
public void shouldCreateOrCondition() {
    Document age = Document.of("age", 26);
    Document name = Document.of("name", "Otavio");
    DocumentCondition condition1 = DefaultDocumentCondition.of(name, Condition.EQUALS);
    DocumentCondition condition2 = DefaultDocumentCondition.of(age, Condition.GREATER_THAN);
    DocumentCondition and = condition1.or(condition2);
    Document andDocument = and.getDocument();
    assertEquals(Condition.OR, and.getCondition());
    assertEquals(Condition.OR.getNameField(), andDocument.getName());
    assertThat(andDocument.getValue().get(new TypeReference<List<DocumentCondition>>() {
    }), Matchers.containsInAnyOrder(condition1, condition2));
}
Also used : TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 5 with TypeReference

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

the class DefaultDocumentConditionTest method shouldAnd.

@Test
public void shouldAnd() {
    DocumentCondition eq = DocumentCondition.eq(Document.of("name", "otavio"));
    DocumentCondition gt = DocumentCondition.gt(Document.of("age", 10));
    DocumentCondition lte = DocumentCondition.lte(Document.of("salary", 10_000.00));
    DocumentCondition and = eq.and(gt);
    List<DocumentCondition> conditions = and.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.AND, and.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
    DocumentCondition result = and.and(lte);
    assertEquals(Condition.AND, result.getCondition());
    assertThat(result.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    }), Matchers.containsInAnyOrder(eq, gt, lte));
}
Also used : List(java.util.List) TypeReference(jakarta.nosql.TypeReference) DocumentCondition(jakarta.nosql.document.DocumentCondition) 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