mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-08 10:49:59 +00:00
Implement Scala MessagePack.
Change Java MessagePack to fit Scala's. Minor version up for Java's MessagePack.
This commit is contained in:
parent
15fb9bbcb2
commit
d5e583b09e
63 changed files with 12077 additions and 645 deletions
|
|
@ -13,6 +13,10 @@ import org.junit.Test;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
public class TestArrays extends TestCase {
|
||||
|
||||
|
||||
|
||||
|
||||
@MessagePackMessage
|
||||
public static class PrimitiveTest {
|
||||
public PrimitiveTest() { }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,133 @@
|
|||
package org.msgpack.template;
|
||||
|
||||
import java.beans.BeanDescriptor;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.msgpack.template.BeansFieldEntryReader;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author takeshita
|
||||
*
|
||||
*/
|
||||
public class BeansEntryReaderTest {
|
||||
|
||||
public static class VariableProps{
|
||||
|
||||
public int getCollect(){
|
||||
return 0;
|
||||
}
|
||||
public void setCollect(int v){}
|
||||
|
||||
public int getOnlyGetter(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setOnlySetter(int v){}
|
||||
|
||||
public boolean isBoolean(){
|
||||
return true;
|
||||
}
|
||||
public void setBoolean(boolean b){}
|
||||
|
||||
|
||||
private int getPrivateBoth(){return 1;}
|
||||
private void setPrivateBoth(int v){}
|
||||
|
||||
private int getPrivateGetter(){return 1;}
|
||||
public void setPrivateGetter(int v){}
|
||||
|
||||
public int getPrivateSetter(){return 1;}
|
||||
private void setPrivateSetter(int v){}
|
||||
|
||||
protected int getProtected(){return 1;}
|
||||
protected void setProtected(int v){}
|
||||
|
||||
int getInternal(){return 1;}
|
||||
void setInternal(int v){}
|
||||
|
||||
public int getWrongGetter(int v){return 1;}
|
||||
public void setWrongGetter(int v){}
|
||||
|
||||
public void getWrongGetter2(){}
|
||||
public void setWrongGetter2(int v){}
|
||||
|
||||
public int isWrongGetter3(){return 1;}
|
||||
public void setWrongGetter3(int v){}
|
||||
|
||||
public int getWrongSetter(){return 1;}
|
||||
public int setWrongSetter(int v){return 1;}
|
||||
|
||||
public int getWrongSetter2(){return 1;}
|
||||
public void setWrongSetter2(){}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
reader = new BeansFieldEntryReader();
|
||||
|
||||
try {
|
||||
info = Introspector.getBeanInfo(VariableProps.class);
|
||||
} catch (IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
BeansFieldEntryReader reader;
|
||||
BeanInfo info;
|
||||
@Test
|
||||
public void testIgnorePropertyDesc(){
|
||||
BeanDescriptor desc = info.getBeanDescriptor();
|
||||
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"collect")),is(false));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"boolean")),is(false));
|
||||
|
||||
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"onlyGetter")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"onlySetter")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"privateBoth")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"privateGetter")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"privateSetter")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"protected")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"internal")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"wrongGetter")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"wrongGetter2")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"wrongGetter3")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"wrongSetter")),is(true));
|
||||
assertThat(reader.isIgnoreProp(getProp(info,"wrongSetter2")),is(true));
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testReadEntries(){
|
||||
|
||||
IFieldEntry[] entries = reader.readFieldEntries(VariableProps.class, FieldOption.DEFAULT);
|
||||
|
||||
assertThat(entries.length, is(2));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public PropertyDescriptor getProp(BeanInfo info , String name){
|
||||
PropertyDescriptor[] props = info.getPropertyDescriptors();
|
||||
for(int i = 0;i < props.length;i++){
|
||||
PropertyDescriptor d = props[i];
|
||||
if(d.getDisplayName().equalsIgnoreCase(name)){
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
83
java/src/test/java/org/msgpack/template/BeansEquals.java
Normal file
83
java/src/test/java/org/msgpack/template/BeansEquals.java
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package org.msgpack.template;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* This matcher compares all get***() methods(except getClass)
|
||||
* @author takeshita
|
||||
*
|
||||
*/
|
||||
public class BeansEquals extends BaseMatcher<Object>{
|
||||
|
||||
Object expected;
|
||||
|
||||
HashSet<String> ignoreNames = new HashSet<String>();
|
||||
|
||||
public BeansEquals(Object expected){
|
||||
this.expected = expected;
|
||||
}
|
||||
public BeansEquals(Object expected,String[] ignoreNames){
|
||||
this.expected = expected;
|
||||
for(int i = 0;i < ignoreNames.length;i++){
|
||||
this.ignoreNames.add(ignoreNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static String errorMessage = "hoge";
|
||||
|
||||
@Override
|
||||
public boolean matches(Object actual) {
|
||||
if(expected == actual){
|
||||
return true;
|
||||
}
|
||||
if(!actual.getClass().equals(expected.getClass())){
|
||||
errorMessage = String.format("Expected class is %s but actual %s",
|
||||
expected.getClass().getName(),
|
||||
actual.getClass().getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Method m : expected.getClass().getMethods()){
|
||||
String n = m.getName();
|
||||
if(n.startsWith("get") &&
|
||||
!n.equals("getClass") &&
|
||||
!ignoreNames.contains(n)){
|
||||
|
||||
if(m.getParameterTypes().length == 0 &&
|
||||
!m.getReturnType().equals(void.class)){
|
||||
try {
|
||||
Object exp = m.invoke(expected);
|
||||
Object act = m.invoke(actual);
|
||||
|
||||
Assert.assertThat("@" + n,act, CoreMatchers.is(exp));
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(String.format(
|
||||
"Exception occured while comparing %s",n), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void describeTo(Description desc) {
|
||||
|
||||
desc.appendText(errorMessage);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -24,7 +24,10 @@ import org.msgpack.Unpacker;
|
|||
import org.msgpack.annotation.MessagePackMessage;
|
||||
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
||||
import org.msgpack.annotation.Optional;
|
||||
import org.msgpack.template.builder.BuilderSelectorRegistry;
|
||||
import org.msgpack.template.builder.TemplateBuilder;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestTemplateBuilderPackConvert extends TestCase {
|
||||
|
|
@ -714,7 +717,9 @@ public class TestTemplateBuilderPackConvert extends TestCase {
|
|||
@Test
|
||||
public void testFinalClass() throws Exception {
|
||||
try {
|
||||
TemplateBuilder.build(FinalModifierClass.class);
|
||||
TemplateBuilder builder = BuilderSelectorRegistry.getInstance().select(FinalModifierClass.class);
|
||||
Assert.assertNull(builder);// no available builder
|
||||
BuilderSelectorRegistry.getInstance().getForceBuilder().buildTemplate(FinalModifierClass.class);
|
||||
assertTrue(true);
|
||||
} catch (TemplateBuildException e) {
|
||||
fail();
|
||||
|
|
@ -731,7 +736,9 @@ public class TestTemplateBuilderPackConvert extends TestCase {
|
|||
@Test
|
||||
public void testInterfaceType00() throws Exception {
|
||||
try {
|
||||
TemplateBuilder.build(SampleInterface.class);
|
||||
TemplateBuilder builder = BuilderSelectorRegistry.getInstance().select(SampleInterface.class);
|
||||
Assert.assertNull(builder);// no available builder
|
||||
BuilderSelectorRegistry.getInstance().getForceBuilder().buildTemplate(SampleInterface.class);
|
||||
fail();
|
||||
} catch (TemplateBuildException e) {
|
||||
assertTrue(true);
|
||||
|
|
@ -742,7 +749,9 @@ public class TestTemplateBuilderPackConvert extends TestCase {
|
|||
@Test
|
||||
public void testInterfaceType01() throws Exception {
|
||||
try {
|
||||
TemplateBuilder.build(SampleInterface.class);
|
||||
TemplateBuilder builder = BuilderSelectorRegistry.getInstance().select(SampleInterface.class);
|
||||
Assert.assertNull(builder);// no available builder
|
||||
BuilderSelectorRegistry.getInstance().getForceBuilder().buildTemplate(SampleInterface.class);
|
||||
fail();
|
||||
} catch (TemplateBuildException e) {
|
||||
assertTrue(true);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,11 @@ import org.msgpack.Unpacker;
|
|||
import org.msgpack.annotation.MessagePackMessage;
|
||||
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
||||
import org.msgpack.annotation.Optional;
|
||||
import org.msgpack.template.TestTemplateBuilderPackConvert.SampleInterface;
|
||||
import org.msgpack.template.builder.BuilderSelectorRegistry;
|
||||
import org.msgpack.template.builder.TemplateBuilder;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestTemplateBuilderPackUnpack extends TestCase {
|
||||
|
|
@ -714,7 +718,9 @@ public class TestTemplateBuilderPackUnpack extends TestCase {
|
|||
@Test
|
||||
public void testFinalClass() throws Exception {
|
||||
try {
|
||||
TemplateBuilder.build(FinalModifierClass.class);
|
||||
TemplateBuilder builder = BuilderSelectorRegistry.getInstance().select(FinalModifierClass.class);
|
||||
Assert.assertNull(builder);
|
||||
BuilderSelectorRegistry.getInstance().getForceBuilder().buildTemplate(FinalModifierClass.class);
|
||||
assertTrue(true);
|
||||
} catch (TemplateBuildException e) {
|
||||
fail();
|
||||
|
|
@ -731,7 +737,9 @@ public class TestTemplateBuilderPackUnpack extends TestCase {
|
|||
@Test
|
||||
public void testInterfaceType00() throws Exception {
|
||||
try {
|
||||
TemplateBuilder.build(SampleInterface.class);
|
||||
TemplateBuilder builder = BuilderSelectorRegistry.getInstance().select(SampleInterface.class);
|
||||
Assert.assertNull(builder);
|
||||
BuilderSelectorRegistry.getInstance().getForceBuilder().buildTemplate(SampleInterface.class);
|
||||
fail();
|
||||
} catch (TemplateBuildException e) {
|
||||
assertTrue(true);
|
||||
|
|
@ -742,7 +750,9 @@ public class TestTemplateBuilderPackUnpack extends TestCase {
|
|||
@Test
|
||||
public void testInterfaceType01() throws Exception {
|
||||
try {
|
||||
TemplateBuilder.build(SampleInterface.class);
|
||||
TemplateBuilder builder = BuilderSelectorRegistry.getInstance().select(SampleInterface.class);
|
||||
Assert.assertNull(builder);
|
||||
BuilderSelectorRegistry.getInstance().getForceBuilder().buildTemplate(SampleInterface.class);
|
||||
fail();
|
||||
} catch (TemplateBuildException e) {
|
||||
assertTrue(true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue