ResourceLoader { public InputStream getResourceAsStream(String name) throws IOException { if (name.startsWith("classpath:")) return openClasspathResource(name); else if (name.startsWith("file:")) return openFileResource(name); else return openWarResource(name); } ResourceLoader(WarMachine war);  ResourceLoader(WarMachine war, String baseDir); InputStream getResourceAsStream(String name); static List<String> decomposeResourceReferences(String resourceConfig); InputStream openClasspathResource(String name); InputStream openFileResource(String name); InputStream openWarResource(String name);  }
@Test public void testRuntimeClasspath() throws Exception { logger.info("testRuntimeClasspath()"); ResourceLoader loader = new ResourceLoader(null); in = loader.getResourceAsStream("classpath:contexts/propContext.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/b:beans/b:bean/b:property[@name='propAsRefId']/@ref") .bindNamespace("b", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "example", testValue); }
@Test public void testWarClasspath() throws Exception { logger.info("testWarClasspath()"); ResourceLoader loader = new ResourceLoader(war); in = loader.getResourceAsStream("classpath:loader/propContext.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/b:beans/b:bean/b:property[@name='propAsRefId']/@ref") .bindNamespace("b", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "example", testValue); }
@Test public void testFileRelativePath() throws Exception { logger.info("testFileRelativePath()"); ResourceLoader loader = new ResourceLoader(null); in = loader.getResourceAsStream("file:src/test/resources/contexts/propContext.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/b:beans/b:bean/b:property[@name='propAsRefId']/@ref") .bindNamespace("b", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "example", testValue); }
@Test public void testFileAbsolutePath() throws Exception { logger.info("testFileAbsolutePath()"); ResourceLoader loader = new ResourceLoader(null); File file = new File("src/test/resources/contexts/propContext.xml"); in = loader.getResourceAsStream("file:" + file.getAbsolutePath()); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/b:beans/b:bean/b:property[@name='propAsRefId']/@ref") .bindNamespace("b", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "example", testValue); }
@Test public void testFileIgnoresWar() throws Exception { logger.info("testFileIgnoresWar()"); ResourceLoader loader = new ResourceLoader(war); in = loader.getResourceAsStream("file:src/test/resources/contexts/propContext.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/b:beans/b:bean/b:property[@name='propAsRefId']/@ref") .bindNamespace("b", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "example", testValue); }
@Test public void testWarInternalAbsolutePathNoBasedir() throws Exception { logger.info("testWarInternalAbsolutePathNoBasedir()"); ResourceLoader loader = new ResourceLoader(war); in = loader.getResourceAsStream("/WEB-INF/web.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/web:web-app/web:servlet/web:servlet-name") .bindNamespace("web", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "Dispatcher", testValue); }
@Test public void testWarInternalRelativePathNoBasedir() throws Exception { logger.info("testWarInternalRelativePathNoBasedir()"); ResourceLoader loader = new ResourceLoader(war); in = loader.getResourceAsStream("WEB-INF/web.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/web:web-app/web:servlet/web:servlet-name") .bindNamespace("web", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "Dispatcher", testValue); }
@Test public void testWarInternalRelativePathWithBasedir() throws Exception { logger.info("testWarInternalRelativePathWithBasedir()"); ResourceLoader loader = new ResourceLoader(war, "/WEB-INF"); in = loader.getResourceAsStream("web.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/web:web-app/web:servlet/web:servlet-name") .bindNamespace("web", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "Dispatcher", testValue); }
@Test public void testWarInternalAbsolutePathWithBasedir() throws Exception { logger.info("testWarInternalAbsolutePathWithBasedir()"); ResourceLoader loader = new ResourceLoader(war, "/WEB-INF"); in = loader.getResourceAsStream("/web.xml"); assertNotNull("returned resource", in); Document dom = ParseUtil.parse(new InputSource(in)); String testValue = new XPathWrapper("/web:web-app/web:servlet/web:servlet-name") .bindNamespace("web", "http: .evaluateAsString(dom); assertEquals("fingerprint on loaded resource", "Dispatcher", testValue); }