|
|
|
|
@@ -15,11 +15,8 @@ import java.util.function.Supplier;
|
|
|
|
|
import org.junit.jupiter.api.*;
|
|
|
|
|
import org.redkale.convert.ConvertColumn;
|
|
|
|
|
import org.redkale.convert.bson.BsonConvert;
|
|
|
|
|
import org.redkale.convert.bson.BsonFactory;
|
|
|
|
|
import org.redkale.convert.json.JsonConvert;
|
|
|
|
|
import org.redkale.convert.json.JsonFactory;
|
|
|
|
|
import org.redkale.convert.pb.ProtobufConvert;
|
|
|
|
|
import org.redkale.convert.pb.ProtobufFactory;
|
|
|
|
|
import org.redkale.util.TypeToken;
|
|
|
|
|
import org.redkale.util.Utility;
|
|
|
|
|
|
|
|
|
|
@@ -30,7 +27,7 @@ import org.redkale.util.Utility;
|
|
|
|
|
public class GenericEntityTest {
|
|
|
|
|
private static final Type ENTITY_TYPE = new TypeToken<GenericEntity<Long, String, SimpleEntity>>() {}.getType();
|
|
|
|
|
private static final String JSON =
|
|
|
|
|
"{\"entry\":{\"key\":\"aaaa\",\"value\":{\"addr\":\"127.0.0.1:6666\",\"addrs\":[22222,33333,44444,55555,66666,77777,88888,99999],\"id\":1000000001,\"lists\":[\"aaaa\",\"bbbb\",\"cccc\"],\"map\":{\"AAA\":111,\"CCC\":333,\"BBB\":222},\"name\":\"this is name\\n \\\"test\",\"strings\":[\"zzz\",\"yyy\",\"xxx\"]}},\"list\":[1234567890],\"name\":\"你好\"}";
|
|
|
|
|
"{\"entry\":{\"key\":\"aaaa\",\"value\":{\"addr\":\"127.0.0.1:6666\",\"addrs\":[22222,33333,44444,55555,66666,77777,88888,99999],\"desc\":\"\",\"id\":1000000001,\"lists\":[\"aaaa\",\"bbbb\",\"cccc\"],\"map\":{\"AAA\":111,\"CCC\":333,\"BBB\":222},\"name\":\"this is name\\n \\\"test\",\"strings\":[\"zzz\",\"yyy\",\"xxx\"]}},\"list\":[1234567890],\"name\":\"你好\"}";
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Throwable {
|
|
|
|
|
GenericEntityTest test = new GenericEntityTest();
|
|
|
|
|
@@ -47,7 +44,6 @@ public class GenericEntityTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runJson1() throws Exception {
|
|
|
|
|
JsonFactory.root().withTinyFeature(true);
|
|
|
|
|
JsonConvert convert = JsonConvert.root();
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
|
|
|
|
String json = convert.convertTo(bean);
|
|
|
|
|
@@ -58,7 +54,6 @@ public class GenericEntityTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runJson2() throws Exception {
|
|
|
|
|
JsonFactory.root().withTinyFeature(true);
|
|
|
|
|
JsonConvert convert = JsonConvert.root();
|
|
|
|
|
InputStream in = ConvertHelper.createInputStream(createBytes());
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
@@ -70,7 +65,6 @@ public class GenericEntityTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runJson3() throws Exception {
|
|
|
|
|
JsonFactory.root().withTinyFeature(true);
|
|
|
|
|
JsonConvert convert = JsonConvert.root();
|
|
|
|
|
ByteBuffer in = ConvertHelper.createByteBuffer(createBytes());
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
@@ -82,7 +76,6 @@ public class GenericEntityTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runPb1() throws Exception {
|
|
|
|
|
ProtobufFactory.root().withTinyFeature(true);
|
|
|
|
|
ProtobufConvert convert = ProtobufConvert.root();
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
|
|
|
|
byte[] bs = convert.convertTo(bean);
|
|
|
|
|
@@ -94,70 +87,65 @@ public class GenericEntityTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runPb2() throws Exception {
|
|
|
|
|
ProtobufFactory.root().withTinyFeature(true);
|
|
|
|
|
ProtobufConvert convert = ProtobufConvert.root();
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
|
|
|
|
byte[] bs = convert.convertTo(bean);
|
|
|
|
|
InputStream in = ConvertHelper.createInputStream(bs);
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
Assertions.assertArrayEquals(bs, out.toByteArray());
|
|
|
|
|
// InputStream in = ConvertHelper.createInputStream(bs);
|
|
|
|
|
// GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
// Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
// convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
// Assertions.assertArrayEquals(bs, out.toByteArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runPb3() throws Exception {
|
|
|
|
|
ProtobufFactory.root().withTinyFeature(true);
|
|
|
|
|
ProtobufConvert convert = ProtobufConvert.root();
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
|
|
|
|
byte[] bs = convert.convertTo(bean);
|
|
|
|
|
ByteBuffer in = ConvertHelper.createByteBuffer(bs);
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
Supplier<ByteBuffer> out = ConvertHelper.createSupplier();
|
|
|
|
|
ByteBuffer[] buffers = convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
Assertions.assertArrayEquals(bs, ConvertHelper.toBytes(buffers));
|
|
|
|
|
// ByteBuffer in = ConvertHelper.createByteBuffer(bs);
|
|
|
|
|
// GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
// Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
// Supplier<ByteBuffer> out = ConvertHelper.createSupplier();
|
|
|
|
|
// ByteBuffer[] buffers = convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
// Assertions.assertArrayEquals(bs, ConvertHelper.toBytes(buffers));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runBson1() throws Exception {
|
|
|
|
|
BsonFactory.root().withTinyFeature(true);
|
|
|
|
|
BsonConvert convert = BsonConvert.root();
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
|
|
|
|
byte[] bs = convert.convertTo(bean);
|
|
|
|
|
Utility.println("bson", bs);
|
|
|
|
|
String rs = convert.convertFrom(ENTITY_TYPE, bs).toString();
|
|
|
|
|
System.out.println();
|
|
|
|
|
Assertions.assertEquals(JSON, rs);
|
|
|
|
|
// Utility.println("bson", bs);
|
|
|
|
|
// String rs = convert.convertFrom(ENTITY_TYPE, bs).toString();
|
|
|
|
|
// System.out.println();
|
|
|
|
|
// Assertions.assertEquals(JSON, rs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runBson2() throws Exception {
|
|
|
|
|
BsonFactory.root().withTinyFeature(true);
|
|
|
|
|
BsonConvert convert = BsonConvert.root();
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
|
|
|
|
byte[] bs = convert.convertTo(bean);
|
|
|
|
|
InputStream in = ConvertHelper.createInputStream(bs);
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
Assertions.assertArrayEquals(bs, out.toByteArray());
|
|
|
|
|
// InputStream in = ConvertHelper.createInputStream(bs);
|
|
|
|
|
// GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
// Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
// convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
// Assertions.assertArrayEquals(bs, out.toByteArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void runBson3() throws Exception {
|
|
|
|
|
BsonFactory.root().withTinyFeature(true);
|
|
|
|
|
BsonConvert convert = BsonConvert.root();
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
|
|
|
|
byte[] bs = convert.convertTo(bean);
|
|
|
|
|
ByteBuffer in = ConvertHelper.createByteBuffer(bs);
|
|
|
|
|
GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
Supplier<ByteBuffer> out = ConvertHelper.createSupplier();
|
|
|
|
|
ByteBuffer[] buffers = convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
Assertions.assertArrayEquals(bs, ConvertHelper.toBytes(buffers));
|
|
|
|
|
// ByteBuffer in = ConvertHelper.createByteBuffer(bs);
|
|
|
|
|
// GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
|
|
|
|
// Assertions.assertEquals(JSON, rs.toString());
|
|
|
|
|
// Supplier<ByteBuffer> out = ConvertHelper.createSupplier();
|
|
|
|
|
// ByteBuffer[] buffers = convert.convertTo(out, ENTITY_TYPE, rs);
|
|
|
|
|
// Assertions.assertArrayEquals(bs, ConvertHelper.toBytes(buffers));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte[] createBytes() {
|
|
|
|
|
|