List of usage examples for org.springframework.core.io ClassPathResource ClassPathResource
public ClassPathResource(String path)
From source file:org.cloudfoundry.identity.uaa.scim.test.TestUtils.java
public static void runScript(DataSource dataSource, String stem) throws Exception { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); String packageName = ClassUtils.getPackageName(TestUtils.class).replace(".", "/"); populator.addScript(new ClassPathResource( packageName.substring(0, packageName.lastIndexOf("/")) + "/" + stem + "-" + platform + ".sql")); Connection connection = dataSource.getConnection(); try {//www.ja va 2s. c o m populator.populate(connection); } catch (ScriptStatementFailedException e) { // ignore } finally { DataSourceUtils.releaseConnection(connection, dataSource); } }
From source file:eu.falcon.semantic.client.DenaClient.java
public static String addInstances(String fileClassPath, String format) { RestTemplate restTemplate = new RestTemplate(); LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); //final String uri = "http://localhost:8090/api/v1/ontology/instances/publish"; final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/instances/publish"; map.add("file", new ClassPathResource(fileClassPath)); map.add("format", format); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<LinkedMultiValueMap<String, Object>>( map, headers);/* w w w .ja v a2s .co m*/ String result = restTemplate.postForObject(uri, entity, String.class); return result; }
From source file:edu.chalmers.dat076.moviefinder.config.ApplicationConfig.java
@Bean public static PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer() { PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); ppc.setLocation(new ClassPathResource("application.properties")); ppc.setIgnoreUnresolvablePlaceholders(true); return ppc;//from w ww. ja v a2 s . c o m }
From source file:de.openity.xmlworks.parsers.ParseXMLTest.java
@Test public void testParse() throws Exception { final ClassPathResource classPathResource = new ClassPathResource("testXMLs/TestRSS.xml"); Collection<RSSEntity> entity = new ParserImpl<RSSEntity>(RSSEntity.class) .parse(classPathResource.getFile()); System.out.println(entity.toString()); System.out.println(entity.size()); }
From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParserTest.java
/** * Test whether the interceptor takes effect or not *///from ww w . j a v a2 s . c om @Test public void testRegisterStatisticsCacheInterceptor() { ClassPathResource resource = new ClassPathResource("AOPDemo.xml"); XmlBeanFactory beanFactory = new XmlBeanFactory(resource); BeanDefinitionRegistry beanDefinitionRegistry = beanFactory; CacheBeanDefinitionParser cacheBeanDefinitionParser = new CacheBeanDefinitionParser() { protected Class<?> getStatisticsCacheInterceptor() { return com.dianping.avatar.cache.spring.DemoInterceptor.class; } }; cacheBeanDefinitionParser.registerStatisticsCacheInterceptor(null, beanDefinitionRegistry); cacheBeanDefinitionParser.registerCacheProxyBean(null, beanDefinitionRegistry, null); BusinessInterface businessBean = (BusinessInterface) beanFactory.getBean("cacheService"); assertEquals(200, businessBean.bye()); beanFactory = new XmlBeanFactory(resource); beanDefinitionRegistry = beanFactory; cacheBeanDefinitionParser = new CacheBeanDefinitionParser() { protected Class<?> getStatisticsCacheInterceptor() { return com.dianping.avatar.cache.spring.DemoInterceptor2.class; } }; cacheBeanDefinitionParser.registerStatisticsCacheInterceptor(null, beanDefinitionRegistry); cacheBeanDefinitionParser.registerCacheProxyBean(null, beanDefinitionRegistry, null); businessBean = (BusinessInterface) beanFactory.getBean("cacheService"); assertEquals(100, businessBean.bye()); }
From source file:org.cloudfoundry.client.lib.SampleProjects.java
/** * Returns a simple spring application.// ww w . j av a2s . c om * * @return the simple-spring-app WAR file * @throws IOException */ public static File simpleSpringApp() throws IOException { ClassPathResource cpr = new ClassPathResource("simple-spring-app.war"); File file = cpr.getFile(); assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists()); return file; }
From source file:com.oreilly.rdf.tenuki.InputStreamChangesetTest.java
@Before public void setUp() throws Exception { ClassPathResource changesetResource = new ClassPathResource("changeset.xml"); changeset = new InputStreamChangeset(changesetResource.getInputStream()); }
From source file:playground.ResourceController.java
@GetMapping(path = "/", produces = MediaType.TEXT_HTML_VALUE) Resource index() { return new ClassPathResource("static/index.html"); }
From source file:com.wavemaker.common.util.ClassLoaderUtilsTest.java
public void testTempClassLoader_getClass() throws Exception { File sourceJar = new ClassPathResource("com/wavemaker/common/foojar.jar").getFile(); File jar = File.createTempFile("testTempClassLoader_getClass", ".jar"); jar.deleteOnExit();//w ww. j ava 2 s . com FileUtils.copyFile(sourceJar, jar); try { ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar); Class<?> klass = ClassLoaderUtils.loadClass("foo.bar.baz.JarType", cl); assertNotNull(klass); } finally { jar.delete(); } }
From source file:org.wso2.carbon.metrics.data.service.MetricsDataServiceTest.java
public static Test suite() { return new TestSetup(new TestSuite(MetricsDataServiceTest.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); }/*from w w w. j ava2 s . c o m*/ protected void tearDown() throws Exception { InitialContext ic = new InitialContext(); ic.unbind("jdbc/WSO2MetricsDB"); ic.unbind("jdbc"); } }; }