/** * @param bcsae the BeanContextServiceAvailableEvent */ public void serviceAvailable(BeanContextServiceAvailableEvent bcsae) { // Get a reference to the context BeanContextServices context = bcsae.getSourceAsBeanContextServices(); // Use the service, if it's available if (context.hasService(TestCounter.class)) { // System.out.println("Attempting to use the service..."); try { // Got the service service = (TestCounter) context.getService(this, this, TestCounter.class, str, this); service.counter(); } catch (Exception e) { } this.bcsae = bcsae; } }
public static void main(String[] args) { for (int i = 0; i < 10; i++) { BeanContextServices container = new BeanContextServicesSupport(); BeanContextChild ms1 = new MyService1(); BeanContextServices ms2 = new MyService2(); BeanContextChild mb = new MyBean(); container.add(ms1); container.add(ms2); ms2.add(mb); // exception thrown here container.remove(ms2); } }
public void testBeanContextServiceRevokedEvent() { BeanContextServices services = new MockBeanContextServices(); BeanContextServiceRevokedEvent event = new MockBeanContextServiceRevokedEvent( services, BeanContext.class, true); assertSame(BeanContext.class, event.getServiceClass()); assertSame(services, event.getSource()); assertSame(services, event.getSourceAsBeanContextServices()); assertTrue(event.isCurrentServiceInvalidNow()); }
public void testIsServiceClass() { BeanContextServices services = new MockBeanContextServices(); BeanContextServiceRevokedEvent event = new MockBeanContextServiceRevokedEvent( services, BeanContext.class, true); assertTrue(event.isServiceClass(BeanContext.class)); assertFalse(event.isServiceClass(Integer.class)); // Regression for HARMONY-1516 assertFalse(event.isServiceClass(null)); }
public void testIsCurrentServiceInvalidNow() { BeanContextServices services = new MockBeanContextServices(); BeanContextServiceRevokedEvent event = new MockBeanContextServiceRevokedEvent( services, BeanContext.class, true); assertTrue(event.isCurrentServiceInvalidNow()); event = new MockBeanContextServiceRevokedEvent(services, BeanContext.class, false); assertFalse(event.isCurrentServiceInvalidNow()); }
public void testConstructor() throws Exception { BeanContextServices bcs = new MockBeanContextServices(); BeanContextServiceRevokedEvent event = new BeanContextServiceRevokedEvent( bcs, ArrayList.class, true); assertEquals(null, event.getPropagatedFrom()); assertEquals(ArrayList.class, event.getServiceClass()); assertSame(bcs, event.getSource()); assertSame(bcs, event.getBeanContext()); assertSame(bcs, event.getSourceAsBeanContextServices()); assertFalse(event.isPropagated()); }
public void testBeanContextServiceAvailableEvent_NullParam() { BeanContextServices services = new MockBeanContextServices(); try { new MockBeanContextServiceAvailableEvent(null, BeanContext.class); fail("IAE expected"); } catch (IllegalArgumentException e) { // expected } BeanContextServiceAvailableEvent event = new MockBeanContextServiceAvailableEvent( services, null); assertNull(event.getServiceClass()); assertSame(services, event.getSource()); assertSame(services, event.getSourceAsBeanContextServices()); }
public void testBeanContextServiceAvailableEvent() { BeanContextServices services = new MockBeanContextServices(); BeanContextServiceAvailableEvent event = new MockBeanContextServiceAvailableEvent( services, BeanContext.class); assertSame(BeanContext.class, event.getServiceClass()); assertSame(services, event.getSource()); assertSame(services, event.getSourceAsBeanContextServices()); }
public void testGetSourceAsBeanContextServices() { BeanContextServices services = new MockBeanContextServices(); BeanContextServiceAvailableEvent event = new MockBeanContextServiceAvailableEvent( services, BeanContext.class); assertSame(services, event.getSource()); assertSame(services, event.getSourceAsBeanContextServices()); }
public void testGetCurrentServiceSelectors() { BeanContextServices services = new MockBeanContextServices(); BeanContextServiceAvailableEvent event = new MockBeanContextServiceAvailableEvent( services, BeanContext.class); Iterator expectedIt = services .getCurrentServiceSelectors(BeanContext.class); Iterator it = event.getCurrentServiceSelectors(); while (expectedIt.hasNext()) { assertSame(expectedIt.next(), it.next()); } assertFalse(expectedIt.hasNext()); assertFalse(it.hasNext()); }
public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) { Object result = Collections.EMPTY_SET; records.add("getService", bcs, requestor, serviceClass, serviceSelector, result); return result; }
public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) { final String str = (String)serviceSelector; return new TestCounter() { public void counter() { String res = str; System.out.println(str); } }; }