@Test(expected = ContentEndpointException.class)
  public void readContentEndpointExceptionExceptionExpected()
      throws ContentEndpointException, ContentFrameworkException, MimeTypeResolutionException {
    ContentFramework framework = mock(ContentFramework.class);
    when(framework.read(isA(ReadRequest.class)))
        .thenThrow(
            new ContentEndpointException("Content Item not found.", Response.Status.NOT_FOUND));

    ContentEndpoint endpoint = new ContentEndpoint(framework, getMockMimeTypeMapper());
    endpoint.read(anyString());
  }
  @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());
  }
  /**
   * 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());
  }
  protected void executeReadTest(String content, String fileName, Long size, String mimeType)
      throws IOException, MimeTypeParseException, ContentFrameworkException,
          MimeTypeResolutionException {

    ContentFramework framework = mock(ContentFramework.class);
    ReadResponse readResponse = mock(ReadResponse.class);

    ContentItem contentItem =
        getMockGoodContentItem(content, fileName, "contentIdValue", size, mimeType);
    when(readResponse.getContentItem()).thenReturn(contentItem);

    when(framework.read(isA(ReadRequest.class))).thenReturn(readResponse);

    ContentEndpoint endpoint = new ContentEndpoint(framework, getMockMimeTypeMapper());
    Response response = endpoint.read(anyString());

    // Assertions for all valid headers returned
    assertThat(response.getStatus(), equalTo(200));
    assertThat(IOUtils.toString((InputStream) response.getEntity()), equalTo(content));

    if (fileName != null) {
      assertThat(
          (String) response.getMetadata().getFirst(CONTENT_DISPOSITION),
          equalToIgnoringWhiteSpace("inline; filename=" + fileName));
    } else {
      assertThat(response.getMetadata().getFirst(CONTENT_DISPOSITION), is(nullValue()));
    }

    if (mimeType != null) {
      assertThat(
          (String) response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE), equalTo(mimeType));
    } else {
      assertThat(
          (String) response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE),
          equalTo(MediaType.APPLICATION_OCTET_STREAM));
    }

    if (size != null) {
      assertThat(
          (String) response.getMetadata().getFirst(HttpHeaders.CONTENT_LENGTH),
          equalTo(String.valueOf(size)));
    } else {
      assertThat(response.getMetadata().getFirst(HttpHeaders.CONTENT_LENGTH), is(nullValue()));
    }
  }