List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.loadsimulator.jmetertest.jmetertest.JmeterTestPlanTask.java
public void run() { if (jmeterEngine != null) { Object[] threadGroups = amsTestPlanTree.getArray(amsTestPlan); for (Object threadGroupObj : threadGroups) { if (threadGroupObj instanceof ThreadGroup) { ThreadGroup threadGroup = (ThreadGroup) threadGroupObj; threadGroup.stop();//from ww w . j a v a 2 s . co m } } amsTestPlanTree.clear(); jmeterEngine.askThreadsToStop(); jmeterEngine.stopTest(); JMeterContextService.endTest(); } //Start the new test plan for the new app. try { //Initialize Jmeter essentials jmeterEngine = new StandardJMeterEngine(); JMeterContextService.getContext().setEngine(jmeterEngine); //Workaround to supply JMeterUtils with jmeter.prooperties from JAR. JMeterUtils.setJMeterHome(""); Field f = new JMeterUtils().getClass().getDeclaredField("appProperties"); f.setAccessible(true); f.set(null, AMSJMeterLoadTest.readProperties(JMETER_PROPERTIES_FILE)); //Copy saveservices.properties file to tmp dir for JMeter to consume. InputStream inputStream = ClassLoader.getSystemResourceAsStream(SAVESERVICE_PROPERTIES_FILE); if (inputStream == null) { inputStream = new FileInputStream(SAVESERVICE_PROPERTIES_FILE); } String tmpDir = System.getProperty("java.io.tmpdir"); OutputStream outputStream = new FileOutputStream(tmpDir + "/saveservice.properties"); IOUtils.copy(inputStream, outputStream); outputStream.close(); JMeterUtils.setProperty("saveservice_properties", tmpDir + "/saveservice.properties"); //Initialize Test plan amsTestPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName()); amsTestPlanTree.add("AMS Test plan", amsTestPlan); //Choose a random APP to run the perform GET metrics request. int currentAppIndex = new Random().nextInt(appGetMetrics.size()); //Create ThreadGroup for the App createThreadGroupHashTree(currentAppIndex, amsJmeterProperties, amsTestPlanTree, amsTestPlan); //Geneates the JMX file that you can use through the GUI mode. //SaveService.saveTree(amsTestPlanTree, new FileOutputStream(JMETER_HOME + "/" + "amsTestPlan.jmx")); //Summarizer output to get test progress in stdout like. Summariser summariser = null; String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary"); if (summariserName.length() > 0) { summariser = new Summariser(summariserName); } //Store execution results into a .jtl file String jmeterLogFile = tmpDir + "/amsJmeterTestResults.jtl"; ResultCollector resultCollector = new ResultCollector(summariser); resultCollector.setFilename(jmeterLogFile); amsTestPlanTree.add(amsTestPlanTree.getArray()[0], resultCollector); jmeterEngine.configure(amsTestPlanTree); jmeterEngine.run(); LOG.info("AMS Jmeter Test started up successfully"); } catch (Exception ioEx) { amsTestPlanTree.clear(); jmeterEngine.askThreadsToStop(); jmeterEngine.stopTest(); JMeterContextService.endTest(); LOG.error("Error occurred while running AMS load test : " + ioEx.getMessage()); ioEx.printStackTrace(); } }
From source file:org.apache.james.http.jetty.JettyHttpServerFactoryTest.java
@Test public void shouldThrowOnUnavailableFilterName() throws Exception { HierarchicalConfiguration configuration = loadConfiguration( ClassLoader.getSystemResourceAsStream("unavailablefiltername.xml")); assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)) .isInstanceOf(ConfigurationException.class); }
From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.parser.PrivateEc2TemplateParserTest.java
@Test public void testTemplateComplete() throws IOException, PrivateEc2ParserException { InputStream templateStream = ClassLoader.getSystemResourceAsStream("./cfn_templates/complete.template"); ToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE); PrivateEc2Template template = ParserUtils.mapJson(PrivateEc2Template.class, templateStream); assertNotNull(template);//from w w w . j a va2 s. c o m }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setUid(UID);/*from w ww . ja v a 2 s . c om*/ spamMail.setModSeq(MOD_SEQ); assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/spamMail.json"), CHARSET)); }
From source file:at.ac.tuwien.dsg.comot.m.common.Utils.java
public static InputStream loadFileFromClassPath(String path) throws IOException { return ClassLoader.getSystemResourceAsStream(path); }
From source file:org.mule.modules.applepush.ApplePushCloudConnector.java
private InputStream getKeyStoreAsStream() { final InputStream keyStore = ClassLoader.getSystemResourceAsStream(keystore); if (keyStore != null) { return keyStore; }/*from www .j a va 2 s .c o m*/ try { return IOUtils.getResourceAsStream(keystore, getClass(), true, false); } catch (final IOException ioe) { throw new MuleRuntimeException(MessageFactory.createStaticMessage( "Failure when trying to get keystore as stream from path: " + keystore), ioe); } }
From source file:com.jhash.oimadmin.Utils.java
public static String readFile(String fileName, String workArea) { logger.trace("readFile({},{})", fileName, workArea); InputStream templateStream = null; File workAreaDirectory;//from www . jav a 2s .c o m logger.trace("Trying to validate whether workarea {} exists and is a directory", workArea); if (workArea != null && (workAreaDirectory = new File(workArea)) != null && workAreaDirectory.exists() && workAreaDirectory.isDirectory()) { File templateFile = new File(workAreaDirectory + File.separator + fileName); logger.trace("Trying to validate if file {} exists", templateFile); if (templateFile.exists() && templateFile.canRead()) { try { logger.trace("Trying to setup {} for reading", templateFile); templateStream = new FileInputStream(templateFile); logger.trace("File can be read using {}", templateStream); } catch (IOException exception) { throw new OIMAdminException("Could not read " + templateFile.getAbsolutePath(), exception); } } } if (templateStream == null) { logger.trace("Trying to setup {} for reading from system classpath ", fileName); templateStream = ClassLoader.getSystemResourceAsStream(fileName); } byte[] readData = new byte[1000]; StringBuilder templateString = new StringBuilder(); try { int readDataSize; while ((readDataSize = templateStream.read(readData)) > 0) { templateString.append(new String(readData, 0, readDataSize, "UTF-8")); } } catch (IOException e1) { throw new OIMAdminException("Failed to read templates/EventHandlerConditional", e1); } return templateString.toString(); }
From source file:org.phenotips.vocabulary.internal.GeneNomenclatureTest.java
@Test public void checkURLConfigurable() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException, InitializationException { when(this.configuration.getProperty("phenotips.ontologies.hgnc.serviceURL", "http://rest.genenames.org/")) .thenReturn("https://proxy/genenames/"); URI expectedURI = new URI("https://proxy/genenames/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")); // Since the component was already initialized in setUp() with the default URL, re-initialize it // with the new configuration mock ((Initializable) this.mocker.getComponentUnderTest()).initialize(); 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);/* w w w.java 2 s . 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.phenotips.vocabulary.internal.RemoteGeneNomenclatureTest.java
@Test public void checkURLConfigurable() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException, InitializationException { when(this.configuration.getProperty("phenotips.ontologies.hgnc.serviceURL", "http://rest.genenames.org/")) .thenReturn("https://proxy/genenames/"); URI expectedURI = new URI("https://proxy/genenames/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")); // Since the component was already initialized in setUp() with the default URL, re-initialize it // with the new configuration mock ((Initializable) this.mocker.getComponentUnderTest()).initialize(); 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);//w w w.j ava 2s . co 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.apache.tika.server.TikaResourceTest.java
@Test public void testPasswordXLS() throws Exception { Response response = WebClient.create(endPoint + TIKA_PATH).type("application/vnd.ms-excel") .accept("text/plain").put(ClassLoader.getSystemResourceAsStream("password.xls")); assertEquals(UNPROCESSEABLE, response.getStatus()); }