#919 - io.ebean package initial

This commit is contained in:
Rob Bygrave
2016-12-11 23:23:22 +13:00
parent 5821dc96b9
commit 971e2dc91b
2134 changed files with 10721 additions and 8652 deletions
@@ -0,0 +1,52 @@
package org.tests.json.include;
import io.ebean.Ebean;
import io.ebean.config.JsonConfig;
import io.ebean.text.json.JsonWriteOptions;
import org.tests.model.basic.Order;
import org.junit.Test;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
public class TestJsonExcludeEmptyList {
@Test
public void testToBeanToJson_NonNull() throws Exception {
Order bean = new Order();
bean.setId(99);
bean.setStatus(null);
bean.setOrderDate(null);
bean.setDetails(new ArrayList<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_NULL);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99,\"details\":[]}";
assertEquals(expectedJson, asJson);
}
@Test
public void testToBeanToJson_NonEmpty() throws Exception {
Order bean = new Order();
bean.setId(99);
bean.setStatus(null);
bean.setOrderDate(null);
bean.setDetails(new ArrayList<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_EMPTY);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99}";
assertEquals(expectedJson, asJson);
}
}
@@ -0,0 +1,48 @@
package org.tests.json.include;
import io.ebean.Ebean;
import io.ebean.config.JsonConfig;
import io.ebean.text.json.JsonWriteOptions;
import org.tests.model.json.EBasicJsonMap;
import org.junit.Test;
import java.util.LinkedHashMap;
import static org.junit.Assert.assertEquals;
public class TestJsonExcludeEmptyMap {
@Test
public void testToBeanToJson_NonNull() throws Exception {
EBasicJsonMap bean = new EBasicJsonMap();
bean.setId(99L);
bean.setContent(new LinkedHashMap<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_NULL);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99,\"content\":{}}";
assertEquals(expectedJson, asJson);
}
@Test
public void testToBeanToJson_NonEmpty() throws Exception {
EBasicJsonMap bean = new EBasicJsonMap();
bean.setId(99L);
bean.setContent(new LinkedHashMap<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_EMPTY);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99,\"content\":{}}";
assertEquals(expectedJson, asJson);
}
}
@@ -0,0 +1,48 @@
package org.tests.json.include;
import io.ebean.Ebean;
import io.ebean.config.JsonConfig;
import io.ebean.text.json.JsonWriteOptions;
import org.tests.model.basic.AttributeHolder;
import org.junit.Test;
import java.util.LinkedHashSet;
import static org.junit.Assert.assertEquals;
public class TestJsonExcludeEmptySet {
@Test
public void testToBeanToJson_NonNull() throws Exception {
AttributeHolder bean = new AttributeHolder();
bean.setId(99);
bean.setAttributes(new LinkedHashSet<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_NULL);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99,\"attributes\":[]}";
assertEquals(expectedJson, asJson);
}
@Test
public void testToBeanToJson_NonEmpty() throws Exception {
AttributeHolder bean = new AttributeHolder();
bean.setId(99);
bean.setAttributes(new LinkedHashSet<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_EMPTY);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99}";
assertEquals(expectedJson, asJson);
}
}
@@ -0,0 +1,31 @@
package org.tests.json.include;
import io.ebean.Ebean;
import io.ebean.config.JsonConfig;
import io.ebean.text.json.JsonWriteOptions;
import org.tests.json.transientproperties.EJsonTransientObject;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJsonExcludeNull {
@Test
public void testToBeanToJson() throws Exception {
EJsonTransientObject bean = new EJsonTransientObject();
bean.setId(99L);
bean.setName(null);
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_NULL);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99}";
assertEquals(expectedJson, asJson);
}
}
@@ -0,0 +1,65 @@
package org.tests.json.include;
import io.ebean.Ebean;
import io.ebean.config.JsonConfig;
import io.ebean.text.PathProperties;
import io.ebean.text.json.JsonWriteOptions;
import org.tests.json.transientproperties.EJsonTransientEntityList;
import org.tests.json.transientproperties.EJsonTransientList;
import org.junit.Test;
import java.util.ArrayList;
import static org.assertj.core.api.StrictAssertions.assertThat;
import static org.junit.Assert.assertEquals;
public class TestJsonExcludeTransientEmptyList {
@Test
public void testToBeanToJson_NonNull() throws Exception {
EJsonTransientList bean = new EJsonTransientList();
bean.setId(99L);
bean.setFileNames(new ArrayList<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_NULL);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99,\"fileNames\":[]}";
assertEquals(expectedJson, asJson);
}
@Test
public void testToBeanToJson_NonEmpty() throws Exception {
EJsonTransientList bean = new EJsonTransientList();
bean.setId(99L);
bean.setFileNames(new ArrayList<>());
JsonWriteOptions options = new JsonWriteOptions();
options.setInclude(JsonConfig.Include.NON_EMPTY);
String asJson = Ebean.json().toJson(bean, options);
String expectedJson = "{\"id\":99}";
assertEquals(expectedJson, asJson);
}
@Test
public void testToJson_with_transientExcludeFromPathProperties() throws Exception {
EJsonTransientEntityList bean = new EJsonTransientEntityList();
bean.setId(99L);
bean.setName("John");
PathProperties pathProps = PathProperties.parse("id,name");
String asJson = Ebean.json().toJson(bean, pathProps);
assertThat(asJson).isEqualTo("{\"id\":99,\"name\":\"John\"}");
}
}