Search in sources :

Example 16 with Resource

use of org.springframework.core.io.Resource in project spring-boot by spring-projects.

the class InitializrServiceMetadataTests method readJson.

private static JSONObject readJson(String version) throws IOException, JSONException {
    Resource resource = new ClassPathResource("metadata/service-metadata-" + version + ".json");
    InputStream stream = resource.getInputStream();
    try {
        return new JSONObject(StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
    } finally {
        stream.close();
    }
}
Also used : JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 17 with Resource

use of org.springframework.core.io.Resource in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method getResourceShouldReturnResource.

@Test
public void getResourceShouldReturnResource() throws Exception {
    Resource resource = this.resolver.getResource("index.html");
    assertThat(resource).isNotNull().isInstanceOf(ClassPathResource.class);
}
Also used : DeletedClassLoaderFileResource(org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) Test(org.junit.Test)

Example 18 with Resource

use of org.springframework.core.io.Resource in project spring-boot by spring-projects.

the class AbstractJsonMarshalTesterTests method readResourceShouldReturnObject.

@Test
public void readResourceShouldReturnObject() throws Exception {
    Resource resource = new ByteArrayResource(JSON.getBytes());
    AbstractJsonMarshalTester<Object> tester = createTester(TYPE);
    assertThat(tester.read(resource)).isEqualTo(OBJECT);
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 19 with Resource

use of org.springframework.core.io.Resource in project spring-boot by spring-projects.

the class BasicJsonTesterTests method fromResourceShouldReturnJsonContent.

@Test
public void fromResourceShouldReturnJsonContent() throws Exception {
    Resource resource = new ByteArrayResource(JSON.getBytes());
    assertThat(this.json.from(resource)).isEqualToJson("source.json");
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 20 with Resource

use of org.springframework.core.io.Resource in project spring-framework by spring-projects.

the class AbstractBeanDefinitionReader method loadBeanDefinitions.

@Override
public int loadBeanDefinitions(Resource... resources) throws BeanDefinitionStoreException {
    Assert.notNull(resources, "Resource array must not be null");
    int counter = 0;
    for (Resource resource : resources) {
        counter += loadBeanDefinitions(resource);
    }
    return counter;
}
Also used : Resource(org.springframework.core.io.Resource)

Aggregations

Resource (org.springframework.core.io.Resource)541 Test (org.junit.Test)248 ClassPathResource (org.springframework.core.io.ClassPathResource)217 IOException (java.io.IOException)86 FileSystemResource (org.springframework.core.io.FileSystemResource)67 File (java.io.File)60 UrlResource (org.springframework.core.io.UrlResource)60 ArrayList (java.util.ArrayList)49 ByteArrayResource (org.springframework.core.io.ByteArrayResource)46 InputStream (java.io.InputStream)33 InputStreamResource (org.springframework.core.io.InputStreamResource)31 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)24 URL (java.net.URL)20 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)18 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)16 ServletContextResource (org.springframework.web.context.support.ServletContextResource)16 URI (java.net.URI)15 ResourceLoader (org.springframework.core.io.ResourceLoader)15 HashMap (java.util.HashMap)13 LinkedHashSet (java.util.LinkedHashSet)13