45 lines
1.4 KiB
Java
45 lines
1.4 KiB
Java
|
package eu.mikroskeem.utils.test.simplerpc;
|
||
|
|
||
|
import eu.mikroskeem.utils.simplerpc.RPCRequest;
|
||
|
import eu.mikroskeem.utils.simplerpc.RPCResponse;
|
||
|
import org.junit.Assert;
|
||
|
import org.junit.Test;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.UUID;
|
||
|
|
||
|
public class TestRPC {
|
||
|
@Test public void testRPCRequestSerialize() throws Exception {
|
||
|
RPCRequest rpcRequest = new RPCRequest();
|
||
|
rpcRequest.setId(UUID.randomUUID().toString());
|
||
|
rpcRequest.setMethod("wut");
|
||
|
rpcRequest.setArguments(new ArrayList<Object>(){{
|
||
|
add("njeeger");
|
||
|
add(20D); // Apparently Gson always converts int/float to double when passed as Object
|
||
|
add("õäöu");
|
||
|
add("( ͡° ͜ʖ ͡°)");
|
||
|
}});
|
||
|
|
||
|
RPCRequest unserialized = RPCRequest.fromByteArray(
|
||
|
rpcRequest.toByteArray()
|
||
|
);
|
||
|
|
||
|
Assert.assertEquals(rpcRequest.toString(), unserialized.toString());
|
||
|
}
|
||
|
|
||
|
@Test public void testRPCResponseSerialize() throws Exception {
|
||
|
RPCResponse rpcResponse = new RPCResponse();
|
||
|
rpcResponse.setStatus(RPCResponse.Status.SUCCESS);
|
||
|
rpcResponse.setMessage("hey");
|
||
|
rpcResponse.setResponse(new ArrayList<Object>(){{
|
||
|
add("my name is jeff");
|
||
|
}});
|
||
|
|
||
|
RPCResponse unserialized = RPCResponse.fromByteArray(
|
||
|
rpcResponse.toByteArray()
|
||
|
);
|
||
|
|
||
|
Assert.assertEquals(rpcResponse.toString(), unserialized.toString());
|
||
|
}
|
||
|
}
|