Search in sources :

Example 11 with TypeReference

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

the class DefaultValueTest method shouldConvertToList.

@Test
public void shouldConvertToList() {
    Value value = Value.of(Arrays.asList(10, 20, 30));
    assertThat(value.get(new TypeReference<List<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 12 with TypeReference

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

the class DocumentTest method shouldReturnGetType.

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

Example 13 with TypeReference

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameBetween.

@Test
public void shouldSelectWhereNameBetween() {
    String documentCollection = "documentCollection";
    Number valueA = 10;
    Number valueB = 20;
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").between(valueA, valueB).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.BETWEEN, condition.getCondition());
    assertEquals("name", document.getName());
    assertThat(document.get(new TypeReference<List<Number>>() {
    }), Matchers.contains(10, 20));
}
Also used : TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 14 with TypeReference

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

the class DefaultDocumentConditionTest method shouldOr.

@Test
public void shouldOr() {
    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 or = eq.or(gt);
    List<DocumentCondition> conditions = or.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.OR, or.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
    DocumentCondition result = or.or(lte);
    assertEquals(Condition.OR, 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)

Example 15 with TypeReference

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

the class DefaultDocumentConditionTest method shouldCreateAndCondition.

@Test
public void shouldCreateAndCondition() {
    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.and(condition2);
    Document andDocument = and.getDocument();
    assertEquals(Condition.AND, and.getCondition());
    assertEquals(Condition.AND.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)

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