public void testStopWithFailure() throws Exception { stopOrder = ""; context.stop(); assertEquals("CBA", stopOrder); assertEquals(5, events.size()); assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0)); assertIsInstanceOf(CamelContextStartedEvent.class, events.get(1)); assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(2)); ServiceStopFailureEvent event = assertIsInstanceOf(ServiceStopFailureEvent.class, events.get(3)); assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(4)); assertEquals("Fail B", event.getCause().getMessage()); assertEquals("Failure to stop service: B due to Fail B", event.toString()); }
@Test @InSequence(3) public void stopCamelContext(CamelContext context, List<Class> events) throws Exception { context.stop(); assertThat("Events fired are incorrect!", events, contains( CamelContextStartingEvent.class, CamelContextStartedEvent.class, ExchangeSendingEvent.class, ExchangeCreatedEvent.class, ExchangeSendingEvent.class, ExchangeSentEvent.class, ExchangeCompletedEvent.class, ExchangeSentEvent.class, CamelContextStoppingEvent.class, CamelContextStoppedEvent.class)); }
@Test public void testEventBridge() throws Exception { EventManager eventManager = new EventManager(); CountingObserver observer = new CountingObserver(); eventManager.addObserver(observer, CamelContextStartedEvent.class); eventManager.addObserver(observer, CamelContextStoppedEvent.class); CamelEventBridge eventBridge = new CamelEventBridge(eventManager); DefaultCamelContext context = new DefaultCamelContext(); context.getManagementStrategy().addEventNotifier(eventBridge); assertTrue(observer.counter == 0); context.start(); assertTrue(observer.counter == 1); context.stop(); assertTrue(observer.counter == 2); }
public void testExchangeDone() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); assertEquals(14, events.size()); assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0)); assertIsInstanceOf(RouteAddedEvent.class, events.get(1)); assertIsInstanceOf(RouteAddedEvent.class, events.get(2)); assertIsInstanceOf(RouteStartedEvent.class, events.get(3)); assertIsInstanceOf(RouteStartedEvent.class, events.get(4)); assertIsInstanceOf(CamelContextStartedEvent.class, events.get(5)); assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(7)); assertIsInstanceOf(ExchangeSentEvent.class, events.get(9)); assertIsInstanceOf(ExchangeSentEvent.class, events.get(11)); assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(12)); // this is the sent using the produce template to start the test assertIsInstanceOf(ExchangeSentEvent.class, events.get(13)); context.stop(); assertEquals(20, events.size()); assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(14)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(15)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(16)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(17)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(18)); assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(19)); }
public void testExchangeFailed() throws Exception { try { template.sendBody("direct:fail", "Hello World"); fail("Should have thrown an exception"); } catch (Exception e) { // expected assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); } assertEquals(10, events.size()); assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0)); assertIsInstanceOf(RouteAddedEvent.class, events.get(1)); assertIsInstanceOf(RouteAddedEvent.class, events.get(2)); assertIsInstanceOf(RouteStartedEvent.class, events.get(3)); assertIsInstanceOf(RouteStartedEvent.class, events.get(4)); assertIsInstanceOf(CamelContextStartedEvent.class, events.get(5)); assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6)); assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(7)); assertIsInstanceOf(ExchangeFailedEvent.class, events.get(8)); // this is the sent using the produce template to start the test assertIsInstanceOf(ExchangeSentEvent.class, events.get(9)); context.stop(); assertEquals(16, events.size()); assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(10)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(11)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(12)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(13)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(14)); assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(15)); }
public void testExchangeFailed() throws Exception { try { template.sendBody("direct:fail", "Hello World"); fail("Should have thrown an exception"); } catch (Exception e) { // expected assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); } assertEquals(10, events.size()); assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0)); assertIsInstanceOf(RouteAddedEvent.class, events.get(1)); assertIsInstanceOf(RouteAddedEvent.class, events.get(2)); assertIsInstanceOf(RouteStartedEvent.class, events.get(3)); assertIsInstanceOf(RouteStartedEvent.class, events.get(4)); assertIsInstanceOf(CamelContextStartedEvent.class, events.get(5)); assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6)); assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(7)); assertIsInstanceOf(ExchangeFailedEvent.class, events.get(8)); assertIsInstanceOf(ExchangeSentEvent.class, events.get(9)); assertEquals(4, events2.size()); context.stop(); assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(0)); assertIsInstanceOf(ExchangeCreatedEvent.class, events2.get(1)); assertIsInstanceOf(ExchangeFailedEvent.class, events2.get(2)); assertIsInstanceOf(ExchangeSentEvent.class, events2.get(3)); assertEquals(16, events.size()); assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(10)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(11)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(12)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(13)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(14)); assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(15)); assertEquals(4, events2.size()); }
public void testExchangeDone() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); assertEquals(14, events.size()); assertIsInstanceOf(CamelContextStartingEvent.class, events.get(0)); assertIsInstanceOf(RouteAddedEvent.class, events.get(1)); assertIsInstanceOf(RouteAddedEvent.class, events.get(2)); assertIsInstanceOf(RouteStartedEvent.class, events.get(3)); assertIsInstanceOf(RouteStartedEvent.class, events.get(4)); assertIsInstanceOf(CamelContextStartedEvent.class, events.get(5)); assertIsInstanceOf(ExchangeSendingEvent.class, events.get(6)); assertIsInstanceOf(ExchangeCreatedEvent.class, events.get(7)); assertIsInstanceOf(ExchangeSendingEvent.class, events.get(8)); assertIsInstanceOf(ExchangeSentEvent.class, events.get(9)); assertIsInstanceOf(ExchangeSendingEvent.class, events.get(10)); assertIsInstanceOf(ExchangeSentEvent.class, events.get(11)); assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(12)); assertIsInstanceOf(ExchangeSentEvent.class, events.get(13)); assertEquals(8, events2.size()); assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(0)); assertIsInstanceOf(ExchangeCreatedEvent.class, events2.get(1)); assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(2)); assertIsInstanceOf(ExchangeSentEvent.class, events2.get(3)); assertIsInstanceOf(ExchangeSendingEvent.class, events2.get(4)); assertIsInstanceOf(ExchangeSentEvent.class, events2.get(5)); assertIsInstanceOf(ExchangeCompletedEvent.class, events2.get(6)); assertIsInstanceOf(ExchangeSentEvent.class, events2.get(7)); context.stop(); assertEquals(20, events.size()); assertIsInstanceOf(CamelContextStoppingEvent.class, events.get(14)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(15)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(16)); assertIsInstanceOf(RouteStoppedEvent.class, events.get(17)); assertIsInstanceOf(RouteRemovedEvent.class, events.get(18)); assertIsInstanceOf(CamelContextStoppedEvent.class, events.get(19)); assertEquals(8, events2.size()); }
private void onCamelContextStoppedEvent(@Observes CamelContextStoppedEvent event, List<Class> events) { events.add(CamelContextStoppedEvent.class); }