Search in sources :

Example 11 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class StoredAsJsonTest method testAnnotatedGetterWithDefaultDeserialization.

@Test
public void testAnnotatedGetterWithDefaultDeserialization() throws JsonProcessingException {
    ObjectNode node = Rosetta.getMapper().createObjectNode();
    node.put("annotatedGetterWithDefault", expected);
    StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
    assertThat(bean.getAnnotatedGetterWithDefault().getStringProperty()).isEqualTo("value");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Example 12 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class StoredAsJsonTest method testAnnotatedSetterWithDefaultDeserialization.

@Test
public void testAnnotatedSetterWithDefaultDeserialization() throws JsonProcessingException {
    ObjectNode node = Rosetta.getMapper().createObjectNode();
    node.put("annotatedSetterWithDefault", expected);
    StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
    assertThat(bean.getAnnotatedSetterWithDefault().getStringProperty()).isEqualTo("value");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Example 13 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class StoredAsJsonTest method testAnnotatedSetterWithDefaultNullDeserialization.

@Test
public void testAnnotatedSetterWithDefaultNullDeserialization() throws JsonProcessingException {
    ObjectNode node = Rosetta.getMapper().createObjectNode();
    node.put("annotatedSetterWithDefault", NullNode.getInstance());
    StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
    assertThat(bean.getAnnotatedSetterWithDefault().getStringProperty()).isEqualTo("value");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Example 14 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class RosettaBinderTest method itBindsStoredAsJsonBeanCorrectly.

@Test
public void itBindsStoredAsJsonBeanCorrectly() {
    InnerBean inner = new InnerBean();
    inner.setStringProperty("value");
    JsonNode innerJsonNode = Rosetta.getMapper().createObjectNode().set("stringProperty", TextNode.valueOf("value"));
    StoredAsJsonBean bean = new StoredAsJsonBean();
    bean.setAnnotatedField(inner);
    bean.setAnnotatedGetter(inner);
    bean.setAnnotatedSetter(inner);
    bean.setAnnotatedFieldWithDefault(inner);
    bean.setAnnotatedGetterWithDefault(inner);
    bean.setAnnotatedSetterWithDefault(inner);
    bean.setOptionalField(Optional.of(inner));
    bean.setOptionalGetter(Optional.of(inner));
    bean.setOptionalSetter(Optional.of(inner));
    bean.setBinaryField(inner);
    bean.setBinaryFieldWithDefault(inner);
    bean.setJsonNodeField(innerJsonNode);
    String json = "{\"stringProperty\":\"value\"}";
    List<Byte> bytes = toList(json.getBytes(StandardCharsets.UTF_8));
    assertThat(bind(bean)).isEqualTo(map("annotatedField", json, "annotatedGetter", json, "annotatedSetter", json, "annotatedFieldWithDefault", json, "annotatedGetterWithDefault", json, "annotatedSetterWithDefault", json, "optionalField", json, "optionalGetter", json, "optionalSetter", json, "binaryField", bytes, "binaryFieldWithDefault", bytes, "jsonNodeField", json));
    assertThat(bindWithPrefix("prefix", bean)).isEqualTo(map("prefix.annotatedField", json, "prefix.annotatedGetter", json, "prefix.annotatedSetter", json, "prefix.annotatedFieldWithDefault", json, "prefix.annotatedGetterWithDefault", json, "prefix.annotatedSetterWithDefault", json, "prefix.optionalField", json, "prefix.optionalGetter", json, "prefix.optionalSetter", json, "prefix.binaryField", bytes, "prefix.binaryFieldWithDefault", bytes, "prefix.jsonNodeField", json));
}
Also used : InnerBean(com.hubspot.rosetta.beans.InnerBean) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 15 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class RosettaMapperTest method itMapsStoredAsJsonBeanCorrectly.

@Test
public void itMapsStoredAsJsonBeanCorrectly() {
    String json = "{\"stringProperty\":\"value\"}";
    initializeResultSet("table.annotatedField", json, "table.annotatedGetter", json, "table.annotatedSetter", json, "table.annotatedFieldWithDefault", json, "table.annotatedGetterWithDefault", json, "table.annotatedSetterWithDefault", json);
    StoredAsJsonBean bean = map(StoredAsJsonBean.class);
    assertThat(bean.getAnnotatedField().getStringProperty()).isEqualTo("value");
    assertThat(bean.getAnnotatedGetter().getStringProperty()).isEqualTo("value");
    assertThat(bean.getAnnotatedSetter().getStringProperty()).isEqualTo("value");
    assertThat(bean.getAnnotatedFieldWithDefault().getStringProperty()).isEqualTo("value");
    assertThat(bean.getAnnotatedGetterWithDefault().getStringProperty()).isEqualTo("value");
    assertThat(bean.getAnnotatedSetterWithDefault().getStringProperty()).isEqualTo("value");
}
Also used : StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Aggregations

StoredAsJsonBean (com.hubspot.rosetta.beans.StoredAsJsonBean)29 Test (org.junit.Test)28 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)24 InnerBean (com.hubspot.rosetta.beans.InnerBean)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Before (org.junit.Before)1