Example usage for java.lang ClassLoader getSystemResource

List of usage examples for java.lang ClassLoader getSystemResource

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResource.

Prototype

public static URL getSystemResource(String name) 

Source Link

Document

Find a resource of the specified name from the search path used to load classes.

Usage

From source file:org.openmrs.module.metadatasharing.util.VersionConverterTest.java

/**
 * @see {@link VersionConverter#convertOutgoingMessage(String,String)}
 *///w w w .j av  a2  s  .co m
@Test
@Verifies(value = "should convert a message down to one dot six", method = "convert(String,String,String)")
public void convert_shouldConvertAMessageDownToOneDotSix() throws Exception {
    String filePath = ClassLoader.getSystemResource("VersionConverterTest-metadata-to-16.xml").getPath();
    String xml = FileUtils.readFileToString(new File(filePath), "UTF-8");
    Assert.assertTrue(xml.indexOf("conceptNameType") > 0);
    Assert.assertTrue(xml.indexOf("localePreferred") > 0);
    Assert.assertTrue(xml.indexOf("FULLY_SPECIFIED") > 0);
    Assert.assertTrue(xml.indexOf("SHORT") > 0);
    Assert.assertTrue(xml.indexOf("preferred name in a language") < 0);

    String output = new VersionConverter().convert(xml, "", "1.6.3");

    Assert.assertTrue(output.indexOf("conceptNameType") < 0);
    Assert.assertTrue(output.indexOf("localePreferred") < 0);
    Assert.assertTrue(output.indexOf("FULLY_SPECIFIED") < 0);
    Assert.assertTrue(output.indexOf("SHORT") < 0);
    Assert.assertTrue(output.indexOf("preferred name in a language") > 0);
}

From source file:org.gwtwidgets.server.spring.test.BaseTest.java

protected String readResource(String resource) throws Exception {
    URL url = getClass().getClassLoader().getResource(resource);
    if (url == null)
        url = ClassLoader.getSystemResource(resource);
    if (url == null)
        url = ClassLoader.getSystemClassLoader().getResource(resource);
    URLConnection conn = url.openConnection();
    byte[] b = new byte[conn.getContentLength()];
    InputStream in = conn.getInputStream();
    in.read(b);/*  w w w .  j  a  v  a2  s . co  m*/
    in.close();
    return new String(b, "UTF-8");
}

From source file:org.qualipso.funkyfactory.test.clock.functionnal.ClockServiceFunctionalTest.java

/**
 * Set up service for all tests./*  w w w. j av  a2  s  .c om*/
 */
@BeforeClass
public static void before() throws NamingException {
    Properties properties = new Properties();
    properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
    properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
    properties.put("java.naming.provider.url", "localhost:1099");
    System.setProperty("java.security.auth.login.config",
            ClassLoader.getSystemResource("jaas.config").getPath());
    context = new InitialContext(properties);
}

From source file:ResourcesUtils.java

/**
 * Returns the URL of the resource on the classpath
 * /* w w  w  . j a  v  a  2  s  . c  om*/
 * @param loader
 *            The classloader used to load the resource
 * @param resource
 *            The resource to find
 * @throws IOException
 *             If the resource cannot be found or read
 * @return The resource
 */
public static URL getResourceURL(ClassLoader loader, String resource) throws IOException {
    URL url = null;
    if (loader != null) {
        url = loader.getResource(resource);
    }
    if (url == null) {
        url = ClassLoader.getSystemResource(resource);
    }
    if (url == null) {
        throw new IOException("Could not find resource " + resource);
    }
    return url;
}

From source file:ComboBox.java

public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
        JComboBox combo = (JComboBox) e.getSource();
        int index = combo.getSelectedIndex();
        display.setIcon(new ImageIcon(ClassLoader.getSystemResource(images[index])));
    }//ww  w.  j  a  v  a2s. c o  m
}

From source file:org.n52.sir.IT.TransformerBindingIT.java

@Test
public void readValidSensorMLAndValidate() throws IOException {
    File f = new File(ClassLoader.getSystemResource("AirBase-test.xml").getFile());
    BufferedReader reader = new BufferedReader(new FileReader(f));
    String s = null;//from ww  w.j av a  2 s . com
    StringBuilder builder = new StringBuilder();
    while ((s = reader.readLine()) != null)
        builder.append(s);
    String sensorML = builder.toString();
    HttpPost post = new HttpPost("http://localhost:8080/OpenSensorSearch/convert/");
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("sensor", sensorML));
    pairs.add(new BasicNameValuePair("output", "ebrim"));
    post.setEntity(new UrlEncodedFormEntity(pairs));

    HttpClient client = new DefaultHttpClient();
    HttpResponse resp = client.execute(post);
    StringBuilder result = new StringBuilder();
    reader = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
    while ((s = reader.readLine()) != null)
        result.append(s);
    //TODO yakoub : complete teh checking here

}

From source file:com.zuoxiaolong.niubi.job.service.impl.AbstractSpringContextTest.java

protected String getSampleJarFile() {
    return ClassLoader.getSystemResource("niubi-job-sample-spring.jar").getFile();
}

From source file:org.n52.sir.IT.ValidatorBindingIT.java

@Test
public void readValidSensorMLAndValidate() throws IOException {
    File f = new File(ClassLoader.getSystemResource("AirBase-test.xml").getFile());
    BufferedReader reader = new BufferedReader(new FileReader(f));
    String s = null;/*from  w w w  .  j  a  v  a  2  s. c  om*/
    StringBuilder builder = new StringBuilder();
    while ((s = reader.readLine()) != null)
        builder.append(s);
    String sensorML = builder.toString();
    HttpPost post = new HttpPost("http://localhost:8080/OpenSensorSearch/api/check/sensorML");
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("sensor", sensorML));
    pairs.add(new BasicNameValuePair("format", "json"));
    post.setEntity(new UrlEncodedFormEntity(pairs));

    HttpClient client = new DefaultHttpClient();
    HttpResponse resp = client.execute(post);
    StringBuilder result = new StringBuilder();
    reader = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
    while ((s = reader.readLine()) != null)
        result.append(s);
    StatusResponse sr = new Gson().fromJson(result.toString(), StatusResponse.class);

    assertEquals("valid", sr.status);
}

From source file:com.linuxbox.enkive.imap.EnkiveIMAPServer.java

public EnkiveIMAPServer(String configurationPath) throws ConfigurationException {

    Logger logger = new org.slf4j.impl.Log4jLoggerFactory().getLogger("com.linuxbox.enkive.imap");
    setLog(logger);/*from w ww . j a  v a2s .  c  o  m*/
    config = new XMLConfiguration(ClassLoader.getSystemResource(configurationPath));
}

From source file:com.dsf.dbxtract.cdc.AppJournalDeleteTest.java

@BeforeTest
public void setUp() throws Exception {

    configFile = ClassLoader.getSystemResource(PROPERTY_RESOURCE).getFile();

    logger.info("Testing Journal-based CDC with delete strategy");
}