package com.ikamobile.ikasoa.rpc.handler;

import org.junit.Test;

import com.ikamobile.ikasoa.rpc.handler.ProtocolHandlerFactory.ProtocolType;
import com.ikamobile.ikasoa.rpc.service.ExampleVO;

import junit.framework.TestCase;

public class TestProtocolHandler extends TestCase {

	private int testId = 1;
	private String testStr = "Protocol测试";
	private ExampleVO evo = new ExampleVO(testId, testStr);

	@Test
	public void testJsonProtocolHandlerImpl() {

		ProtocolHandlerFactory<Object[], ExampleVO> chf = new ProtocolHandlerFactory<Object[], ExampleVO>();
		ReturnData rd = new ReturnData(ExampleVO.class);
		ProtocolHandler<Object[], ExampleVO> ch = chf.getProtocolHandler(rd);

		String as = ch.argToStr(new Object[] { evo });
		Object[] evoo = ch.strToArg(as);
		ExampleVO aevo = (ExampleVO) evoo[0];
		assertNotNull(aevo);
		assertEquals(aevo.getId(), testId);
		assertEquals(aevo.getString(), testStr);

		String rs = ch.resultToStr(evo);
		ExampleVO revo = ch.strToResult(rs);
		assertNotNull(revo);
		assertEquals(revo.getId(), testId);
		assertEquals(revo.getString(), testStr);
	}

	@Test
	public void testXmlProtocolHandlerImpl() {

		ProtocolHandlerFactory<Object[], ExampleVO> chf = new ProtocolHandlerFactory<Object[], ExampleVO>();
		ReturnData rd = new ReturnData(ExampleVO.class);
		ProtocolHandler<Object[], ExampleVO> ch = chf.getProtocolHandler(rd, ProtocolType.XML);

		String as = ch.argToStr(new Object[] { evo });
		Object[] evoo = ch.strToArg(as);
		ExampleVO aevo = (ExampleVO) evoo[0];
		assertNotNull(aevo);
		assertEquals(aevo.getId(), testId);
		assertEquals(aevo.getString(), testStr);

		String rs = ch.resultToStr(evo);
		ExampleVO revo = ch.strToResult(rs);
		assertNotNull(revo);
		assertEquals(revo.getId(), testId);
		assertEquals(revo.getString(), testStr);
	}

}

@@ -1855,11 +1855,742 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@Test%0D%0A%09public void testKryoProtocolHandlerImpl() %7B%0D%0A%0D%0A%09%09ProtocolHandlerFactory%3CObject%5B%5D, ExampleVO%3E chf = new ProtocolHandlerFactory%3CObject%5B%5D, ExampleVO%3E();%0D%0A%09%09ReturnData rd = new ReturnData(ExampleVO.class);%0D%0A%09%09ProtocolHandler%3CObject%5B%5D, ExampleVO%3E ch = chf.getProtocolHandler(rd, ProtocolType.KRYO);%0D%0A%0D%0A%09%09String as = ch.argToStr(new Object%5B%5D %7B evo %7D);%0D%0A%09%09Object%5B%5D evoo = ch.strToArg(as);%0D%0A%09%09ExampleVO aevo = (ExampleVO) evoo%5B0%5D;%0D%0A%09%09assertNotNull(aevo);%0D%0A%09%09assertEquals(aevo.getId(), testId);%0D%0A%09%09assertEquals(aevo.getString(), testStr);%0D%0A%0D%0A%09%09String rs = ch.resultToStr(evo);%0D%0A%09%09ExampleVO revo = ch.strToResult(rs);%0D%0A%09%09assertNotNull(revo);%0D%0A%09%09assertEquals(revo.getId(), testId);%0D%0A%09%09assertEquals(revo.getString(), testStr);%0D%0A%09%7D%0D%0A%0D%0A
 %7D%0D%0A

add kryo protocol test.