Search in sources :

Example 1 with InnerBean

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

the class RosettaBinderTest method itBindsNestedBeanCorrectly.

@Test
public void itBindsNestedBeanCorrectly() {
    InnerBean inner = new InnerBean();
    inner.setStringProperty("value");
    NestedBean bean = new NestedBean();
    bean.setInner(inner);
    assertThat(bind(bean)).isEqualTo(map("inner.stringProperty", "value"));
    assertThat(bindWithPrefix("prefix", bean)).isEqualTo(map("prefix.inner.stringProperty", "value"));
}
Also used : NestedBean(com.hubspot.rosetta.beans.NestedBean) InnerBean(com.hubspot.rosetta.beans.InnerBean) Test(org.junit.Test)

Example 2 with InnerBean

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

the class StoredAsJsonTest method setup.

@Before
public void setup() {
    bean = new StoredAsJsonBean();
    inner = new InnerBean();
    inner.setStringProperty("value");
}
Also used : InnerBean(com.hubspot.rosetta.beans.InnerBean) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Before(org.junit.Before)

Example 3 with InnerBean

use of com.hubspot.rosetta.beans.InnerBean 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)

Aggregations

InnerBean (com.hubspot.rosetta.beans.InnerBean)3 StoredAsJsonBean (com.hubspot.rosetta.beans.StoredAsJsonBean)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 NestedBean (com.hubspot.rosetta.beans.NestedBean)1 Before (org.junit.Before)1