Ejemplo n.º 1
0
  @Test
  public void testParseAttachmentContentTypeSpecified() throws Exception {
    InputStream is = IOUtils.toInputStream(TEST_JSON);
    MetadataMap<String, String> headers = new MetadataMap<String, String>();
    headers.add(CONTENT_DISPOSITION, "form-data; name=file; filename=C:\\DDF\\geojson_valid.json");
    headers.add(CONTENT_TYPE, "application/json;id=geojson");
    Attachment attachment = new Attachment(is, headers);

    ContentFramework framework = mock(ContentFramework.class);
    ContentEndpoint endpoint = new ContentEndpoint(framework, getMockMimeTypeMapper());
    CreateInfo createInfo = endpoint.parseAttachment(attachment);
    Assert.assertNotNull(createInfo);
    Assert.assertEquals("application/json;id=geojson", createInfo.getContentType());
    Assert.assertEquals("geojson_valid.json", createInfo.getFilename());
  }
Ejemplo n.º 2
0
  /**
   * No filename or Content-Type specified by client, so ContentEndpoint sets the Content-Type to
   * text/plain (per CXF JAXRS default in Attachment.getContentType()) andgenerates default filename
   * of file.txt ("file" is default filename and ".txt" extension due to Content-Type of
   * text/plain).
   *
   * @throws Exception
   */
  @Test
  public void testParseAttachmentNoFilenameOrContentTypeSpecified() throws Exception {
    InputStream is = IOUtils.toInputStream(TEST_JSON);
    MetadataMap<String, String> headers = new MetadataMap<String, String>();
    headers.add(ContentEndpoint.CONTENT_DISPOSITION, "form-data; name=file");
    Attachment attachment = new Attachment(is, headers);

    ContentFramework framework = mock(ContentFramework.class);
    ContentEndpoint endpoint = new ContentEndpoint(framework, getMockMimeTypeMapper());
    CreateInfo createInfo = endpoint.parseAttachment(attachment);
    Assert.assertNotNull(createInfo);
    // Content-Type of text/plain is the default returned from CXF JAXRS
    Assert.assertEquals("text/plain", createInfo.getContentType());
    Assert.assertEquals(ContentEndpoint.DEFAULT_FILE_NAME + ".txt", createInfo.getFilename());
  }