mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-28 07:26:56 +00:00
#304 - ElasticSearch integration part 1 / doc store integration
This commit is contained in:
1 parent
cb1fe297d6
commit
8d3b4a0407
209 files changed
+6736
-573
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class WriteJsonDirtyTest {
|
||||
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
List<Customer> customers = Ebean.find(Customer.class).findList();
|
||||
|
||||
Customer customer = Ebean.find(Customer.class).setId(customers.get(0).getId())
|
||||
.setUseCache(false)
|
||||
.findUnique();
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);
|
||||
|
||||
customer.setName("dirtyCustName");
|
||||
customer.setAnniversary(new Date(System.currentTimeMillis()));
|
||||
|
||||
EntityBean entityBean = (EntityBean)customer;
|
||||
boolean[] dirtyProperties = entityBean._ebean_getIntercept().getDirtyProperties();
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonGenerator generator = jsonFactory.createGenerator(writer);
|
||||
|
||||
WriteJson writeJson = new WriteJson(server, generator, null, null, null, null);
|
||||
descriptor.jsonWriteDirty(writeJson, entityBean, dirtyProperties);
|
||||
|
||||
generator.flush();
|
||||
generator.close();
|
||||
|
||||
String jsonContent = writer.toString();
|
||||
assertTrue(jsonContent.contains("\"name\":"));
|
||||
assertTrue(jsonContent.contains("\"anniversary\":"));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.text.PathProperties;
|
||||
import com.avaje.ebean.FetchPath;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import org.junit.Test;
|
||||
@@ -19,8 +20,8 @@ public class WriteJsonTest {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonGenerator generator = jsonFactory.createGenerator(new StringWriter());
|
||||
|
||||
PathProperties pathProperties = PathProperties.parse("id,status,name,customer(id,name,address(street,city)),orders(qty,product(sku,prodName))");
|
||||
WriteJson writeJson = new WriteJson(null, generator, pathProperties, null, null, JsonConfig.Include.ALL);
|
||||
FetchPath fetchPath = PathProperties.parse("id,status,name,customer(id,name,address(street,city)),orders(qty,product(sku,prodName))");
|
||||
WriteJson writeJson = new WriteJson(null, generator, fetchPath, null, null, JsonConfig.Include.ALL);
|
||||
|
||||
WriteJson.WriteBean rootLevel = writeJson.createWriteBean(null, null);
|
||||
assertTrue(rootLevel.currentIncludeProps.contains("id"));
|
||||
|
||||
Reference in new issue
Block a user