Search in sources :

Example 6 with MwQueryResponse

use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.

the class GalleryItemClientTest method testRequestSuccessForVideo.

@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testRequestSuccessForVideo() throws Throwable {
    enqueueFromFile("gallery_item_video.json");
    Callback cb = mock(Callback.class);
    Call<MwQueryResponse> call = request(cb, true);
    server().takeRequest();
    ArgumentCaptor<GalleryItem> captor = ArgumentCaptor.forClass(GalleryItem.class);
    // noinspection unchecked
    verify(cb).success(eq(call), captor.capture());
    // noinspection unchecked
    GalleryItem galleryItem = captor.getValue();
    assertThat(galleryItem != null, is(true));
    assertThat(String.valueOf(galleryItem.getHeight()), is("720"));
    assertThat(String.valueOf(galleryItem.getWidth()), is("400"));
    assertThat(galleryItem.getThumbUrl(), is("https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Wood_cleaving_-_2016.webm/400px--Wood_cleaving_-_2016.webm.jpg"));
    assertThat(galleryItem.getMimeType(), is("video/webm"));
    assertThat(galleryItem.getUrl(), is("https://upload.wikimedia.org/wikipedia/commons/e/eb/Wood_cleaving_-_2016.webm"));
    assertThat(galleryItem.getDerivatives().size(), is(11));
}
Also used : Callback(org.wikipedia.gallery.GalleryItemClient.Callback) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Example 7 with MwQueryResponse

use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.

the class GalleryItemClientTest method testRequestResponseMalformed.

@Test
public void testRequestResponseMalformed() throws Throwable {
    server().enqueue("'");
    GalleryItemClient.Callback cb = mock(GalleryItemClient.Callback.class);
    Call<MwQueryResponse> call = request(cb, false);
    server().takeRequest();
    assertCallbackFailure(call, cb, MalformedJsonException.class);
}
Also used : Callback(org.wikipedia.gallery.GalleryItemClient.Callback) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Example 8 with MwQueryResponse

use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.

the class GalleryItemClientTest method testRequestResponseApiError.

@Test
public void testRequestResponseApiError() throws Throwable {
    enqueueFromFile("api_error.json");
    GalleryItemClient.Callback cb = mock(GalleryItemClient.Callback.class);
    Call<MwQueryResponse> call = request(cb, false);
    server().takeRequest();
    assertCallbackFailure(call, cb, MwException.class);
}
Also used : Callback(org.wikipedia.gallery.GalleryItemClient.Callback) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Example 9 with MwQueryResponse

use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.

the class GalleryItemClientTest method testRequestResponseFailure.

@Test
public void testRequestResponseFailure() throws Throwable {
    enqueue404();
    GalleryItemClient.Callback cb = mock(GalleryItemClient.Callback.class);
    Call<MwQueryResponse> call = request(cb, false);
    server().takeRequest();
    assertCallbackFailure(call, cb, HttpStatusException.class);
}
Also used : Callback(org.wikipedia.gallery.GalleryItemClient.Callback) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Example 10 with MwQueryResponse

use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.

the class DescriptionClientTest method testRequestSuccess.

@Test
public void testRequestSuccess() throws Throwable {
    enqueueFromFile("reading_list_page_info.json");
    DescriptionClient.Callback cb = mock(DescriptionClient.Callback.class);
    Call<MwQueryResponse> call = request(cb);
    server().takeRequest();
    ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
    verify(cb).success(eq(call), captor.capture());
    List<MwQueryPage> result = captor.getValue();
    MwQueryPage biden = result.get(0);
    MwQueryPage obama = result.get(1);
    assertThat(biden.title(), is("Joe Biden"));
    assertThat(biden.description(), is("47th Vice President of the United States"));
    assertThat(obama.title(), is("Barack Obama"));
    assertThat(obama.description(), is("44th President of the United States of America"));
}
Also used : MwQueryPage(org.wikipedia.dataclient.mwapi.MwQueryPage) MwQueryResponse(org.wikipedia.dataclient.mwapi.MwQueryResponse) List(java.util.List) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Aggregations

MwQueryResponse (org.wikipedia.dataclient.mwapi.MwQueryResponse)27 MwException (org.wikipedia.dataclient.mwapi.MwException)14 VisibleForTesting (android.support.annotation.VisibleForTesting)12 IOException (java.io.IOException)12 Test (org.junit.Test)7 MockWebServerTest (org.wikipedia.test.MockWebServerTest)7 MwQueryPage (org.wikipedia.dataclient.mwapi.MwQueryPage)5 Callback (org.wikipedia.gallery.GalleryItemClient.Callback)5 ArrayList (java.util.ArrayList)3 NonNull (android.support.annotation.NonNull)2 List (java.util.List)2 Map (java.util.Map)2 PageTitle (org.wikipedia.page.PageTitle)2 PageImage (org.wikipedia.pageimages.PageImage)2 PageImagesClient (org.wikipedia.pageimages.PageImagesClient)2 Bitmap (android.graphics.Bitmap)1 ArrayMap (android.support.v4.util.ArrayMap)1 JsonParseException (com.google.gson.JsonParseException)1 HashMap (java.util.HashMap)1 ServiceError (org.wikipedia.dataclient.ServiceError)1