Search in sources :

Example 56 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project nakadi by zalando.

the class PartitionsControllerTest method before.

@Before
public void before() throws InternalNakadiException, NoSuchEventTypeException {
    eventTypeRepositoryMock = mock(EventTypeRepository.class);
    topicRepositoryMock = mock(TopicRepository.class);
    eventTypeCache = mock(EventTypeCache.class);
    timelineService = Mockito.mock(TimelineService.class);
    cursorOperationsService = Mockito.mock(CursorOperationsService.class);
    when(timelineService.getActiveTimelinesOrdered(eq(UNKNOWN_EVENT_TYPE))).thenThrow(NoSuchEventTypeException.class);
    when(timelineService.getActiveTimelinesOrdered(eq(TEST_EVENT_TYPE))).thenReturn(Collections.singletonList(TIMELINE));
    when(timelineService.getAllTimelinesOrdered(eq(TEST_EVENT_TYPE))).thenReturn(Collections.singletonList(TIMELINE));
    when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepositoryMock);
    final CursorConverter cursorConverter = new CursorConverterImpl(eventTypeCache, timelineService);
    final PartitionsController controller = new PartitionsController(timelineService, cursorConverter, cursorOperationsService, eventTypeRepositoryMock, authorizationValidator);
    settings = mock(SecuritySettings.class);
    final FeatureToggleService featureToggleService = Mockito.mock(FeatureToggleService.class);
    mockMvc = standaloneSetup(controller).setMessageConverters(new StringHttpMessageConverter(), TestUtils.JACKSON_2_HTTP_MESSAGE_CONVERTER).setCustomArgumentResolvers(new ClientResolver(settings, featureToggleService)).setControllerAdvice(new ExceptionHandling()).build();
}
Also used : CursorConverterImpl(org.zalando.nakadi.service.converter.CursorConverterImpl) SecuritySettings(org.zalando.nakadi.config.SecuritySettings) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) CursorConverter(org.zalando.nakadi.service.CursorConverter) ClientResolver(org.zalando.nakadi.security.ClientResolver) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) CursorOperationsService(org.zalando.nakadi.service.CursorOperationsService) FeatureToggleService(org.zalando.nakadi.service.FeatureToggleService) EventTypeRepository(org.zalando.nakadi.repository.EventTypeRepository) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) TopicRepository(org.zalando.nakadi.repository.TopicRepository) Before(org.junit.Before)

Example 57 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project nakadi by zalando.

the class EventPublishingControllerTest method setUp.

@Before
public void setUp() {
    metricRegistry = new MetricRegistry();
    publisher = mock(EventPublisher.class);
    eventTypeMetricRegistry = new EventTypeMetricRegistry(metricRegistry);
    kpiPublisher = mock(NakadiKpiPublisher.class);
    settings = mock(SecuritySettings.class);
    when(settings.getAuthMode()).thenReturn(OFF);
    when(settings.getAdminClientId()).thenReturn("nakadi");
    blacklistService = Mockito.mock(BlacklistService.class);
    when(blacklistService.isProductionBlocked(any(), any())).thenReturn(false);
    final FeatureToggleService featureToggleService = Mockito.mock(FeatureToggleService.class);
    final EventPublishingController controller = new EventPublishingController(publisher, eventTypeMetricRegistry, blacklistService, kpiPublisher, "kpiEventTypeName");
    mockMvc = standaloneSetup(controller).setMessageConverters(new StringHttpMessageConverter(), TestUtils.JACKSON_2_HTTP_MESSAGE_CONVERTER).setCustomArgumentResolvers(new ClientResolver(settings, featureToggleService)).build();
}
Also used : EventPublisher(org.zalando.nakadi.service.EventPublisher) FeatureToggleService(org.zalando.nakadi.service.FeatureToggleService) BlacklistService(org.zalando.nakadi.service.BlacklistService) EventTypeMetricRegistry(org.zalando.nakadi.metrics.EventTypeMetricRegistry) MetricRegistry(com.codahale.metrics.MetricRegistry) NakadiKpiPublisher(org.zalando.nakadi.service.NakadiKpiPublisher) SecuritySettings(org.zalando.nakadi.config.SecuritySettings) ClientResolver(org.zalando.nakadi.security.ClientResolver) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) EventTypeMetricRegistry(org.zalando.nakadi.metrics.EventTypeMetricRegistry) Before(org.junit.Before)

Example 58 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project nakadi by zalando.

the class EventStreamControllerTest method setup.

@Before
public void setup() throws NakadiException, UnknownHostException, InvalidCursorException {
    EVENT_TYPE.setName(TEST_EVENT_TYPE_NAME);
    timeline = buildTimelineWithTopic(TEST_TOPIC);
    eventTypeRepository = mock(EventTypeRepository.class);
    topicRepositoryMock = mock(TopicRepository.class);
    adminService = mock(AdminService.class);
    authorizationService = mock(AuthorizationService.class);
    when(topicRepositoryMock.topicExists(TEST_TOPIC)).thenReturn(true);
    eventStreamFactoryMock = mock(EventStreamFactory.class);
    eventTypeCache = mock(EventTypeCache.class);
    requestMock = mock(HttpServletRequest.class);
    when(requestMock.getRemoteAddr()).thenReturn(InetAddress.getLoopbackAddress().getHostAddress());
    when(requestMock.getRemotePort()).thenReturn(12345);
    responseMock = mock(HttpServletResponse.class);
    metricRegistry = new MetricRegistry();
    streamMetrics = new MetricRegistry();
    final EventConsumer.LowLevelConsumer eventConsumerMock = mock(EventConsumer.LowLevelConsumer.class);
    when(topicRepositoryMock.createEventConsumer(eq(KAFKA_CLIENT_ID), any())).thenReturn(eventConsumerMock);
    final ClosedConnectionsCrutch crutch = mock(ClosedConnectionsCrutch.class);
    when(crutch.listenForConnectionClose(requestMock)).thenReturn(new AtomicBoolean(true));
    blacklistService = Mockito.mock(BlacklistService.class);
    Mockito.when(blacklistService.isConsumptionBlocked(any(), any())).thenReturn(false);
    final ConsumerLimitingService consumerLimitingService = Mockito.mock(ConsumerLimitingService.class);
    when(consumerLimitingService.acquireConnectionSlots(any(), any(), any())).thenReturn(ImmutableList.of());
    featureToggleService = mock(FeatureToggleService.class);
    timelineService = mock(TimelineService.class);
    when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepositoryMock);
    when(timelineService.getTopicRepository((EventTypeBase) any())).thenReturn(topicRepositoryMock);
    when(timelineService.getTopicRepository((Storage) any())).thenReturn(topicRepositoryMock);
    when(timelineService.getActiveTimelinesOrdered(any())).thenReturn(Collections.singletonList(timeline));
    when(timelineService.getAllTimelinesOrdered(any())).thenReturn(Collections.singletonList(timeline));
    authorizationValidator = mock(AuthorizationValidator.class);
    eventTypeChangeListener = mock(EventTypeChangeListener.class);
    when(eventTypeChangeListener.registerListener(any(), any())).thenReturn(mock(Closeable.class));
    controller = new EventStreamController(eventTypeRepository, timelineService, TestUtils.OBJECT_MAPPER, eventStreamFactoryMock, metricRegistry, streamMetrics, crutch, blacklistService, consumerLimitingService, featureToggleService, new CursorConverterImpl(eventTypeCache, timelineService), authorizationValidator, eventTypeChangeListener, null);
    settings = mock(SecuritySettings.class);
    when(settings.getAuthMode()).thenReturn(OFF);
    when(settings.getAdminClientId()).thenReturn("nakadi");
    mockMvc = standaloneSetup(controller).setMessageConverters(new StringHttpMessageConverter(), TestUtils.JACKSON_2_HTTP_MESSAGE_CONVERTER).setCustomArgumentResolvers(new ClientResolver(settings, featureToggleService)).build();
}
Also used : AdminService(org.zalando.nakadi.service.AdminService) AuthorizationValidator(org.zalando.nakadi.service.AuthorizationValidator) ClosedConnectionsCrutch(org.zalando.nakadi.service.ClosedConnectionsCrutch) BlacklistService(org.zalando.nakadi.service.BlacklistService) Closeable(java.io.Closeable) SecuritySettings(org.zalando.nakadi.config.SecuritySettings) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpServletRequest(javax.servlet.http.HttpServletRequest) EventConsumer(org.zalando.nakadi.repository.EventConsumer) FeatureToggleService(org.zalando.nakadi.service.FeatureToggleService) EventTypeChangeListener(org.zalando.nakadi.service.EventTypeChangeListener) TopicRepository(org.zalando.nakadi.repository.TopicRepository) ConsumerLimitingService(org.zalando.nakadi.service.ConsumerLimitingService) MetricRegistry(com.codahale.metrics.MetricRegistry) CursorConverterImpl(org.zalando.nakadi.service.converter.CursorConverterImpl) HttpServletResponse(javax.servlet.http.HttpServletResponse) EventTypeCache(org.zalando.nakadi.repository.db.EventTypeCache) ClientResolver(org.zalando.nakadi.security.ClientResolver) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AuthorizationService(org.zalando.nakadi.plugin.api.authz.AuthorizationService) EventTypeRepository(org.zalando.nakadi.repository.EventTypeRepository) TimelineService(org.zalando.nakadi.service.timeline.TimelineService) EventStreamFactory(org.zalando.nakadi.service.EventStreamFactory) Before(org.junit.Before)

Example 59 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project earth-snow by justlive1.

the class WebConfig method stringConverter.

@Bean
public HttpMessageConverter<String> stringConverter() {
    StringHttpMessageConverter converter = new StringHttpMessageConverter();
    converter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.ALL));
    return converter;
}
Also used : StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) Bean(org.springframework.context.annotation.Bean)

Example 60 with StringHttpMessageConverter

use of org.springframework.http.converter.StringHttpMessageConverter in project thingsboard by thingsboard.

the class AbstractControllerTest method readResponse.

@SuppressWarnings("unchecked")
protected <T> T readResponse(ResultActions result, Class<T> responseClass) throws Exception {
    byte[] content = result.andReturn().getResponse().getContentAsByteArray();
    MockHttpInputMessage mockHttpInputMessage = new MockHttpInputMessage(content);
    HttpMessageConverter converter = responseClass.equals(String.class) ? stringHttpMessageConverter : mappingJackson2HttpMessageConverter;
    return (T) converter.read(responseClass, mockHttpInputMessage);
}
Also used : MockHttpInputMessage(org.springframework.mock.http.MockHttpInputMessage) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Aggregations

StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)93 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)48 ArrayList (java.util.ArrayList)38 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)27 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)24 RestTemplate (org.springframework.web.client.RestTemplate)23 Test (org.junit.jupiter.api.Test)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)18 Test (org.junit.Test)16 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)16 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)11 MediaType (org.springframework.http.MediaType)9 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)9 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)7 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)7 URI (java.net.URI)7 HashMap (java.util.HashMap)7 MethodParameter (org.springframework.core.MethodParameter)7 MapPropertySource (org.springframework.core.env.MapPropertySource)7 StandardEnvironment (org.springframework.core.env.StandardEnvironment)7