camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [03/27] git commit: Add https server to tests
Date Tue, 15 Jul 2014 11:39:57 GMT
Add https server to tests


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/31ec7e5b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/31ec7e5b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/31ec7e5b

Branch: refs/heads/master
Commit: 31ec7e5b1dab20bc38b32ae6c70cb36e0723e850
Parents: 2d0cb27
Author: Doug Turnbull <dturnbull@o19s.com>
Authored: Mon Apr 28 16:49:04 2014 -0400
Committer: Doug Turnbull <dturnbull@o19s.com>
Committed: Mon Apr 28 16:49:04 2014 -0400

----------------------------------------------------------------------
 .../camel/component/solr/JettySolrFactory.java  |  66 ++++++++++++++
 .../camel/component/solr/SolrAddBeanTest.java   |   6 +-
 .../solr/SolrComponentTestSupport.java          |  65 ++++++++------
 .../camel/component/solr/SolrDeleteTest.java    |   7 +-
 .../camel/component/solr/SolrFixtures.java      |  87 +++++++++++++++++++
 .../camel/component/solr/SolrTestSupport.java   |   8 +-
 .../component/solr/SolrTransactionsTest.java    |   7 +-
 .../camel/component/solr/SolrUpdateTest.java    |   9 +-
 .../src/test/resources/solrtest.keystore        | Bin 0 -> 2208 bytes
 9 files changed, 222 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/JettySolrFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/JettySolrFactory.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/JettySolrFactory.java
new file mode 100644
index 0000000..7a92837
--- /dev/null
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/JettySolrFactory.java
@@ -0,0 +1,66 @@
+package org.apache.camel.component.solr;
+
+import java.io.File;
+import java.util.SortedMap;
+
+import org.apache.lucene.util.Constants;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.embedded.SSLConfig;
+import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
+import org.eclipse.jetty.servlet.ServletHolder;
+
+// Create embedded's Solrs for testing,
+// based on SolrJettyTestBase
+public class JettySolrFactory {
+
+	public static File TEST_KEYSTORE = new File("./target/test-classes/solrtest.keystore");
+
+	private static String TEST_KEYSTORE_PATH = TEST_KEYSTORE.getAbsolutePath();
+	private static String TEST_KEYSTORE_PASSWORD = "secret";
+	private static HttpClientConfigurer DEFAULT_CONFIGURER = new HttpClientConfigurer();
+
+	private static SSLConfig buildSSLConfig(boolean useSsl,
+			boolean sslClientAuth) {
+		SSLConfig sslConfig = new SSLConfig(useSsl, false,
+				TEST_KEYSTORE_PATH, TEST_KEYSTORE_PASSWORD,
+				TEST_KEYSTORE_PATH, TEST_KEYSTORE_PASSWORD);
+		return sslConfig;
+	}
+
+	private static JettySolrRunner createJetty(String solrHome,
+			String configFile, String schemaFile, String context,
+			boolean stopAtShutdown,
+			SortedMap<ServletHolder, String> extraServlets, boolean ssl) throws Exception {
+		// Set appropriate paths for Solr to use.
+        System.setProperty("solr.solr.home", solrHome);
+        System.setProperty("jetty.testMode", "true");
+        System.setProperty("solr.data.dir", "target/test-classes/solr/data");
+
+        // Instruct Solr to keep the index in memory, for faster testing.
+        System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");
+
+
+		SSLConfig sslConfig = buildSSLConfig(ssl, false); 
+		
+		context = context == null ? "/solr" : context;
+		JettySolrRunner jetty = new JettySolrRunner(solrHome, context, 0, configFile,
+				schemaFile, stopAtShutdown, extraServlets, sslConfig);
+
+		jetty.start();
+		int port = jetty.getLocalPort();
+		return jetty;
+	}
+	
+	public static JettySolrRunner createJettyTestFixture(boolean useSsl) throws Exception {
+		String solrHome ="src/test/resources/solr";
+		String configFile = null;
+		String schemaFile = null;
+		String context = "/solr";
+		boolean stopAtShutdown = true;
+		SortedMap<ServletHolder, String> extraServlets = null;
+		
+		return createJetty(solrHome, configFile, schemaFile, context, stopAtShutdown, extraServlets,
useSsl);
+		
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrAddBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrAddBeanTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrAddBeanTest.java
index 20dd3855..5f06730 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrAddBeanTest.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrAddBeanTest.java
@@ -21,7 +21,11 @@ import org.junit.Test;
 
 public class SolrAddBeanTest extends SolrComponentTestSupport {
 
-    @Test
+    public SolrAddBeanTest(Boolean useHttps) {
+		super(useHttps);
+	}
+
+	@Test
     public void testAddBean() throws Exception {
 
         //add bean

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
index c4b5522..3779621 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrComponentTestSupport.java
@@ -16,29 +16,50 @@
  */
 package org.apache.camel.component.solr;
 
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.SortedMap;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
 import org.apache.solr.client.solrj.impl.HttpSolrServer;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.eclipse.jetty.servlet.ServletHolder;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
+@RunWith(Parameterized.class)
 public class SolrComponentTestSupport extends SolrTestSupport {
-    protected static final String SOLR_ROUTE_URI = "solr://localhost:" + getPort() + "/solr";
     protected static final String TEST_ID = "test1";
     protected static final String TEST_ID2 = "test2";
-    protected static JettySolrRunner solrRunner;
-    protected static HttpSolrServer solrServer;
+   
+    private SolrFixtures solrFixtures;
+   
 
     protected void solrInsertTestEntry() {
         solrInsertTestEntry(TEST_ID);
     }
+    
+    protected static Collection secureOrNot() {
+    	return Arrays.asList(new Object[][] {{true}, {false}});
+    }
+    
+    public SolrComponentTestSupport(Boolean useHttps) {
+    	this.solrFixtures = new SolrFixtures(useHttps);
+    }
+    
+    String solrRouteUri() {
+    	return solrFixtures.solrRouteUri();
+    }
 
     protected void solrInsertTestEntry(String id) {
         Map<String, Object> headers = new HashMap<String, Object>();
@@ -54,30 +75,18 @@ public class SolrComponentTestSupport extends SolrTestSupport {
     protected QueryResponse executeSolrQuery(String query) throws SolrServerException {
         SolrQuery solrQuery = new SolrQuery();
         solrQuery.setQuery(query);
+        SolrServer solrServer = solrFixtures.getServer();
         return solrServer.query(solrQuery);
     }
 
     @BeforeClass
     public static void beforeClass() throws Exception {
-        // Set appropriate paths for Solr to use.
-        System.setProperty("solr.solr.home", "src/test/resources/solr");
-        System.setProperty("solr.data.dir", "target/test-classes/solr/data");
-
-        // Instruct Solr to keep the index in memory, for faster testing.
-        System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");
-
-        // Start a Solr instance.
-        solrRunner = new JettySolrRunner("src/test/resources/solr", "/solr", getPort());
-        solrRunner.start();
-
-        solrServer = new HttpSolrServer("http://localhost:" + getPort() + "/solr");
+        SolrFixtures.createSolrFixtures();
     }
-
+ 
     @AfterClass
     public static void afterClass() throws Exception {
-        if (solrRunner != null) {
-            solrRunner.stop();
-        }
+    	SolrFixtures.teardownSolrFixtures();
     }
 
     @Override
@@ -85,23 +94,25 @@ public class SolrComponentTestSupport extends SolrTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to(SOLR_ROUTE_URI);
+                from("direct:start").to(solrRouteUri());
                 from("direct:splitThenCommit")
                     .split(body())
-                        .to(SOLR_ROUTE_URI)
+                        .to(solrRouteUri())
                     .end()
                     .setHeader(SolrConstants.OPERATION, constant(SolrConstants.OPERATION_COMMIT))
-                    .to(SOLR_ROUTE_URI);
+                    .to(solrRouteUri());
             }
         };
     }
+    
+    @Parameters
+    public static Collection<Object[]> serverTypes() {
+    	Object[][] serverTypes = {{true}, {false}};
+    	return Arrays.asList(serverTypes);
+    }
 
     @Before
     public void clearIndex() throws Exception {
-        if (solrServer != null) {
-            // Clear the Solr index.
-            solrServer.deleteByQuery("*:*");
-            solrServer.commit();
-        }
+    	solrFixtures.clearIndex();	
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrDeleteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrDeleteTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrDeleteTest.java
index de5dd4b..4ad80ff 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrDeleteTest.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrDeleteTest.java
@@ -21,7 +21,12 @@ import org.junit.Test;
 
 public class SolrDeleteTest extends SolrComponentTestSupport {
 
-    @Test
+    public SolrDeleteTest(Boolean useHttps) {
+		super(useHttps);
+		// TODO Auto-generated constructor stub
+	}
+
+	@Test
     public void testDeleteById() throws Exception {
 
         //insert, commit and verify

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrFixtures.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrFixtures.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrFixtures.java
new file mode 100644
index 0000000..64cfb77
--- /dev/null
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrFixtures.java
@@ -0,0 +1,87 @@
+package org.apache.camel.component.solr;
+import java.io.IOException;
+
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.log4j.Logger;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.HttpSolrServer;;
+
+public class SolrFixtures {
+	static Logger log = Logger.getLogger(SolrFixtures.class);
+	
+    private static JettySolrRunner solrRunner;
+    private static JettySolrRunner solrHttpsRunner;
+    private static HttpSolrServer solrServer;
+    private static HttpSolrServer solrHttpsServer;
+    boolean useHttps;
+    
+	private static int port;
+	private static int httpsPort;
+
+    SolrFixtures(boolean useHttps) {
+    	this.useHttps = useHttps;
+    }
+    
+    String solrRouteUri() {
+		if (useHttps) {
+			return "solrs://localhost:" + httpsPort + "/solr";
+		} else {
+			return "solr://localhost:" + port + "/solr";
+		}
+    }
+    
+    SolrServer getServer() {
+    	if (useHttps) {
+    		return this.solrHttpsServer;
+    	} else {
+    		return this.solrServer;
+    	}
+    }
+    
+    static void createSolrFixtures() throws Exception {
+    	solrHttpsRunner = JettySolrFactory.createJettyTestFixture(true);
+    	httpsPort = solrHttpsRunner.getLocalPort();
+    	log.info("Started Https Test Server: " + solrHttpsRunner.getBaseUrl());;
+    	
+    	solrRunner = JettySolrFactory.createJettyTestFixture(false);
+    	port = solrRunner.getLocalPort();
+    	
+    	log.info("Started Test Server: " + solrRunner.getBaseUrl());
+
+    }
+    
+    public static void teardownSolrFixtures() throws Exception {
+        if (solrRunner != null) {
+            solrRunner.stop();
+        }
+        if (solrHttpsRunner != null) {
+            solrHttpsRunner.stop();
+        }
+    }
+    
+    public void clearFixtures() throws SolrServerException, IOException {
+    	 if (solrServer != null) {
+             // Clear the Solr index.
+             solrServer.deleteByQuery("*:*");
+             solrServer.commit();
+         }
+         if (solrHttpsServer != null) {
+         	solrHttpsServer.deleteByQuery("*:*");
+         	solrHttpsServer.commit();
+         }
+    }
+    
+    public void clearIndex() throws SolrServerException, IOException {
+    	 if (solrServer != null) {
+             // Clear the Solr index.
+             solrServer.deleteByQuery("*:*");
+             solrServer.commit();
+         }
+         if (solrHttpsServer != null) {
+         	solrHttpsServer.deleteByQuery("*:*");
+         	solrHttpsServer.commit();
+         }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
index 5d7b120..58e0800 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTestSupport.java
@@ -23,15 +23,21 @@ import org.junit.BeforeClass;
 
 public abstract class SolrTestSupport extends CamelTestSupport {
 
-    private static int port;
+	private static int port;
+	private static int httpsPort;
 
     @BeforeClass
     public static void initPort() throws Exception {
         port = AvailablePortFinder.getNextAvailable(8999);
+        httpsPort = AvailablePortFinder.getNextAvailable(8999);
     }
 
     protected static int getPort() {
         return port;
     }
+    
+    protected static int getHttpsPort() {
+        return httpsPort;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTransactionsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTransactionsTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTransactionsTest.java
index 0284fc9..3927bea 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTransactionsTest.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrTransactionsTest.java
@@ -20,7 +20,12 @@ import org.junit.Test;
 
 public class SolrTransactionsTest extends SolrComponentTestSupport {
 
-    @Test
+    public SolrTransactionsTest(Boolean useHttps) {
+		super(useHttps);
+		// TODO Auto-generated constructor stub
+	}
+
+	@Test
     public void testCommit() throws Exception {
 
         //insert and verify

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
index a4111c6..73027d0 100644
--- a/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
+++ b/components/camel-solr/src/test/java/org/apache/camel/component/solr/SolrUpdateTest.java
@@ -31,13 +31,18 @@ import org.junit.Test;
 
 public class SolrUpdateTest extends SolrComponentTestSupport {
 
-    private SolrEndpoint solrEndpoint;
+    public SolrUpdateTest(Boolean useHttps) {
+		super(useHttps);
+		// TODO Auto-generated constructor stub
+	}
+
+	private SolrEndpoint solrEndpoint;
 
     @Override
     @Before
     public void setUp() throws Exception {
         super.setUp();
-        solrEndpoint = getMandatoryEndpoint(SOLR_ROUTE_URI, SolrEndpoint.class);
+        solrEndpoint = getMandatoryEndpoint(solrRouteUri(), SolrEndpoint.class);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/camel/blob/31ec7e5b/components/camel-solr/src/test/resources/solrtest.keystore
----------------------------------------------------------------------
diff --git a/components/camel-solr/src/test/resources/solrtest.keystore b/components/camel-solr/src/test/resources/solrtest.keystore
new file mode 100644
index 0000000..bcc6ec0
Binary files /dev/null and b/components/camel-solr/src/test/resources/solrtest.keystore differ


Mime
View raw message