Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getBean

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext getBean.

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:org.springframework.integration.etcd.leader.EtcdTests.java

@Test
public void testSimpleLeader() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SimpleTestConfig.class);
    TestCandidate candidate = ctx.getBean(TestCandidate.class);
    TestEventListener listener = ctx.getBean(TestEventListener.class);
    assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true));
    assertThat(listener.onEventLatch.await(5, TimeUnit.SECONDS), is(true));
    assertThat(listener.events.size(), is(1));
    ctx.close();/*from  w  w  w  .  j av a 2s  .c  o m*/
}

From source file:org.springframework.integration.etcd.leader.EtcdTests.java

@Test
public void testLeaderYield() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(YieldTestConfig.class);
    YieldTestCandidate candidate = ctx.getBean(YieldTestCandidate.class);
    YieldTestEventListener listener = ctx.getBean(YieldTestEventListener.class);
    assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true));
    assertThat(candidate.onRevokedLatch.await(10, TimeUnit.SECONDS), is(true));
    assertThat(listener.onEventsLatch.await(1, TimeUnit.MILLISECONDS), is(true));
    assertThat(listener.events.size(), is(2));
    ctx.close();//from   www.j a v  a2 s.com
}

From source file:org.springframework.integration.etcd.leader.EtcdTests.java

@Test
public void testBlockingThreadLeader() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
            BlockingThreadTestConfig.class);
    BlockingThreadTestCandidate candidate = ctx.getBean(BlockingThreadTestCandidate.class);
    YieldTestEventListener listener = ctx.getBean(YieldTestEventListener.class);
    assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true));
    Thread.sleep(2000); // Let the grant-notification thread run for a while
    candidate.ctx.yield(); // Internally interrupts the grant notification thread
    assertThat(candidate.onRevokedLatch.await(10, TimeUnit.SECONDS), is(true));
    assertThat(listener.onEventsLatch.await(1, TimeUnit.MILLISECONDS), is(true));
    assertThat(listener.events.size(), is(2));
    ctx.close();//w  ww.  j  ava2  s.c o m
}

From source file:org.springframework.integration.etcd.leader.EtcdTests.java

@Test
public void testFailingCandidateGrantCallback() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
            FailingCandidateTestConfig.class);
    FailingTestCandidate candidate = ctx.getBean(FailingTestCandidate.class);
    YieldTestEventListener listener = ctx.getBean(YieldTestEventListener.class);
    assertThat(candidate.onGrantedLatch.await(5, TimeUnit.SECONDS), is(true));
    assertThat(candidate.onRevokedLatch.await(10, TimeUnit.SECONDS), is(true));
    assertThat(listener.onEventsLatch.await(10, TimeUnit.SECONDS), is(true));
    assertThat(listener.events.size(), is(2));
    ctx.close();/*from w ww.  ja  v  a 2  s  .  c  o m*/
}

From source file:org.springframework.integration.ftp.inbound.RotatingServersTests.java

@Test
public void testStandard() throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(StandardConfig.class);
    StandardConfig config = ctx.getBean(StandardConfig.class);
    ctx.getBean(StandardIntegrationFlow.class).stop();
    assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
    List<Integer> sfCalls = config.sessionSources.stream().limit(17).collect(Collectors.toList());
    assertThat(sfCalls).containsExactly(1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1);
    File f1 = new File(tmpDir + File.separator + "standard" + File.separator + "f1");
    assertThat(f1.exists()).isTrue();//from  w ww.j  a v  a2s. c  om
    File f2 = new File(tmpDir + File.separator + "standard" + File.separator + "f2");
    assertThat(f2.exists()).isTrue();
    File f3 = new File(tmpDir + File.separator + "standard" + File.separator + "f3");
    assertThat(f3.exists()).isTrue();
    assertThat(ctx.getBean("files", QueueChannel.class).getQueueSize()).isEqualTo(3);
    ctx.close();
}

From source file:org.springframework.integration.ftp.inbound.RotatingServersTests.java

@Test
public void testFair() throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FairConfig.class);
    StandardConfig config = ctx.getBean(StandardConfig.class);
    ctx.getBean(StandardIntegrationFlow.class).stop();
    assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
    List<Integer> sfCalls = config.sessionSources.stream().limit(17).collect(Collectors.toList());
    assertThat(sfCalls).containsExactly(1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3);
    File f1 = new File(tmpDir + File.separator + "fair" + File.separator + "f1");
    assertThat(f1.exists()).isTrue();//from  ww  w . java  2 s  . c  o m
    File f2 = new File(tmpDir + File.separator + "fair" + File.separator + "f2");
    assertThat(f2.exists()).isTrue();
    File f3 = new File(tmpDir + File.separator + "fair" + File.separator + "f3");
    assertThat(f3.exists()).isTrue();
    assertThat(ctx.getBean("files", QueueChannel.class).getQueueSize()).isEqualTo(3);
    ctx.close();
}

From source file:org.springframework.integration.ftp.inbound.RotatingServersTests.java

@Test
public void testVariableLocalDir() throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(VariableLocalConfig.class);
    StandardConfig config = ctx.getBean(StandardConfig.class);
    assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
    ctx.getBean(StandardIntegrationFlow.class).stop();
    List<Integer> sfCalls = config.sessionSources.stream().limit(17).collect(Collectors.toList());
    assertThat(sfCalls).containsExactly(1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1);
    File f1 = new File(tmpDir + File.separator + "variable" + File.separator + "foo" + File.separator + "f1");
    assertThat(f1.exists()).isTrue();//from  w  w w .  j ava 2 s  . c o m
    File f2 = new File(tmpDir + File.separator + "variable" + File.separator + "baz" + File.separator + "f2");
    assertThat(f2.exists()).isTrue();
    File f3 = new File(tmpDir + File.separator + "variable" + File.separator + "fiz" + File.separator + "f3");
    assertThat(f3.exists()).isTrue();
    assertThat(ctx.getBean("files", QueueChannel.class).getQueueSize()).isEqualTo(3);
    ctx.close();
}

From source file:org.springframework.integration.ftp.inbound.RotatingServersTests.java

@Test
public void testStreaming() throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(StreamingConfig.class);
    StandardConfig config = ctx.getBean(StandardConfig.class);
    ctx.getBean(StandardIntegrationFlow.class).stop();
    assertThat(config.latch.await(10, TimeUnit.SECONDS)).isTrue();
    List<Integer> sfCalls = config.sessionSources.stream().limit(17).collect(Collectors.toList());
    // there's an extra getSession() with this adapter in listFiles
    assertThat(sfCalls).containsExactly(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 2, 2, 3);
    assertThat(ctx.getBean("files", QueueChannel.class).getQueueSize()).isEqualTo(3);
    ctx.close();//from w ww. j av  a2 s  .  com
}

From source file:org.springframework.remoting.jbr.TestJbossRemotingExporter.java

@Test
public void testRetreivingDataFromRpc() throws Throwable {

    AnnotationConfigApplicationContext client = null, server = null;

    try {/*  ww w .  ja  v a  2  s  . com*/
        server = new AnnotationConfigApplicationContext(ServerConfiguration.class);
        client = new AnnotationConfigApplicationContext(ClientConfiguration.class);
        Crm clientBean = client.getBean(Crm.class);

        long id = 8709;
        Customer customer = clientBean.getCustomerById(id);
        Assert.assertNotNull(customer);
        Assert.assertEquals(customer.getId(), id);

        if (log.isDebugEnabled()) {
            log.debug(customer.toString());
        }
    } finally {
        if (null != client) {
            client.stop();
        }
        if (null != server) {
            server.stop();
        }
    }
}