Skip to content

Commit 960c26a

Browse files
committed
tests: fixed and improved downloader tests
1 parent 2aa64f2 commit 960c26a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Mage.Client/src/test/java/mage/client/util/DownloaderTest.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,35 @@ public class DownloaderTest {
1616

1717
@Test
1818
public void test_DownloadText_ByHttp() {
19-
String s = XmageURLConnection.downloadText("http://google.com");
19+
String s = XmageURLConnection.downloadText("http://example.com");
2020
Assert.assertTrue("must have text data", s.contains("<head>"));
2121
}
2222

2323
@Test
2424
public void test_DownloadText_ByHttps() {
25-
String s = XmageURLConnection.downloadText("https://google.com");
25+
String s = XmageURLConnection.downloadText("https://example.com");
2626
Assert.assertTrue("must have text data", s.contains("<head>"));
2727
}
2828

29+
@Test
30+
public void test_DownloadText_ByRedirectProtocol() {
31+
// http to https restricted by design, see https://stackoverflow.com/a/1884427/1276632
32+
// it's not critical for a client (e.g. for images download), so no needs in custom implementation
33+
// like xmage launcher does
34+
String s = XmageURLConnection.downloadText("http://github.com");
35+
Assert.assertTrue("must have fail on https redirect (301 result)", s.isEmpty());
36+
}
37+
38+
@Test
39+
public void test_DownloadText_ByRedirectUri() {
40+
String s = XmageURLConnection.downloadText("https://github.com/magefree/mage/issues/new");
41+
Assert.assertTrue("must have text data (redirect to login page)", s.contains("Sign in to GitHub"));
42+
}
43+
2944
@Test
3045
public void test_DownloadFile_ByHttp() throws IOException {
3146
// use any public image here
32-
InputStream stream = XmageURLConnection.downloadBinary("http://www.google.com/tia/tia.png");
47+
InputStream stream = XmageURLConnection.downloadBinary("http://xmage.today/images/xmage-logo.png");
3348
Assert.assertNotNull(stream);
3449
BufferedImage image = ImageIO.read(stream);
3550
Assert.assertNotNull(stream);
@@ -39,7 +54,7 @@ public void test_DownloadFile_ByHttp() throws IOException {
3954
@Test
4055
public void test_DownloadFile_ByHttps() throws IOException {
4156
// use any public image here
42-
InputStream stream = XmageURLConnection.downloadBinary("https://www.google.com/tia/tia.png");
57+
InputStream stream = XmageURLConnection.downloadBinary("https://xmage.today/images/xmage-logo.png");
4358
Assert.assertNotNull(stream);
4459
BufferedImage image = ImageIO.read(stream);
4560
Assert.assertNotNull(stream);

0 commit comments

Comments
 (0)