Merge pull request #853 from eugenp/ivanp81-master

fixing incorrect merge
This commit is contained in:
Jim Kerak 2016-11-21 09:12:53 -05:00 committed by GitHub
commit 8e92dd7e07
5 changed files with 8 additions and 40 deletions

View File

@ -27,15 +27,12 @@ public class OkHttpFileUploadingLiveTest {
@Before @Before
public void init() { public void init() {
client = new OkHttpClient(); client = new OkHttpClient();
} }
@Test @Test
public void whenUploadFile_thenCorrect() throws IOException { public void whenUploadFile_thenCorrect() throws IOException {
client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder() RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)
.addFormDataPart("file", "file.txt", .addFormDataPart("file", "file.txt",
@ -56,8 +53,6 @@ public class OkHttpFileUploadingLiveTest {
@Test @Test
public void whenGetUploadFileProgress_thenCorrect() throws IOException { public void whenGetUploadFileProgress_thenCorrect() throws IOException {
client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder() RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)
.addFormDataPart("file", "file.txt", .addFormDataPart("file", "file.txt",

View File

@ -13,6 +13,7 @@ import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
public class OkHttpGetLiveTest { public class OkHttpGetLiveTest {
private static final String BASE_URL = "http://localhost:8080/spring-rest"; private static final String BASE_URL = "http://localhost:8080/spring-rest";
@ -27,9 +28,6 @@ public class OkHttpGetLiveTest {
@Test @Test
public void whenGetRequest_thenCorrect() throws IOException { public void whenGetRequest_thenCorrect() throws IOException {
client = new OkHttpClient();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(BASE_URL + "/date") .url(BASE_URL + "/date")
.build(); .build();
@ -42,9 +40,6 @@ public class OkHttpGetLiveTest {
@Test @Test
public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException { public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException {
client = new OkHttpClient();
HttpUrl.Builder urlBuilder = HttpUrl.parse(BASE_URL + "/ex/bars").newBuilder(); HttpUrl.Builder urlBuilder = HttpUrl.parse(BASE_URL + "/ex/bars").newBuilder();
urlBuilder.addQueryParameter("id", "1"); urlBuilder.addQueryParameter("id", "1");
@ -62,9 +57,6 @@ public class OkHttpGetLiveTest {
@Test @Test
public void whenAsynchronousGetRequest_thenCorrect() throws InterruptedException { public void whenAsynchronousGetRequest_thenCorrect() throws InterruptedException {
client = new OkHttpClient();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(BASE_URL + "/date") .url(BASE_URL + "/date")
.build(); .build();

View File

@ -24,9 +24,6 @@ public class OkHttpHeaderLiveTest {
@Test @Test
public void whenSetHeader_thenCorrect() throws IOException { public void whenSetHeader_thenCorrect() throws IOException {
client = new OkHttpClient();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(SAMPLE_URL) .url(SAMPLE_URL)
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")
@ -40,7 +37,7 @@ public class OkHttpHeaderLiveTest {
@Test @Test
public void whenSetDefaultHeader_thenCorrect() throws IOException { public void whenSetDefaultHeader_thenCorrect() throws IOException {
OkHttpClient client = new OkHttpClient.Builder() OkHttpClient clientWithInterceptor = new OkHttpClient.Builder()
.addInterceptor(new DefaultContentTypeInterceptor("application/json")) .addInterceptor(new DefaultContentTypeInterceptor("application/json"))
.build(); .build();
@ -48,7 +45,7 @@ public class OkHttpHeaderLiveTest {
.url(SAMPLE_URL) .url(SAMPLE_URL)
.build(); .build();
Call call = client.newCall(request); Call call = clientWithInterceptor.newCall(request);
Response response = call.execute(); Response response = call.execute();
response.close(); response.close();
} }

View File

@ -34,8 +34,7 @@ public class OkHttpMiscLiveTest {
@Test @Test
public void whenSetRequestTimeout_thenFail() throws IOException { public void whenSetRequestTimeout_thenFail() throws IOException {
OkHttpClient clientWithTimeout = new OkHttpClient.Builder()
OkHttpClient client = new OkHttpClient.Builder()
.readTimeout(1, TimeUnit.SECONDS) .readTimeout(1, TimeUnit.SECONDS)
.build(); .build();
@ -43,18 +42,15 @@ public class OkHttpMiscLiveTest {
.url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay. .url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay.
.build(); .build();
Call call = client.newCall(request); Call call = clientWithTimeout.newCall(request);
Response response = call.execute(); Response response = call.execute();
response.close(); response.close();
} }
@Test(expected = IOException.class) @Test(expected = IOException.class)
public void whenCancelRequest_thenCorrect() throws IOException { public void whenCancelRequest_thenCorrect() throws IOException {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
client = new OkHttpClient();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay. .url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay.
.build(); .build();
@ -85,7 +81,7 @@ public class OkHttpMiscLiveTest {
File cacheDirectory = new File("src/test/resources/cache"); File cacheDirectory = new File("src/test/resources/cache");
Cache cache = new Cache(cacheDirectory, cacheSize); Cache cache = new Cache(cacheDirectory, cacheSize);
OkHttpClient client = new OkHttpClient.Builder() OkHttpClient clientCached = new OkHttpClient.Builder()
.cache(cache) .cache(cache)
.build(); .build();
@ -93,10 +89,10 @@ public class OkHttpMiscLiveTest {
.url("http://publicobject.com/helloworld.txt") .url("http://publicobject.com/helloworld.txt")
.build(); .build();
Response response1 = client.newCall(request).execute(); Response response1 = clientCached.newCall(request).execute();
logResponse(response1); logResponse(response1);
Response response2 = client.newCall(request).execute(); Response response2 = clientCached.newCall(request).execute();
logResponse(response2); logResponse(response2);
} }

View File

@ -34,9 +34,6 @@ public class OkHttpPostingLiveTest {
@Test @Test
public void whenSendPostRequest_thenCorrect() throws IOException { public void whenSendPostRequest_thenCorrect() throws IOException {
client = new OkHttpClient();
RequestBody formBody = new FormBody.Builder() RequestBody formBody = new FormBody.Builder()
.add("username", "test") .add("username", "test")
.add("password", "test") .add("password", "test")
@ -55,11 +52,8 @@ public class OkHttpPostingLiveTest {
@Test @Test
public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException { public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException {
String postBody = "test post"; String postBody = "test post";
client = new OkHttpClient();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(URL_SECURED_BY_BASIC_AUTHENTICATION) .url(URL_SECURED_BY_BASIC_AUTHENTICATION)
.addHeader("Authorization", Credentials.basic("test", "test")) .addHeader("Authorization", Credentials.basic("test", "test"))
@ -74,9 +68,6 @@ public class OkHttpPostingLiveTest {
@Test @Test
public void whenPostJson_thenCorrect() throws IOException { public void whenPostJson_thenCorrect() throws IOException {
client = new OkHttpClient();
String json = "{\"id\":1,\"name\":\"John\"}"; String json = "{\"id\":1,\"name\":\"John\"}";
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
@ -94,9 +85,6 @@ public class OkHttpPostingLiveTest {
@Test @Test
public void whenSendMultipartRequest_thenCorrect() throws IOException { public void whenSendMultipartRequest_thenCorrect() throws IOException {
client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder() RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM) .setType(MultipartBody.FORM)
.addFormDataPart("username", "test") .addFormDataPart("username", "test")