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.util.Collection;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.MultipartConfigElement;
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.ServletMapping;
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.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.MetaData;
import org.eclipse.jetty.webapp.MetaData.OriginInfo;
import org.eclipse.jetty.webapp.MetaInfConfiguration;
@ -796,9 +792,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
Resource quickStartWebXml = _quickStartWebXml;
if (_quickStartWebXml == null)
quickStartWebXml = context.getBaseResource().addPath("/WEB-INF/quickstart-web.xml");
if (!quickStartWebXml.exists())
quickStartWebXml.getFile().createNewFile();
quickStartWebXml = context.getWebInf().addPath("/quickstart-web.xml");
try (FileOutputStream fos = new FileOutputStream(quickStartWebXml.getFile(),false))
{
generateQuickStartWebXml(context,fos);

View File

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

View File

@ -18,40 +18,49 @@
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 org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
public class PreconfigureSpecWar
{
private static final long __start=System.nanoTime();
private static final long __start = System.nanoTime();
private static final Logger LOG = Log.getLogger(Server.class);
public static void main(String[] args) throws Exception
{
String target="target/test-spec-preconfigured";
File file = new File(target);
if (file.exists())
IO.delete(file);
File realmPropertiesDest = new File ("target/test-spec-realm.properties");
if (realmPropertiesDest.exists())
IO.delete(realmPropertiesDest);
Resource realmPropertiesSrc = Resource.newResource("src/test/resources/realm.properties");
realmPropertiesSrc.copyTo(realmPropertiesDest);
System.setProperty("jetty.home", "target");
PreconfigureQuickStartWar.main("target/test-spec.war",target, "src/test/resources/test-spec.xml");
Path target = MavenTestingUtils.getTargetPath().resolve("test-spec-preconfigured");
if (Files.exists(target))
{
IO.delete(target.toFile());
}
Files.createDirectories(target.resolve("WEB-INF"));
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 realmPropertiesDest = MavenTestingUtils.getTargetPath().resolve("test-spec-realm.properties");
Files.deleteIfExists(realmPropertiesDest);
Path realmPropertiesSrc = MavenTestingUtils.getTestResourcePath("realm.properties");
Files.copy(realmPropertiesSrc, realmPropertiesDest);
System.setProperty("jetty.home", MavenTestingUtils.getTargetDir().getAbsolutePath());
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));
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;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.InputStream;
import java.net.HttpURLConnection;
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.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO;
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.webapp.WebDescriptor;
import org.eclipse.jetty.xml.XmlConfiguration;
@ -36,6 +37,10 @@ import org.eclipse.jetty.xml.XmlParser.Node;
import org.hamcrest.Matchers;
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
{
@ -89,8 +94,11 @@ public class QuickStartTest
public void testSpecWar() throws Exception
{
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.parse();
Node node = descriptor.getRoot();
@ -99,7 +107,7 @@ public class QuickStartTest
System.setProperty("jetty.home", "target");
//war file or dir to start
String war = "target/test-spec-preconfigured";
String war = "target/test-spec-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test-spec.xml");