@Before public void setUp() throws Exception { producer = new TimerProducer(endpoint); inOrder = Mockito.inOrder(endpoint, exchange, registry, timer, context, in); when(endpoint.getRegistry()).thenReturn(registry); when(registry.timer(METRICS_NAME)).thenReturn(timer); when(timer.time()).thenReturn(context); when(exchange.getIn()).thenReturn(in); }
@Test public void testProcessNoAction() throws Exception { when(endpoint.getAction()).thenReturn(null); when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(null); producer.doProcess(exchange, endpoint, registry, METRICS_NAME); inOrder.verify(exchange, times(1)).getIn(); inOrder.verify(endpoint, times(1)).getAction(); inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class); inOrder.verifyNoMoreInteractions(); }
@Test public void testProcessNoActionOverride() throws Exception { when(endpoint.getAction()).thenReturn(null); when(in.getHeader(HEADER_TIMER_ACTION, null, TimerAction.class)).thenReturn(TimerAction.start); producer.doProcess(exchange, endpoint, registry, METRICS_NAME); inOrder.verify(exchange, times(1)).getIn(); inOrder.verify(endpoint, times(1)).getAction(); inOrder.verify(in, times(1)).getHeader(HEADER_TIMER_ACTION, null, TimerAction.class); inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class); inOrder.verify(registry, times(1)).timer(METRICS_NAME); inOrder.verify(timer, times(1)).time(); inOrder.verify(exchange, times(1)).setProperty(PROPERTY_NAME, context); inOrder.verifyNoMoreInteractions(); }
@Test public void testProcessStop() throws Exception { when(endpoint.getAction()).thenReturn(TimerAction.stop); when(in.getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class)) .thenReturn(TimerAction.stop); when(exchange.getProperty(PROPERTY_NAME, Timer.Context.class)).thenReturn(context); producer.doProcess(exchange, endpoint, registry, METRICS_NAME); inOrder.verify(exchange, times(1)).getIn(); inOrder.verify(endpoint, times(1)).getAction(); inOrder .verify(in, times(1)) .getHeader(HEADER_TIMER_ACTION, TimerAction.stop, TimerAction.class); inOrder.verify(exchange, times(1)).getProperty(PROPERTY_NAME, Timer.Context.class); inOrder.verify(context, times(1)).stop(); inOrder.verify(exchange, times(1)).removeProperty(PROPERTY_NAME); inOrder.verifyNoMoreInteractions(); }