Search in sources :

Example 1 with JavaBean1

use of org.immutables.criteria.javabean.JavaBean1 in project immutables by immutables.

the class KeyExtractorTest method javaBean.

@Test
void javaBean() {
    KeyExtractor extractor = KeyExtractor.defaultFactory().create(JavaBean1.class);
    check(extractor.metadata().isKeyDefined());
    check(extractor.metadata().isExpression());
    check(extractor.metadata().keys()).hasSize(1);
    Member member = (Member) Visitors.toPath(extractor.metadata().keys().get(0)).element();
    check(member.getName()).is("string1");
    JavaBean1 bean1 = new JavaBean1();
    bean1.setString1("foo");
    check(extractor.extract(bean1)).is("foo");
}
Also used : Member(java.lang.reflect.Member) JavaBean1(org.immutables.criteria.javabean.JavaBean1) Test(org.junit.jupiter.api.Test)

Example 2 with JavaBean1

use of org.immutables.criteria.javabean.JavaBean1 in project immutables by immutables.

the class IdAnnotationModuleTest method javaBean.

/**
 * Check annotation lookup for java beans
 */
@ParameterizedTest
@MethodSource("mappers")
void javaBean(ObjectMapper mapper) throws IOException {
    JavaBean1 bean1 = new JavaBean1();
    bean1.setString1("id123");
    bean1.setInt1(42);
    bean1.setBase("base1");
    ObjectNode node = mapper.valueToTree(bean1);
    check(ImmutableList.copyOf(node.fieldNames())).has("_id");
    check(node.get("_id").asText()).is("id123");
    check(ImmutableList.copyOf(node.fieldNames())).not().has("string1");
    JavaBean1 bean2 = mapper.treeToValue(node, JavaBean1.class);
    check(bean2.getString1()).is("id123");
    check(bean2.getInt1()).is(42);
    check(bean2.getBase()).is("base1");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JavaBean1(org.immutables.criteria.javabean.JavaBean1) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

JavaBean1 (org.immutables.criteria.javabean.JavaBean1)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Member (java.lang.reflect.Member)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1