public static void main(String[] args) { System.out.println("--------------InterfaceABImpl---------------"); InterfaceABImpl abimpl1 = new InterfaceABImpl(); abimpl1.method1(); abimpl1.method2(); abimpl1.method3(); abimpl1.method4(); InterfaceA ia1 = abimpl1; InterfaceB ib1 = abimpl1; System.out.println("--------------InterfaceA---------------"); ia1.method1(); ia1.method1(); System.out.println("--------------InterfaceB---------------"); ib1.method3(); ib1.method4(); System.out.println("------------final field-----------------"); System.out.println(InterfaceA.MEMBER1); System.out.println(InterfaceA.MEMBER2); System.out.println(InterfaceB.MEMBER3); System.out.println(InterfaceB.MEMBER4); System.out.println(InterfaceABImpl.MEMBER1); System.out.println(InterfaceABImpl.MEMBER2); System.out.println(InterfaceABImpl.MEMBER3); System.out.println(InterfaceABImpl.MEMBER4); System.out.println("------------------InterfaceA,InterfaceB--------------------"); InterfaceA ia2 = new InterfaceABImpl(); ia2.method1(); ia2.method2(); InterfaceB ib2 = (InterfaceB) ia2; ib2.method3(); ib2.method4(); System.out.println("-------------------Interface[Array]-------------------------"); InterfaceA[] iaArray = { new InterfaceABImpl(), new InterfaceABImpl(), new InterfaceABImpl(), new InterfaceABImpl(), new InterfaceABImpl(), new InterfaceABImpl(), new InterfaceABImpl(), new InterfaceABImpl(), new InterfaceABImpl() }; for (int i = 0; i < iaArray.length; i++) { System.out.println("╟╢ц╪аж╪р : " + iaArray[i]); iaArray[i].method1(); iaArray[i].method2(); InterfaceB tempIb = (InterfaceB) iaArray[i]; tempIb.method3(); tempIb.method4(); } }
@Test public void testSubresourceProxy() throws Exception { String url = TestPortProvider.generateURL("/foobar"); InterfaceA a = ProxyFactory.create(InterfaceA.class, url); assertEquals("FOO", a.getFoo()); InterfaceB b = ((ResteasyClientProxy) a).as(InterfaceB.class); assertEquals("BAR", b.getBar()); }
private void checkReentrancy(ProxyBusObject proxy) { try { /* does the proxy implement InterfaceB? */ InterfaceB intf = proxy.getInterface(InterfaceB.class); try { String id = intf.methodB(); assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id); } catch (BusException e) { // OK we might get ER_BUS_BLOCKING_CALL_NOT_ALLOWED here if (!e.getMessage().equals("ER_BUS_BLOCKING_CALL_NOT_ALLOWED")) { e.printStackTrace(); fail("recieved an unexpected BusException."); } } bus.enableConcurrentCallbacks(); try { String id = intf.methodB(); assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id); } catch (BusException e) { fail("method invocation failed: " + e); } } catch (ClassCastException cce) { /* no it doesn't -> then it must implement InterfaceA, right? */ InterfaceA intf = proxy.getInterface(InterfaceA.class); try { String id = intf.methodA(); assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id); } catch (BusException e) { // OK we might get ER_BUS_BLOCKING_CALL_NOT_ALLOWED here if (!e.getMessage().equals("ER_BUS_BLOCKING_CALL_NOT_ALLOWED")) { e.printStackTrace(); fail("recieved an unexpected BusException."); } } bus.enableConcurrentCallbacks(); try { String id = intf.methodA(); assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id); } catch (BusException e) { fail("method invocation failed: " + e); } } }
public void simpleScenario(Participant provider, Participant consumer) { provider.createA("justA"); provider.createB("justB"); provider.createAB("both"); final Observer obsA = newObserver(consumer, InterfaceA.class); final ObserverListener listenerA = new ObserverListener(consumer); obsA.registerListener(listenerA); final Observer obsB = newObserver(consumer, InterfaceB.class); final ObserverListener listenerB = new ObserverListener(consumer); obsB.registerListener(listenerB); final Observer obsAB = newObserver(consumer, InterfaceA.class, InterfaceB.class); final ObserverListener listenerAB = new ObserverListener(consumer); obsAB.registerListener(listenerAB); Lambda allDone = new Lambda() { @Override public boolean func() { return listenerA.getCounter() == 0 && listenerB.getCounter() == 0 && listenerAB.getCounter() == 0; } }; /* let provider publish objects on the bus */ listenerA.expectInvocations(2); listenerB.expectInvocations(2); listenerAB.expectInvocations(1); provider.registerObject("justA"); provider.registerObject("justB"); provider.registerObject("both"); assertTrue(waitForLambda(3000, allDone)); /* remove justA from the bus */ listenerA.expectInvocations(1); listenerB.expectInvocations(0); listenerAB.expectInvocations(0); provider.unregisterObject("justA"); assertTrue(waitForLambda(3000, allDone)); /* remove "both" from the bus */ listenerA.expectInvocations(1); listenerB.expectInvocations(1); listenerAB.expectInvocations(1); provider.unregisterObject("both"); assertTrue(waitForLambda(3000, allDone)); /* count the number of proxies left in the Observers. * There should be 0 in A, 1 in B, 0 in AB */ assertEquals(0, countProxies(obsA)); assertEquals(1, countProxies(obsB)); assertEquals(0, countProxies(obsAB)); /* remove all listeners */ obsA.unregisterAllListeners(); obsB.unregisterAllListeners(); obsAB.unregisterListener(listenerAB); /* remove "justB" and reinstate the other objects */ listenerA.expectInvocations(0); listenerB.expectInvocations(0); listenerAB.expectInvocations(0); provider.unregisterObject("justB"); provider.registerObject("justA"); provider.registerObject("both"); /* busy-wait for a second at most */ assertTrue( waitForLambda( 1000, new Lambda() { @Override public boolean func() { return 2 == countProxies(obsA) && 1 == countProxies(obsB) && 1 == countProxies(obsAB); } })); /* reinstate listeners & test triggerOnExisting functionality */ listenerA.expectInvocations(2); listenerB.expectInvocations(1); listenerAB.expectInvocations(1); obsA.registerListener(listenerA); obsB.registerListener(listenerB); obsAB.registerListener(listenerAB); assertTrue(waitForLambda(3000, allDone)); /* test multiple listeners for same observer */ final ObserverListener listenerB2 = new ObserverListener(consumer); listenerB2.expectInvocations(0); obsB.registerListener(listenerB2, false); Lambda allDone2 = new Lambda() { @Override public boolean func() { return listenerA.getCounter() == 0 && listenerB.getCounter() == 0 && listenerB2.getCounter() == 0 && listenerAB.getCounter() == 0; } }; listenerA.expectInvocations(0); listenerB.expectInvocations(1); listenerB2.expectInvocations(1); listenerAB.expectInvocations(0); provider.registerObject("justB"); assertTrue(waitForLambda(1000, allDone2)); /* are all objects back where they belong? */ assertEquals(2, countProxies(obsA)); assertEquals(2, countProxies(obsB)); assertEquals(1, countProxies(obsAB)); /* test multiple observers for the same set of interfaces */ final Observer obsB2 = newObserver(consumer, InterfaceB.class); obsB.unregisterListener( listenerB2); /* unregister listenerB2 from obsB so we can reuse it here */ listenerA.expectInvocations(0); listenerB.expectInvocations(0); listenerB2.expectInvocations(2); listenerAB.expectInvocations(0); obsB2.registerListener(listenerB2); assertTrue(waitForLambda(1000, allDone2)); /* test Observer::Get() and the proxy creation functionality */ ProxyBusObject proxy; proxy = obsA.get(provider.bus.getUniqueName(), makePath("justA")); assertTrue(null != proxy); proxy = obsA.get(provider.bus.getUniqueName(), makePath("both")); assertTrue(null != proxy); /* verify that we can indeed perform method calls */ InterfaceA intfA = proxy.getInterface(InterfaceA.class); try { String id = intfA.methodA(); assertEquals(provider.bus.getUniqueName() + "@" + makePath("both"), id); } catch (BusException e) { fail("method call failed: " + e); } }