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:net.cnmconsulting.spring.config.PropertiesFactoryBeanAutowireTest.java

@Test
public void testCreateProperties() {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean(stringEncryptor);
    Resource location = new ClassPathResource("props-test.properties");
    propertiesFactoryBean.setLocation(location);
    try {/* www . j a  va2  s . c om*/
        Properties props = propertiesFactoryBean.createProperties();
        assertNotNull(props);
        String pass = (String) props.getProperty("pass");
        assertNotNull(pass);

    } catch (IOException e) {
        e.printStackTrace();
        fail(e.toString());
    }

}

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

@Test
public void testFlatFileReader2() throws Exception {

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

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

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

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

From source file:org.araneaframework.ioc.spring.SimpleAraneaSpringDispatcherServlet.java

public void init() throws ServletException {
    beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

    rootConf = new XmlBeanFactory(
            new ClassPathResource("spring-property-conf/property-custom-webapp-aranea-conf.xml"), beanFactory);
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(new ClassPathResource("spring-property-conf/default-aranea-conf.properties"));

    Properties localConf = new Properties();
    try {/*from  ww w.j ava2 s.c  o  m*/
        if (getServletContext().getResource("/WEB-INF/aranea-conf.properties") != null)
            localConf.load(getServletContext().getResourceAsStream("/WEB-INF/aranea-conf.properties"));
    } catch (IOException e) {
        throw new ServletException(e);
    }
    cfg.setProperties(localConf);
    cfg.setLocalOverride(true);

    cfg.postProcessBeanFactory(rootConf);

    super.init();
}

From source file:org.megam.deccanplato.core.test.ProvidersTest.java

@Test
public void allTest() throws IOException {

    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
    ctx.refresh();/*from  w w w. ja v  a  2s .co  m*/
    ProviderRegistry registry = (ProviderRegistry) ctx.getBean("registry");

    List<String> providerlist = new ArrayList<String>();
    //providerlist.add("salesforce");
    //providerlist.add("sugarcrm");
    providerlist.add("zohocrm");

    List<String> userlist = new ArrayList<String>();
    userlist.add("user_create.json");
    userlist.add("user_list.json");
    userlist.add("user_update.json");
    userlist.add("user_delete.json");

    List<String> accountlist = new ArrayList<String>();
    accountlist.add("account_create.json");
    accountlist.add("account_list.json");
    accountlist.add("account_update.json");
    accountlist.add("account_delete.json");

    List<String> leadlist = new ArrayList<String>();
    leadlist.add("lead_create.json");
    leadlist.add("lead_list.json");
    leadlist.add("lead_update.json");
    leadlist.add("lead_delete.json");

    List<String> contactlist = new ArrayList<String>();
    contactlist.add("contact_create.json");
    contactlist.add("contact_list.json");
    contactlist.add("contact_update.json");
    contactlist.add("contact_delete.json");

    List<String> migratelist = new ArrayList<String>();
    migratelist.add("migration.json");
    /*
          for (String provid : providerlist) {
             for (String user : userlist) {
    ct.testCommonTest(provid, user);
             }
             for(String account: accountlist) {
    ct.testCommonTest(provid, account);
             }
             for(String lead: leadlist) {
    ct.testCommonTest(provid, lead);
             }
          }      
             for(String user: userlist) {
    ct.testCommonTest("googleapps", user);
             }
             for(String contact: contactlist) {
    ct.testCommonTest("googleapps", contact);
             }
             for(String migrate: migratelist) {
    ct.testCommonTest("googleapps", migrate);
             }   */
}

From source file:com.graphaware.test.integration.EmbeddedDatabaseIntegrationTest.java

/**
 * Instantiate a database. By default this will be {@link org.neo4j.test.ImpermanentGraphDatabase}.
 *
 * @return new database.//from ww w .  j  a  va2  s .  com
 */
@Override
protected GraphDatabaseService createDatabase() {
    GraphDatabaseBuilder builder = createGraphDatabaseBuilder();

    if (configFile() != null) {
        try {
            builder = builder
                    .loadPropertiesFromFile(new ClassPathResource(configFile()).getFile().getAbsolutePath());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        populateConfig(builder);
    }

    GraphDatabaseService database = builder.newGraphDatabase();
    registerShutdownHook(database);
    return database;
}

From source file:com.thoughtworks.go.server.database.SqlMapClientFactory.java

private Resource[] addToConfigLocations(Resource[] configLocations, String ibatisConfigXmlLocation) {
    if (StringUtils.isBlank(ibatisConfigXmlLocation)) {
        return configLocations;
    }/*from w w  w . j a  v a 2 s.  com*/
    return (Resource[]) ArrayUtils.add(configLocations, new ClassPathResource(ibatisConfigXmlLocation));
}

From source file:org.jasig.portlet.proxy.service.ClasspathResourceContentService.java

@Override
public GenericContentResponseImpl getContent(final GenericContentRequestImpl proxyRequest,
        final PortletRequest request) {

    // get the resource corresponding to the configured location
    final Resource resource = new ClassPathResource(proxyRequest.getProxiedLocation());

    try {/*from  ww  w.ja  v a 2s.  c  o m*/
        // construct a content response using this resource
        final GenericContentResponseImpl proxyResponse = new GenericContentResponseImpl(
                proxyRequest.getProxiedLocation(), resource.getInputStream());
        return proxyResponse;
    } catch (IOException e) {
        log.error("IOException retrieving resource {}", proxyRequest.getProxiedLocation());
    }

    return null;
}

From source file:org.wso2.carbon.metrics.impl.ReporterTest.java

public static Test suite() {
    return new TestSetup(new TestSuite(ReporterTest.class)) {

        protected void setUp() throws Exception {
            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);

            // Set setup system property to cover database creator logic
            System.setProperty("setup", "");
        }//ww w  .  j a v  a  2  s  .  com

        protected void tearDown() throws Exception {
            InitialContext ic = new InitialContext();
            ic.unbind("jdbc/WSO2MetricsDB");
            ic.unbind("jdbc");
        }
    };
}

From source file:nl.flotsam.calendar.core.CalendarParserTest.java

@Test
public void shouldUnfoldCorrectly() throws IOException {
    UnfoldingReader reader = new UnfoldingReader(
            new InputStreamReader(new ClassPathResource("sample-single-line.ical").getInputStream(), "UTF-8"),
            3000);//from   w ww . j  av a  2  s . co m
    IOUtils.copy(reader, System.out);
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.restserver.reports.GenerateReportsRest.java

public Representation getHandler() {
    String result = null;/*from w w  w. j a  va 2 s .c om*/
    try {
        getParameters();

        // Generate Reports at MCC level for dates
        if (topAccountId != null && dateStart != null && dateEnd != null) {

            getContext().getParameters().add("maxThreads", "512");

            Resource resource = new ClassPathResource(file);
            if (!resource.exists()) {
                resource = new FileSystemResource(file);
            }
            DynamicPropertyPlaceholderConfigurer.setDynamicResource(resource);
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);

            ReportProcessor processor = getApplicationContext().getBean(ReportProcessor.class);

            // Launching a new Service(Thread) to make the request async.
            RunnableReport runnableReport = new RunnableReport(topAccountId, processor, properties, dateStart,
                    dateEnd);

            taskService.submit(runnableReport);

            result = "OK - Task created, this usually takes 10-15mins for 1000 accounts/month";
        } else {
            taskService.getContext();
        }
    } catch (Exception exception) {
        return handleException(exception);
    }
    addReadOnlyHeaders();
    return createJsonResult(result);
}