Skip to content

Commit

Permalink
Issue #10084 - Addressing ResourceFactory usage review
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed Jul 11, 2023
1 parent 7176fdc commit 9d6679b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ public void testGetResourceFromCollection() throws Exception
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(ResourceFactory.combine(
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/"))));
context.getResourceFactory().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
context.getResourceFactory().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/"))));
server.setHandler(context);
server.start();

Expand All @@ -531,8 +531,8 @@ public void testGetResourcePathsFromCollection() throws Exception
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(ResourceFactory.combine(
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/"))));
context.getResourceFactory().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
context.getResourceFactory().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/"))));
server.setHandler(context);
server.start();

Expand All @@ -548,9 +548,9 @@ public void testGetResourcePathsWithDirsFromCollection() throws Exception
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(ResourceFactory.combine(
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/")),
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("wars/with_dirs/"))
context.getResourceFactory().newResource(MavenTestingUtils.getTestResourcePath("wars/layer0/")),
context.getResourceFactory().newResource(MavenTestingUtils.getTestResourcePath("wars/layer1/")),
context.getResourceFactory().newResource(MavenTestingUtils.getTestResourcePath("wars/with_dirs/"))
));
server.setHandler(context);
server.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.resource.FileSystemPool;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.resource.Resources;
Expand All @@ -71,6 +72,7 @@
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
Expand All @@ -91,15 +93,15 @@ public class WebAppContextTest
@BeforeEach
public void beforeEach()
{
//assertThat(FileSystemPool.INSTANCE.mounts(), empty());
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}

@AfterEach
public void tearDown()
{
lifeCycles.forEach(LifeCycle::stop);
Configurations.cleanKnown();
//assertThat(FileSystemPool.INSTANCE.mounts(), empty());
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}

private Server newServer()
Expand Down Expand Up @@ -354,7 +356,7 @@ public void testAlias(WorkDir workDir) throws Exception
FS.touch(someClass);

WebAppContext context = new WebAppContext();
context.setBaseResource(ResourceFactory.root().newResource(tempDir));
context.setBaseResource(context.getResourceFactory().newResource(tempDir));

context.setResourceAlias("/WEB-INF/classes/", "/classes/");

Expand Down Expand Up @@ -385,7 +387,7 @@ public void testProtectedTarget() throws Exception

WebAppContext context = new WebAppContext();
Path testWebapp = MavenTestingUtils.getTargetPath("test-classes/webapp");
context.setBaseResource(ResourceFactory.root().newResource(testWebapp));
context.setBaseResource(context.getResourceFactory().newResource(testWebapp));
context.setContextPath("/");

contexts.addHandler(context);
Expand Down Expand Up @@ -446,7 +448,7 @@ public void testProtectedTargetFailure(String path) throws Exception

WebAppContext context = new WebAppContext();
Path testWebapp = MavenTestingUtils.getTargetPath("test-classes/webapp");
context.setBaseResource(ResourceFactory.root().newResource(testWebapp));
context.setBaseResource(context.getResourceFactory().newResource(testWebapp));
context.setContextPath("/");
contexts.addHandler(context);

Expand Down Expand Up @@ -500,7 +502,7 @@ public void testNullSessionAndSecurityHandler() throws Exception
ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
context.setContextPath("/");
Path testWebapp = MavenTestingUtils.getTargetPath("test-classes/webapp");
context.setBaseResource(ResourceFactory.root().newResource(testWebapp));
context.setBaseResource(context.getResourceFactory().newResource(testWebapp));
contexts.addHandler(context);

LocalConnector connector = new LocalConnector(server);
Expand Down Expand Up @@ -559,8 +561,8 @@ public void testGetResourceFromCollection() throws Exception
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(ResourceFactory.combine(
ResourceFactory.root().newResource(MavenPaths.findTestResourceDir("wars/layer0/")),
ResourceFactory.root().newResource(MavenPaths.findTestResourceDir("wars/layer1/"))));
context.getResourceFactory().newResource(MavenPaths.findTestResourceDir("wars/layer0/")),
context.getResourceFactory().newResource(MavenPaths.findTestResourceDir("wars/layer1/"))));
server.setHandler(context);
server.start();

Expand All @@ -577,8 +579,8 @@ public void testGetResourcePathsFromCollection() throws Exception
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(ResourceFactory.combine(
ResourceFactory.root().newResource(MavenPaths.findTestResourceDir("wars/layer0/")),
ResourceFactory.root().newResource(MavenPaths.findTestResourceDir("wars/layer1/"))));
context.getResourceFactory().newResource(MavenPaths.findTestResourceDir("wars/layer0/")),
context.getResourceFactory().newResource(MavenPaths.findTestResourceDir("wars/layer1/"))));
server.setHandler(context);
server.start();

Expand All @@ -594,9 +596,9 @@ public void testGetResourcePathsWithDirsFromCollection() throws Exception
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(ResourceFactory.combine(
ResourceFactory.root().newResource(MavenPaths.findTestResourceDir("wars/layer0/")),
ResourceFactory.root().newResource(MavenPaths.findTestResourceDir("wars/layer1/")),
ResourceFactory.root().newResource(MavenPaths.findTestResourceDir("wars/with_dirs/"))
context.getResourceFactory().newResource(MavenPaths.findTestResourceDir("wars/layer0/")),
context.getResourceFactory().newResource(MavenPaths.findTestResourceDir("wars/layer1/")),
context.getResourceFactory().newResource(MavenPaths.findTestResourceDir("wars/with_dirs/"))
));
server.setHandler(context);
server.start();
Expand Down

0 comments on commit 9d6679b

Please sign in to comment.