You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/11/15 21:02:50 UTC

[05/50] git commit: updated refs/heads/ui-restyle to 06ccb84

Add assumtion on OpenJDK for tests that build on JCE

This patch adds an assumption that OpenJDK is used in some of the tests.
OpenJDK detection utility also added. By specifying -Dcloudstack.jce.enabled=true in the test parameters the OpenJDK detection can be overridden.

Signed-off-by: Laszlo Hornyak <la...@gmail.com>


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

Branch: refs/heads/ui-restyle
Commit: f091b6ae1d81a21f7f1c4f8374493598adbd4abb
Parents: 5d41d79
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Tue Nov 12 20:22:44 2013 +0100
Committer: Laszlo Hornyak <la...@gmail.com>
Committed: Tue Nov 12 22:06:12 2013 +0100

----------------------------------------------------------------------
 .../cloudstack/network/lb/CertServiceTest.java  | 76 ++++++++++++++------
 1 file changed, 53 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f091b6ae/server/test/org/apache/cloudstack/network/lb/CertServiceTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/network/lb/CertServiceTest.java b/server/test/org/apache/cloudstack/network/lb/CertServiceTest.java
index 97c8b7b..a37e626 100644
--- a/server/test/org/apache/cloudstack/network/lb/CertServiceTest.java
+++ b/server/test/org/apache/cloudstack/network/lb/CertServiceTest.java
@@ -16,21 +16,13 @@
 // under the License.
 package org.apache.cloudstack.network.lb;
 
-import com.cloud.network.dao.*;
-import com.cloud.user.Account;
-import com.cloud.user.AccountManager;
-import com.cloud.user.AccountVO;
-import com.cloud.user.UserVO;
-import com.cloud.user.dao.AccountDao;
-import com.cloud.utils.db.EntityManager;
-import com.cloud.utils.db.TransactionLegacy;
-import org.apache.cloudstack.api.command.user.loadbalancer.DeleteSslCertCmd;
-import org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd;
-import org.apache.cloudstack.context.CallContext;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
+import static org.apache.commons.io.FileUtils.readFileToString;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
 
 import java.io.File;
 import java.io.IOException;
@@ -40,11 +32,27 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
-import static org.apache.commons.io.FileUtils.readFileToString;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.when;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertTrue;
+import org.apache.cloudstack.api.command.user.loadbalancer.DeleteSslCertCmd;
+import org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.cloud.network.dao.LoadBalancerCertMapDao;
+import com.cloud.network.dao.LoadBalancerCertMapVO;
+import com.cloud.network.dao.LoadBalancerVO;
+import com.cloud.network.dao.SslCertDao;
+import com.cloud.network.dao.SslCertVO;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.UserVO;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.db.EntityManager;
+import com.cloud.utils.db.TransactionLegacy;
 
 public class CertServiceTest {
 
@@ -60,12 +68,30 @@ public class CertServiceTest {
         CallContext.unregister();
     }
 
+    /**
+     * JCE is known to be working fine without additional configuration in OpenJDK.
+     * This checks if the tests are running in OpenJDK;
+     * @return  true if openjdk environment
+     */
+    static boolean isOpenJdk() {
+        //TODO: find a better way for OpenJDK detection
+        return System.getProperty("java.home").toLowerCase().contains("openjdk");
+    }
+
+    /**
+     * One can run the tests on Oracle JDK after installing JCE by specifying -Dcloudstack.jce.enabled=true
+     * @return true if the jce enable property was set to true
+     */
+    static boolean isJCEInstalled() {
+        return Boolean.getBoolean("cloudstack.jce.enabled");
+    }
+    
     @Test
     /**
      * Given a certificate signed by a CA and a valid CA chain, upload should succeed
      */
     public void runUploadSslCertWithCAChain() throws Exception {
-        //To change body of created methods use File | Settings | File Templates.
+        Assume.assumeTrue(isOpenJdk() || isJCEInstalled());
 
         TransactionLegacy txn = TransactionLegacy.open("runUploadSslCertWithCAChain");
 
@@ -218,7 +244,8 @@ public class CertServiceTest {
 
     @Test
     public void runUploadSslCertBadChain()  throws IOException, IllegalAccessException, NoSuchFieldException {
-        //To change body of created methods use File | Settings | File Templates.
+        Assume.assumeTrue(isOpenJdk() || isJCEInstalled());
+
         String certFile  = getClass().getResource("/certs/rsa_ca_signed.crt").getFile();
         String keyFile   = getClass().getResource("/certs/rsa_ca_signed.key").getFile();
         String chainFile = getClass().getResource("/certs/rsa_self_signed.crt").getFile();
@@ -271,7 +298,8 @@ public class CertServiceTest {
     @Test
     public void runUploadSslCertNoRootCert()  throws IOException, IllegalAccessException, NoSuchFieldException {
 
-                //To change body of created methods use File | Settings | File Templates.
+        Assume.assumeTrue(isOpenJdk() || isJCEInstalled());
+
         String certFile  = getClass().getResource("/certs/rsa_ca_signed.crt").getFile();
         String keyFile   = getClass().getResource("/certs/rsa_ca_signed.key").getFile();
         String chainFile = getClass().getResource("/certs/rsa_ca_signed2.crt").getFile();
@@ -325,6 +353,8 @@ public class CertServiceTest {
     @Test
     public void runUploadSslCertNoChain() throws IOException, IllegalAccessException, NoSuchFieldException {
 
+        Assume.assumeTrue(isOpenJdk() || isJCEInstalled());
+        
         String certFile = getClass().getResource("/certs/rsa_ca_signed.crt").getFile();
         String keyFile  = getClass().getResource("/certs/rsa_ca_signed.key").getFile();
         String password = "user";