HaloNetClient { @Api(2.0) public Response request(@NonNull HaloRequest haloRequest) throws HaloNetException { Request request = haloRequest.buildOkRequest(); try { Response response = mClient.newCall(request).execute(); if (response.isSuccessful()) { return response; } else { throw new HaloNetworkExceptionResolver().resolve(response); } } catch (HaloNetException e) { throw e; } catch (Exception e) { throw new HaloNetworkExceptionResolver().resolve(e, request, HaloUtils.isNetworkConnected(mContext)); } } HaloNetClient(@NonNull Context context, @NonNull OkHttpClient.Builder clientBuilder, @NonNull HaloEndpointCluster endpoints, boolean disableKitKatCertificate); @NonNull @Api(2.0) OkHttpClient.Builder buildCertificates(@NonNull OkHttpClient.Builder okBuilder); @Api(2.0) Response request(@NonNull HaloRequest haloRequest); @SuppressWarnings("unchecked") @Api(2.0) T request(@NonNull HaloRequest haloRequest, @NonNull final TypeReference<T> type); @SuppressWarnings("unchecked") @Api(2.0) T request(@NonNull HaloRequest haloRequest, @NonNull Class<T> clazz); @Api(2.0) HaloEndpointCluster endpoints(); @NonNull @Api(2.0) OkHttpClient ok(); @Api(2.0) void overrideOk(@NonNull OkHttpClient.Builder builder); @NonNull @Api(2.0) Context context(); @NonNull @Api(2.4) void closeCache();  }
@Test public void thatMakeARequest() throws IOException { enqueueServerFile(mMockServer,GET_TEST_ITEM); HaloNetworkApi networkApi = givenAHaloNetWorkApi(mFramework,mEndpointURL); HaloRequest request = givenAGetRequest(networkApi); Response response = mHaloNetClient.request(request); assertThat(response).isNotNull(); assertThat(response.isSuccessful()).isTrue(); }
@Test public void thatMakeARequestWithClass() throws IOException, HaloParsingException, JSONException { enqueueServerFile(mMockServer,GET_TEST_ITEM); HaloNetworkApi networkApi = givenAHaloNetWorkApi(mFramework,mEndpointURL); HaloRequest request = givenAGetRequestTyped(networkApi); String response = mHaloNetClient.request(request,String.class); assertThat(response).isNotNull(); assertThat(response).isEqualTo("ExampleResponseTestFromNetWork"); }
@Test public void thatMakeARequestWithTyped() throws IOException, HaloParsingException, JSONException { enqueueServerFile(mMockServer,GET_TEST_ITEM); HaloNetworkApi networkApi = givenAHaloNetWorkApi(mFramework,mEndpointURL); HaloRequest request = givenAGetRequestTyped(networkApi); String response = mHaloNetClient.request(request, new TypeReference<String>(){}); assertThat(response).isNotNull(); assertThat(response).isEqualTo("ExampleResponseTestFromNetWork"); }
@Test public void thatCanPostARequestWithStringBody() throws IOException { enqueueServerFile(mMockServer,GET_TEST_ITEM); HaloNetworkApi networkApi = givenAHaloNetWorkApi(mFramework,mEndpointURL); HaloRequest request = givenAPostRequestWithStringBody(networkApi); String response = mHaloNetClient.request(request,String.class); assertThat(response).isNotNull(); assertThat(response).isEqualTo("ExampleResponseTestFromNetWork"); }
@Test public void thatCanPostARequestWithFormBody() throws IOException { enqueueServerFile(mMockServer,GET_TEST_ITEM); HaloNetworkApi networkApi = givenAHaloNetWorkApi(mFramework,mEndpointURL); HaloRequest request = givenAPostRequestWithFormBody(networkApi); String response = mHaloNetClient.request(request,String.class); assertThat(response).isNotNull(); assertThat(response).isEqualTo("ExampleResponseTestFromNetWork"); }
@Test public void thatCanPostARequestWithJSONObjectBody() throws IOException, JSONException { enqueueServerFile(mMockServer,GET_TEST_ITEM); HaloNetworkApi networkApi = givenAHaloNetWorkApi(mFramework,mEndpointURL); HaloRequest request = givenAPostRequestWithJSONObjectBody(networkApi); String response = mHaloNetClient.request(request,String.class); assertThat(response).isNotNull(); assertThat(response).isEqualTo("ExampleResponseTestFromNetWork"); }
@Test public void thatCanPostARequestWithJSONArrayBody() throws IOException, JSONException { enqueueServerFile(mMockServer,GET_TEST_ITEM); HaloNetworkApi networkApi = givenAHaloNetWorkApi(mFramework,mEndpointURL); HaloRequest request = givenAPostRequestWithJSONArrayBody(networkApi); String response = mHaloNetClient.request(request,String.class); assertThat(response).isNotNull(); assertThat(response).isEqualTo("ExampleResponseTestFromNetWork"); }