|
@@ -17,25 +17,43 @@
|
|
|
*/
|
|
|
package org.apache.ambari.server.upgrade;
|
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.UnknownHostException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.powermock.api.easymock.PowerMock;
|
|
|
+import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
+import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
+import static org.easymock.EasyMock.expect;
|
|
|
import static org.junit.Assert.*;
|
|
|
+import static org.powermock.api.easymock.PowerMock.replayAll;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @author root
|
|
|
*/
|
|
|
+@RunWith(PowerMockRunner.class)
|
|
|
+@PrepareForTest({StackUpgradeHelper.class})
|
|
|
public class StackUpgradeHelperTest {
|
|
|
|
|
|
public StackUpgradeHelperTest() {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testUpdateStackVersion() {
|
|
|
+ public void testUpdateStackVersion() throws Exception {
|
|
|
System.out.println("updateStackVersion");
|
|
|
+ String repoUrl="http://foo.bar";
|
|
|
+ String fullUrl=repoUrl+"/repodata/repomd.xml";
|
|
|
+ URL url = PowerMock.createMockAndExpectNew(URL.class, fullUrl);
|
|
|
+ HttpURLConnection urlConnectionMock = PowerMock.createNiceMock(HttpURLConnection.class);
|
|
|
+ expect(url.openConnection()).andReturn(urlConnectionMock);
|
|
|
+ expect(urlConnectionMock.getResponseCode()).andThrow(new UnknownHostException(fullUrl));
|
|
|
+ PowerMock.replayAll();
|
|
|
Map<String, String> stackInfo = new HashMap<String, String>();
|
|
|
- stackInfo.put("repo_url", "http://foo.bar");
|
|
|
+ stackInfo.put("repo_url", repoUrl);
|
|
|
stackInfo.put("repo_url_os", "centos6");
|
|
|
stackInfo.put("HDP", "1.3.0");
|
|
|
StackUpgradeHelper instance = new StackUpgradeHelper();
|
|
@@ -43,7 +61,7 @@ public class StackUpgradeHelperTest {
|
|
|
instance.updateStackVersion(stackInfo);
|
|
|
} catch (Exception ex) {
|
|
|
assertEquals("UnknownHostException, Responce: 0, "
|
|
|
- + "during check URL: http://foo.bar/repodata/repomd.xml", ex.getMessage());
|
|
|
+ + "during check URL: " + fullUrl, ex.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|