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:de.decoit.simu.cbor.xml.dictionary.DictionaryTest.java

@Test
public void testFindAttributeByPath() throws Exception {
    Path input = Paths.get(ClassLoader.getSystemResource("namespace-with-complex-elements.dict").toURI());

    Dictionary instance = new Dictionary();
    instance.extendDictionary(input);/*ww w.  j  a  v a 2 s.c o m*/

    String dictPath = "<http://www.trustedcomputinggroup.org/2010/IFMAP/2>access-request@name";

    DictionarySimpleAttribute result = instance.findAttributeByPath(dictPath);

    assertNotNull(result);
}

From source file:org.jboss.pressgang.ccms.contentspec.client.commands.StatusCommandTest.java

@Test
public void shouldShutdownWhenLocalHasBeenModified() throws URISyntaxException, IOException {
    URL specFileUrl = ClassLoader.getSystemResource("StatusCommand-post.contentspec");
    File specFile = new File(specFileUrl.toURI());
    String specFilePath = specFile.getParentFile().getAbsolutePath() + File.separator;
    // Given a valid csprocessor.cfg
    given(cspConfig.getContentSpecId()).willReturn(id);
    // and a valid id
    given(contentSpecProvider.getContentSpec(anyInt(), anyInt())).willReturn(contentSpecWrapper);
    given(contentSpecProvider.getContentSpecAsString(anyInt(), anyInt()))
            .willReturn("CHECKSUM=" + randomNumber + "\n");
    // and the file it should find is inn the resources folder
    given(contentSpecWrapper.getTitle()).willReturn("");
    // Note: this is a bypass since the command works on the current directory, however the actual file might be in a different
    // location for tests.
    PowerMockito.mockStatic(DocBookUtilities.class);
    when(DocBookUtilities.escapeTitle(anyString())).thenReturn(specFilePath + "StatusCommand");
    // and that file should contain the server checksum
    PowerMockito.mockStatic(FileUtils.class);
    when(FileUtils.readFileToString(any(File.class)))
            .thenReturn("CHECKSUM=" + randomNumber + "\nTitle = Test Content " + "Specification\n");

    // When processing the command
    try {/*from w  ww.ja  va 2s .  c  o  m*/
        command.process();
        // Then an error is printed and the program is shut down
        fail(SYSTEM_EXIT_ERROR);
    } catch (CheckExitCalled e) {
        assertThat(e.getStatus(), is(9));
    }

    // Then make sure an error message is printed and the command shutdown
    assertThat(getStdOutLogs(), containsString(
            "The local copy of the Content Specification has been updated and is out of sync with the server. Please use "
                    + "\"csprocessor push\" to update the server copy."));
}

From source file:llc.rockford.webcast.EC2Driver.java

private void createAndShowGUI() {
    // Set the look and feel.
    initLookAndFeel();/*  w w  w  .  j  a v a2  s  .  co  m*/

    // Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    // Create and set up the window.
    JFrame frame = new JFrame("Webcast Utility");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(300, 400));
    java.net.URL url = ClassLoader.getSystemResource("llc/rockford/webcast/resources/internet.png");
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image img = kit.createImage(url);
    frame.setIconImage(img);
    Component contents = createComponents();
    frame.getContentPane().add(contents, BorderLayout.CENTER);

    // Display the window.
    frame.pack();
    frame.setVisible(true);

}

From source file:org.apache.tajo.QueryTestCaseBase.java

@BeforeClass
public static void setUpClass() throws Exception {
    client = testBase.getTestingCluster().newTajoClient();

    URL datasetBaseURL = ClassLoader.getSystemResource("dataset");
    Preconditions.checkNotNull(datasetBaseURL, "dataset directory is absent.");
    datasetBasePath = new Path(datasetBaseURL.toString());
    URL queryBaseURL = ClassLoader.getSystemResource("queries");
    Preconditions.checkNotNull(queryBaseURL, "queries directory is absent.");
    queryBasePath = new Path(queryBaseURL.toString());
    URL resultBaseURL = ClassLoader.getSystemResource("results");
    Preconditions.checkNotNull(resultBaseURL, "results directory is absent.");
    resultBasePath = new Path(resultBaseURL.toString());
}

From source file:net.team2xh.crt.gui.util.GUIToolkit.java

/**
 * Provides a Image from a file name./* ww w .ja  v a  2s .c o  m*/
 *
 * @param path Picture file name
 * @return     Image
 */
public static Image getImage(String path) {
    Image img = null;
    try {
        img = ImageIO.read(ClassLoader.getSystemResource(path));
    } catch (IOException ex) {
        Logger.getLogger(GUIToolkit.class.getName()).log(Level.SEVERE, null, ex);
    }
    return img;
}

From source file:org.richie.codeGen.ui.configui.ConstantConfigWin.java

private JPanel getButtonPanel() {
    if (buttonPanel == null) {
        buttonPanel = new JPanel();
        addLineBtn = new JButton("??");
        addLineBtn.setIcon(new ImageIcon(ClassLoader.getSystemResource("resources/images/add.gif")));
        addLineBtn.addActionListener(this);
        buttonPanel.add(addLineBtn);/*from   w ww  . j a v  a2  s.  c om*/
        saveBtn = new JButton("?");
        saveBtn.setIcon(new ImageIcon(ClassLoader.getSystemResource("resources/images/save.png")));
        saveBtn.addActionListener(this);
        buttonPanel.add(saveBtn);
    }
    return buttonPanel;
}

From source file:de.decoit.simu.cbor.xml.dictionary.DictionaryTest.java

@Test
public void testFindAttributeByPath_NotExistentNamespace() throws Exception {
    Path input = Paths.get(ClassLoader.getSystemResource("namespace-with-complex-elements.dict").toURI());

    Dictionary instance = new Dictionary();
    instance.extendDictionary(input);/*from ww  w .  j  a va 2  s.c om*/

    String dictPath = "<this-is-my-namespace>access-request@name";

    DictionarySimpleAttribute result = instance.findAttributeByPath(dictPath);

    assertNull(result);
}

From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java

@Test
public void recursiveEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
    MailboxMessage recursiveMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/recursiveMail.eml"))),
            new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
            propertyBuilder, MAILBOX_ID);
    recursiveMail.setModSeq(MOD_SEQ);/*from w  ww . j  a va  2 s  . co m*/
    recursiveMail.setUid(UID);
    assertThatJson(messageToElasticSearchJson.convertToJson(recursiveMail,
            ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER)
                    .when(IGNORING_VALUES)
                    .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMail.json")));
}

From source file:org.usapi.PropertyHelper.java

/**
 * Load a properties file from the classpath and make its properties
 * available in the environment, unless overridden by -D arg to JVM
 */// w w  w. j  ava 2  s  .  com
private static void loadTestProperties() {
    //Properties sysProps = System.getProperties();
    Properties testProps = new Properties();

    // load defaults
    testProps.put(SERVER_HOST, "");
    testProps.put(SERVER_PORT, "");
    testProps.put(CHROMEDRIVER_HOST, "127.0.0.1");
    testProps.put(CHROMEDRIVER_PORT, "9515");
    testProps.put(CHROMEDRIVER_EXECUTABLE, getChromeDriverFilename());
    testProps.put(BROWSER_CMD, "*firefox");
    testProps.put(BROWSER_URL, "http://localhost");
    testProps.put(EXECUTION_SPEED, "0");
    testProps.put(FAILURECAPTURE_DIR, failureCaptureDir);
    testProps.put(ENABLE_JAVASCRIPT, "true");
    testProps.put(ENABLE_NATIVE_EVENTS, "false"); // if we leave native events on, FF on Windoze can start acting up
    testProps.put(JQUERY_WAIT_FOR_AJAX, "false");

    String properties = System.getProperty(SELENIUM_PROPERTIES);
    properties = properties == null ? SELENIUM_PROPERTIES : properties;
    log.info("Using properties file " + properties);

    URL url = ClassLoader.getSystemResource(properties);
    try {
        testProps.load(url.openStream());
    } catch (Exception e) {
        log.info("Unable to load default properties file from classpath: " + properties);
    }

    Enumeration keys = testProps.keys();
    String key, value = null;
    while (keys.hasMoreElements()) {
        key = (String) keys.nextElement();
        value = testProps.getProperty(key);
        // property might already be set at invocation/from the cmd line
        // so we do not want to override it here
        // values loaded at this point should be override-able from the
        // cmd line
        String existingProp = System.getProperty(key);
        log.info("Using system property " + key + ", value: " + (existingProp == null ? value : existingProp));
        if (existingProp == null) {
            System.setProperty(key, value);
        }
    }
}

From source file:Proiect.uploadFTP.java

/**
 * Save State//from  w  w  w .j  ava  2 s  .  c om
 */
public void saveState() {
    try {
        String index1 = adressf.getText();
        String index2 = userf.getText();
        String index3 = String.valueOf(passf.getPassword());
        FileOutputStream fileStream = new FileOutputStream(
                ClassLoader.getSystemResource("upload.prop").getPath());
        ObjectOutputStream os = new ObjectOutputStream(fileStream);
        os.writeObject(index1);
        os.writeObject(index2);
        os.writeObject(index3);
        os.close();
        fileStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}