mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Migrated OkHttpJsonApiClient#getMedia and getPictureOfTheDay to MediaClient (#3056)
* With media client APIs migrated to retrofit (#2998) * With media client APIs migrated to retrofit * Add test cases and java docs * Fix test * Fix build * Fix build and other minor issues * Fix tests * Categories related client API's migrated to retrofit (#3053) * Commit 1 * searchCategories migrated to retrofit * SearchCategoriesFragment migrated to new API * Removed unused code * Created tests * implemented searching by prefix fixed SearchCategoryFragment behaviour where the same categories would be added to the list instead of new ones. * added tests * Migrated searchTitles to searchCategories, function behaviour seems identical * With media client APIs migrated to retrofit (#2998) * With media client APIs migrated to retrofit * Add test cases and java docs * Fix test * Fix build * Fix build and other minor issues * Fix tests * Categories related client API's migrated to retrofit (#3053) * Commit 1 * searchCategories migrated to retrofit * SearchCategoriesFragment migrated to new API * Removed unused code * Created tests * implemented searching by prefix fixed SearchCategoryFragment behaviour where the same categories would be added to the list instead of new ones. * added tests * Migrated searchTitles to searchCategories, function behaviour seems identical * OkHttpJsonApi#getMediaList migrated to retrofit (#3054) * Migrated OkHttpJsonApi#getMediaList partially to MediaClient#getCategoryImages * Migrated rest of OkHttpJsonApi#getMediaList functionality to MediaClient#getCategoryImages * Removed unused code and tests * Fixed small bug * Added tests * Removed unused CategoryImageController * getSubCategoryList and getParentCategoryList migrated to retrofit (#3055) * Migrated getSubCategoryList to retrofit * Migrated getParentCategoryList to retrofit * Removed obsolete functions * Added tests * Fixed small bugs * Migrated OkHttpJsonApiClient#getMedia and getPictureOfTheDay to MediaClient * Removed obsolete functions and added tests * Fixed merge errors * With media client APIs migrated to retrofit (#2998) * With media client APIs migrated to retrofit * Add test cases and java docs * Fix test * Fix build * Fix build and other minor issues * Fix tests * Categories related client API's migrated to retrofit (#3053) * Commit 1 * searchCategories migrated to retrofit * SearchCategoriesFragment migrated to new API * Removed unused code * Created tests * implemented searching by prefix fixed SearchCategoryFragment behaviour where the same categories would be added to the list instead of new ones. * added tests * Migrated searchTitles to searchCategories, function behaviour seems identical * OkHttpJsonApi#getMediaList migrated to retrofit (#3054) * Migrated OkHttpJsonApi#getMediaList partially to MediaClient#getCategoryImages * Migrated rest of OkHttpJsonApi#getMediaList functionality to MediaClient#getCategoryImages * Removed unused code and tests * Fixed small bug * Added tests * Removed unused CategoryImageController * getSubCategoryList and getParentCategoryList migrated to retrofit (#3055) * Migrated getSubCategoryList to retrofit * Migrated getParentCategoryList to retrofit * Removed obsolete functions * Added tests * Fixed small bugs * Consume login client from data client library (#2894) Fix actions for review client Use data client library for notifications With delete helper migrated to data client With wikidata edits With notifications and modifications migrated to data client With upload migrated to retrofit Delete unused code Reuse thank interface from the library
This commit is contained in:
parent
d24ca9d4fe
commit
8b36ee52d1
15 changed files with 181 additions and 159 deletions
|
|
@ -24,7 +24,13 @@ class MediaDataExtractorTest {
|
|||
internal var mwApi: MediaWikiApi? = null
|
||||
|
||||
@Mock
|
||||
internal var okHttpJsonApiClient: OkHttpJsonApiClient? = null
|
||||
internal var mediaClient: MediaClient? = null
|
||||
|
||||
@Mock
|
||||
internal var mediaClient: MediaClient? = null
|
||||
|
||||
@Mock
|
||||
internal var mediaClient: MediaClient? = null
|
||||
|
||||
@Mock
|
||||
internal var mediaClient: MediaClient? = null
|
||||
|
|
@ -46,7 +52,7 @@ class MediaDataExtractorTest {
|
|||
*/
|
||||
@Test
|
||||
fun fetchMediaDetails() {
|
||||
`when`(okHttpJsonApiClient?.getMedia(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean()))
|
||||
`when`(mediaClient?.getMedia(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(mock(Media::class.java)))
|
||||
|
||||
`when`(mediaClient?.checkPageExistsUsingTitle(ArgumentMatchers.anyString()))
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.bookmarks.Bookmark;
|
||||
import fr.free.nrw.commons.media.MediaClient;
|
||||
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
|
||||
import io.reactivex.Single;
|
||||
|
||||
|
|
@ -29,7 +30,7 @@ import static org.mockito.Mockito.when;
|
|||
public class BookmarkPicturesControllerTest {
|
||||
|
||||
@Mock
|
||||
OkHttpJsonApiClient okHttpJsonApiClient;
|
||||
MediaClient mediaClient;
|
||||
@Mock
|
||||
BookmarkPicturesDao bookmarkDao;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ public class BookmarkPicturesControllerTest {
|
|||
Media mockMedia = getMockMedia();
|
||||
when(bookmarkDao.getAllBookmarks())
|
||||
.thenReturn(getMockBookmarkList());
|
||||
when(okHttpJsonApiClient.getMedia(anyString(), anyBoolean()))
|
||||
when(mediaClient.getMedia(anyString()))
|
||||
.thenReturn(Single.just(mockMedia));
|
||||
}
|
||||
|
||||
|
|
@ -75,9 +76,9 @@ public class BookmarkPicturesControllerTest {
|
|||
*/
|
||||
@Test
|
||||
public void loadBookmarkedPicturesForNullMedia() {
|
||||
when(okHttpJsonApiClient.getMedia("File:Test1.jpg", false))
|
||||
when(mediaClient.getMedia("File:Test1.jpg"))
|
||||
.thenReturn(Single.error(new NullPointerException("Error occurred")));
|
||||
when(okHttpJsonApiClient.getMedia("File:Test2.jpg", false))
|
||||
when(mediaClient.getMedia("File:Test2.jpg"))
|
||||
.thenReturn(Single.just(getMockMedia()));
|
||||
List<Media> bookmarkedPictures = bookmarkPicturesController.loadBookmarkedPictures().blockingGet();
|
||||
assertEquals(1, bookmarkedPictures.size());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.media
|
||||
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.utils.CommonsDateUtil
|
||||
import io.reactivex.Observable
|
||||
import junit.framework.Assert.*
|
||||
import org.junit.Before
|
||||
|
|
@ -102,6 +103,68 @@ class MediaClientTest {
|
|||
assertFalse(checkFileExistsUsingSha)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getMedia() {
|
||||
val imageInfo = ImageInfo()
|
||||
|
||||
val mwQueryPage = mock(MwQueryPage::class.java)
|
||||
`when`(mwQueryPage.title()).thenReturn("Test")
|
||||
`when`(mwQueryPage.imageInfo()).thenReturn(imageInfo)
|
||||
|
||||
val mwQueryResult = mock(MwQueryResult::class.java)
|
||||
`when`(mwQueryResult.firstPage()).thenReturn(mwQueryPage)
|
||||
val mockResponse = mock(MwQueryResponse::class.java)
|
||||
`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
||||
|
||||
`when`(mediaInterface!!.getMedia(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(mockResponse))
|
||||
|
||||
assertEquals("Test", mediaClient!!.getMedia("abcde").blockingGet().filename)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getMediaNull() {
|
||||
val imageInfo = ImageInfo()
|
||||
|
||||
val mwQueryPage = mock(MwQueryPage::class.java)
|
||||
`when`(mwQueryPage.title()).thenReturn("Test")
|
||||
`when`(mwQueryPage.imageInfo()).thenReturn(imageInfo)
|
||||
|
||||
val mwQueryResult = mock(MwQueryResult::class.java)
|
||||
`when`(mwQueryResult.firstPage()).thenReturn(null)
|
||||
val mockResponse = mock(MwQueryResponse::class.java)
|
||||
`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
||||
|
||||
`when`(mediaInterface!!.getMedia(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Observable.just(mockResponse))
|
||||
|
||||
assertEquals(Media.EMPTY, mediaClient!!.getMedia("abcde").blockingGet())
|
||||
}
|
||||
@Captor
|
||||
private val filenameCaptor: ArgumentCaptor<String>? = null
|
||||
|
||||
@Test
|
||||
fun getPictureOfTheDay() {
|
||||
val template = "Template:Potd/" + CommonsDateUtil.getIso8601DateFormatShort().format(Date())
|
||||
|
||||
val imageInfo = ImageInfo()
|
||||
|
||||
val mwQueryPage = mock(MwQueryPage::class.java)
|
||||
`when`(mwQueryPage.title()).thenReturn("Test")
|
||||
`when`(mwQueryPage.imageInfo()).thenReturn(imageInfo)
|
||||
|
||||
val mwQueryResult = mock(MwQueryResult::class.java)
|
||||
`when`(mwQueryResult.firstPage()).thenReturn(mwQueryPage)
|
||||
val mockResponse = mock(MwQueryResponse::class.java)
|
||||
`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
||||
|
||||
`when`(mediaInterface!!.getMediaWithGenerator(filenameCaptor!!.capture()))
|
||||
.thenReturn(Observable.just(mockResponse))
|
||||
|
||||
assertEquals("Test", mediaClient!!.getPictureOfTheDay().blockingGet().filename)
|
||||
assertEquals(template, filenameCaptor.value);
|
||||
}
|
||||
|
||||
@Captor
|
||||
private val continuationCaptor: ArgumentCaptor<Map<String, String>>? = null
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import fr.free.nrw.commons.Media
|
|||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.utils.CommonsDateUtil
|
||||
import junit.framework.Assert.assertEquals
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
|
|
@ -67,83 +66,6 @@ class OkHttpJsonApiClientTest {
|
|||
campaignsServer.shutdown()
|
||||
}
|
||||
|
||||
/**
|
||||
* Test response for getting media without generator
|
||||
*/
|
||||
@Test
|
||||
fun getMedia() {
|
||||
server.enqueue(getMediaList("", "", "", 1))
|
||||
|
||||
val media = testObject.getMedia("Test.jpg", false)!!.blockingGet()
|
||||
|
||||
assertBasicRequestParameters(server, "GET").let { request ->
|
||||
parseQueryParams(request).let { body ->
|
||||
Assert.assertEquals("json", body["format"])
|
||||
Assert.assertEquals("2", body["formatversion"])
|
||||
Assert.assertEquals("query", body["action"])
|
||||
Assert.assertEquals("Test.jpg", body["titles"])
|
||||
Assert.assertEquals("imageinfo", body["prop"])
|
||||
Assert.assertEquals("url|extmetadata", body["iiprop"])
|
||||
Assert.assertEquals("DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl", body["iiextmetadatafilter"])
|
||||
}
|
||||
}
|
||||
|
||||
assert(media is Media)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test response for getting media with generator
|
||||
* Equivalent of testing POTD
|
||||
*/
|
||||
@Test
|
||||
fun getImageWithGenerator() {
|
||||
val template = "Template:Potd/" + CommonsDateUtil.getIso8601DateFormatShort().format(Date())
|
||||
server.enqueue(getMediaList("", "", "", 1))
|
||||
|
||||
val media = testObject.getMedia(template, true)!!.blockingGet()
|
||||
|
||||
assertBasicRequestParameters(server, "GET").let { request ->
|
||||
parseQueryParams(request).let { body ->
|
||||
Assert.assertEquals("json", body["format"])
|
||||
Assert.assertEquals("2", body["formatversion"])
|
||||
Assert.assertEquals("query", body["action"])
|
||||
Assert.assertEquals(template, body["titles"])
|
||||
Assert.assertEquals("images", body["generator"])
|
||||
Assert.assertEquals("imageinfo", body["prop"])
|
||||
Assert.assertEquals("url|extmetadata", body["iiprop"])
|
||||
Assert.assertEquals("DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl", body["iiextmetadatafilter"])
|
||||
}
|
||||
}
|
||||
|
||||
assert(media is Media)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test response for getting picture of the day
|
||||
*/
|
||||
@Test
|
||||
fun getPictureOfTheDay() {
|
||||
val template = "Template:Potd/" + CommonsDateUtil.getIso8601DateFormatShort().format(Date())
|
||||
server.enqueue(getMediaList("", "", "", 1))
|
||||
|
||||
val media = testObject.pictureOfTheDay?.blockingGet()
|
||||
|
||||
assertBasicRequestParameters(server, "GET").let { request ->
|
||||
parseQueryParams(request).let { body ->
|
||||
Assert.assertEquals("json", body["format"])
|
||||
Assert.assertEquals("2", body["formatversion"])
|
||||
Assert.assertEquals("query", body["action"])
|
||||
Assert.assertEquals(template, body["titles"])
|
||||
Assert.assertEquals("images", body["generator"])
|
||||
Assert.assertEquals("imageinfo", body["prop"])
|
||||
Assert.assertEquals("url|extmetadata", body["iiprop"])
|
||||
Assert.assertEquals("DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl", body["iiextmetadatafilter"])
|
||||
}
|
||||
}
|
||||
|
||||
assert(media is Media)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a MockResponse object which contains a list of media pages
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,10 +29,6 @@ class ReviewHelperTest {
|
|||
@Mock
|
||||
internal var reviewInterface: ReviewInterface? = null
|
||||
@Mock
|
||||
internal var okHttpJsonApiClient: OkHttpJsonApiClient? = null
|
||||
@Mock
|
||||
internal var mediaWikiApi: MediaWikiApi? = null
|
||||
@Mock
|
||||
internal var mediaClient: MediaClient? = null
|
||||
|
||||
@InjectMocks
|
||||
|
|
@ -68,7 +64,7 @@ class ReviewHelperTest {
|
|||
|
||||
val media = mock(Media::class.java)
|
||||
`when`(media.filename).thenReturn("File:Test.jpg")
|
||||
`when`(okHttpJsonApiClient?.getMedia(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean()))
|
||||
`when`(mediaClient?.getMedia(ArgumentMatchers.anyString()))
|
||||
.thenReturn(Single.just(media))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue