List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.underworldlabs.util.FileUtils.java
public static Properties loadPropertiesResource(String path) throws IOException { InputStream input = null;/*w w w. j ava 2 s . c o m*/ try { ClassLoader cl = FileUtils.class.getClassLoader(); if (cl != null) { input = cl.getResourceAsStream(path); } else { input = ClassLoader.getSystemResourceAsStream(path); } Properties properties = new Properties(); properties.load(input); return properties; } finally { if (input != null) { input.close(); } } }
From source file:org.apache.tika.server.UnpackerResourceTest.java
@Test public void test415() throws Exception { Response response = WebClient.create(endPoint + UNPACKER_PATH).type("xxx/xxx").accept("*/*") .put(ClassLoader.getSystemResourceAsStream(TEST_DOC_WAV)); assertEquals(415, response.getStatus()); }
From source file:org.apache.james.mailets.crypto.SMIMEDecryptIntegrationTest.java
@Test public void cryptedMessageWithAttachmentShouldBeDecryptedWhenCertificateMatches() throws Exception { try (SMTPMessageSender messageSender = SMTPMessageSender.authentication(LOCALHOST_IP, SMTP_SECURE_PORT, DEFAULT_DOMAIN, FROM, PASSWORD); IMAPMessageReader imapMessageReader = new IMAPMessageReader(LOCALHOST_IP, IMAP_PORT)) { messageSender.sendMessageWithHeaders(FROM, FROM, IOUtils.toString(ClassLoader.getSystemResourceAsStream("eml/crypted_with_attachment.eml"))); calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent); calmlyAwait.atMost(Duration.ONE_MINUTE) .until(() -> imapMessageReader.userReceivedMessage(FROM, PASSWORD)); assertThat(imapMessageReader.readFirstMessageInInbox(FROM, PASSWORD)) .containsSequence("Crypted Content with attachment"); }/*w w w .j a v a 2s . c o m*/ }
From source file:org.phenotips.vocabulary.internal.GeneNomenclatureTest.java
@Test public void getTermFetchesFromRemoteServer() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException { URI expectedURI = new URI("http://rest.genenames.org/fetch/symbol/BRCA1"); CapturingMatcher<HttpUriRequest> reqCapture = new CapturingMatcher<>(); when(this.client.execute(Matchers.argThat(reqCapture))).thenReturn(this.response); when(this.response.getEntity()).thenReturn(this.responseEntity); when(this.responseEntity.getContent()).thenReturn(ClassLoader.getSystemResourceAsStream("BRCA1.json")); VocabularyTerm result = this.mocker.getComponentUnderTest().getTerm("BRCA1"); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertNotNull(result);/*from w ww . j a va 2s . c om*/ Assert.assertEquals("BRCA1", result.get("symbol")); Assert.assertEquals("breast cancer 1, early onset", result.getName()); JSONArray aliases = (JSONArray) result.get("alias_symbol"); Assert.assertArrayEquals(new String[] { "RNF53", "BRCC1", "PPP1R53" }, aliases.toArray()); verify(this.cache).set("BRCA1", result); }
From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java
@Test public void excelTest() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/calc.xlsx"); assertThat(inputStream).isNotNull(); assertThat(textExtractor// ww w. j av a 2 s . c o m .extractContent(inputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") .getTextualContent()) .contains("Feuille1\n" + "\tThis is an aesome LibreOffice document!\n" + "\n" + "&A\t\n" + "\n" + "Page &P\t\n" + "\n" + "\n"); }
From source file:org.phenotips.ontology.internal.GeneNomenclatureTest.java
@Test public void getTermFetchesFromRemoteServer() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException { URI expectedURI = new URI("http://rest.genenames.org/fetch/symbol/BRCA1"); CapturingMatcher<HttpUriRequest> reqCapture = new CapturingMatcher<>(); when(this.client.execute(Matchers.argThat(reqCapture))).thenReturn(this.response); when(this.response.getEntity()).thenReturn(this.responseEntity); when(this.responseEntity.getContent()).thenReturn(ClassLoader.getSystemResourceAsStream("BRCA1.json")); OntologyTerm result = this.mocker.getComponentUnderTest().getTerm("BRCA1"); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertNotNull(result);/*from w ww.j av a2 s.com*/ Assert.assertEquals("BRCA1", result.get("symbol")); Assert.assertEquals("breast cancer 1, early onset", result.getName()); JSONArray aliases = (JSONArray) result.get("alias_symbol"); Assert.assertArrayEquals(new String[] { "RNF53", "BRCC1", "PPP1R53" }, aliases.toArray()); verify(this.cache).set("BRCA1", result); }
From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java
@Bean Queue queue_emsRegistrator() {/* ww w . j av a 2 s. co m*/ Properties properties = new Properties(); try { properties.load(ClassLoader.getSystemResourceAsStream("conf.properties")); } catch (IOException e) { e.printStackTrace(); } queueName_emsRegistrator = "ems." + properties.getProperty("type") + ".register"; return new Queue(queueName_emsRegistrator, durable, exclusive, autodelete); }
From source file:org.phenotips.vocabulary.internal.RemoteGeneNomenclatureTest.java
@Test public void getTermFetchesFromRemoteServer() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException { URI expectedURI = new URI("http://rest.genenames.org/fetch/symbol/BRCA1"); CapturingMatcher<HttpUriRequest> reqCapture = new CapturingMatcher<>(); when(this.client.execute(Matchers.argThat(reqCapture))).thenReturn(this.response); when(this.response.getEntity()).thenReturn(this.responseEntity); when(this.responseEntity.getContent()).thenReturn(ClassLoader.getSystemResourceAsStream("BRCA1.json")); VocabularyTerm result = this.mocker.getComponentUnderTest().getTerm("BRCA1"); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertNotNull(result);//from w w w. j ava 2 s . c o m Assert.assertEquals("BRCA1", result.get("symbol")); Assert.assertEquals("breast cancer 1, early onset", result.getName()); JSONArray aliases = (JSONArray) result.get("alias_symbol"); String[] expected = new String[] { "RNF53", "BRCC1", "PPP1R53" }; Assert.assertEquals(expected.length, aliases.length()); for (int i = 0; i < expected.length; ++i) { Assert.assertEquals(expected[i], aliases.get(i)); } verify(this.cache).set("BRCA1", result); }
From source file:org.openmrs.module.hl7query.MockBaseTest.java
public void setupStandardTemplates() throws Exception { Map<String, String> templateNamesToPaths = new HashMap<String, String>(); templateNamesToPaths.put("Generic PV1", "templates/PV1.xml"); templateNamesToPaths.put("Generic OBX", "templates/obx_orur01.xml"); templateNamesToPaths.put("Generic ORUR01", "templates/complete_orur01.xml"); templateNamesToPaths.put("Generic PID", "templates/PID.xml"); templateNamesToPaths.put("Generic Patient", "templates/patient_orur01.xml"); templateNamesToPaths.put("Default Patient Identifier", "templates/DefaultPatientIdentifier.xml"); templateNamesToPaths.put("Default Patient Name", "templates/DefaultPatientNameTemplate.xml"); templateNamesToPaths.put("MSH", "templates/MSH.xml"); templateNamesToPaths.put("Generic Obs Group", "templates/OBR-OBS-GROUP.xml"); templateNamesToPaths.put("Generic Obs Group Header", "templates/OBR-OBS-GROUP-HEADER.xml"); for (Entry<String, String> templateNameToPath : templateNamesToPaths.entrySet()) { InputStream resource = ClassLoader.getSystemResourceAsStream(templateNameToPath.getValue()); HL7Template template = new HL7Template(); template.setName(templateNameToPath.getKey()); template.setTemplate(IOUtils.toString(resource)); Mockito.when(hl7QueryDAOMock.getHL7TemplateByName(templateNameToPath.getKey())).thenReturn(template); }/*from w w w.j a va 2s .c o m*/ }
From source file:org.jboss.arquillian.ajocado.framework.AjaxSeleniumImpl.java
/** * Loads the list of resource names from the given resource. * /* w ww. jav a2s . c om*/ * @param resourceName * the path to resource on classpath * @return the list of resource names from the given resource. */ @SuppressWarnings("unchecked") protected static List<String> getExtensionsListFromResource(String resourceName) { try { return IOUtils.readLines(ClassLoader.getSystemResourceAsStream(resourceName)); } catch (IOException e) { throw new IllegalStateException(e); } }