// Path: mappingrpc-connector/src/main/java/github/mappingrpc/core/io/wamp/constant/MsgTypeConstant.java
// public class MsgTypeConstant {
// 	public static final int hello = 1; // doing
// 	public static final int wellcome = 2; // doing
// 	public static final int error = 8;
// 	public static final int call = 48;
// 	public static final int result = 50;
// }
// 
// Path: mappingrpc-connector/src/main/java/github/mappingrpc/core/io/wamp/domain/command/CallCommand.java
// public class CallCommand implements WampCommandBase {
// 	private int msgType = MsgTypeConstant.call;
// 	private long requestId = 1;
// 	private JSONObject options = new JSONObject();
// 	private String procedureUri;
// 	private Object[] args;
// 	
// 	static AtomicLong requestIdPool = new AtomicLong(1);
// 	
// 	public CallCommand(){
// 		requestId = requestIdPool.incrementAndGet();
// 	}
// 
// 	@Override
// 	public int getMsgType() {
// 		return msgType;
// 	}
// 
// 	public long getRequestId() {
// 		return requestId;
// 	}
// 
// 	public void setRequestId(long requestId) {
// 		this.requestId = requestId;
// 	}
// 
// 	public JSONObject getOptions() {
// 		return options;
// 	}
// 
// 	public void setOptions(JSONObject options) {
// 		this.options = options;
// 	}
// 
// 	public String getProcedureUri() {
// 		return procedureUri;
// 	}
// 
// 	public void setProcedureUri(String procedureUrl) {
// 		this.procedureUri = procedureUrl;
// 	}
// 
// 	public Object[] getArgs() {
// 		return args;
// 	}
// 
// 	public void setArgs(Object[] args) {
// 		this.args = args;
// 	}
// 
// 	@Override
// 	public Object[] fieldToArray() {
// 		return new Object[]{msgType, requestId, options, procedureUri, args};
// 	}
// 
// 	@Override
// 	public String toCommandJson() {
// 		return JSONObject.toJSONString(fieldToArray());
// 	}
// 
// }
// 
// Path: mappingrpc-connector/src/test/java/com/github/mappingrpc/connector/test/domain/User.java
// public class User implements Serializable {
// 	private static final long serialVersionUID = -5128432017050518465L;
// 
// 	private long id;
// 	private String displayName;
// 	private long flagBit;
// 	private String features = "{}";
// 	transient private JSONObject featuresJson = null;
// 
// 	public long getId() {
// 		return id;
// 	}
// 
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 
// 	public String getDisplayName() {
// 		return displayName;
// 	}
// 
// 	public void setDisplayName(String displayName) {
// 		this.displayName = displayName;
// 	}
// 
// 	public long getFlagBit() {
// 		return flagBit;
// 	}
// 
// 	public void setFlagBit(long flagBit) {
// 		this.flagBit = flagBit;
// 	}
// 
// 	public String getFeatures() {
// 		return features;
// 	}
// 
// 	public void setFeatures(String features) {
// 		this.features = features;
// 	}
// 
// 	public JSONObject getFeaturesJson() {
// 		return featuresJson;
// 	}
// 
// 	public void setFeaturesJson(JSONObject featuresJson) {
// 		this.featuresJson = featuresJson;
// 	}
// 
// }
// 
// Path: mappingrpc-connector/src/test/java/com/github/mappingrpc/connector/test/domain/option/RegisterOption.java
// public class RegisterOption {
// 
// }


import github.mappingrpc.core.io.wamp.constant.MsgTypeConstant;
import github.mappingrpc.core.io.wamp.domain.command.CallCommand;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Random;
import org.junit.Test;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.mappingrpc.connector.test.domain.User;
import com.github.mappingrpc.connector.test.domain.option.RegisterOption;
package mappingrpc.test.commandjson;





public class CommandJsonTest {
	Random rand = new Random();

	@Test
	public void test_CallCommand_序列化_期望成功() {
		CallCommand cmd = new CallCommand();
		cmd.setRequestId(rand.nextLong());
		cmd.setProcedureUri("/userService/registerUser/v20140308/");
		User user = new User();
		user.setId(6688);
		user.setDisplayName("lokki");
		RegisterOption registerOption = new RegisterOption();
		cmd.setArgs(new Object[] { user, "psw", registerOption });
		String json = JSONObject.toJSONString(cmd.fieldToArray());
		System.out.println(json);
	}

	@Test
	public void test_CallCommand_反序列化_期望成功() {
		String jsonText = "[48,4881004229002152578,\"{}\",\"/userService/registerUser/v20140308/\",[{\"displayName\":\"lokki\",\"features\":\"{}\",\"flagBit\":0,\"id\":6688},\"psw\",{}]]";
		JSONArray array = JSONObject.parseArray(jsonText);
		int i = 0;
		int msgType = array.getIntValue(i++);
		switch (msgType) {
		case MsgTypeConstant.call:
			CallCommand callCmd = new CallCommand();
			assert array.size() >= 5;
			callCmd.setRequestId(array.getLongValue(i++));
			callCmd.setOptions(new JSONObject());
			callCmd.setProcedureUri(array.getString(i++));

			// 以下需要 JSONArray.getArray(int index, Type[] types)更直接的功能
// Path: mappingrpc-connector/src/main/java/github/mappingrpc/core/io/wamp/constant/MsgTypeConstant.java
// public class MsgTypeConstant {
// 	public static final int hello = 1; // doing
// 	public static final int wellcome = 2; // doing
// 	public static final int error = 8;
// 	public static final int call = 48;
// 	public static final int result = 50;
// }
// 
// Path: mappingrpc-connector/src/main/java/github/mappingrpc/core/io/wamp/domain/command/CallCommand.java
// public class CallCommand implements WampCommandBase {
// 	private int msgType = MsgTypeConstant.call;
// 	private long requestId = 1;
// 	private JSONObject options = new JSONObject();
// 	private String procedureUri;
// 	private Object[] args;
// 	
// 	static AtomicLong requestIdPool = new AtomicLong(1);
// 	
// 	public CallCommand(){
// 		requestId = requestIdPool.incrementAndGet();
// 	}
// 
// 	@Override
// 	public int getMsgType() {
// 		return msgType;
// 	}
// 
// 	public long getRequestId() {
// 		return requestId;
// 	}
// 
// 	public void setRequestId(long requestId) {
// 		this.requestId = requestId;
// 	}
// 
// 	public JSONObject getOptions() {
// 		return options;
// 	}
// 
// 	public void setOptions(JSONObject options) {
// 		this.options = options;
// 	}
// 
// 	public String getProcedureUri() {
// 		return procedureUri;
// 	}
// 
// 	public void setProcedureUri(String procedureUrl) {
// 		this.procedureUri = procedureUrl;
// 	}
// 
// 	public Object[] getArgs() {
// 		return args;
// 	}
// 
// 	public void setArgs(Object[] args) {
// 		this.args = args;
// 	}
// 
// 	@Override
// 	public Object[] fieldToArray() {
// 		return new Object[]{msgType, requestId, options, procedureUri, args};
// 	}
// 
// 	@Override
// 	public String toCommandJson() {
// 		return JSONObject.toJSONString(fieldToArray());
// 	}
// 
// }
// 
// Path: mappingrpc-connector/src/test/java/com/github/mappingrpc/connector/test/domain/User.java
// public class User implements Serializable {
// 	private static final long serialVersionUID = -5128432017050518465L;
// 
// 	private long id;
// 	private String displayName;
// 	private long flagBit;
// 	private String features = "{}";
// 	transient private JSONObject featuresJson = null;
// 
// 	public long getId() {
// 		return id;
// 	}
// 
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 
// 	public String getDisplayName() {
// 		return displayName;
// 	}
// 
// 	public void setDisplayName(String displayName) {
// 		this.displayName = displayName;
// 	}
// 
// 	public long getFlagBit() {
// 		return flagBit;
// 	}
// 
// 	public void setFlagBit(long flagBit) {
// 		this.flagBit = flagBit;
// 	}
// 
// 	public String getFeatures() {
// 		return features;
// 	}
// 
// 	public void setFeatures(String features) {
// 		this.features = features;
// 	}
// 
// 	public JSONObject getFeaturesJson() {
// 		return featuresJson;
// 	}
// 
// 	public void setFeaturesJson(JSONObject featuresJson) {
// 		this.featuresJson = featuresJson;
// 	}
// 
// }
// 
// Path: mappingrpc-connector/src/test/java/com/github/mappingrpc/connector/test/domain/option/RegisterOption.java
// public class RegisterOption {
// 
// }


// Path: mappingrpc-connector/src/test/java/mappingrpc/test/commandjson/CommandJsonTest.java
import github.mappingrpc.core.io.wamp.constant.MsgTypeConstant;
import github.mappingrpc.core.io.wamp.domain.command.CallCommand;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Random;
import org.junit.Test;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.mappingrpc.connector.test.domain.User;
import com.github.mappingrpc.connector.test.domain.option.RegisterOption;

package mappingrpc.test.commandjson;





public class CommandJsonTest {
	Random rand = new Random();

	@Test
	public void test_CallCommand_序列化_期望成功() {
		CallCommand cmd = new CallCommand();
		cmd.setRequestId(rand.nextLong());
		cmd.setProcedureUri("/userService/registerUser/v20140308/");
		User user = new User();
		user.setId(6688);
		user.setDisplayName("lokki");
		RegisterOption registerOption = new RegisterOption();
		cmd.setArgs(new Object[] { user, "psw", registerOption });
		String json = JSONObject.toJSONString(cmd.fieldToArray());
		System.out.println(json);
	}

	@Test
	public void test_CallCommand_反序列化_期望成功() {
		String jsonText = "[48,4881004229002152578,\"{}\",\"/userService/registerUser/v20140308/\",[{\"displayName\":\"lokki\",\"features\":\"{}\",\"flagBit\":0,\"id\":6688},\"psw\",{}]]";
		JSONArray array = JSONObject.parseArray(jsonText);
		int i = 0;
		int msgType = array.getIntValue(i++);
		switch (msgType) {
		case MsgTypeConstant.call:
			CallCommand callCmd = new CallCommand();
			assert array.size() >= 5;
			callCmd.setRequestId(array.getLongValue(i++));
			callCmd.setOptions(new JSONObject());
			callCmd.setProcedureUri(array.getString(i++));

			// 以下需要 JSONArray.getArray(int index, Type[] types)更直接的功能
			List<Object> args = JSONObject.parseArray(array.getString(i++), new Type[] { User.class, String.class, RegisterOption.class });