use of org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody in project nakadi by zalando.
the class EventStreamControllerTest method whenNormalCaseThenParametersArePassedToConfigAndStreamStarted.
@Test
public void whenNormalCaseThenParametersArePassedToConfigAndStreamStarted() throws Exception {
final EventConsumer eventConsumerMock = mock(EventConsumer.class);
when(eventTypeRepository.findByName(TEST_EVENT_TYPE_NAME)).thenReturn(EVENT_TYPE);
when(timelineService.createEventConsumer(eq(KAFKA_CLIENT_ID), eq(ImmutableList.of(NakadiCursor.of(timeline, "0", "000000000000000000"))))).thenReturn(eventConsumerMock);
when(timelineService.getActiveTimeline(eq(EVENT_TYPE))).thenReturn(timeline);
final ArgumentCaptor<Integer> statusCaptor = getStatusCaptor();
final ArgumentCaptor<String> contentTypeCaptor = getContentTypeCaptor();
final ArgumentCaptor<EventStreamConfig> configCaptor = ArgumentCaptor.forClass(EventStreamConfig.class);
final EventStream eventStreamMock = mock(EventStream.class);
when(eventStreamFactoryMock.createEventStream(any(), any(), configCaptor.capture(), any())).thenReturn(eventStreamMock);
final StreamingResponseBody responseBody = createStreamingResponseBody(1, 2, 3, 4, 5, "[{\"partition\":\"0\",\"offset\":\"000000000000000000\"}]");
final OutputStream outputStream = mock(OutputStream.class);
responseBody.writeTo(outputStream);
final EventStreamConfig streamConfig = configCaptor.getValue();
assertThat(streamConfig, equalTo(EventStreamConfig.builder().withCursors(ImmutableList.of(NakadiCursor.of(timeline, "0", "000000000000000000"))).withBatchLimit(1).withStreamLimit(2).withBatchTimeout(3).withStreamTimeout(4).withStreamKeepAliveLimit(5).build()));
assertThat(statusCaptor.getValue(), equalTo(HttpStatus.OK.value()));
assertThat(contentTypeCaptor.getValue(), equalTo("application/x-json-stream"));
verify(timelineService, times(1)).createEventConsumer(eq(KAFKA_CLIENT_ID), eq(ImmutableList.of(NakadiCursor.of(timeline, "0", "000000000000000000"))));
verify(eventStreamFactoryMock, times(1)).createEventStream(eq(outputStream), eq(eventConsumerMock), eq(streamConfig), any());
verify(eventStreamMock, times(1)).streamEvents(any(), any());
verify(outputStream, times(2)).flush();
verify(outputStream, times(1)).close();
}
Aggregations