List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:com.github.sardine.AuthenticationTest.java
@Before public void properties() throws Exception { thrown.expect(NullPointerException.class); properties = new Properties(); properties.load(ClassLoader.getSystemResourceAsStream(TEST_PROPERTIES_FILENAME)); }
From source file:org.apache.camel.component.schematron.SchematronComponentTest.java
/** * @throws Exception/*from w w w . j a va 2s. c o m*/ */ @Test public void testSendBodyAsInputStreamInvalidXML() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMinimumMessageCount(1); String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); template.sendBody("direct:start", payload); assertMockEndpointsSatisfied(); String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT, String.class); // should throw two assertions because of the missing chapters in the XML. assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert[1]/svrl:text", result)); assertEquals("A chapter should have a title", Utils.evaluate("//svrl:failed-assert[2]/svrl:text", result)); }
From source file:gridool.Settings.java
private static void importExternalFiles(final Properties props, final String userDir) { final String externals = props.getProperty("prop.external"); if (externals == null) { return;/*from ww w . j ava 2 s . c o m*/ } String[] filePaths = externals.split(";"); for (String fp : filePaths) { fp = fp.trim(); if (fp.length() == 0) { continue; } final InputStream is = ClassLoader.getSystemResourceAsStream(fp); if (is != null) { try { props.load(is); LOG.info("Loaded an external property file in the classpath: " + fp); } catch (IOException e) { LOG.warn("An error caused while loading a property file: " + fp); } String fileName = FileUtils.basename(fp, '/'); File propFile = new File(userDir, fileName); if (propFile.exists()) { try { props.load(new FileInputStream(propFile)); LOG.info("Loaded an external property file in the user dir: " + fp); } catch (IOException e) { LOG.warn("An error caused while loading a property file: " + propFile.getAbsolutePath()); } } } } }
From source file:org.pentaho.di.job.entries.pig.JobEntryPigScriptExecutorTest.java
@Before public void setup() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream( "resources/org/pentaho/di/job/entries/pig/JobEntryPigScriptExecutorTest.ref"))); m_reference = readResource(br);/*from w ww .j a va2s . c o m*/ }
From source file:org.apache.hadoop.gateway.services.topology.DefaultTopologyServiceTest.java
private File createFile(File parent, String name, String resource, long timestamp) throws IOException { File file = new File(parent, name); if (!file.exists()) { FileUtils.touch(file);/*from w w w . j a v a2s .c o m*/ } InputStream input = ClassLoader.getSystemResourceAsStream(resource); OutputStream output = FileUtils.openOutputStream(file); IOUtils.copy(input, output); //KNOX-685: output.flush(); input.close(); output.close(); file.setLastModified(timestamp); assertTrue("Failed to create test file " + file.getAbsolutePath(), file.exists()); assertTrue("Failed to populate test file " + file.getAbsolutePath(), file.length() > 0); return file; }
From source file:net.ontopia.topicmaps.viz.AboutFrame.java
private Icon getAboutImage() { ByteArrayOutputStream output = new ByteArrayOutputStream(); InputStream input = ClassLoader.getSystemResourceAsStream("net/ontopia/topicmaps/viz/logo.gif"); if (input == null) return null; try {//from www.j a va2 s . c o m IOUtils.copy(input, output); } catch (IOException e) { e.printStackTrace(); return null; } return new ImageIcon(output.toByteArray()); }
From source file:org.openengsb.openengsbplugin.tools.ToolsTest.java
@Test public void testXPath() throws Exception { Document doc = Tools.parseXMLFromString( IOUtils.toString(ClassLoader.getSystemResourceAsStream(LICENSECHECK_CONFIG_PATH))); Node n = Tools.evaluateXPath("//c:config", doc, NS_CONTEXT, XPathConstants.NODE, Node.class); assertEquals("config", n.getLocalName()); }
From source file:edu.hawaii.soest.pacioos.text.SimpleTextSourceTest.java
/** * Start a mock DataTurbine and a MockDataSource, both of which will be connected to * by the SocketTextSource class being tested. * @throws java.lang.Exception/*from w w w.ja va 2 s . c om*/ */ @Before public void setUp() throws Exception { // get the resources directory InputStream propsStream = ClassLoader.getSystemResourceAsStream("test.properties"); Properties properties = new Properties(); try { properties.load(propsStream); testResourcesDirectory = properties.getProperty("test.resources.directory"); } catch (IOException e) { e.printStackTrace(); } // start up a mock DataTurbine instance FileUtils.deleteDirectory(new File("/tmp/dt")); FileUtils.forceMkdir(new File("/tmp/dt")); String[] options = new String[] { "-a", "127.0.0.1:33333", "-H", "/tmp/dt" }; mockDT = Server.launchNewServer(options); log.info("Dataturbine is running on " + mockDT.getAddress()); Thread.sleep(2000); }
From source file:org.wte4j.impl.word.Docx4JWordTemplateTest.java
@Test public void findContentControlsTest() throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream("org/wte4j/impl/word/ContentControls.docx"); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(in); in.close();//from w w w. j a va 2 s. com List<SdtElement> elements = Docx4JWordTemplate.findContentControls(wordMLPackage.getMainDocumentPart()); assertEquals(9, elements.size()); }
From source file:com.pinterest.pinlater.backends.mysql.PinLaterMySQLBackendTest.java
@BeforeClass public static void beforeClass() throws Exception { QUEUE_NAME = "pinlater_mysql_backend_test"; // If there is no local MySQL, skip this test. boolean isLocalMySQLRunning = LocalMySQLChecker.isRunning(); Assume.assumeTrue(isLocalMySQLRunning); PropertiesConfiguration configuration = new PropertiesConfiguration(); try {/*from www . j a v a2s . c om*/ configuration.load(ClassLoader.getSystemResourceAsStream("pinlater.test.properties")); } catch (ConfigurationException e) { throw new RuntimeException(e); } System.setProperty("backend_config", "mysql.local.json"); backend = new PinLaterMySQLBackend(configuration, "localhost", System.currentTimeMillis()); }