Search in sources :

Example 11 with ClassLoaderFile

use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFile in project spring-boot by spring-projects.

the class HttpRestartServerTests method sendClassLoaderFiles.

@Test
public void sendClassLoaderFiles() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    ClassLoaderFiles files = new ClassLoaderFiles();
    files.addFile("name", new ClassLoaderFile(Kind.ADDED, new byte[0]));
    byte[] bytes = serialize(files);
    request.setContent(bytes);
    this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
    verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
    assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) Test(org.junit.Test)

Example 12 with ClassLoaderFile

use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFile in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method getResourceWhenDeletedShouldReturnDeletedResource.

@Test
public void getResourceWhenDeletedShouldReturnDeletedResource() throws Exception {
    File folder = this.temp.newFolder();
    File file = createFile(folder, "name.class");
    this.files.addFile(folder.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
    Resource resource = this.resolver.getResource("file:" + file.getAbsolutePath());
    assertThat(resource).isNotNull().isInstanceOf(DeletedClassLoaderFileResource.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) File(java.io.File) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) Test(org.junit.Test)

Example 13 with ClassLoaderFile

use of org.springframework.boot.devtools.restart.classloader.ClassLoaderFile in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method getResourcesWhenDeletedShouldFilterDeleted.

@Test
public void getResourcesWhenDeletedShouldFilterDeleted() throws Exception {
    File folder = this.temp.newFolder();
    createFile(folder, "name.class");
    this.files.addFile(folder.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
    Resource[] resources = this.resolver.getResources("file:" + folder.getAbsolutePath() + "/**");
    assertThat(resources).isEmpty();
}
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) File(java.io.File) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) Test(org.junit.Test)

Aggregations

ClassLoaderFile (org.springframework.boot.devtools.restart.classloader.ClassLoaderFile)13 Test (org.junit.Test)7 ClassLoaderFiles (org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles)6 File (java.io.File)5 URL (java.net.URL)5 URLClassLoader (java.net.URLClassLoader)4 SourceFolder (org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder)4 Resource (org.springframework.core.io.Resource)3 ServletContextResource (org.springframework.web.context.support.ServletContextResource)3 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 DeletedClassLoaderFileResource (org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Kind (org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind)1 ClassLoaderFileURLStreamHandler (org.springframework.boot.devtools.restart.classloader.ClassLoaderFileURLStreamHandler)1 AbstractResource (org.springframework.core.io.AbstractResource)1 UrlResource (org.springframework.core.io.UrlResource)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1