@Test public void testSingletonResource() throws Exception { System.out.println( "-----------------------------------" + tcpRestServer.getClass().getCanonicalName() + "--------------------------------"); Object instance = new SingletonCounterResource(2); tcpRestServer.addSingletonResource(instance); TcpRestClientFactory factory = new TcpRestClientFactory(Counter.class, "localhost", tcpRestServer.getServerPort()); Counter client = factory.getInstance(); assertEquals(2, client.getCounter()); client.increaseCounter(); assertEquals(3, client.getCounter()); tcpRestServer.deleteSingletonResource(instance); tcpRestServer.addResource(SingletonCounterResource.class); assertEquals(0, client.getCounter()); client.increaseCounter(); assertEquals(0, client.getCounter()); }
@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 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)); }