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

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

Introduction

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

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

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 www.ja  va  2 s . com
    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 source file:org.springframework.integration.mqtt.MqttAdapterTests.java

@SuppressWarnings("unchecked")
@Test/*from w  w w  . j  a  v  a 2 s  .co  m*/
public void testCustomExpressions() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
    MqttPahoMessageHandler handler = ctx.getBean("handler", MqttPahoMessageHandler.class);
    GenericMessage<String> message = new GenericMessage<>("foo");
    assertEquals("fooTopic", TestUtils.getPropertyValue(handler, "topicProcessor", MessageProcessor.class)
            .processMessage(message));
    assertEquals(1, TestUtils.getPropertyValue(handler, "converter.qosProcessor", MessageProcessor.class)
            .processMessage(message));
    assertEquals(Boolean.TRUE,
            TestUtils.getPropertyValue(handler, "converter.retainedProcessor", MessageProcessor.class)
                    .processMessage(message));

    handler = ctx.getBean("handlerWithNullExpressions", MqttPahoMessageHandler.class);
    assertEquals(1, TestUtils.getPropertyValue(handler, "converter", DefaultPahoMessageConverter.class)
            .fromMessage(message, null).getQos());
    assertEquals(Boolean.TRUE,
            TestUtils.getPropertyValue(handler, "converter", DefaultPahoMessageConverter.class)
                    .fromMessage(message, null).isRetained());
    ctx.close();
}

From source file:org.springframework.statemachine.listener.ListenerTests.java

@Test
public void testStateEvents() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config1.class);
    assertTrue(ctx.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
    @SuppressWarnings("unchecked")
    ObjectStateMachine<TestStates, TestEvents> machine = ctx
            .getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);
    machine.start();//from  ww  w.  j  a v a 2s  .co  m

    TestStateMachineListener listener = new TestStateMachineListener();
    machine.addStateListener(listener);

    assertThat(machine, notNullValue());
    machine.sendEvent(MessageBuilder.withPayload(TestEvents.E1).setHeader("foo", "jee1").build());
    assertThat(listener.states.size(), is(1));
    assertThat(listener.states.get(0).from.getIds(), contains(TestStates.S1));
    assertThat(listener.states.get(0).to.getIds(), contains(TestStates.S2));
    machine.sendEvent(MessageBuilder.withPayload(TestEvents.E2).setHeader("foo", "jee2").build());
    assertThat(listener.states.size(), is(2));
    assertThat(listener.states.get(1).from.getIds(), contains(TestStates.S2));
    assertThat(listener.states.get(1).to.getIds(), contains(TestStates.S3));
    machine.sendEvent(MessageBuilder.withPayload(TestEvents.E4).setHeader("foo", "jee2").build());
    assertThat(listener.states.size(), is(2));

    ctx.close();
}

From source file:org.springframework.statemachine.listener.ListenerTests.java

@Test
public void testStartEndEvents() throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config2.class);
    assertTrue(ctx.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
    @SuppressWarnings("unchecked")
    ObjectStateMachine<TestStates, TestEvents> machine = ctx
            .getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

    TestStateMachineListener listener = new TestStateMachineListener();
    machine.addStateListener(listener);//w  w w .j  a  v a 2  s  .c om

    machine.start();
    machine.sendEvent(TestEvents.E1);
    machine.sendEvent(TestEvents.E2);
    assertThat(listener.stopLatch.await(2, TimeUnit.SECONDS), is(true));
    assertThat(listener.started, is(1));
    assertThat(listener.stopped, is(1));
    ctx.close();
}

From source file:org.springframework.statemachine.listener.ListenerTests.java

@Test
public void testExtendedStateEvents() throws Exception {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config2.class);
    assertTrue(ctx.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
    @SuppressWarnings("unchecked")
    ObjectStateMachine<TestStates, TestEvents> machine = ctx
            .getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, ObjectStateMachine.class);

    TestStateMachineListener listener = new TestStateMachineListener();
    machine.addStateListener(listener);//from www . j a va 2  s .  c  om
    machine.start();

    machine.getExtendedState().getVariables().put("foo", "jee");
    assertThat(listener.extendedLatch.await(2, TimeUnit.SECONDS), is(true));
    assertThat(listener.extended.size(), is(1));
    assertThat(listener.extended.get(0).key, is("foo"));
    assertThat(listener.extended.get(0).value, is("jee"));
    ctx.close();
}

From source file:org.springframework.yarn.support.statemachine.ListenerTests.java

@Test
public void testStateEvents() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
    assertTrue(ctx.containsBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE));
    @SuppressWarnings("unchecked")
    EnumStateMachine<TestStates, TestEvents> machine = ctx
            .getBean(StateMachineSystemConstants.DEFAULT_ID_STATEMACHINE, EnumStateMachine.class);

    TestStateMachineListener listener = new TestStateMachineListener();
    machine.addStateListener(listener);/*from  ww  w.  j  a v a2s.c o m*/

    assertThat(machine, notNullValue());
    machine.sendEvent(MessageBuilder.withPayload(TestEvents.E1).setHeader("foo", "jee1").build());
    assertThat(listener.states.size(), is(1));
    assertThat(listener.states.get(0).from.getId(), is(TestStates.S1));
    assertThat(listener.states.get(0).to.getId(), is(TestStates.S2));
    machine.sendEvent(MessageBuilder.withPayload(TestEvents.E2).setHeader("foo", "jee2").build());
    assertThat(listener.states.size(), is(2));
    assertThat(listener.states.get(1).from.getId(), is(TestStates.S2));
    assertThat(listener.states.get(1).to.getId(), is(TestStates.S3));
    machine.sendEvent(MessageBuilder.withPayload(TestEvents.E4).setHeader("foo", "jee2").build());
    assertThat(listener.states.size(), is(2));

    ctx.close();
}