Search in sources :

Example 1 with ComplexBean

use of com.alipay.sofa.rpc.test.generic.bean.ComplexBean in project sofa-rpc by sofastack.

the class GenericTest method createMyComplexBean.

/**
 * 构建自定义扩展对象构成bean
 */
private ComplexBean createMyComplexBean() {
    ComplexBean complexBean = new ComplexBean();
    complexBean.setStrs(new String[] { null, "123", null });
    complexBean.setClazz(MyList.class);
    complexBean.setJobs(new Job[] { null, new Job("coder"), null });
    ArrayList list = new MyList();
    list.add(null);
    list.add(1);
    list.add(null);
    complexBean.setList(list);
    MyMap map = new MyMap();
    map.put("1", new Job("coder"));
    map.put(1, new People("wang", null));
    complexBean.setMap(map);
    return complexBean;
}
Also used : MyMap(com.alipay.sofa.rpc.test.generic.bean.MyMap) ArrayList(java.util.ArrayList) MyList(com.alipay.sofa.rpc.test.generic.bean.MyList) People(com.alipay.sofa.rpc.test.generic.bean.People) Job(com.alipay.sofa.rpc.test.generic.bean.Job) ComplexBean(com.alipay.sofa.rpc.test.generic.bean.ComplexBean)

Example 2 with ComplexBean

use of com.alipay.sofa.rpc.test.generic.bean.ComplexBean in project sofa-rpc by sofastack.

the class GenericTest method testComplexBean.

private void testComplexBean(GenericService proxy) {
    ComplexBean complexBean = createJdkComplexBean();
    Object obj = proxy.$genericInvoke("helloComplexBean", new String[] { ComplexBean.class.getName() }, new Object[] { complexBean });
    assertJdkGenericResult(obj);
    obj = GenericUtils.convertToObject(obj);
    assertJdkResult(obj);
    obj = proxy.$genericInvoke("helloComplexBean", new String[] { ComplexBean.class.getName() }, new Object[] { complexBean }, ComplexBean.class);
    assertJdkResult(obj);
    obj = GenericUtils.convertToGenericObject(obj);
    assertJdkGenericResult(obj);
    complexBean = createMyComplexBean();
    obj = proxy.$genericInvoke("helloComplexBean", new String[] { ComplexBean.class.getName() }, new Object[] { complexBean });
    assertMyGenericResult(obj);
    obj = GenericUtils.convertToObject(obj);
    assertMyComplexBeanResult(obj);
    obj = proxy.$genericInvoke("helloComplexBean", new String[] { ComplexBean.class.getName() }, new Object[] { complexBean }, ComplexBean.class);
    assertMyComplexBeanResult(obj);
    obj = GenericUtils.convertToGenericObject(obj);
    assertMyGenericResult(obj);
}
Also used : GenericObject(com.alipay.hessian.generic.model.GenericObject) ComplexBean(com.alipay.sofa.rpc.test.generic.bean.ComplexBean)

Example 3 with ComplexBean

use of com.alipay.sofa.rpc.test.generic.bean.ComplexBean in project sofa-rpc by sofastack.

the class GenericTest method assertJdkResult.

private void assertJdkResult(Object obj) {
    Assert.assertEquals(ComplexBean.class, obj.getClass());
    ComplexBean cx1 = createJdkComplexBean();
    ComplexBean cx2 = (ComplexBean) obj;
    assertArrayEquals(cx1.getStrs(), cx2.getStrs());
    assertArrayEquals(cx1.getJobs(), cx2.getJobs());
    assertEquals(cx1.getList(), cx2.getList());
    assertEquals(cx1.getMap(), cx2.getMap());
    assertEquals(cx1.getList().getClass(), cx2.getList().getClass());
    assertEquals(cx1.getClass(), cx2.getClass());
}
Also used : ComplexBean(com.alipay.sofa.rpc.test.generic.bean.ComplexBean)

Example 4 with ComplexBean

use of com.alipay.sofa.rpc.test.generic.bean.ComplexBean in project sofa-rpc by sofastack.

the class GenericTest method assertMyComplexBeanResult.

private void assertMyComplexBeanResult(Object obj) {
    Assert.assertEquals(ComplexBean.class, obj.getClass());
    ComplexBean cx1 = createMyComplexBean();
    ComplexBean cx2 = (ComplexBean) obj;
    assertArrayEquals(cx1.getStrs(), cx2.getStrs());
    assertArrayEquals(cx1.getJobs(), cx2.getJobs());
    assertEquals(cx1.getList(), cx2.getList());
    assertEquals(cx1.getMap(), cx2.getMap());
    assertEquals(cx1.getList().getClass(), cx2.getList().getClass());
    assertEquals(cx1.getMap().getClass(), cx2.getMap().getClass());
    assertEquals(cx1.getClass(), cx2.getClass());
}
Also used : ComplexBean(com.alipay.sofa.rpc.test.generic.bean.ComplexBean)

Example 5 with ComplexBean

use of com.alipay.sofa.rpc.test.generic.bean.ComplexBean in project sofa-rpc by sofastack.

the class GenericTest method assertMyGenericResult.

private void assertMyGenericResult(Object obj) {
    ComplexBean complexBean = createMyComplexBean();
    Assert.assertEquals(GenericObject.class, obj.getClass());
    GenericObject gb = (GenericObject) obj;
    Assert.assertEquals(gb.getType(), ComplexBean.class.getName());
    assertArrayEquals(gb.getField("strs"), complexBean.getStrs());
    Assert.assertEquals(gb.getField("jobs").getClass(), GenericArray.class);
    assertArrayEquals(GenericUtils.convertToObject(gb.getField("jobs")), complexBean.getJobs());
    Assert.assertEquals(gb.getField("list").getClass(), GenericCollection.class);
    Assert.assertEquals(GenericUtils.convertToObject(gb.getField("list")).getClass(), MyList.class);
    assertEquals(GenericUtils.convertToObject(gb.getField("list")), complexBean.getList());
    Assert.assertEquals(gb.getField("map").getClass(), GenericMap.class);
    Assert.assertEquals(GenericUtils.convertToObject(gb.getField("map")).getClass(), MyMap.class);
    assertEquals(GenericUtils.convertToObject(gb.getField("map")), complexBean.getMap());
}
Also used : GenericObject(com.alipay.hessian.generic.model.GenericObject) ComplexBean(com.alipay.sofa.rpc.test.generic.bean.ComplexBean)

Aggregations

ComplexBean (com.alipay.sofa.rpc.test.generic.bean.ComplexBean)7 GenericObject (com.alipay.hessian.generic.model.GenericObject)3 Job (com.alipay.sofa.rpc.test.generic.bean.Job)2 ArrayList (java.util.ArrayList)2 MyList (com.alipay.sofa.rpc.test.generic.bean.MyList)1 MyMap (com.alipay.sofa.rpc.test.generic.bean.MyMap)1 People (com.alipay.sofa.rpc.test.generic.bean.People)1