Spring Framework ClassPathResource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ClassPathResource class.

This code example shows how to use the following methods:
		assertEquals(resource, result); 
	} 
 
	@Test 
	public void syntaxErrorInManifest() throws Exception { 
		Resource resource = new ClassPathResource("test/error.manifest", getClass()); 
		given(this.chain.transform(this.request, resource)).willReturn(resource); 
 
		Resource result = this.transformer.transform(this.request, resource, this.chain); 
		assertEquals(resource, result); 
	} 
 
	@Test 
	public void transformManifest() throws Exception { 
 
		VersionResourceResolver versionResolver = new VersionResourceResolver(); 
		versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy())); 
 
		PathResourceResolver pathResolver = new PathResourceResolver(); 
		pathResolver.setAllowedLocations(new ClassPathResource("test/", getClass())); 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:exists
	 * in the class-level Javadoc for {@link TestPropertySource}. 
	 */ 
	private static String detectDefaultPropertiesFile(Class<?> testClass) {
		String resourcePath = ClassUtils.convertClassNameToResourcePath(testClass.getName()) + ".properties";
		String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
		ClassPathResource classPathResource = new ClassPathResource(resourcePath);
 
		if (classPathResource.exists()) {
			if (logger.isInfoEnabled()) {
				logger.info(String.format("Detected default properties file \"%s\" for test class [%s]",
					prefixedResourcePath, testClass.getName()));
			} 
			return prefixedResourcePath;
		} 
		else { 
			String msg = String.format("Could not detect default properties file for test [%s]: "
					+ "%s does not exist. Either declare the 'locations' or 'properties' attributes " 
					+ "of @TestPropertySource or make the default properties file available.", testClass.getName(),
				classPathResource);
			logger.error(msg);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        String resName = "/" + getClass().getPackage().getName().replace('.', '/') + filename;
        return resName;
    } 
 
    private void testConfigureJaasCase(JaasAuthenticationProvider p1, JaasAuthenticationProvider p2) throws Exception {
        p1.setLoginConfig(new ClassPathResource(resolveConfigFile("/test1.conf")));
        p1.setLoginContextName("test1");
        p1.setCallbackHandlers(new JaasAuthenticationCallbackHandler[] {new TestCallbackHandler(), new JaasNameCallbackHandler(), new JaasPasswordCallbackHandler()});
        p1.setAuthorityGranters(new AuthorityGranter[] {new TestAuthorityGranter()});
        p1.afterPropertiesSet();
        testAuthenticate(p1);
 
        p2.setLoginConfig(new ClassPathResource(resolveConfigFile("/test2.conf")));
        p2.setLoginContextName("test2");
        p2.setCallbackHandlers(new JaasAuthenticationCallbackHandler[] {new TestCallbackHandler(), new JaasNameCallbackHandler(), new JaasPasswordCallbackHandler()});
        p2.setAuthorityGranters(new AuthorityGranter[] {new TestAuthorityGranter()});
        p2.afterPropertiesSet();
        testAuthenticate(p2);
    } 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:exists, getInputStream
            long userId = 5; 
            File profilePhotoForUser5 = new File(ServiceConfiguration.CRM_STORAGE_PROFILES_DIRECTORY, Long.toString(userId)); 
            if (!profilePhotoForUser5.exists()) { 
                // copy the profile photo back 
                String pathForProfilePhoto = "/sample-photos/spring-dog-2.png"; 
                ClassPathResource classPathResource = new ClassPathResource(pathForProfilePhoto); 
                Assert.isTrue(classPathResource.exists(), "the resource " + pathForProfilePhoto + " does not exist"); 
                OutputStream outputStream = new FileOutputStream(profilePhotoForUser5); 
                InputStream inputStream = classPathResource.getInputStream(); 
                try { 
                    IOUtils.copy(inputStream, outputStream); 
                } finally { 
                    IOUtils.closeQuietly(inputStream); 
                    IOUtils.closeQuietly(outputStream); 
                } 
                log.debug("setup photo " + profilePhotoForUser5.getAbsolutePath() + " for the sample user #" + Long.toString(userId) + "'s profile photo."); 
            } 
            if (!profilePhotoForUser5.exists()) { 
                throw new RuntimeException("couldn't setup profile photos at " + profilePhotoForUser5.getAbsolutePath() + "."); 
            } 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	@Test
	public void duplicateBeanIdsWithinSameNestingLevelRaisesError() { 
		DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
		try { 
			reader.loadBeanDefinitions(new ClassPathResource("DuplicateBeanIdTests-sameLevel-context.xml", this.getClass()));
			fail("expected parsing exception due to duplicate ids in same nesting level"); 
		} catch (Exception ex) {
			// expected 
		} 
	} 
 
	@Test
	public void duplicateBeanIdsAcrossNestingLevels() { 
		DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
		reader.loadBeanDefinitions(new ClassPathResource("DuplicateBeanIdTests-multiLevel-context.xml", this.getClass()));
		TestBean testBean = bf.getBean(TestBean.class); // there should be only one
		assertThat(testBean.getName(), equalTo("nested"));
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	public void setUp() { 
		VersionResourceResolver versionResolver = new VersionResourceResolver(); 
		versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy())); 
 
		PathResourceResolver pathResolver = new PathResourceResolver(); 
		pathResolver.setAllowedLocations(new ClassPathResource("test/", getClass())); 
 
		List<ResourceResolver> resolvers = Arrays.asList(versionResolver, pathResolver); 
		List<ResourceTransformer> transformers = Arrays.asList(new CssLinkResourceTransformer()); 
 
		ResourceResolverChain resolverChain = new DefaultResourceResolverChain(resolvers); 
		this.transformerChain = new DefaultResourceTransformerChain(resolverChain, transformers); 
 
		this.request = new MockHttpServletRequest(); 
	} 
 
 
	@Test 
	public void transform() throws Exception { 
		Resource css = new ClassPathResource("test/main.css", getClass()); 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	@Override 
	public void setUp() throws Exception {
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
		reader.setEventListener(this.eventListener);
		reader.loadBeanDefinitions(new ClassPathResource("txNamespaceHandlerTests.xml", getClass()));
	} 
 
	public void testComponentEventReceived() { 
		ComponentDefinition component = this.eventListener.getComponentDefinition("txAdvice");
		assertTrue(component instanceof BeanComponentDefinition);
	} 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInputStream
    this.setUpConfigurationProperties(configLocationPath);
  } 
 
  private void setUpConfigurationProperties(String configLocationPath)
      throws Exception {
    configLocation = new ClassPathResource(configLocationPath);
    cacheManagerFactoryBean.setConfigLocation(configLocation);
 
    InputStream inputStream = configLocation.getInputStream();
    configProperties = new Properties();
    configProperties.load(inputStream);
  } 
 
  private void setUpDefaultConfigurationProperties() throws Exception {
    this.setUpConfigurationProperties(DEFAULT_CONFIG_RESOURCE_NAME);
  } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:exists, getInputStream
    String propertiesFile = filterConfig.getInitParameter("apis-resource-server.properties.file");
    if (StringUtils.isNotEmpty(propertiesFile)) {
      res = new ClassPathResource(propertiesFile);
    } 
    if (res == null || !res.exists()) {
      res = new ClassPathResource("apis-resource-server.properties");
    } 
    if (res != null && res.exists()) {
      Properties prop = new Properties();
      try { 
        prop.load(res.getInputStream());
      } catch (IOException e) {
        throw new RuntimeException("Error in reading the apis-resource-server.properties file", e);
      } 
      resourceServerKey = prop.getProperty("adminService.resourceServerKey");
      resourceServerSecret = prop.getProperty("adminService.resourceServerSecret");
      authorizationServerUrl = prop.getProperty("adminService.tokenVerificationUrl");
      cacheEnabled = Boolean.valueOf(prop.getProperty("adminService.cacheEnabled"));
      String allowCorsRequestsProperty = prop.getProperty("adminService.allowCorsRequests");
      if (StringUtils.isNotEmpty(allowCorsRequestsProperty)) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework ClassPathResource Methods: