Example usage for org.springframework.http MediaType TEXT_PLAIN

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

Introduction

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

Prototype

MediaType TEXT_PLAIN

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

Click Source Link

Document

Public constant media type for text/plain .

Usage

From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java

@Test
public void should_force_a_widget_import() throws Exception {
    //We construct a mockfile (the first arg is the name of the property expected in the controller
    MockMultipartFile file = new MockMultipartFile("file", "myfile.zip", "application/zip", "foo".getBytes());
    ImportReport expectedReport = anImportReportFor(aWidget().id("aWidget").name("myWidgetName")).build();
    when(pathImporter.forceImportFromPath(unzipedPath, widgetImporter)).thenReturn(expectedReport);

    mockMvc.perform(fileUpload("/import/widget?force=true").file(file))
            .andExpect(content().contentType(MediaType.TEXT_PLAIN)).andExpect(status().isCreated())
            .andExpect(jsonPath("element.id").value("aWidget"))
            .andExpect(jsonPath("element.name").value("myWidgetName"));
}

From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java

@Test
public void should_force_an_uncompleted_import() throws Exception {
    ImportReport expectedReport = anImportReportFor(aWidget().id("aWidget").name("myWidgetName")).build();
    Path aPath = Paths.get("widget/import/path");
    Import t = new Import(widgetImporter, "import-uuid", aPath);
    when(importStore.get("import-uuid")).thenReturn(t);
    when(widgetImporter.forceImport(any(Import.class))).thenReturn(expectedReport);

    mockMvc.perform(post("/import/import-uuid/force")).andExpect(content().contentType(MediaType.TEXT_PLAIN))
            .andExpect(status().isCreated()).andExpect(jsonPath("element.id").value("aWidget"))
            .andExpect(jsonPath("element.name").value("myWidgetName"));
}

From source file:business.services.FileService.java

public HttpEntity<InputStreamResource> downloadAccessLog(String filename,
        boolean writeContentDispositionHeader) {
    try {/*from   ww w  .  j av a  2  s . co  m*/
        FileSystem fileSystem = FileSystems.getDefault();
        Path path = fileSystem.getPath(accessLogsPath).normalize();
        filename = filename.replace(fileSystem.getSeparator(), "_");
        filename = URLEncoder.encode(filename, "utf-8");

        Path f = fileSystem.getPath(accessLogsPath, filename).normalize();
        // filter path names that point to places outside the logs path.
        // E.g., to prevent that in cases where clients use '../' in the filename
        // arbitrary locations are reachable.
        if (!Files.isSameFile(path, f.getParent())) {
            // Path f is not in the upload path. Maybe 'name' contains '..'?
            log.error("Invalid filename: " + filename);
            throw new FileDownloadError("Invalid file name");
        }
        if (!Files.isReadable(f)) {
            log.error("File does not exist: " + filename);
            throw new FileDownloadError("File does not exist");
        }

        InputStream input = new FileInputStream(f.toFile());
        InputStreamResource resource = new InputStreamResource(input);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.TEXT_PLAIN);
        if (writeContentDispositionHeader) {
            headers.set("Content-Disposition", "attachment; filename=" + filename.replace(" ", "_"));
        }
        HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers);
        return response;
    } catch (IOException e) {
        log.error(e);
        throw new FileDownloadError();
    }
}

From source file:com.orange.ngsi2.client.Ngsi2Client.java

/**
 * Retrieve the attribute of an entity//  ww  w.  j a v a 2  s.  co  m
 * @param entityId the entity ID
 * @param type optional entity type to avoid ambiguity when multiple entities have the same ID, null or zero-length for empty
 * @param attributeName the attribute name
 * @return
 */
public ListenableFuture<String> getAttributeValueAsString(String entityId, String type, String attributeName) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL);
    builder.path("v2/entities/{entityId}/attrs/{attributeName}/value");
    addParam(builder, "type", type);
    HttpHeaders httpHeaders = cloneHttpHeaders();
    httpHeaders.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN));
    return adapt(request(HttpMethod.GET, builder.buildAndExpand(entityId, attributeName).toUriString(),
            httpHeaders, null, String.class));
}

From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java

@Test
public void should_respond_an_error_with_ok_code_when_import_exception_occurs_while_importing_a_widget()
        throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", "myfile.zip", "application/zip", "foo".getBytes());
    when(pathImporter.importFromPath(unzipedPath, widgetImporter))
            .thenThrow(new ImportException(Type.SERVER_ERROR, "an error messge"));

    mockMvc.perform(fileUpload("/import/widget").file(file))
            .andExpect(content().contentType(MediaType.TEXT_PLAIN)).andExpect(status().isAccepted())
            .andExpect(jsonPath("type").value("SERVER_ERROR"))
            .andExpect(jsonPath("message").value("an error messge"));
}

From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java

@Test
public void should_respond_an_error_with_ok_code_when_import_exception_occurs_while_zip_file_could_not_be_opened()
        throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", "myfile.zip", "application/zip", "foo".getBytes());
    when(unzipper.unzipInTempDir(any(InputStream.class), anyString())).thenThrow(ZipException.class);

    mockMvc.perform(fileUpload("/import/widget").file(file))
            .andExpect(content().contentType(MediaType.TEXT_PLAIN)).andExpect(status().isAccepted())
            .andExpect(jsonPath("type").value("CANNOT_OPEN_ZIP"))
            .andExpect(jsonPath("message").value("Cannot open zip file"));

    mockMvc.perform(fileUpload("/import/page").file(file))
            .andExpect(content().contentType(MediaType.TEXT_PLAIN)).andExpect(status().isAccepted())
            .andExpect(jsonPath("type").value("CANNOT_OPEN_ZIP"))
            .andExpect(jsonPath("message").value("Cannot open zip file"));
}

From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java

@Test
public void testGetAttributeValueAsString_Number() throws Exception {

    mockServer.expect(requestTo(baseURL + "/v2/entities/room1/attrs/text/value?type=Room"))
            .andExpect(method(HttpMethod.GET)).andExpect(header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN_VALUE))
            .andRespond(withSuccess("some random text", MediaType.TEXT_PLAIN));

    String result = ngsiClient.getAttributeValueAsString("room1", "Room", "text").get();

    assertEquals("some random text", result);
}

From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java

@Test
public void should_respond_an_error_with_ok_code_when_import_exception_occurs_while_unzipping()
        throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", "myfile.zip", "application/zip", "foo".getBytes());
    when(unzipper.unzipInTempDir(any(InputStream.class), anyString())).thenThrow(IOException.class);

    mockMvc.perform(fileUpload("/import/widget").file(file))
            .andExpect(content().contentType(MediaType.TEXT_PLAIN)).andExpect(status().isAccepted())
            .andExpect(jsonPath("type").value("SERVER_ERROR"))
            .andExpect(jsonPath("message").value("Error while unzipping zip file"));

    mockMvc.perform(fileUpload("/import/page").file(file))
            .andExpect(content().contentType(MediaType.TEXT_PLAIN)).andExpect(status().isAccepted())
            .andExpect(jsonPath("type").value("SERVER_ERROR"))
            .andExpect(jsonPath("message").value("Error while unzipping zip file"));
}

From source file:org.bonitasoft.web.designer.controller.ImportControllerTest.java

@Test
public void should_import_an_artifact() throws Exception {
    //We construct a mockfile (the first arg is the name of the property expected in the controller
    MockMultipartFile file = new MockMultipartFile("file", "myfile.zip", "application/zip", "foo".getBytes());
    ImportReport expectedReport = anImportReportFor(aWidget().id("aWidget").name("myWidgetName")).build();
    doReturn(widgetImporter).when(importerResolver).getImporter(unzipedPath);
    when(pathImporter.importFromPath(unzipedPath, widgetImporter)).thenReturn(expectedReport);

    mockMvc.perform(fileUpload("/import/artifact").file(file))
            .andExpect(content().contentType(MediaType.TEXT_PLAIN)).andExpect(status().isCreated())
            .andExpect(jsonPath("element.id").value("aWidget"))
            .andExpect(jsonPath("element.name").value("myWidgetName"));
}

From source file:it.reply.orchestrator.controller.DeploymentControllerTest.java

@Test
public void createDeploymentUnsupportedMediaType() throws Exception {
    DeploymentRequest request = new DeploymentRequest();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("cpus", 1);
    request.setParameters(parameters);//from   ww  w .  j  a v  a  2  s .c om
    request.setTemplate("template");
    request.setCallback("http://localhost:8080/callback");
    mockMvc.perform(post("/deployments").contentType(MediaType.TEXT_PLAIN)
            .content(TestUtil.convertObjectToJsonBytes(request))).andExpect(status().isUnsupportedMediaType());

}