You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/07/26 07:02:43 UTC
[25/27] james-project git commit: JAMES-2481 Replace Spark by Jetty
in tests
JAMES-2481 Replace Spark by Jetty in tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2f3aaaeb
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2f3aaaeb
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2f3aaaeb
Branch: refs/heads/master
Commit: 2f3aaaeb83046c68058ff37fb5c380863c461da6
Parents: aaa2d08
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed Jul 25 13:21:13 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 26 13:51:07 2018 +0700
----------------------------------------------------------------------
server/container/core/pom.xml | 20 +++++--
server/container/filesystem-api/pom.xml | 19 +++++-
.../filesystem/api/AbstractFileSystemTest.java | 63 ++++++++++++++------
server/container/spring/pom.xml | 5 --
4 files changed, 77 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/2f3aaaeb/server/container/core/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/core/pom.xml b/server/container/core/pom.xml
index 6f64917..4771b55 100644
--- a/server/container/core/pom.xml
+++ b/server/container/core/pom.xml
@@ -82,11 +82,6 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
- <groupId>com.sparkjava</groupId>
- <artifactId>spark-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
@@ -109,6 +104,21 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2f3aaaeb/server/container/filesystem-api/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/filesystem-api/pom.xml b/server/container/filesystem-api/pom.xml
index 225ff0d..e92f358 100644
--- a/server/container/filesystem-api/pom.xml
+++ b/server/container/filesystem-api/pom.xml
@@ -34,8 +34,8 @@
<dependencies>
<dependency>
- <groupId>com.sparkjava</groupId>
- <artifactId>spark-core</artifactId>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -57,6 +57,21 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/2f3aaaeb/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
----------------------------------------------------------------------
diff --git a/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java b/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
index cc9f420..e8d2c54 100644
--- a/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
+++ b/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
@@ -27,8 +27,17 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -36,11 +45,10 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
+import com.google.common.base.Strings;
+
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
-import spark.Request;
-import spark.Response;
-import spark.Service;
@RunWith(JUnitParamsRunner.class)
public abstract class AbstractFileSystemTest {
@@ -54,24 +62,47 @@ public abstract class AbstractFileSystemTest {
protected FileSystem fileSystem;
- private Service httpServer;
+ private Server httpServer;
private File rootDirectory;
protected abstract FileSystem buildFileSystem(String configurationRootDirectory);
@Before
public void setUp() throws Exception {
- httpServer = Service.ignite().port(RANDOM_PORT);
- httpServer.get("/", (Request request, Response response) -> "content");
- httpServer.awaitInitialization();
-
+ httpServer = new Server(RANDOM_PORT);
+
+ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ context.setContextPath("/");
+ httpServer.setHandler(context);
+ context.addServlet(new ServletHolder(new ContentServlet()), "/*");
+
+ httpServer.start();
+
rootDirectory = tmpFolder.getRoot();
createSubFolderWithAFileIn("conf", "conf.txt", "confcontent");
createSubFolderWithAFileIn("var", "var.txt", "varcontent");
-
+
fileSystem = buildFileSystem(rootDirectory.getAbsolutePath());
}
+ private static class ContentServlet extends HttpServlet {
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ if (isRootPath(request.getPathInfo())) {
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().println("content");
+ } else {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
+ }
+
+ private boolean isRootPath(String pathInfo) {
+ return Strings.isNullOrEmpty(pathInfo)
+ || pathInfo == "/";
+ }
+ }
+
private void createSubFolderWithAFileIn(String folderName, String fileName, String fileContent) throws IOException {
File folder = tmpFolder.newFolder(folderName);
File file = new File(folder.getAbsolutePath() + "/" + fileName);
@@ -127,9 +158,7 @@ public abstract class AbstractFileSystemTest {
@Test(expected = FileNotFoundException.class)
@Parameters(source = UrlsAsFileThrowingFileNotFoundExceptionProvider.class)
public final void urlAsFileThrowingFileNotFoundException(String url) throws Exception {
- url = replacePort(url);
-
- fileSystem.getFile(url);
+ fileSystem.getFile(replacePort(url));
}
public static class NonExistingFilesProvider {
@@ -163,9 +192,7 @@ public abstract class AbstractFileSystemTest {
@Test(expected = FileNotFoundException.class)
@Parameters(source = NonAvailableStreamsProvider.class)
public final void getFakeHttpResourceAsInputStreamShouldThrow(String url) throws Exception {
- url = replacePort(url);
-
- fileSystem.getResource(url);
+ fileSystem.getResource(replacePort(url));
}
public static class AvailableStreamsProvider {
@@ -184,14 +211,14 @@ public abstract class AbstractFileSystemTest {
@Test
@Parameters(source = AvailableStreamsProvider.class)
public final void availableInputStreamShouldReturnANonEmptyStream(String url) throws Exception {
- url = replacePort(url);
- try (InputStream inputStream = fileSystem.getResource(url)) {
+ try (InputStream inputStream = fileSystem.getResource(replacePort(url))) {
assertThat(IOUtils.toByteArray(inputStream).length).isGreaterThan(0);
}
}
private String replacePort(String url) {
- return url.replace("$PORT$", String.valueOf(httpServer.port()));
+ int port = ((ServerConnector) httpServer.getConnectors()[0]).getLocalPort();
+ return url.replace("$PORT$", String.valueOf(port));
}
public static class FileToCreateProvider {
http://git-wip-us.apache.org/repos/asf/james-project/blob/2f3aaaeb/server/container/spring/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/pom.xml b/server/container/spring/pom.xml
index 61c2213..3fbf7e6 100644
--- a/server/container/spring/pom.xml
+++ b/server/container/spring/pom.xml
@@ -80,11 +80,6 @@
<artifactId>james-server-protocols-library</artifactId>
</dependency>
<dependency>
- <groupId>com.sparkjava</groupId>
- <artifactId>spark-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org