fix tests

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2022-08-03 18:04:01 +02:00
parent 7a28563bcc
commit dd72e844a3
4 changed files with 41 additions and 21 deletions

View File

@ -18,6 +18,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.resource.FileSystemPool; import org.eclipse.jetty.util.resource.FileSystemPool;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
@ -152,17 +153,26 @@ public class MetaInfConfigurationTest
{ {
MetaInfConfiguration config = new MetaInfConfiguration(); MetaInfConfiguration config = new MetaInfConfiguration();
WebAppContext context = new WebAppContext(); WebAppContext context = new WebAppContext();
context.setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN, ".*servlet-api-[^/]*\\.jar$|.*/foo-bar-janb.jar"); context.setServer(new Server());
WebAppClassLoader loader = new WebAppClassLoader(context); config.preConfigure(context);
context.setClassLoader(loader); try
config.findAndFilterContainerPaths(context);
List<Resource> containerResources = context.getMetaData().getContainerResources();
assertEquals(2, containerResources.size());
for (Resource r : containerResources)
{ {
String s = r.toString(); context.setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN, ".*servlet-api-[^/]*\\.jar$|.*/foo-bar-janb.jar");
assertTrue(s.endsWith("foo-bar-janb.jar") || s.contains("servlet-api")); WebAppClassLoader loader = new WebAppClassLoader(context);
context.setClassLoader(loader);
config.findAndFilterContainerPaths(context);
List<Resource> containerResources = context.getMetaData().getContainerResources();
assertEquals(2, containerResources.size());
for (Resource r : containerResources)
{
String s = r.toString();
assertTrue(s.endsWith("foo-bar-janb.jar") || s.contains("servlet-api"));
}
}
finally
{
config.postConfigure(context);
} }
} }
} }

View File

@ -68,7 +68,7 @@ public class TestMetaData
nonFragFile = new File(jarDir, "sigma.jar"); nonFragFile = new File(jarDir, "sigma.jar");
nonFragResource = resourceFactory.newResource(nonFragFile.toPath()); nonFragResource = resourceFactory.newResource(nonFragFile.toPath());
assertTrue(nonFragFile.exists()); assertTrue(nonFragFile.exists());
webfragxml = resourceFactory.newResource(fragFile.toPath()).resolve("/META-INF/web-fragment.xml"); webfragxml = resourceFactory.newJarFileResource(fragFile.toPath().toUri()).resolve("/META-INF/web-fragment.xml");
containerDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("container").toPath()); containerDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("container").toPath());
webInfClassesDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("webinfclasses").toPath()); webInfClassesDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("webinfclasses").toPath());
wac = new WebAppContext(); wac = new WebAppContext();

View File

@ -18,6 +18,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.resource.FileSystemPool; import org.eclipse.jetty.util.resource.FileSystemPool;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
@ -152,16 +153,25 @@ public class MetaInfConfigurationTest
{ {
MetaInfConfiguration config = new MetaInfConfiguration(); MetaInfConfiguration config = new MetaInfConfiguration();
WebAppContext context = new WebAppContext(); WebAppContext context = new WebAppContext();
context.setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN, ".*servlet-api-[^/]*\\.jar$|.*/foo-bar-janb.jar"); context.setServer(new Server());
WebAppClassLoader loader = new WebAppClassLoader(context); config.preConfigure(context);
context.setClassLoader(loader); try
config.findAndFilterContainerPaths(context);
List<Resource> containerResources = context.getMetaData().getContainerResources();
assertEquals(2, containerResources.size());
for (Resource r : containerResources)
{ {
String s = r.toString(); context.setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN, ".*servlet-api-[^/]*\\.jar$|.*/foo-bar-janb.jar");
assertTrue(s.endsWith("foo-bar-janb.jar") || s.contains("servlet-api")); WebAppClassLoader loader = new WebAppClassLoader(context);
context.setClassLoader(loader);
config.findAndFilterContainerPaths(context);
List<Resource> containerResources = context.getMetaData().getContainerResources();
assertEquals(2, containerResources.size());
for (Resource r : containerResources)
{
String s = r.toString();
assertTrue(s.endsWith("foo-bar-janb.jar") || s.contains("servlet-api"));
}
}
finally
{
config.postConfigure(context);
} }
} }
} }

View File

@ -68,7 +68,7 @@ public class TestMetaData
nonFragFile = new File(jarDir, "sigma.jar"); nonFragFile = new File(jarDir, "sigma.jar");
nonFragResource = resourceFactory.newResource(nonFragFile.toPath()); nonFragResource = resourceFactory.newResource(nonFragFile.toPath());
assertTrue(nonFragFile.exists()); assertTrue(nonFragFile.exists());
webfragxml = resourceFactory.newResource(fragFile.toPath()).resolve("/META-INF/web-fragment.xml"); webfragxml = resourceFactory.newJarFileResource(fragFile.toPath().toUri()).resolve("/META-INF/web-fragment.xml");
containerDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("container").toPath()); containerDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("container").toPath());
webInfClassesDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("webinfclasses").toPath()); webInfClassesDir = resourceFactory.newResource(MavenTestingUtils.getTargetTestingDir("webinfclasses").toPath());
wac = new WebAppContext(); wac = new WebAppContext();