Example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean.

Prototype

@Override
    public <T> T getBean(String name, Class<T> requiredType) throws BeansException 

Source Link

Usage

From source file:org.springframework.integration.core.MessageIdGenerationTests.java

@Test
public void testCustomIdGenerationWithChildRegistrar() throws Exception {
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext(
            "MessageIdGenerationTests-context.xml", this.getClass());
    ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
            new String[] { "MessageIdGenerationTests-context-withGenerator.xml" }, this.getClass(), parent);

    IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class);
    Mockito.reset(idGenerator);/*  w  w w  .ja  v a2s.c  o  m*/
    MessageChannel inputChannel = child.getBean("input", MessageChannel.class);
    inputChannel.send(new GenericMessage<Integer>(0));
    verify(idGenerator, atLeastOnce()).generateId();
    child.close();
    parent.close();
    this.assertDestroy();
}

From source file:org.springframework.integration.core.MessageIdGenerationTests.java

@Test
public void testCustomIdGenerationWithChildRegistrarClosed() throws Exception {
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext(
            "MessageIdGenerationTests-context.xml", this.getClass());
    ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext(
            new String[] { "MessageIdGenerationTests-context-withGenerator.xml" }, this.getClass(), parent);

    IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class);
    Mockito.reset(idGenerator);//from  w  w  w.ja  va2s  .  c o  m
    MessageChannel inputChannel = child.getBean("input", MessageChannel.class);
    inputChannel.send(new GenericMessage<Integer>(0));
    verify(idGenerator, atLeastOnce()).generateId();
    child.close();
    parent.close();
    this.assertDestroy();
}