Adding missing tests post-merge

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-09-28 17:58:57 -05:00
parent 3c7cd43148
commit 1f2ccda056
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
2 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,96 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.demos;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
/**
* Test the configuration found in WEB-INF/web.xml for purposes of the demo-base
*/
public class ProxyWebAppTest
{
private Server server;
private HttpClient client;
@BeforeEach
public void setup() throws Exception
{
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
WebAppContext webapp = new WebAppContext();
// This is a pieced together WebApp.
// We don't have a valid WEB-INF/lib to rely on at this point.
// So, open up server classes here, for purposes of this testcase.
webapp.getServerClassMatcher().add("-org.eclipse.jetty.proxy.");
webapp.setWar(MavenTestingUtils.getProjectDirPath("src/main/webapp").toString());
webapp.setExtraClasspath(MavenTestingUtils.getTargetPath().resolve("classes").toString());
server.setHandler(webapp);
server.start();
client = new HttpClient();
client.start();
}
@AfterEach
public void teardown()
{
LifeCycle.stop(client);
LifeCycle.stop(server);
}
@Test
@Tag("external")
public void testProxyRequest() throws InterruptedException, ExecutionException, TimeoutException
{
ContentResponse response = client.newRequest(server.getURI().resolve("/proxy/current/"))
.followRedirects(false)
.send();
// Expecting a 200 OK (not a 302 redirect or other error)
// If we got an error here, that means our configuration in web.xml is bad / out of date.
// Such as the redirect from the eclipse website, we want all of the requests to go through
// this proxy configuration, not redirected to the actual website.
assertThat("response status", response.getStatus(), is(HttpStatus.OK_200));
// Expecting a Javadoc / APIDoc response - look for something unique for APIdoc.
assertThat("response", response.getContentAsString(), containsString("All&nbsp;Classes"));
}
}

View File

@ -0,0 +1,5 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
#org.eclipse.jetty.LEVEL=WARN
#org.eclipse.jetty.client.LEVEL=DEBUG
#org.eclipse.jetty.http.LEVEL=DEBUG
#org.eclipse.jetty.proxy.LEVEL=DEBUG