Re-enable and fix loginservice tests ee10 (#8683)

This commit is contained in:
Jan Bartel 2022-10-06 07:33:51 +11:00 committed by GitHub
parent 4c74dac122
commit b85f904520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 8 deletions

View File

@ -34,7 +34,6 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mariadb.jdbc.MariaDbDataSource;
import org.testcontainers.junit.jupiter.Testcontainers;
@ -44,7 +43,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* DataSourceLoginServiceTest
*/
@Disabled //TODO needs DefaultServlet
@Testcontainers(disabledWithoutDocker = true)
public class DataSourceLoginServiceTest
{

View File

@ -98,6 +98,26 @@ public class DatabaseLoginServiceTestServer
}
}
public static class ExtendedDefaultServlet extends DefaultServlet
{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
if (resp.getStatus() == HttpServletResponse.SC_OK)
return;
super.doPost(req, resp);
}
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
if (resp.getStatus() == HttpServletResponse.SC_CREATED)
return;
super.doPut(req, resp);
}
}
public static class TestFilter extends HttpFilter
{
private final Path _resourcePath;
@ -119,8 +139,9 @@ public class DatabaseLoginServiceTestServer
OutputStream out = null;
if (req.getMethod().equals("PUT"))
{
Path p = _resourcePath.resolve(URLDecoder.decode(req.getPathInfo(), "utf-8"));
//remove leading slash from pathinfo
Path p = _resourcePath.resolve(URLDecoder.decode(req.getPathInfo().substring(1), "utf-8"));
File file = p.toFile();
FS.ensureDirExists(file.getParentFile());
@ -224,12 +245,12 @@ public class DatabaseLoginServiceTestServer
root.setSecurityHandler(security);
root.setContextPath("/");
root.setBaseResource(_resourceBase);
ServletHolder servletHolder = new ServletHolder(new DefaultServlet());
ServletHolder servletHolder = new ServletHolder(new ExtendedDefaultServlet());
servletHolder.setInitParameter("gzip", "true");
root.addServlet(servletHolder, "/*");
_filter = new TestFilter(_resourceBase);
root.addFilter(_filter, "/", EnumSet.allOf(DispatcherType.class));
root.addFilter(_filter, "/*", EnumSet.allOf(DispatcherType.class));
_server.setHandler(root);
}

View File

@ -39,14 +39,12 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Testcontainers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Disabled //TODO needs DefaultServlet
@Testcontainers(disabledWithoutDocker = true)
public class JdbcLoginServiceTest
{