@Test(expectedExceptions = Exception.class) public void clientSideTimeoutTest() { System.out.println( "-----------------------------------" + tcpRestServer.getClass().getCanonicalName() + "--------------------------------"); tcpRestServer.addResource(HelloWorldResource.class); TcpRestClientFactory factory = new TcpRestClientFactory(HelloWorld.class, "localhost", tcpRestServer.getServerPort()); HelloWorld client = (HelloWorld) factory.getInstance(); client.timeout(); }
@Test public void testClient() throws Exception { System.out.println( "-----------------------------------" + tcpRestServer.getClass().getCanonicalName() + "--------------------------------"); tcpRestServer.addResource(HelloWorldResource.class); TcpRestClientFactory factory = new TcpRestClientFactory(HelloWorld.class, "localhost", tcpRestServer.getServerPort()); HelloWorld client = (HelloWorld) factory.getInstance(); assertEquals("Hello, world!", client.helloWorld()); assertEquals("a,2,true123.0111", client.allTypes("a", 2, true, (short) 1, 2L, 3.0, (byte) 'o')); }
@Test public void largeDataTest() { StringBuilder builder = new StringBuilder(); String[] alpha = {"a", "b", "c", "d", "e", "f"}; for (int i = 0; i < 1024 * 10; i++) { builder.append(alpha[i % alpha.length]); } String req = builder.toString(); tcpRestServer.addSingletonResource(new HelloWorldResource()); System.out.println( "-----------------------------------" + tcpRestServer.getClass().getCanonicalName() + "--------------------------------"); TcpRestClientFactory factory = new TcpRestClientFactory(HelloWorld.class, "localhost", tcpRestServer.getServerPort()); HelloWorld client = (HelloWorld) factory.getInstance(); assertEquals(req, client.echo(req)); }
@Test public void testProxy() throws Exception { System.out.println( "-----------------------------------" + tcpRestServer.getClass().getCanonicalName() + "--------------------------------"); tcpRestServer.addResource(HelloWorldResource.class); HelloWorld client = (HelloWorld) Proxy.newProxyInstance( HelloWorld.class.getClassLoader(), new Class[] {HelloWorld.class}, new TcpRestClientProxy( HelloWorld.class.getCanonicalName(), "localhost", tcpRestServer.getServerPort())); assertEquals("Hello, world!", client.helloWorld()); assertEquals("x,2,false", client.oneTwoThree("x", 2, false)); }
@Test public void testArray() { System.out.println( "-----------------------------------" + tcpRestServer.getClass().getCanonicalName() + "--------------------------------"); tcpRestServer.addSingletonResource(new HelloWorldResource()); HelloWorld client = (HelloWorld) Proxy.newProxyInstance( HelloWorld.class.getClassLoader(), new Class[] {HelloWorld.class}, new TcpRestClientProxy( HelloWorld.class.getCanonicalName(), "localhost", tcpRestServer.getServerPort())); String[] in = new String[] {"a", "b", "c"}; String[] out = client.getArray(in); for (int i = 0; i < in.length; i++) { assertEquals(in[i], out[i]); } }