DefaultSpringWadlResourceDocument implements IWadlDocumentResource { @Override public InputStream getResourceAsStream() throws IOException { Enumeration<URL> urls; urls = springResource.getClassLoader().getResources( WADL_NAME ); InputStream is = null; URL url = null; String systemPath = getSystemPath(); while ( urls.hasMoreElements() ) { url = urls.nextElement(); if ( !isPlugin ) { break; } else { String urlString = url.getPath(); if ( urlString.contains( systemPath + "/" + pluginId ) ) { break; } } } if ( url != null ) { try { is = getInputStream( url ); } catch ( IOException e ) { e.printStackTrace(); } } return is; } DefaultSpringWadlResourceDocument( Resource resource ); @Override InputStream getResourceAsStream(); @Override boolean isFromPlugin(); @Override String getPluginId();  }
@Test public void testGetResourceAsStream() throws Exception { URL urlReporting = new URL( "file:system/reporting/wadlExtension.xml" ), urlMyPlugin = new URL( "file:system/myplugin/wadlExtension.xml" ); Set<URL> urls = new HashSet<URL>(); urls.add( urlReporting ); urls.add( urlMyPlugin ); Enumeration<URL> urlsEnumeration = java.util.Collections.enumeration( urls ); doReturn( urlsEnumeration ).when( pluginClassLoader ).getResources( WADL_NAME ); doReturn( "system" ).when( wadlResourceDocumentPluginSpy ).getSystemPath(); doReturn( mock( InputStream.class ) ).when( wadlResourceDocumentPluginSpy ).getInputStream( urlReporting ); assertNotNull( wadlResourceDocumentPluginSpy.getResourceAsStream() ); urlsEnumeration = java.util.Collections.enumeration( urls ); doReturn( urlsEnumeration ).when( webAppClassLoader ).getResources( WADL_NAME ); doReturn( "system" ).when( wadlResourceDocumentWebappSpy ).getSystemPath(); doReturn( mock( InputStream.class ) ).when( wadlResourceDocumentWebappSpy ).getInputStream( urlReporting ); doReturn( mock( InputStream.class ) ).when( wadlResourceDocumentWebappSpy ).getInputStream( urlMyPlugin ); assertNotNull( wadlResourceDocumentWebappSpy.getResourceAsStream() ); urls = new HashSet<URL>(); urls.add( urlMyPlugin ); urlsEnumeration = java.util.Collections.enumeration( urls ); doReturn( urlsEnumeration ).when( pluginClassLoader ).getResources( WADL_NAME ); assertNull( wadlResourceDocumentPluginSpy.getResourceAsStream() ); }