mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#587 - Refactor - Change JsonContext.getScalar() to JsonContext.writeScalar()
This commit is contained in:
@@ -2,23 +2,18 @@ package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public abstract class BaseElasticTest extends BaseTestCase {
|
||||
|
||||
public static JsonFactory factory = new JsonFactory();
|
||||
|
||||
public ElasticExpressionContext context(StringWriter sb) throws IOException {
|
||||
public ElasticExpressionContext context() throws IOException {
|
||||
|
||||
BeanDescriptor<Order> desc = getBeanDescriptor(Order.class);
|
||||
JsonGenerator gen = factory.createGenerator(sb);
|
||||
return new ElasticExpressionContext(gen, desc);
|
||||
return new ElasticExpressionContext(Ebean.json(), desc);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-7
@@ -3,24 +3,19 @@ package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SimpleExpressionElasticTest extends BaseElasticTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void writeElastic() throws Exception {
|
||||
|
||||
SimpleExpression eqExp = new SimpleExpression("name", Op.EQ, "rob");
|
||||
|
||||
StringWriter sb = new StringWriter();
|
||||
ElasticExpressionContext context = context(sb);
|
||||
ElasticExpressionContext context = context();
|
||||
eqExp.writeElastic(context);
|
||||
context.json().flush();
|
||||
|
||||
String json = sb.toString();
|
||||
String json = context.flush();
|
||||
|
||||
assertThat(json).isEqualTo("{\"term\":{\"name\":\"rob\"}}");
|
||||
}
|
||||
|
||||
+4
-10
@@ -11,7 +11,6 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -28,8 +27,7 @@ public class DefaultOrmQueryElasticTest extends BaseElasticTest {
|
||||
|
||||
SpiExpressionList<Order> whereExpressions = spiQuery.getWhereExpressions();
|
||||
|
||||
StringWriter sb = new StringWriter();
|
||||
ElasticExpressionContext context = context(sb);
|
||||
ElasticExpressionContext context = context();
|
||||
JsonGenerator json = context.json();
|
||||
json.writeStartObject();
|
||||
json.writeFieldName("filter");
|
||||
@@ -37,9 +35,8 @@ public class DefaultOrmQueryElasticTest extends BaseElasticTest {
|
||||
whereExpressions.writeElastic(context);
|
||||
|
||||
json.writeEndObject();
|
||||
context.flush();
|
||||
|
||||
assertThat(sb.toString()).isEqualTo("{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}");
|
||||
assertThat(context.flush()).isEqualTo("{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,13 +49,10 @@ public class DefaultOrmQueryElasticTest extends BaseElasticTest {
|
||||
|
||||
SpiQuery<Order> spiQuery = (SpiQuery<Order>)query;
|
||||
|
||||
StringWriter sb = new StringWriter();
|
||||
ElasticExpressionContext context = context(sb);
|
||||
|
||||
ElasticExpressionContext context = context();
|
||||
spiQuery.writeElastic(context);
|
||||
context.flush();
|
||||
|
||||
assertThat(sb.toString()).isEqualTo("{\"fields\":[\"status\",\"customer.name\",\"details.product.id\"],\"query\":{\"filtered\":{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}}}");
|
||||
assertThat(context.flush()).isEqualTo("{\"fields\":[\"status\",\"customer.name\",\"details.product.id\"],\"query\":{\"filtered\":{\"filter\":{\"term\":{\"customer.name\":\"Rob\"}}}}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user