Search in sources :

Example 6 with SmartLifecycle

use of org.springframework.context.SmartLifecycle in project spring-integration by spring-projects.

the class SmartLifecycleRoleControllerTests method testOrder.

@Test
public void testOrder() {
    SmartLifecycle lc1 = mock(SmartLifecycle.class);
    when(lc1.getPhase()).thenReturn(2);
    SmartLifecycle lc2 = mock(SmartLifecycle.class);
    when(lc2.getPhase()).thenReturn(1);
    MultiValueMap<String, SmartLifecycle> map = new LinkedMultiValueMap<>();
    map.add("foo", lc1);
    map.add("foo", lc2);
    SmartLifecycleRoleController controller = new SmartLifecycleRoleController(map);
    controller.startLifecyclesInRole("foo");
    controller.stopLifecyclesInRole("foo");
    InOrder inOrder = inOrder(lc1, lc2);
    inOrder.verify(lc2).start();
    inOrder.verify(lc1).start();
    inOrder.verify(lc1).stop();
    inOrder.verify(lc2).stop();
}
Also used : InOrder(org.mockito.InOrder) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) SmartLifecycle(org.springframework.context.SmartLifecycle) Test(org.junit.Test)

Example 7 with SmartLifecycle

use of org.springframework.context.SmartLifecycle in project spring-integration by spring-projects.

the class SmartLifecycleRoleControllerTests method allEndpointRunning.

@Test
public void allEndpointRunning() {
    SmartLifecycle lc1 = new PseudoSmartLifecycle();
    SmartLifecycle lc2 = new PseudoSmartLifecycle();
    MultiValueMap<String, SmartLifecycle> map = new LinkedMultiValueMap<>();
    map.add("foo", lc1);
    map.add("foo", lc2);
    try {
        new SmartLifecycleRoleController(map);
    } catch (Exception e) {
        assertThat(e.getMessage()).contains("Cannot add the Lifecycle 'bar' to the role 'foo' " + "because a Lifecycle with the name 'bar' is already present.");
    }
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) SmartLifecycle(org.springframework.context.SmartLifecycle) Test(org.junit.Test)

Example 8 with SmartLifecycle

use of org.springframework.context.SmartLifecycle in project spring-integration by spring-projects.

the class SmartLifecycleRoleController method doAddLifecyclesToRole.

private void doAddLifecyclesToRole(String role, List<String> lifecycleBeanNames) {
    lifecycleBeanNames.forEach(lifecycleBeanName -> {
        try {
            SmartLifecycle lifecycle = this.applicationContext.getBean(lifecycleBeanName, SmartLifecycle.class);
            addLifecycleToRole(role, lifecycle);
        } catch (NoSuchBeanDefinitionException e) {
            logger.warn("Skipped; no such bean: " + lifecycleBeanName);
        }
    });
}
Also used : SmartLifecycle(org.springframework.context.SmartLifecycle) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 9 with SmartLifecycle

use of org.springframework.context.SmartLifecycle in project spring-integration by spring-projects.

the class MarshallingTransformerParserTests method testParse.

@Test
public void testParse() throws Exception {
    EventDrivenConsumer consumer = (EventDrivenConsumer) appContext.getBean("parseOnly");
    assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
    assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
    assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
    assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
    SmartLifecycleRoleController roleController = appContext.getBean(SmartLifecycleRoleController.class);
    @SuppressWarnings("unchecked") List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles", MultiValueMap.class).get("foo");
    assertThat(list, contains((SmartLifecycle) consumer));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) SmartLifecycleRoleController(org.springframework.integration.support.SmartLifecycleRoleController) List(java.util.List) SmartLifecycle(org.springframework.context.SmartLifecycle) Test(org.junit.Test)

Example 10 with SmartLifecycle

use of org.springframework.context.SmartLifecycle in project spring-integration by spring-projects.

the class UnmarshallingTransformerParserTests method testParse.

@Test
public void testParse() throws Exception {
    EventDrivenConsumer consumer = (EventDrivenConsumer) appContext.getBean("parseOnly");
    assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
    assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
    assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
    assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
    SmartLifecycleRoleController roleController = appContext.getBean(SmartLifecycleRoleController.class);
    @SuppressWarnings("unchecked") List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles", MultiValueMap.class).get("foo");
    assertThat(list, contains((SmartLifecycle) consumer));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) SmartLifecycleRoleController(org.springframework.integration.support.SmartLifecycleRoleController) List(java.util.List) SmartLifecycle(org.springframework.context.SmartLifecycle) Test(org.junit.Test)

Aggregations

SmartLifecycle (org.springframework.context.SmartLifecycle)16 Test (org.junit.Test)11 SmartLifecycleRoleController (org.springframework.integration.support.SmartLifecycleRoleController)8 List (java.util.List)7 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)7 Lifecycle (org.springframework.context.Lifecycle)3 LinkedHashMap (java.util.LinkedHashMap)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Log (org.apache.commons.logging.Log)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 InOrder (org.mockito.InOrder)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 EnableMessageHistory (org.springframework.integration.config.EnableMessageHistory)1