Deprecated as of 4.3.13, in favor of selective use of ClassPathResource.ClassPathResource(String, ClassLoader) vs ClassPathResource.ClassPathResource(String, Class)
public void afterPropertiesSet() throws Exception { ClassPathResource resource = new ClassPathResource("logo.png"); ImageIcon icon = new ImageIcon(resource.getURL()); JLabel logo = new JLabel(icon);
@Test public void testPersistenceUnitRootUrlWithJar() throws Exception { ClassPathResource archive = new ClassPathResource("/org/springframework/orm/jpa/jpa-archive.jar"); String newRoot = "jar:" + archive.getURL().toExternalForm() + "!/META-INF/persist.xml"; Resource insideArchive = new UrlResource(newRoot); // make sure the location actually exists assertTrue(insideArchive.exists()); URL url = PersistenceUnitReader.determinePersistenceUnitRootUrl(insideArchive); assertTrue("the archive location should have been returned", archive.getURL().sameFile(url)); }
@Test public void testMetaInfCase() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
@Test public void testExample3() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example3.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement3", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals(0, info[0].getProperties().keySet().size()); assertNull(info[0].getJtaDataSource()); assertNull(info[0].getNonJtaDataSource()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
@Test public void testExample5() throws Exception { PersistenceUnitReader reader = new PersistenceUnitReader( new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup()); String resource = "/org/springframework/orm/jpa/persistence-example5.xml"; PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource); assertNotNull(info); assertEquals(1, info.length); assertEquals("OrderManagement5", info[0].getPersistenceUnitName()); assertEquals(2, info[0].getMappingFileNames().size()); assertEquals("order1.xml", info[0].getMappingFileNames().get(0)); assertEquals("order2.xml", info[0].getMappingFileNames().get(1)); assertEquals(2, info[0].getJarFileUrls().size()); assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0)); assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1)); assertEquals("com.acme.AcmePersistence", info[0].getPersistenceProviderClassName()); assertEquals(0, info[0].getProperties().keySet().size()); assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses()); }
assertEquals(new ClassPathResource("order.jar").getURL(), pu1.getJarFileUrls().get(0));
new ClassPathResource(uri.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), this.classLoader); try { String url = resource.getURL().toString(); setValue(createURI(url));
@Test(expected = IllegalArgumentException.class) public void testFailureWhenNotInitialized() throws Exception { URL url = new ClassPathResource("org/springframework/integration/feed/sample.rss").getURL(); FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url, "foo"); feedEntrySource.receive(); }
@Test public void testReceiveFeedWithNoEntries() throws Exception { URL url = new ClassPathResource("org/springframework/integration/feed/empty.rss").getURL(); FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(url, "foo"); feedEntrySource.setBeanName("feedReader"); feedEntrySource.setBeanFactory(mock(BeanFactory.class)); feedEntrySource.afterPropertiesSet(); assertNull(feedEntrySource.receive()); }
public URL getURL() throws IOException { // delegate to ClassPathResource return classPathResource.getURL(); }
/** * * @param path * a path like '/folder/file' in folder in a folder in the classpath * @return */ public static URL getResourceURL(String path) { try { return new ClassPathResource(path).getURL(); } catch (IOException e) { // Do not throw the explicit IOException so this method can be used for field definition in tests throw new RuntimeException(e); } }
/** * * @param path * a path like '/folder/file' in folder in a folder in the classpath * @return */ public static URL getResourceURL(String path) { try { return new ClassPathResource(path).getURL(); } catch (IOException e) { // Do not throw the explicit IOException so this method can be used for field definition in tests throw new RuntimeException(e); } }
@Bean public org.modeshape.jcr.RepositoryConfiguration repoConfiguration() throws Exception { return org.modeshape.jcr.RepositoryConfiguration.read(new ClassPathResource(repositoryConfigFile).getURL()); }
static Resource initBaseDir() { ClassPathResource classPath = new ClassPathResource(""); try { if (classPath.getURL().toString().startsWith("jar:")) { return classPath; } } catch (IOException e) { // Ignore } FileSystemResource resources = new FileSystemResource("src/main/resources"); if (resources.exists()) { return resources; } return new FileSystemResource("."); }
/** * This implementation returns a File reference for the underlying class path * resource, provided that it refers to a file in the file system. * @see org.springframework.util.ResourceUtils#getFile(java.net.URL, String) */ public File getFile() throws IOException { return ResourceUtils.getFile(getURL(), getDescription()); }
protected Source createXslSource() throws IOException { return new StreamSource(getXslResource().getInputStream(), getXslResource().getURL().toString()); }
protected Source createXslSource() throws IOException { return new StreamSource(getXslResource().getInputStream(), getXslResource().getURL().toString()); }
@Override protected URL getURL(String name) { ClassPathResource cpr = new ClassPathResource(name); if (cpr.exists()) { try { return cpr.getURL(); } catch (IOException e) { return null; } } FileSystemResource fsr = new FileSystemResource(name); if (fsr.exists()) { try { return fsr.getURL(); } catch (IOException e) { return null; } } return null; } }
private static File getFileForLastModifiedCheck(ClassPathResource resource) throws IOException { URL url = resource.getURL(); if (ResourceUtils.isJarURL(url)) { URL actualUrl = ResourceUtils.extractJarFileURL(url); return ResourceUtils.getFile(actualUrl); } else { return ResourceUtils.getFile(url, resource.getDescription()); } }
@Before @Override public void setUp() throws Exception { setStartEventd(false); super.setUp(); m_mockAgent = MockSnmpAgent.createAgentAndRun(new ClassPathResource("org/opennms/netmgt/snmp/snmpTestData1.properties").getURL(), InetAddressUtils.str(myLocalHost()) + "/9161"); m_config = new MockDataCollectionConfig(); DataCollectionConfigFactory.setInstance(m_config); m_sysNameOid = SnmpObjId.get(".1.3.6.1.2.1.1.5"); m_ifOutOctets = SnmpObjId.get("..1.3.6.1.2.1.2.2.1.16"); m_invalid = SnmpObjId.get(".1.5.6.1.2.1.1.5"); m_ifDescr = SnmpObjId.get(".1.3.6.1.2.1.2.2.1.2"); m_easyMockUtils = new EasyMockUtils(); m_ifaceDao = m_easyMockUtils.createMock(IpInterfaceDao.class); createAgent(1, PrimaryType.PRIMARY); }