Example usage for org.springframework.http MediaType APPLICATION_XML

List of usage examples for org.springframework.http MediaType APPLICATION_XML

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_XML.

Prototype

MediaType APPLICATION_XML

To view the source code for org.springframework.http MediaType APPLICATION_XML.

Click Source Link

Document

Public constant media type for application/xml .

Usage

From source file:se.skltp.cooperation.web.rest.v1.controller.CooperationControllerTest.java

@Test
public void testGetAllAsXml_shouldReturnWithInclude() throws Exception {

    when(cooperationServiceMock.findAll(any(CooperationCriteria.class))).thenReturn(Arrays.asList(c1, c2));
    when(mapperMock.map(c1, CooperationDTO.class)).thenReturn(dto1);
    when(mapperMock.map(c2, CooperationDTO.class)).thenReturn(dto2);

    mockMvc.perform(//from   w  w  w .  j a  va2  s  . c  o  m
            get("/api/v1/cooperations?include?connectionPoint,serviceConsumer,logicalAddress,serviceContract")
                    .accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_XML))
            .andExpect(xpath("/cooperations/cooperation[1]/id").string(is(dto1.getId().toString())))
            .andExpect(xpath("/cooperations/cooperation[1]/connectionPoint/platform")
                    .string(is(dto1.getConnectionPoint().getPlatform())))
            .andExpect(xpath("/cooperations/cooperation[1]/logicalAddress/description")
                    .string(is(dto1.getLogicalAddress().getDescription())))
            .andExpect(xpath("/cooperations/cooperation[1]/serviceConsumer/hsaId")
                    .string(is(dto1.getServiceConsumer().getHsaId())))
            .andExpect(xpath("/cooperations/cooperation[1]/serviceContract/name")
                    .string(is(dto1.getServiceContract().getName())))
            .andExpect(xpath("/cooperations/cooperation[2]/id").string(is(dto2.getId().toString())))
            .andExpect(xpath("/cooperations/cooperation[2]/connectionPoint/platform")
                    .string(is(dto2.getConnectionPoint().getPlatform())))
            .andExpect(xpath("/cooperations/cooperation[2]/logicalAddress/description")
                    .string(is(dto2.getLogicalAddress().getDescription())))
            .andExpect(xpath("/cooperations/cooperation[2]/serviceConsumer/hsaId")
                    .string(is(dto2.getServiceConsumer().getHsaId())))
            .andExpect(xpath("/cooperations/cooperation[2]/serviceContract/name")
                    .string(is(dto2.getServiceContract().getName())));

    verify(cooperationServiceMock, times(1)).findAll(any(CooperationCriteria.class));
    verifyNoMoreInteractions(cooperationServiceMock);

}

From source file:com.orange.ngsi.server.NgsiBaseControllerTest.java

@Test
public void checkUnsubscribeContextImplementedInXml() throws Exception {
    mockMvc.perform(//from w ww .  ja  v a 2  s .  co  m
            post("/i/unsubscribeContext").content(xmlmapper.writeValueAsString(Util.createUnsubscribeContext()))
                    .contentType(MediaType.APPLICATION_XML).header("Host", "localhost")
                    .accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk());
}

From source file:access.deploy.geoserver.PiazzaEnvironment.java

/**
 * Creates the Piazza Postgres vector data store
 *///from  w  w w  . j  a  v a 2 s .  c o  m
private void createPostgresStore() {
    // Get Request XML
    ClassLoader classLoader = getClass().getClassLoader();
    InputStream inputStream = null;
    String dataStoreBody = null;
    try {
        inputStream = classLoader.getResourceAsStream("templates" + File.separator + "createDataStore.xml");
        dataStoreBody = IOUtils.toString(inputStream);
    } catch (Exception exception) {
        LOGGER.error("Error reading GeoServer Data Store Template.", exception);
    } finally {
        try {
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (Exception exception) {
            LOGGER.error("Error closing GeoServer Data Store Template Stream.", exception);
        }
    }
    // Create Workspace
    if (dataStoreBody != null) {
        // Insert the credential data into the template
        dataStoreBody = dataStoreBody.replace("$DB_USER", postgresServiceKeyUser);
        dataStoreBody = dataStoreBody.replace("$DB_PASSWORD", postgresServiceKeyPassword);
        dataStoreBody = dataStoreBody.replace("$DB_PORT", postgresPort);
        dataStoreBody = dataStoreBody.replace("$DB_NAME", postgresDatabase);
        dataStoreBody = dataStoreBody.replace("$DB_HOST", postgresHost);

        // POST Data Store to GeoServer
        authHeaders.setContentType(MediaType.APPLICATION_XML);
        HttpEntity<String> request = new HttpEntity<>(dataStoreBody, authHeaders.get());
        String uri = String.format("%s/rest/workspaces/piazza/datastores",
                accessUtilities.getGeoServerBaseUrl());
        try {
            pzLogger.log(String.format("Creating Piazza Data Store to %s", uri), Severity.INFORMATIONAL,
                    new AuditElement(ACCESS, "tryCreateGeoServerDataStore", uri));
            restTemplate.exchange(uri, HttpMethod.POST, request, String.class);
        } catch (HttpClientErrorException | HttpServerErrorException exception) {
            String error = String.format("HTTP Error occurred while trying to create Piazza Data Store: %s",
                    exception.getResponseBodyAsString());
            LOGGER.info(error, exception);
            pzLogger.log(error, Severity.WARNING);
            determineExit();
        } catch (Exception exception) {
            String error = String.format(
                    "Unexpected Error occurred while trying to create Piazza Data Store: %s",
                    exception.getMessage());
            LOGGER.error(error, exception);
            pzLogger.log(error, Severity.ERROR);
            determineExit();
        }
    } else {
        pzLogger.log("Could not create GeoServer Data Store. Could not load Request XML from local Resources.",
                Severity.ERROR);
    }
}

From source file:se.skltp.cooperation.web.rest.v1.controller.ConnectionPointControllerTest.java

@Test
public void getAllAcceptXml_shouldReturnEmptyList() throws Exception {

    ConnectionPointCriteria criteria = new ConnectionPointCriteria(null, null, null, null, null, null);
    when(connectionPointServiceMock.findAll(criteria)).thenReturn(new ArrayList<ConnectionPoint>());

    mockMvc.perform(get("/api/v1/connectionPoints").accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_XML))
            .andExpect(xpath("/connectionPoints").nodeCount(1))
            .andExpect(xpath("/connectionPoints/*").nodeCount(0));

}

From source file:com.orange.ngsi.server.NgsiBaseControllerTest.java

@Test
public void checkQueryContextImplementedInXml() throws Exception {
    mockMvc.perform(//www. ja va2  s.  com
            post("/i/queryContext").content(xmlmapper.writeValueAsString(Util.createQueryContextTemperature()))
                    .contentType(MediaType.APPLICATION_XML).header("Host", "localhost")
                    .accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk());
}

From source file:edu.mayo.qdm.webapp.rest.controller.TranslatorController.java

/**
 * Builds the response./*from   w  w  w.  ja  va  2  s . c o m*/
 *
 * @param request the request
 * @param bean the bean
 * @param xml the xml
 * @return the object
 */
protected Object buildResponse(HttpServletRequest request, String view, Object bean, String xml) {

    if (this.isHtmlRequest(request)) {
        ModelAndView mav;
        if (StringUtils.isNotBlank(view)) {
            mav = new ModelAndView(view);
        } else {
            mav = new ModelAndView();
        }
        mav.addObject(bean.getClass().getSimpleName(), bean);
        return mav;
    } else {
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_XML);

        return new ResponseEntity<Object>(xml, headers, HttpStatus.OK);
    }
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplIntegrationTest.java

/**
 * Tests {@link SpringApiClientImpl#getMyChannels} when the API user has zero channels.
 *//*from www  . j  ava 2s  . c  o  m*/
@Test
public void getMyChannelsWhenZeroChannels() {
    String expectedRequestUrl = this.apiClient.getApiServiceBaseUri()
            + ChannelsResource.MY_CHANNELS_RELATIVE_URI_TEMPLATE;

    // Configure mock API service to respond to API call
    this.mockReportingApiService.expect(method(HttpMethod.GET)).andExpect(requestTo(expectedRequestUrl))
            .andRespond(withSuccess("<channels/>", MediaType.APPLICATION_XML));

    // Perform the test
    ChannelsResource channelsResource = this.apiClient.getMyChannels(null);

    this.mockReportingApiService.verify();
    assertThat(channelsResource, notNullValue());
    assertThat(channelsResource.getChannels(), hasSize(0));
    assertThat(channelsResource.getLinks(), hasSize(0));
}

From source file:com.orange.ngsi.server.NgsiBaseControllerTest.java

@Test
public void xmlSyntaxErrorHandling() throws Exception {

    mockMvc.perform(post("/ni/notifyContext").content("bad xml").contentType(MediaType.APPLICATION_XML)
            .header("Host", "localhost").accept(MediaType.APPLICATION_XML)).andExpect(status().isOk())
            .andExpect(MockMvcResultMatchers.xpath("notifyContextResponse/responseCode/code")
                    .string(CodeEnum.CODE_400.getLabel()))
            .andExpect(MockMvcResultMatchers.xpath("notifyContextResponse/responseCode/reasonPhrase")
                    .string(CodeEnum.CODE_400.getShortPhrase()))
            .andExpect(MockMvcResultMatchers.xpath("notifyContextResponse/responseCode/details")
                    .string(CodeEnum.CODE_400.getLongPhrase()));
}

From source file:com.orange.ngsi.Util.java

static public String xml(MappingJackson2XmlHttpMessageConverter mapping, Object o) throws IOException {
    MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
    mapping.write(o, MediaType.APPLICATION_XML, mockHttpOutputMessage);
    return mockHttpOutputMessage.getBodyAsString();
}

From source file:se.skltp.cooperation.web.rest.v1.controller.ConnectionPointControllerTest.java

@Test
public void getAccept_shouldReturnOneAsXml() throws Exception {

    when(connectionPointServiceMock.find(cp1.getId())).thenReturn(cp1);
    when(mapperMock.map(cp1, ConnectionPointDTO.class)).thenReturn(dto1);

    mockMvc.perform(get("/api/v1/connectionPoints/{id}", cp1.getId()).accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk())//from  w  w  w.j a va2  s .  c  o m
            .andExpect(content().contentType(MediaType.APPLICATION_XML + ";charset=UTF-8"))
            .andExpect(xpath("/connectionPoint/id").string(is(dto1.getId().toString())))
            .andExpect(xpath("/connectionPoint/platform").string(is(dto1.getPlatform())))
            .andExpect(xpath("/connectionPoint/environment").string(is(dto1.getEnvironment())))
            .andExpect(xpath("/connectionPoint/snapshotTime")
                    .string(is(isoDateFormatter.print(dto1.getSnapshotTime().getTime()))));
}