public void testLoadFileNotFound() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.start();

    try {
      ResourceHelper.resolveMandatoryResourceAsInputStream(
          context, "file:src/test/resources/notfound.txt");
      fail("Should not find file");
    } catch (FileNotFoundException e) {
      assertTrue(e.getMessage().contains("notfound.txt"));
    }

    context.stop();
  }
  public void testLoadClasspathNotFound() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.start();

    try {
      ResourceHelper.resolveMandatoryResourceAsInputStream(context, "classpath:notfound.txt");
      fail("Should not find file");
    } catch (FileNotFoundException e) {
      assertEquals(
          "Cannot find resource: classpath:notfound.txt in classpath for URI: classpath:notfound.txt",
          e.getMessage());
    }

    context.stop();
  }
  public void testLoadClasspathDefault() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.start();

    InputStream is =
        ResourceHelper.resolveMandatoryResourceAsInputStream(context, "log4j2.properties");
    assertNotNull(is);

    String text = context.getTypeConverter().convertTo(String.class, is);
    assertNotNull(text);
    assertTrue(text.contains("log4j"));
    is.close();

    context.stop();
  }
  public void testLoadRegistry() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("myBean", "This is a log4j logging configuation file");

    CamelContext context = new DefaultCamelContext(registry);
    context.start();

    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, "ref:myBean");
    assertNotNull(is);

    String text = context.getTypeConverter().convertTo(String.class, is);
    assertNotNull(text);
    assertTrue(text.contains("log4j"));
    is.close();

    context.stop();
  }
  public void testLoadFileWithSpace() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.start();

    createDirectory("target/my space");
    FileUtil.copyFile(
        new File("src/test/resources/log4j2.properties"),
        new File("target/my space/log4j2.properties"));

    InputStream is =
        ResourceHelper.resolveMandatoryResourceAsInputStream(
            context, "file:target/my%20space/log4j2.properties");
    assertNotNull(is);

    String text = context.getTypeConverter().convertTo(String.class, is);
    assertNotNull(text);
    assertTrue(text.contains("log4j"));
    is.close();

    context.stop();
  }