Пример #1
0
  private void verifyFileFromURLResourceReader(
      URI uri, String filename, String expectedMimeType, URLConnection conn)
      throws URISyntaxException, IOException, ResourceNotFoundException {

    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper);

    resourceReader.setConn(conn);

    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();

    // Test using the URL ResourceReader
    LOGGER.info("URI: " + uri.toString());

    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);

    Resource resource = resourceResponse.getResource();
    assert (resource != null);

    LOGGER.info("MimeType: " + resource.getMimeType());
    LOGGER.info("Got resource: " + resource.getName());
    String name = resource.getName();
    assertNotNull(name);
    assertTrue(name.equals(filename));
    assertTrue(resource.getMimeType().toString().contains(expectedMimeType));
  }
Пример #2
0
  private void verifyFile(String filePath, String filename, String expectedMimeType) {
    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper);

    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();

    try {
      LOGGER.info("Getting resource: " + filePath);

      // Test using the URL ResourceReader
      File file = new File(filePath);

      URI uri = file.toURI();
      LOGGER.info("URI: " + uri.toString());

      ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);

      Resource resource = resourceResponse.getResource();
      assert (resource != null);

      LOGGER.info("MimeType: " + resource.getMimeType());
      LOGGER.info("Got resource: " + resource.getName());
      String name = resource.getName();
      assertNotNull(name);
      assertTrue(name.equals(filename));
      assertTrue(resource.getMimeType().toString().contains(expectedMimeType));

    } catch (IOException e) {
      LOGGER.info("Caught unexpected IOException");
      fail();
    } catch (ResourceNotFoundException e) {
      LOGGER.info("Caught unexpected ResourceNotFoundException");
      e.printStackTrace();
      fail();
    }
  }
Пример #3
0
  @Test
  public void testURLResourceReaderQualifierSet() {
    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper);

    Set<String> qualifiers = resourceReader.getSupportedSchemes();

    assert (qualifiers != null);
    assert (qualifiers.contains(HTTP_SCHEME));
    assert (qualifiers.size() == 3);
  }
Пример #4
0
  @Test
  public void testUrlToNonExistentFile() {
    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper);

    String filePath = ABSOLUTE_PATH + TEST_PATH + "NonExistentFile.jpg";

    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    try {
      LOGGER.info("Getting resource: " + filePath);
      File file = new File(filePath);
      URI uri = file.toURI();
      resourceReader.retrieveResource(uri, arguments);
    } catch (IOException e) {
      LOGGER.info("Successfully caught IOException");
      assert (true);
    } catch (ResourceNotFoundException e) {
      LOGGER.info("Caught unexpected ResourceNotFoundException");
      fail();
    }
  }
Пример #5
0
  @Test
  public void testURLResourceIOException() {
    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper);

    String filePath = "JUMANJI!!!!";

    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    try {
      LOGGER.info("Getting resource: " + filePath);
      URI uri = new URI(FILE_SCHEME_PLUS_SEP + filePath);
      resourceReader.retrieveResource(uri, arguments);
    } catch (IOException e) {
      LOGGER.info("Successfully caught IOException");
      assert (true);
    } catch (ResourceNotFoundException e) {
      LOGGER.info("Caught unexpected ResourceNotFoundException");
      fail();
    } catch (URISyntaxException e) {
      LOGGER.info("Caught unexpected URISyntaxException");
      fail();
    }
  }