-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
FileDownloadITest.java
91 lines (73 loc) · 3.78 KB
/
FileDownloadITest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.restassured.itest.java;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.itest.java.support.WithJetty;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.WriterOutputStream;
import org.junit.Ignore;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.StringWriter;
import static io.restassured.RestAssured.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
// TODO Fix test!!
@Ignore("Temporary ignored since the remote zip file (powermock) is no longer downloadable")
public class FileDownloadITest extends WithJetty {
@Test
public void canDownloadLargeFiles() throws Exception {
int expectedSize = IOUtils.toByteArray(getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip")).length;
final InputStream inputStream = expect().log().headers().when().get("http://powermock.googlecode.com/files/powermock-easymock-junit-1.4.12.zip").asInputStream();
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, byteArrayOutputStream);
IOUtils.closeQuietly(byteArrayOutputStream);
IOUtils.closeQuietly(inputStream);
assertThat(byteArrayOutputStream.size(), equalTo(expectedSize));
}
@Test
public void canDownloadLargeFilesWhenLoggingIfValidationFailsIsEnabled() throws Exception {
int expectedSize = IOUtils.toByteArray(getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip")).length;
final InputStream inputStream = when().get("http://powermock.googlecode.com/files/powermock-easymock-junit-1.4.12.zip").then().log().ifValidationFails().extract().asInputStream();
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, byteArrayOutputStream);
IOUtils.closeQuietly(byteArrayOutputStream);
IOUtils.closeQuietly(inputStream);
assertThat(byteArrayOutputStream.size(), equalTo(expectedSize));
}
@Test
public void loggingWithBinaryCharsetWorks() throws Exception {
int expectedSize = IOUtils.toByteArray(getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip")).length;
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
final InputStream inputStream =
given().
config(RestAssuredConfig.config().logConfig(new LogConfig(captor, false))).
expect().
log().all().
when().
get("http://powermock.googlecode.com/files/powermock-easymock-junit-1.4.12.zip").asInputStream();
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, byteArrayOutputStream);
IOUtils.closeQuietly(byteArrayOutputStream);
IOUtils.closeQuietly(inputStream);
assertThat(writer.toString(), not(emptyOrNullString()));
assertThat(byteArrayOutputStream.size(), equalTo(expectedSize));
}
}