You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2011/11/21 17:40:26 UTC
svn commit: r1204584 - in
/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2:
provider/http/test/HttpProviderTestCase.java
provider/http/test/NHttpServer.java
provider/url/test/UrlProviderHttpTestCase.java util/NHttpServer.java
Author: ggregory
Date: Mon Nov 21 16:40:25 2011
New Revision: 1204584
URL: http://svn.apache.org/viewvc?rev=1204584&view=rev
Log:
[VFS-391] Build tests URL HTTP file system with an embedded HTTP server (Apache HttpComponent Core). Move NHttpServer to the test util package.
Added:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/NHttpServer.java (contents, props changed)
- copied, changed from r1203678, commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/NHttpServer.java
Removed:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/NHttpServer.java
Modified:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java?rev=1204584&r1=1204583&r2=1204584&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpProviderTestCase.java Mon Nov 21 16:40:25 2011
@@ -27,6 +27,7 @@ import org.apache.commons.vfs2.provider.
import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
import org.apache.commons.vfs2.test.ProviderTestSuite;
import org.apache.commons.vfs2.util.FreeSocketPortUtil;
+import org.apache.commons.vfs2.util.NHttpServer;
/**
* Test cases for the HTTP provider.
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java?rev=1204584&r1=1204583&r2=1204584&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/url/test/UrlProviderHttpTestCase.java Mon Nov 21 16:40:25 2011
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2.provider.url.test;
+import java.io.IOException;
+
import junit.framework.Test;
import org.apache.commons.vfs2.FileObject;
@@ -24,47 +26,109 @@ import org.apache.commons.vfs2.impl.Defa
import org.apache.commons.vfs2.provider.url.UrlFileProvider;
import org.apache.commons.vfs2.test.AbstractProviderTestConfig;
import org.apache.commons.vfs2.test.ProviderTestSuite;
+import org.apache.commons.vfs2.util.FreeSocketPortUtil;
+import org.apache.commons.vfs2.util.NHttpServer;
/**
* Test cases for HTTP with the default provider.
- *
+ *
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
*/
-public class UrlProviderHttpTestCase
- extends AbstractProviderTestConfig
+public class UrlProviderHttpTestCase extends AbstractProviderTestConfig
{
+ private static NHttpServer Server;
+
+ private static int SocketPort;
+
private static final String TEST_URI = "test.http.uri";
- public static Test suite() throws Exception
+ /**
+ * Use %40 for @ in URLs
+ */
+ private static String ConnectionUri;
+
+ private static String getSystemTestUriOverride()
+ {
+ return System.getProperty(TEST_URI);
+ }
+
+ /**
+ * Creates and starts an embedded Apache HTTP Server ().
+ *
+ * @throws Exception
+ */
+ private static void setUpClass() throws Exception
{
- if (System.getProperty(TEST_URI) != null)
+ Server = new NHttpServer();
+ if (!Server.run(SocketPort, getTestDirectory(), 5000))
{
- return new ProviderTestSuite(new UrlProviderTestCase());
+ throw new IllegalStateException("The embedded HTTP server has not completed startup, increase wait time");
}
- else
+ }
+
+ public static Test suite() throws Exception
+ {
+ return new ProviderTestSuite(new UrlProviderHttpTestCase())
{
- return notConfigured(UrlProviderHttpTestCase.class);
- }
+ @Override
+ protected void setUp() throws Exception
+ {
+ if (getSystemTestUriOverride() == null)
+ {
+ setUpClass();
+ }
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ tearDownClass();
+ super.tearDown();
+ }
+ };
}
/**
- * Prepares the file system manager.
+ * Stops the embedded Apache HTTP Server ().
+ *
+ * @throws IOException
*/
- @Override
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
+ private static void tearDownClass() throws IOException
{
- manager.addProvider("http", new UrlFileProvider());
+ if (Server != null)
+ {
+ Server.stop();
+ }
+ }
+
+ public UrlProviderHttpTestCase() throws IOException
+ {
+ SocketPort = FreeSocketPortUtil.findFreeLocalPort();
+ // Use %40 for @ in the a URL a @
+ ConnectionUri = "http://localhost:" + SocketPort;
}
/**
* Returns the base folder for tests.
*/
@Override
- public FileObject getBaseTestFolder(final FileSystemManager manager)
- throws Exception
+ public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
{
- final String uri = System.getProperty(TEST_URI);
+ String uri = getSystemTestUriOverride();
+ if (uri == null)
+ {
+ uri = ConnectionUri;
+ }
return manager.resolveFile(uri);
}
+
+ /**
+ * Prepares the file system manager.
+ */
+ @Override
+ public void prepare(final DefaultFileSystemManager manager) throws Exception
+ {
+ manager.addProvider("http", new UrlFileProvider());
+ }
}
Copied: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/NHttpServer.java (from r1203678, commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/NHttpServer.java)
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/NHttpServer.java?p2=commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/NHttpServer.java&p1=commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/NHttpServer.java&r1=1203678&r2=1204584&rev=1204584&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/http/test/NHttpServer.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/NHttpServer.java Mon Nov 21 16:40:25 2011
@@ -24,7 +24,7 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.commons.vfs2.provider.http.test;
+package org.apache.commons.vfs2.util;
import java.io.File;
import java.io.IOException;
@@ -87,7 +87,7 @@ import org.apache.http.util.EntityUtils;
* efficient way of building an HTTP server.
* </p>
*
- * @version $Id: $
+ * @version $Id$
* @since 2.1
*/
public class NHttpServer
@@ -296,6 +296,8 @@ public class NHttpServer
} catch (IOException e)
{
// ignore
+ // System.out.println("While waiting: " + e);
+ // e.printStackTrace();
}
Thread.sleep(100);
}
Propchange: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/util/NHttpServer.java
------------------------------------------------------------------------------
svn:keywords = Id