Fixing post-merge test failure in QuickStartTest

Signed-off-by: Joakim Erdfelt <joakim@erdfelt.com>
This commit is contained in:
Joakim Erdfelt 2019-02-14 14:56:26 -05:00
parent 7b686fa4b6
commit 14d09bac5c
4 changed files with 47 additions and 39 deletions

View File

@ -25,11 +25,9 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EventListener;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.MultipartConfigElement; import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -55,13 +53,11 @@ import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletMapping; import org.eclipse.jetty.servlet.ServletMapping;
import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.MetaData; import org.eclipse.jetty.webapp.MetaData;
import org.eclipse.jetty.webapp.MetaData.OriginInfo; import org.eclipse.jetty.webapp.MetaData.OriginInfo;
import org.eclipse.jetty.webapp.MetaInfConfiguration; import org.eclipse.jetty.webapp.MetaInfConfiguration;
@ -796,9 +792,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
Resource quickStartWebXml = _quickStartWebXml; Resource quickStartWebXml = _quickStartWebXml;
if (_quickStartWebXml == null) if (_quickStartWebXml == null)
quickStartWebXml = context.getBaseResource().addPath("/WEB-INF/quickstart-web.xml"); quickStartWebXml = context.getWebInf().addPath("/quickstart-web.xml");
if (!quickStartWebXml.exists())
quickStartWebXml.getFile().createNewFile();
try (FileOutputStream fos = new FileOutputStream(quickStartWebXml.getFile(),false)) try (FileOutputStream fos = new FileOutputStream(quickStartWebXml.getFile(),false))
{ {
generateQuickStartWebXml(context,fos); generateQuickStartWebXml(context,fos);

View File

@ -74,14 +74,11 @@ public class ResourceCollection extends Resource
} }
else else
{ {
assertResourceValid(r);
list.add(r); list.add(r);
} }
} }
_resources = list.toArray(new Resource[0]); _resources = list.toArray(new Resource[0]);
for (Resource r : _resources)
{
assertResourceValid(r);
}
} }
/** /**

View File

@ -18,14 +18,16 @@
package org.eclipse.jetty.quickstart; package org.eclipse.jetty.quickstart;
import java.io.File; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
public class PreconfigureSpecWar public class PreconfigureSpecWar
{ {
@ -34,24 +36,31 @@ public class PreconfigureSpecWar
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
String target="target/test-spec-preconfigured"; Path target = MavenTestingUtils.getTargetPath().resolve("test-spec-preconfigured");
File file = new File(target); if (Files.exists(target))
if (file.exists()) {
IO.delete(file); IO.delete(target.toFile());
}
Files.createDirectories(target.resolve("WEB-INF"));
File realmPropertiesDest = new File ("target/test-spec-realm.properties"); Path realmPropertiesDest = MavenTestingUtils.getTargetPath().resolve("test-spec-realm.properties");
if (realmPropertiesDest.exists()) Files.deleteIfExists(realmPropertiesDest);
IO.delete(realmPropertiesDest);
Resource realmPropertiesSrc = Resource.newResource("src/test/resources/realm.properties"); Path realmPropertiesSrc = MavenTestingUtils.getTestResourcePath("realm.properties");
realmPropertiesSrc.copyTo(realmPropertiesDest); Files.copy(realmPropertiesSrc, realmPropertiesDest);
System.setProperty("jetty.home", "target"); System.setProperty("jetty.home", MavenTestingUtils.getTargetDir().getAbsolutePath());
PreconfigureQuickStartWar.main("target/test-spec.war",target, "src/test/resources/test-spec.xml"); PreconfigureQuickStartWar.main(
MavenTestingUtils.getTargetFile("test-spec.war").toString(),
target.toString(),
MavenTestingUtils.getTestResourceFile("test-spec.xml").toString());
LOG.info("Preconfigured in {}ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - __start)); LOG.info("Preconfigured in {}ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - __start));
// IO.copy(new FileInputStream("target/test-spec-preconfigured/WEB-INF/quickstart-web.xml"),System.out); Path quickStartXml = target.resolve("WEB-INF/quickstart-web.xml");
try (InputStream in = Files.newInputStream(quickStartXml))
{
IO.copy(in, System.out);
}
} }
} }

View File

@ -18,17 +18,18 @@
package org.eclipse.jetty.quickstart; package org.eclipse.jetty.quickstart;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebDescriptor; import org.eclipse.jetty.webapp.WebDescriptor;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
@ -36,6 +37,10 @@ import org.eclipse.jetty.xml.XmlParser.Node;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class QuickStartTest public class QuickStartTest
{ {
@ -90,7 +95,10 @@ public class QuickStartTest
{ {
PreconfigureSpecWar.main(new String[]{}); PreconfigureSpecWar.main(new String[]{});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-spec-preconfigured/WEB-INF/quickstart-web.xml")); Path webXmlPath = MavenTestingUtils.getTargetPath().resolve("test-spec-preconfigured/WEB-INF/quickstart-web.xml");
assertTrue(Files.exists(webXmlPath), "Path should exist:" + webXmlPath);
WebDescriptor descriptor = new WebDescriptor(new PathResource(webXmlPath));
descriptor.setValidating(!Log.getLogger(QuickStartGeneratorConfiguration.class).isDebugEnabled()); descriptor.setValidating(!Log.getLogger(QuickStartGeneratorConfiguration.class).isDebugEnabled());
descriptor.parse(); descriptor.parse();
Node node = descriptor.getRoot(); Node node = descriptor.getRoot();