You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ds...@apache.org on 2016/04/18 11:30:04 UTC

ambari git commit: AMBARI-15841 testUpdateRepoUrlController unit test fails (dsen)

Repository: ambari
Updated Branches:
  refs/heads/trunk 10cda6ed6 -> a788b3517


AMBARI-15841 testUpdateRepoUrlController unit test fails (dsen)


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

Branch: refs/heads/trunk
Commit: a788b3517f3508a0d9dc39bcd0bd3a1785b8cba8
Parents: 10cda6e
Author: Dmytro Sen <ds...@apache.org>
Authored: Mon Apr 18 12:29:21 2016 +0300
Committer: Dmytro Sen <ds...@apache.org>
Committed: Mon Apr 18 12:29:43 2016 +0300

----------------------------------------------------------------------
 .../AmbariManagementControllerImpl.java         |  8 +++++--
 .../AmbariManagementControllerTest.java         | 23 +++++++++++++++++---
 2 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a788b351/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index c38a236..58bab59 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -41,6 +41,7 @@ import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_LIST
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.VERSION;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.lang.reflect.Type;
@@ -3902,6 +3903,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     String repoName = repositoryInfo.getRepoName();
 
     String errorMessage = null;
+    Exception e = null;
 
     String[] suffixes = configs.getRepoValidationSuffixes(request.getOsType());
     for (String suffix : suffixes) {
@@ -3926,6 +3928,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
         File f = new File(filePath);
         if(!f.exists()){
           errorMessage = "Could not access base url . " + spec + " . ";
+          e = new FileNotFoundException(errorMessage);
           break;
         }
 
@@ -3933,6 +3936,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
         try {
           IOUtils.readLines(usp.readFrom(spec));
         } catch (IOException ioe) {
+          e = ioe;
           errorMessage = "Could not access base url . " + request.getBaseUrl() + " . ";
           if (LOG.isDebugEnabled()) {
             errorMessage += ioe;
@@ -3944,9 +3948,9 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       }
     }
 
-    if (errorMessage != null) {
+    if (e != null) {
       LOG.error(errorMessage);
-      throw new IllegalArgumentException(errorMessage);
+      throw new IllegalArgumentException(errorMessage, e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a788b351/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 5e38920..4ab9099 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -36,6 +36,7 @@ import static org.junit.Assert.fail;
 
 import java.io.StringReader;
 import java.lang.reflect.Type;
+import java.net.UnknownHostException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -48,6 +49,9 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
 import javax.persistence.EntityManager;
 
 import org.apache.ambari.server.AmbariException;
@@ -157,6 +161,7 @@ import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.powermock.api.mockito.PowerMockito;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -8495,7 +8500,7 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testUpdateRepoUrlController() throws Exception {
-    String badUrl = "http://hortonworks.com";
+    String badUrl = "http://some_custom.url";
     RepositoryInfo repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
     RepositoryRequest request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
     request.setBaseUrl(badUrl);
@@ -8518,11 +8523,23 @@ public class AmbariManagementControllerTest {
 
     requests.clear();
     request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
-    request.setBaseUrl("https://hortonworks.com");
+    request.setBaseUrl("https://some_custom.url");
     request.setVerifyBaseUrl(false);
     requests.add(request);
+    HostnameVerifier defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
+    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
+      public boolean verify(String hostName, SSLSession session) {
+        return true;
+      }
+    });
     // test https url
-    controller.updateRepositories(requests);
+    try {
+      controller.updateRepositories(requests);
+    } catch(Exception e) {
+      // verification passed, but unable to connect to https://some_custom.url
+      assertTrue(e.getCause() instanceof UnknownHostException);
+    }
+    HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
 
     requests.clear();
     request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);