Example usage for org.springframework.core.io ClassPathResource ClassPathResource

List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource ClassPathResource.

Prototype

public ClassPathResource(String path) 

Source Link

Document

Create a new ClassPathResource for ClassLoader usage.

Usage

From source file:TopicsTest.java

@Test
public void testJDBCTemplateInsertPersonne() {

    ListableBeanFactory bf;//  w w  w  .  java 2 s.co m
    bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
    ITopics m = (ITopics) bf.getBean("topicsDao");
    System.out.print("Je suis ici");
    List<Topics> u = m.findAllById(1);
    System.out.print("Je suis ici");
    for (Topics p : u) {
        System.out.println("nom=" + p.getUsername());
    }

}

From source file:org.wso2.carbon.metrics.jdbc.core.BaseReporterTest.java

@BeforeSuite
protected static void init() throws Exception {
    if (logger.isInfoEnabled()) {
        logger.info("Initializing the data source and populating data");
    }//from   w ww. j av  a  2  s.  c  o  m
    // Setup datasource
    dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");
    template = new JdbcTemplate(dataSource);
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("dbscripts/h2.sql"));
    populator.populate(dataSource.getConnection());

    // Create initial context
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
    InitialContext ic = new InitialContext();
    ic.createSubcontext("jdbc");
    ic.bind("jdbc/WSO2MetricsDB", dataSource);

    if (logger.isInfoEnabled()) {
        logger.info("Creating Metrics");
    }
    metrics = new Metrics(TestUtils.getConfigProvider("metrics.yaml"));
    metrics.activate();
    metricService = metrics.getMetricService();
    metricManagementService = metrics.getMetricManagementService();
}

From source file:dk.nsi.minlog.export.config.ApplicationRootConfig.java

@Bean
public static PropertyPlaceholderConfigurer configuration() {
    final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
    props.setLocations(new Resource[] { new ClassPathResource("default.properties"),
            new FileSystemResource(getProperty("jboss.server.config.url") + "minlog." + getProperty("user.name")
                    + ".properties"),
            new ClassPathResource("minlog." + getProperty("user.name") + ".properties"),
            new ClassPathResource("jdbc.default.properties"),
            new FileSystemResource(getProperty("jboss.server.config.url") + "jdbc." + getProperty("user.name")
                    + ".properties"),
            new ClassPathResource("jdbc." + getProperty("user.name") + ".properties"),
            new FileSystemResource(getProperty("user.home") + "/.minlog/passwords.properties") });
    props.setIgnoreResourceNotFound(true);
    props.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);

    return props;
}

From source file:edu.wisc.jmeter.dao.JdbcMonitorDaoTest.java

@Before
public void setup() throws Exception {
    this.ds = new SimpleDriverDataSource(new jdbcDriver(), "jdbc:hsqldb:mem:JdbcMonitorTest", "sa", "");
    this.jdbcTemplate = new JdbcTemplate(this.ds);
    SimpleJdbcTestUtils.executeSqlScript(new SimpleJdbcTemplate(this.jdbcTemplate),
            new ClassPathResource("/tables_hsql.sql"), false);

    this.jdbcMonitorDao = new JdbcMonitorDao(this.ds, Integer.MAX_VALUE, Integer.MAX_VALUE);
    this.jdbcMonitorDao.afterPropertiesSet();
}

From source file:de.brands4friends.daleq.integration.beans.PrepareMysqlSchema.java

@Override
public void afterPropertiesSet() throws IOException {
    final ClassPathResource script = new ClassPathResource("schema-mysql.sql");
    logger.info("Preparing Schema with file {}", script.getFile().getAbsolutePath());
    JdbcTestUtils.executeSqlScript(new JdbcTemplate(dataSource), script, false);
}

From source file:de.mediait.batch.FlatFileItemReaderTest.java

@Test
public void testFlatFileReader() throws Exception {

    final FlatFileItemReader<String[]> reader = createFlatFileReader(';', '\'');

    reader.setResource(new ClassPathResource("csv-fix-samples/fixsemicolon.txt"));

    final ExecutionContext executionContext = new ExecutionContext();
    reader.open(executionContext);//  w ww.  j  a va2 s.c o m
    final String[] object = (String[]) reader.read();
    reader.close();

    assertArrayEquals(new String[] { "begin", "abc' \"d\" 'ef", "end" }, object);
}

From source file:com.wavemaker.tools.webapp.WebXmlSupportTest.java

public void testReadWrite() throws Exception {

    File f = new ClassPathResource("com/wavemaker/tools/webapp/" + ProjectConstants.WEB_XML).getFile();
    assertTrue(f.exists());//  www .  j  av  a  2  s  . co  m

    WebAppType wat = WebXmlSupport.readWebXml(new FileSystemResource(f));

    for (Object o : wat.getDescriptionAndDisplayNameAndIcon()) {
        if (o instanceof DisplayNameType) {
            DisplayNameType dnt = (DisplayNameType) o;
            assertEquals("ActiveGrid Studio", dnt.getValue());
        } else if (o instanceof ServletType) {
            ServletType st = (ServletType) o;
            assertEquals("springapp", st.getServletName().getValue());
        } else {
            // System.out.println("o: "+o);
        }
    }

    File fp = File.createTempFile("TestWebXmlSupport_testReadWrite", ".xml");
    fp.deleteOnExit();

    try {
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(fp));
        WebXmlSupport.writeWebXml(wat, osw);
        String fpContents = FileUtils.readFileToString(fp);

        assertTrue(fpContents.contains("ActiveGrid Studio"));
        assertTrue(fpContents.contains("springapp"));

        WebXmlSupport.readWebXml(new FileSystemResource(fp));
    } finally {
        fp.delete();
    }
}

From source file:nl.flotsam.hamcrest.schema.relaxng.RelaxNGMatchersTest.java

@Test
public void shouldWorkCorrectly() {
    Resource schema = new ClassPathResource("/sample.rng");
    Resource document = new ClassPathResource("/valid-sample.xml");
    assertThat(document, RelaxNGMatchers.isValidatedBy(schema));
}

From source file:de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolverTest.java

@Test
public void test_concatenation() throws IOException {
    Resource testResource = new ClassPathResource("/testResource.txt");
    List<Resource> resources = asList(testResource, testResource, testResource);

    Resource resolvedResource = new ConcatenatingResourceResolver(";".getBytes()).resolveResource(null,
            "/foo.txt", resources, null);

    assertThat(resolvedResource.getFilename(), is("foo.txt"));
    assertThat(resolvedResource.lastModified(), is(testResource.lastModified()));
    assertThat(resolvedResource.getDescription(), is(
            "Byte array resource [(class path resource [testResource.txt], class path resource [testResource.txt], class path resource [testResource.txt])]"));
    assertThat(copyToByteArray(resolvedResource.getInputStream()), is("Foobar;Foobar;Foobar".getBytes()));
}

From source file:org.activiti.crystalball.simulator.impl.cfg.BeansConfigurationHelper.java

public static SimulationEngineConfiguration parseSimulationEngineConfigurationFromResource(String resource,
        String beanName) {/*from   w  w w.j av  a2  s . c  o m*/
    Resource springResource = new ClassPathResource(resource);
    return parseSimulationEngineConfiguration(springResource, beanName);
}