Better cleanup of LoginService tests

This commit is contained in:
Joakim Erdfelt 2014-07-17 20:55:58 -07:00
parent dcee2bd5c4
commit a09d05ee9d
2 changed files with 10 additions and 17 deletions

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty; package org.eclipse.jetty;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.File; import java.io.File;
@ -27,6 +28,7 @@ import java.net.URI;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.Statement; import java.sql.Statement;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -76,9 +78,6 @@ public class DataSourceLoginServiceTest
System.setProperty("derby.system.home", dbPath); System.setProperty("derby.system.home", dbPath);
FS.ensureEmpty(_dbRoot); FS.ensureEmpty(_dbRoot);
File dstest = new File(_dbRoot, "dstest");
FS.ensureEmpty(dstest);
File scriptFile = MavenTestingUtils.getTestResourceFile("createdb.sql"); File scriptFile = MavenTestingUtils.getTestResourceFile("createdb.sql");
DatabaseLoginServiceTestServer.createDB(dbPath, scriptFile, "jdbc:derby:dstest;create=true"); DatabaseLoginServiceTestServer.createDB(dbPath, scriptFile, "jdbc:derby:dstest;create=true");
@ -125,7 +124,7 @@ public class DataSourceLoginServiceTest
ds.setDatabaseName(db.getAbsolutePath()); ds.setDatabaseName(db.getAbsolutePath());
org.eclipse.jetty.plus.jndi.Resource binding = new org.eclipse.jetty.plus.jndi.Resource(null, "dstest", org.eclipse.jetty.plus.jndi.Resource binding = new org.eclipse.jetty.plus.jndi.Resource(null, "dstest",
ds); ds);
assertThat("Created binding for dstest", binding, notNullValue());
return loginService; return loginService;
} }
@ -145,7 +144,7 @@ public class DataSourceLoginServiceTest
String newpwd = String.valueOf(System.currentTimeMillis()); String newpwd = String.valueOf(System.currentTimeMillis());
changePassword("jetty", newpwd); changePassword("jetty", newpwd);
Thread.currentThread().sleep(2*__cacheInterval); //pause to ensure cache invalidates TimeUnit.MILLISECONDS.sleep(2*__cacheInterval); //pause to ensure cache invalidates
startClient("jetty", newpwd); startClient("jetty", newpwd);

View File

@ -19,6 +19,9 @@
package org.eclipse.jetty; package org.eclipse.jetty;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -44,7 +47,6 @@ import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.security.authentication.BasicAuthenticator; import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection;
@ -54,8 +56,6 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.security.Constraint; import org.eclipse.jetty.util.security.Constraint;
@ -64,7 +64,6 @@ import org.eclipse.jetty.util.security.Constraint;
*/ */
public class DatabaseLoginServiceTestServer public class DatabaseLoginServiceTestServer
{ {
private static final Logger LOG = Log.getLogger(DatabaseLoginServiceTestServer.class);
protected Server _server; protected Server _server;
protected static String _protocol; protected static String _protocol;
protected static URI _baseUri; protected static URI _baseUri;
@ -73,7 +72,7 @@ public class DatabaseLoginServiceTestServer
protected TestHandler _handler; protected TestHandler _handler;
protected static String _requestContent; protected static String _requestContent;
protected static boolean createDB(String homeDir, File scriptFile, String dbUrl) protected static void createDB(String homeDir, File scriptFile, String dbUrl) throws Exception
{ {
try (FileInputStream fileStream = new FileInputStream(scriptFile)) try (FileInputStream fileStream = new FileInputStream(scriptFile))
{ {
@ -83,12 +82,7 @@ public class DatabaseLoginServiceTestServer
OutputStream out = new ByteArrayOutputStream(); OutputStream out = new ByteArrayOutputStream();
int result = ij.runScript(connection, fileStream, "UTF-8", out, "UTF-8"); int result = ij.runScript(connection, fileStream, "UTF-8", out, "UTF-8");
return (result==0); assertThat("runScript result",result, is(0));
}
catch (Exception e)
{
LOG.warn("Unable to create EmbeddedDriver",e);
return false;
} }
} }
@ -118,7 +112,7 @@ public class DatabaseLoginServiceTestServer
{ {
baseRequest.setHandled(true); baseRequest.setHandled(true);
File file = new File(_resourcePath, URLDecoder.decode(request.getPathInfo())); File file = new File(_resourcePath, URLDecoder.decode(request.getPathInfo(), "utf-8"));
FS.ensureDirExists(file.getParentFile()); FS.ensureDirExists(file.getParentFile());
out = new FileOutputStream(file); out = new FileOutputStream(file);