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:infowall.infrastructure.service.GroovyExecutorTest.java

@Test
public void testExec() throws Exception {

    Resource resource = new ClassPathResource("/groovy/simple_groovy.groovy");

    GroovyExecutor executor = new GroovyExecutor();
    assertThat(executor.exec(resource.getFile()), is("hello world\n"));
}

From source file:ar.com.zauber.commons.spring.beans.factory.SwitchConditionalFactoryBeanTest.java

/** testeo de unidad */
public final void testFoo() {
    final BeanFactory testFactory = new XmlBeanFactory(new ClassPathResource("spring-test-switch.xml"));
    assertEquals("es aretha", testFactory.getBean("test1"));
}

From source file:com.jim.im.config.GenericDBConfig.java

@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);/*from ww  w.j a  v a  2 s.  co m*/
    bean.setConfigLocation(new ClassPathResource("/mybatis-config.xml"));
    return bean.getObject();
}

From source file:com.thinkbiganalytics.feedmgr.rest.model.FeedMetadataJsonTest.java

@Test
public void deserializationSortedTest() throws Exception {

    Resource r = new ClassPathResource("sorted-feed.json");
    String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
    FeedMetadata feed = ObjectMapperSerializer.deserialize(json, FeedMetadata.class);
    assertNotNull(feed);/*from  w w  w  . j ava  2s .  c  om*/
}

From source file:de.steilerdev.myVerein.server.apns.PushService.java

/**
 * This function creates a new APNS instance. If the function returns null, APNS is not supported.
 * @return The current APNS instance. If null APNS is not supported by this server.
 *///from  w w w .  ja  v  a 2 s  . c  om
public static PushManager<SimpleApnsPushNotification> getInstanced() {
    if (pushManager == null) {
        logger.debug("Creating new APNS instance");
        try {
            Resource settingsResource = new ClassPathResource(apnsSettingsFile);
            Properties settings = PropertiesLoaderUtils.loadProperties(settingsResource);

            InputStream certFile = Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream(settings.getProperty(fileKey));

            pushManager = new PushManager<>(ApnsEnvironment.getSandboxEnvironment(),
                    SSLContextUtil.createDefaultSSLContext(certFile, settings.getProperty(passwordKey)), null, // Optional: custom event loop group
                    null, // Optional: custom ExecutorService for calling listeners
                    null, // Optional: custom BlockingQueue implementation
                    new PushManagerConfiguration(), "ExamplePushManager");

            logger.debug("Created new APNS instance, starting");
            //pushManager.start();
        } catch (IOException e) {
            logger.warn("Unable to load APNS settings file: {}", e.getMessage());
            return null;
        } catch (Exception e) {
            logger.warn("An unknown error occurred: {}", e.getMessage());
        }
    }
    logger.info("Returning APNS instance");
    return pushManager;
}

From source file:wsconfig.PaysRepository.java

/**
 * Renvoye un pays trouv dans la base de donne
 * @param name Le nom du pays que l'on veut trouver
 * @return Le pays correspondant//from  w  w w .  j  av a2s . com
 */
public Pays findPays(String name) {

    ListableBeanFactory bf;
    bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
    IPaysMetier instance = (IPaysMetier) bf.getBean("paysMetier");

    Pays result = new Pays();
    String libelle = name;
    try {
        result = instance.findPays(libelle);
        System.out.println("libelle get : " + result.getLibelleFr());
    } catch (PaysNotFoundException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:biz.c24.io.spring.integration.test.TestUtils.java

public static byte[] loadJsonBytes() throws Exception {

    ClassPathResource resource = new ClassPathResource("valid-1.json");
    byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream());
    return valid1;
}

From source file:com.eventattend.portal.Factory.UserFactory.java

public static UserController updateUserContactInfo() throws Exception {
    ClassPathResource resource = new ClassPathResource("BusinessObjectFactory.xml");
    BeanFactory factory = new XmlBeanFactory(resource);
    return (UserController) factory.getBean("User");
}

From source file:io.pivotal.ecosystem.servicebroker.service.CatalogService.java

private static String getContents(String fileName) throws IOException {
    URI u = new ClassPathResource(fileName).getURI();
    return new String(Files.readAllBytes(Paths.get(u)));
}

From source file:com.octo.captcha.engine.bufferedengine.QuartzBufferedEngineContainerTest.java

public void testBasic() throws Exception {
    Resource ressource = new ClassPathResource("testQuartzBufferedEngine.xml");
    ConfigurableBeanFactory bf = new XmlBeanFactory(ressource);
    BufferedEngineContainer container = (BufferedEngineContainer) bf.getBean("container");
    Object scheduler = bf.getBean("quartz");
    Thread.sleep(10000);/*from   w  w w  .ja v  a  2 s .c om*/
    for (int i = 0; i < 100; i++) {
        assertNotNull(container.getNextCaptcha());
    }
}