java类java.beans.beancontext.BeanContextServiceAvailableEvent的实例源码

BeanContextServicesSupportTest.java 文件源码 项目:cn1 阅读 29 收藏 0 点赞 0 评论 0
public void testFireServiceAddedBeanContextServiceAvailableEvent() {
    MockBeanContextServicesSupport support = new MockBeanContextServicesSupport();
    MockBeanContextServicesSupport childSupport = new MockBeanContextServicesSupport();
    support.add(childSupport);
    MockBeanContextServicesListener l1 = new MockBeanContextServicesListener();
    MockBeanContextServicesListener l2 = new MockBeanContextServicesListener();
    support.addBeanContextServicesListener(l1);
    childSupport.addBeanContextServicesListener(l2);
    support.records.assertRecord("initialize", null);
    childSupport.records.assertRecord("initialize", null);

    BeanContextServiceAvailableEvent evt = new BeanContextServiceAvailableEvent(
            support, Collection.class);
    support.publicFireServiceAdded(evt);

    support.records.assertEndOfRecords();
    childSupport.records.assertEndOfRecords();
    assertSame(evt, l1.lastAvailableEvent);
    assertNull(l2.lastAvailableEvent);
}
BeanContextServicesSupportTest.java 文件源码 项目:cn1 阅读 20 收藏 0 点赞 0 评论 0
public void test_serviceAvailable_LBeanContextServiceRevokedEvent() {
    BeanContextServicesSupport support = new BeanContextServicesSupport();

    support.add(new MySupport());
    support.addBeanContextServicesListener(new MyListener());
    Class c = Object.class;

    support.addService(c, new MyProvider());

    BeanContextServiceAvailableEvent availableEvent = new BeanContextServiceAvailableEvent(
            support, c);
    support.serviceAvailable(availableEvent);
       assertEquals(0, serviceRevoked);
       assertEquals(2, serviceAvailable);

}
BeanContextServiceAvailableEventTest.java 文件源码 项目:cn1 阅读 23 收藏 0 点赞 0 评论 0
private void assertEqualsSerially(BeanContextServiceAvailableEvent orig,
        BeanContextServiceAvailableEvent ser) {
    assertNull(ser.getSource());

    // check propagatedFrom
    if (orig.getPropagatedFrom() instanceof Serializable) {
        BeanContext origFrom = orig.getPropagatedFrom();
        BeanContext serFrom = ser.getPropagatedFrom();
        assertEquals(origFrom.getClass(), serFrom.getClass());
        if (origFrom instanceof MockBeanContextDelegateS) {
            assertEquals(((MockBeanContextDelegateS) origFrom).id,
                    ((MockBeanContextDelegateS) serFrom).id);
        }
    }

    // check serviceClass
    assertEquals(orig.getServiceClass(), ser.getServiceClass());
}
BeanContextServicesSupportTest.java 文件源码 项目:freeVM 阅读 34 收藏 0 点赞 0 评论 0
public void testFireServiceAddedBeanContextServiceAvailableEvent() {
    MockBeanContextServicesSupport support = new MockBeanContextServicesSupport();
    MockBeanContextServicesSupport childSupport = new MockBeanContextServicesSupport();
    support.add(childSupport);
    MockBeanContextServicesListener l1 = new MockBeanContextServicesListener();
    MockBeanContextServicesListener l2 = new MockBeanContextServicesListener();
    support.addBeanContextServicesListener(l1);
    childSupport.addBeanContextServicesListener(l2);
    support.records.assertRecord("initialize", null);
    childSupport.records.assertRecord("initialize", null);

    BeanContextServiceAvailableEvent evt = new BeanContextServiceAvailableEvent(
            support, Collection.class);
    support.publicFireServiceAdded(evt);

    support.records.assertEndOfRecords();
    childSupport.records.assertEndOfRecords();
    assertSame(evt, l1.lastAvailableEvent);
    assertNull(l2.lastAvailableEvent);
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 22 收藏 0 点赞 0 评论 0
private void assertEqualsSerially(BeanContextServiceAvailableEvent orig,
        BeanContextServiceAvailableEvent ser) {
    assertNull(ser.getSource());

    // check propagatedFrom
    if (orig.getPropagatedFrom() instanceof Serializable) {
        BeanContext origFrom = orig.getPropagatedFrom();
        BeanContext serFrom = ser.getPropagatedFrom();
        assertEquals(origFrom.getClass(), serFrom.getClass());
        if (origFrom instanceof MockBeanContextDelegateS) {
            assertEquals(((MockBeanContextDelegateS) origFrom).id,
                    ((MockBeanContextDelegateS) serFrom).id);
        }
    }

    // check serviceClass
    assertEquals(orig.getServiceClass(), ser.getServiceClass());
}
BeanContextServicesSupportTest.java 文件源码 项目:freeVM 阅读 25 收藏 0 点赞 0 评论 0
public void testFireServiceAddedBeanContextServiceAvailableEvent() {
    MockBeanContextServicesSupport support = new MockBeanContextServicesSupport();
    MockBeanContextServicesSupport childSupport = new MockBeanContextServicesSupport();
    support.add(childSupport);
    MockBeanContextServicesListener l1 = new MockBeanContextServicesListener();
    MockBeanContextServicesListener l2 = new MockBeanContextServicesListener();
    support.addBeanContextServicesListener(l1);
    childSupport.addBeanContextServicesListener(l2);
    support.records.assertRecord("initialize", null);
    childSupport.records.assertRecord("initialize", null);

    BeanContextServiceAvailableEvent evt = new BeanContextServiceAvailableEvent(
            support, Collection.class);
    support.publicFireServiceAdded(evt);

    support.records.assertEndOfRecords();
    childSupport.records.assertEndOfRecords();
    assertSame(evt, l1.lastAvailableEvent);
    assertNull(l2.lastAvailableEvent);
}
BeanContextServicesSupportTest.java 文件源码 项目:freeVM 阅读 28 收藏 0 点赞 0 评论 0
public void test_serviceAvailable_LBeanContextServiceRevokedEvent() {
    BeanContextServicesSupport support = new BeanContextServicesSupport();

    support.add(new MySupport());
    support.addBeanContextServicesListener(new MyListener());
    Class c = Object.class;

    support.addService(c, new MyProvider());

    BeanContextServiceAvailableEvent availableEvent = new BeanContextServiceAvailableEvent(
            support, c);
    support.serviceAvailable(availableEvent);
       assertEquals(0, serviceRevoked);
       assertEquals(2, serviceAvailable);

}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 23 收藏 0 点赞 0 评论 0
private void assertEqualsSerially(BeanContextServiceAvailableEvent orig,
        BeanContextServiceAvailableEvent ser) {
    assertNull(ser.getSource());

    // check propagatedFrom
    if (orig.getPropagatedFrom() instanceof Serializable) {
        BeanContext origFrom = orig.getPropagatedFrom();
        BeanContext serFrom = ser.getPropagatedFrom();
        assertEquals(origFrom.getClass(), serFrom.getClass());
        if (origFrom instanceof MockBeanContextDelegateS) {
            assertEquals(((MockBeanContextDelegateS) origFrom).id,
                    ((MockBeanContextDelegateS) serFrom).id);
        }
    }

    // check serviceClass
    assertEquals(orig.getServiceClass(), ser.getServiceClass());
}
ServiceBean.java 文件源码 项目:freeVM 阅读 29 收藏 0 点赞 0 评论 0
/**
 * @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;
    }
}
BeanContextServicesSupportTest.java 文件源码 项目:cn1 阅读 24 收藏 0 点赞 0 评论 0
public void testAddServiceClassBeanContextServiceProvider_ParentContext() {
    MockBeanContextServicesSupport support = new MockBeanContextServicesSupport();
    MockBeanContextServicesSupport childSupport = new MockBeanContextServicesSupport();
    support.add(childSupport);
    MockBeanContextServicesListener l1 = new MockBeanContextServicesListener();
    MockBeanContextServicesListener l2 = new MockBeanContextServicesListener();
    support.addBeanContextServicesListener(l1);
    childSupport.addBeanContextServicesListener(l2);
    support.records.assertRecord("initialize", null);
    childSupport.records.assertRecord("initialize", null);

    MockBeanContextServiceProvider provider = new MockBeanContextServiceProvider();
    boolean result = support.addService(Collection.class, provider);
    assertTrue(result);
    assertEquals(1, support.services().size());
    assertEquals(0, childSupport.services().size());
    Object bcssProvider = support.services().get(Collection.class);
    support.records.assertRecord("createBCSSServiceProvider",
            Collection.class, provider, bcssProvider);
    support.records.assertEndOfRecords();
    BeanContextServiceAvailableEvent evt = (BeanContextServiceAvailableEvent) childSupport.records
            .getArg(0);
    childSupport.records.assertRecord("serviceAvailable", evt, null);
    assertSame(support, evt.getSourceAsBeanContextServices());
    assertSame(Collection.class, evt.getServiceClass());
    childSupport.records.assertEndOfRecords();
    assertSame(support, l1.lastAvailableEvent
            .getSourceAsBeanContextServices());
    assertSame(Collection.class, l1.lastAvailableEvent.getServiceClass());
    assertSame(support, l2.lastAvailableEvent
            .getSourceAsBeanContextServices());
    assertSame(Collection.class, l2.lastAvailableEvent.getServiceClass());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:cn1 阅读 29 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:cn1 阅读 46 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:cn1 阅读 30 收藏 0 点赞 0 评论 0
public void testGetSourceAsBeanContextServices() {
    BeanContextServices services = new MockBeanContextServices();
    BeanContextServiceAvailableEvent event = new MockBeanContextServiceAvailableEvent(
            services, BeanContext.class);
    assertSame(services, event.getSource());
    assertSame(services, event.getSourceAsBeanContextServices());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:cn1 阅读 32 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:cn1 阅读 27 收藏 0 点赞 0 评论 0
public void testSerialization() throws IOException, ClassNotFoundException {
    BeanContextServiceAvailableEvent event = new BeanContextServiceAvailableEvent(
            new MockBeanContextServices(), ArrayList.class);
    event.setPropagatedFrom(new MockBeanContextDelegateS("from ID"));

    assertEqualsSerially(event,
            (BeanContextServiceAvailableEvent) SerializationTester
                    .getDeserilizedObject(event));
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:cn1 阅读 26 收藏 0 点赞 0 评论 0
public void testSerialization_Compatibility() throws Exception {
    BeanContextServiceAvailableEvent event = new BeanContextServiceAvailableEvent(
            new MockBeanContextServices(), ArrayList.class);
    event.setPropagatedFrom(new MockBeanContextDelegateS("from ID"));
    SerializationTest.verifyGolden(this, event, new SerializableAssert(){
        public void assertDeserialized(Serializable orig, Serializable ser) {
            assertEqualsSerially((BeanContextServiceAvailableEvent) orig,
                    (BeanContextServiceAvailableEvent) ser);
        }
    });
}
BeanContextServicesSupportTest.java 文件源码 项目:freeVM 阅读 21 收藏 0 点赞 0 评论 0
public void testAddServiceClassBeanContextServiceProvider_ParentContext() {
    MockBeanContextServicesSupport support = new MockBeanContextServicesSupport();
    MockBeanContextServicesSupport childSupport = new MockBeanContextServicesSupport();
    support.add(childSupport);
    MockBeanContextServicesListener l1 = new MockBeanContextServicesListener();
    MockBeanContextServicesListener l2 = new MockBeanContextServicesListener();
    support.addBeanContextServicesListener(l1);
    childSupport.addBeanContextServicesListener(l2);
    support.records.assertRecord("initialize", null);
    childSupport.records.assertRecord("initialize", null);

    MockBeanContextServiceProvider provider = new MockBeanContextServiceProvider();
    boolean result = support.addService(Collection.class, provider);
    assertTrue(result);
    assertEquals(1, support.services().size());
    assertEquals(0, childSupport.services().size());
    Object bcssProvider = support.services().get(Collection.class);
    support.records.assertRecord("createBCSSServiceProvider",
            Collection.class, provider, bcssProvider);
    support.records.assertEndOfRecords();
    BeanContextServiceAvailableEvent evt = (BeanContextServiceAvailableEvent) childSupport.records
            .getArg(0);
    childSupport.records.assertRecord("serviceAvailable", evt, null);
    assertSame(support, evt.getSourceAsBeanContextServices());
    assertSame(Collection.class, evt.getServiceClass());
    childSupport.records.assertEndOfRecords();
    assertSame(support, l1.lastAvailableEvent
            .getSourceAsBeanContextServices());
    assertSame(Collection.class, l1.lastAvailableEvent.getServiceClass());
    assertSame(support, l2.lastAvailableEvent
            .getSourceAsBeanContextServices());
    assertSame(Collection.class, l2.lastAvailableEvent.getServiceClass());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 28 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 30 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 27 收藏 0 点赞 0 评论 0
public void testGetSourceAsBeanContextServices() {
    BeanContextServices services = new MockBeanContextServices();
    BeanContextServiceAvailableEvent event = new MockBeanContextServiceAvailableEvent(
            services, BeanContext.class);
    assertSame(services, event.getSource());
    assertSame(services, event.getSourceAsBeanContextServices());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 33 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 21 收藏 0 点赞 0 评论 0
public void testSerialization() throws IOException, ClassNotFoundException {
    BeanContextServiceAvailableEvent event = new BeanContextServiceAvailableEvent(
            new MockBeanContextServices(), ArrayList.class);
    event.setPropagatedFrom(new MockBeanContextDelegateS("from ID"));

    assertEqualsSerially(event,
            (BeanContextServiceAvailableEvent) SerializationTester
                    .getDeserilizedObject(event));
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 80 收藏 0 点赞 0 评论 0
public void testSerialization_Compatibility() throws Exception {
    BeanContextServiceAvailableEvent event = new BeanContextServiceAvailableEvent(
            new MockBeanContextServices(), ArrayList.class);
    event.setPropagatedFrom(new MockBeanContextDelegateS("from ID"));

    assertEqualsSerially(
            event,
            (BeanContextServiceAvailableEvent) SerializationTester
                    .readObject(event,
                            "serialization/java/beans/beancontext/BeanContextServiceAvailableEvent.ser"));
}
BeanContextServicesSupportTest.java 文件源码 项目:freeVM 阅读 19 收藏 0 点赞 0 评论 0
public void testAddServiceClassBeanContextServiceProvider_ParentContext() {
    MockBeanContextServicesSupport support = new MockBeanContextServicesSupport();
    MockBeanContextServicesSupport childSupport = new MockBeanContextServicesSupport();
    support.add(childSupport);
    MockBeanContextServicesListener l1 = new MockBeanContextServicesListener();
    MockBeanContextServicesListener l2 = new MockBeanContextServicesListener();
    support.addBeanContextServicesListener(l1);
    childSupport.addBeanContextServicesListener(l2);
    support.records.assertRecord("initialize", null);
    childSupport.records.assertRecord("initialize", null);

    MockBeanContextServiceProvider provider = new MockBeanContextServiceProvider();
    boolean result = support.addService(Collection.class, provider);
    assertTrue(result);
    assertEquals(1, support.services().size());
    assertEquals(0, childSupport.services().size());
    Object bcssProvider = support.services().get(Collection.class);
    support.records.assertRecord("createBCSSServiceProvider",
            Collection.class, provider, bcssProvider);
    support.records.assertEndOfRecords();
    BeanContextServiceAvailableEvent evt = (BeanContextServiceAvailableEvent) childSupport.records
            .getArg(0);
    childSupport.records.assertRecord("serviceAvailable", evt, null);
    assertSame(support, evt.getSourceAsBeanContextServices());
    assertSame(Collection.class, evt.getServiceClass());
    childSupport.records.assertEndOfRecords();
    assertSame(support, l1.lastAvailableEvent
            .getSourceAsBeanContextServices());
    assertSame(Collection.class, l1.lastAvailableEvent.getServiceClass());
    assertSame(support, l2.lastAvailableEvent
            .getSourceAsBeanContextServices());
    assertSame(Collection.class, l2.lastAvailableEvent.getServiceClass());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 39 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 38 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 25 收藏 0 点赞 0 评论 0
public void testGetSourceAsBeanContextServices() {
    BeanContextServices services = new MockBeanContextServices();
    BeanContextServiceAvailableEvent event = new MockBeanContextServiceAvailableEvent(
            services, BeanContext.class);
    assertSame(services, event.getSource());
    assertSame(services, event.getSourceAsBeanContextServices());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 22 收藏 0 点赞 0 评论 0
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());
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 26 收藏 0 点赞 0 评论 0
public void testSerialization() throws IOException, ClassNotFoundException {
    BeanContextServiceAvailableEvent event = new BeanContextServiceAvailableEvent(
            new MockBeanContextServices(), ArrayList.class);
    event.setPropagatedFrom(new MockBeanContextDelegateS("from ID"));

    assertEqualsSerially(event,
            (BeanContextServiceAvailableEvent) SerializationTester
                    .getDeserilizedObject(event));
}
BeanContextServiceAvailableEventTest.java 文件源码 项目:freeVM 阅读 47 收藏 0 点赞 0 评论 0
public void testSerialization_Compatibility() throws Exception {
    BeanContextServiceAvailableEvent event = new BeanContextServiceAvailableEvent(
            new MockBeanContextServices(), ArrayList.class);
    event.setPropagatedFrom(new MockBeanContextDelegateS("from ID"));
    SerializationTest.verifyGolden(this, event, new SerializableAssert(){
        public void assertDeserialized(Serializable orig, Serializable ser) {
            assertEqualsSerially((BeanContextServiceAvailableEvent) orig,
                    (BeanContextServiceAvailableEvent) ser);
        }
    });
}


问题


面经


文章

微信
公众号

扫码关注公众号