mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
tests: fixed and improved downloader tests
This commit is contained in:
parent
2aa64f252c
commit
960c26a291
1 changed files with 19 additions and 4 deletions
|
|
@ -16,20 +16,35 @@ public class DownloaderTest {
|
|||
|
||||
@Test
|
||||
public void test_DownloadText_ByHttp() {
|
||||
String s = XmageURLConnection.downloadText("http://google.com");
|
||||
String s = XmageURLConnection.downloadText("http://example.com");
|
||||
Assert.assertTrue("must have text data", s.contains("<head>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_DownloadText_ByHttps() {
|
||||
String s = XmageURLConnection.downloadText("https://google.com");
|
||||
String s = XmageURLConnection.downloadText("https://example.com");
|
||||
Assert.assertTrue("must have text data", s.contains("<head>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_DownloadText_ByRedirectProtocol() {
|
||||
// http to https restricted by design, see https://stackoverflow.com/a/1884427/1276632
|
||||
// it's not critical for a client (e.g. for images download), so no needs in custom implementation
|
||||
// like xmage launcher does
|
||||
String s = XmageURLConnection.downloadText("http://github.com");
|
||||
Assert.assertTrue("must have fail on https redirect (301 result)", s.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_DownloadText_ByRedirectUri() {
|
||||
String s = XmageURLConnection.downloadText("https://github.com/magefree/mage/issues/new");
|
||||
Assert.assertTrue("must have text data (redirect to login page)", s.contains("Sign in to GitHub"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_DownloadFile_ByHttp() throws IOException {
|
||||
// use any public image here
|
||||
InputStream stream = XmageURLConnection.downloadBinary("http://www.google.com/tia/tia.png");
|
||||
InputStream stream = XmageURLConnection.downloadBinary("http://xmage.today/images/xmage-logo.png");
|
||||
Assert.assertNotNull(stream);
|
||||
BufferedImage image = ImageIO.read(stream);
|
||||
Assert.assertNotNull(stream);
|
||||
|
|
@ -39,7 +54,7 @@ public class DownloaderTest {
|
|||
@Test
|
||||
public void test_DownloadFile_ByHttps() throws IOException {
|
||||
// use any public image here
|
||||
InputStream stream = XmageURLConnection.downloadBinary("https://www.google.com/tia/tia.png");
|
||||
InputStream stream = XmageURLConnection.downloadBinary("https://xmage.today/images/xmage-logo.png");
|
||||
Assert.assertNotNull(stream);
|
||||
BufferedImage image = ImageIO.read(stream);
|
||||
Assert.assertNotNull(stream);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue