Search in sources :

Example 1 with JsonMessageConverter

use of org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter in project dhis2-core by dhis2.

the class DataElementOperandControllerTest method setUp.

@BeforeEach
public void setUp() {
    ContextService contextService = new DefaultContextService();
    QueryService _queryService = new DefaultQueryService(new DefaultJpaQueryParser(schemaService), new DefaultQueryPlanner(schemaService), mock(JpaCriteriaQueryEngine.class), new InMemoryQueryEngine<>(schemaService, mock(AclService.class), currentUserService));
    // Use "spy" on queryService, because we want a partial mock: we only
    // want to
    // mock the method "count"
    queryService = spy(_queryService);
    // Controller under test
    final DataElementOperandController controller = new DataElementOperandController(manager, queryService, fieldFilterService, linkService, contextService, schemaService, dataElementCategoryService);
    // Set custom Node Message converter //
    NodeService nodeService = new DefaultNodeService();
    Jackson2JsonNodeSerializer serializer = new Jackson2JsonNodeSerializer(staticJsonMapper());
    ReflectionTestUtils.setField(nodeService, "nodeSerializers", Lists.newArrayList(serializer));
    ReflectionTestUtils.invokeMethod(nodeService, "init");
    JsonMessageConverter jsonMessageConverter = new JsonMessageConverter(nodeService, Compression.NONE);
    mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(jsonMessageConverter).build();
    // End mockmvc setup
    when(schemaService.getDynamicSchema(DataElementOperand.class)).thenReturn(new Schema(DataElementOperand.class, "", ""));
    when(currentUserService.getCurrentUser()).thenReturn(rnd.nextObject(User.class));
}
Also used : Jackson2JsonNodeSerializer(org.hisp.dhis.node.serializers.Jackson2JsonNodeSerializer) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ContextService(org.hisp.dhis.webapi.service.ContextService) DefaultContextService(org.hisp.dhis.webapi.service.DefaultContextService) User(org.hisp.dhis.user.User) JsonMessageConverter(org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter) DefaultContextService(org.hisp.dhis.webapi.service.DefaultContextService) NodeService(org.hisp.dhis.node.NodeService) DefaultNodeService(org.hisp.dhis.node.DefaultNodeService) Schema(org.hisp.dhis.schema.Schema) DefaultQueryPlanner(org.hisp.dhis.query.planner.DefaultQueryPlanner) JpaCriteriaQueryEngine(org.hisp.dhis.query.JpaCriteriaQueryEngine) DefaultNodeService(org.hisp.dhis.node.DefaultNodeService) QueryService(org.hisp.dhis.query.QueryService) DefaultQueryService(org.hisp.dhis.query.DefaultQueryService) DefaultQueryService(org.hisp.dhis.query.DefaultQueryService) DefaultJpaQueryParser(org.hisp.dhis.query.DefaultJpaQueryParser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with JsonMessageConverter

use of org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter in project dhis2-core by dhis2.

the class MvcTestConfig method configureMessageConverters.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    Arrays.stream(Compression.values()).forEach(compression -> converters.add(new JsonMessageConverter(nodeService(), compression)));
    Arrays.stream(Compression.values()).forEach(compression -> converters.add(new XmlMessageConverter(nodeService(), compression)));
    converters.add(new StringHttpMessageConverter());
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new FormHttpMessageConverter());
    converters.add(mappingJackson2HttpMessageConverter());
    converters.add(mappingJackson2XmlHttpMessageConverter());
}
Also used : FormHttpMessageConverter(org.springframework.http.converter.FormHttpMessageConverter) JsonMessageConverter(org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) XmlMessageConverter(org.hisp.dhis.webapi.mvc.messageconverter.XmlMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 3 with JsonMessageConverter

use of org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter in project dhis2-core by dhis2.

the class WebMvcConfig method configureMessageConverters.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    Arrays.stream(Compression.values()).forEach(compression -> converters.add(new JsonMessageConverter(nodeService(), compression)));
    Arrays.stream(Compression.values()).forEach(compression -> converters.add(new XmlMessageConverter(nodeService(), compression)));
    converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new FormHttpMessageConverter());
    converters.add(mappingJackson2HttpMessageConverter());
    converters.add(mappingJackson2XmlHttpMessageConverter());
}
Also used : FormHttpMessageConverter(org.springframework.http.converter.FormHttpMessageConverter) JsonMessageConverter(org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) XmlMessageConverter(org.hisp.dhis.webapi.mvc.messageconverter.XmlMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Aggregations

JsonMessageConverter (org.hisp.dhis.webapi.mvc.messageconverter.JsonMessageConverter)3 XmlMessageConverter (org.hisp.dhis.webapi.mvc.messageconverter.XmlMessageConverter)2 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)2 FormHttpMessageConverter (org.springframework.http.converter.FormHttpMessageConverter)2 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)2 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)1 DefaultNodeService (org.hisp.dhis.node.DefaultNodeService)1 NodeService (org.hisp.dhis.node.NodeService)1 Jackson2JsonNodeSerializer (org.hisp.dhis.node.serializers.Jackson2JsonNodeSerializer)1 DefaultJpaQueryParser (org.hisp.dhis.query.DefaultJpaQueryParser)1 DefaultQueryService (org.hisp.dhis.query.DefaultQueryService)1 JpaCriteriaQueryEngine (org.hisp.dhis.query.JpaCriteriaQueryEngine)1 QueryService (org.hisp.dhis.query.QueryService)1 DefaultQueryPlanner (org.hisp.dhis.query.planner.DefaultQueryPlanner)1 Schema (org.hisp.dhis.schema.Schema)1 User (org.hisp.dhis.user.User)1 ContextService (org.hisp.dhis.webapi.service.ContextService)1 DefaultContextService (org.hisp.dhis.webapi.service.DefaultContextService)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1