mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Fix build (#3172)
This commit is contained in:
parent
4fd9374e8b
commit
d897cfe28b
3 changed files with 12 additions and 202 deletions
|
|
@ -19,8 +19,8 @@ dependencies {
|
||||||
// Utils
|
// Utils
|
||||||
implementation 'com.github.nicolas-raoul:Quadtree:ac16ea8035bf07'
|
implementation 'com.github.nicolas-raoul:Quadtree:ac16ea8035bf07'
|
||||||
implementation 'com.google.code.gson:gson:2.8.5'
|
implementation 'com.google.code.gson:gson:2.8.5'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
|
implementation 'com.squareup.okhttp3:okhttp:4.2.0'
|
||||||
implementation 'com.squareup.okio:okio:1.15.0'
|
implementation 'com.squareup.okio:okio:2.2.2'
|
||||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
|
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
|
||||||
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
|
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
|
||||||
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
|
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
|
||||||
|
|
@ -67,21 +67,21 @@ dependencies {
|
||||||
testImplementation 'org.robolectric:robolectric:4.3'
|
testImplementation 'org.robolectric:robolectric:4.3'
|
||||||
testImplementation 'androidx.test:core:1.2.0'
|
testImplementation 'androidx.test:core:1.2.0'
|
||||||
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
|
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
|
||||||
testImplementation 'com.squareup.okhttp3:mockwebserver:3.10.0'
|
testImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
|
||||||
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
|
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
|
||||||
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
|
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
|
||||||
|
|
||||||
// Android testing
|
// Android testing
|
||||||
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
|
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
|
||||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||||
androidTestImplementation 'androidx.test:rules:1.1.1'
|
androidTestImplementation 'androidx.test:rules:1.2.0'
|
||||||
androidTestImplementation 'androidx.annotation:annotation:1.0.2'
|
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
|
||||||
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.10.0'
|
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
|
||||||
androidTestImplementation 'org.mockito:mockito-core:2.10.0'
|
androidTestImplementation 'org.mockito:mockito-core:2.13.0'
|
||||||
androidTestUtil 'androidx.test:orchestrator:1.1.1'
|
androidTestUtil 'androidx.test:orchestrator:1.2.0'
|
||||||
|
|
||||||
// Debugging
|
// Debugging
|
||||||
debugImplementation "com.squareup.leakcanary:leakcanary-android:$LEAK_CANARY_VERSION"
|
debugImplementation "com.squareup.leakcanary:leakcanary-android:$LEAK_CANARY_VERSION"
|
||||||
|
|
|
||||||
|
|
@ -1,171 +0,0 @@
|
||||||
package fr.free.nrw.commons.mwapi
|
|
||||||
|
|
||||||
import com.google.gson.Gson
|
|
||||||
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
|
|
||||||
import okhttp3.mockwebserver.MockWebServer
|
|
||||||
import okhttp3.mockwebserver.RecordedRequest
|
|
||||||
import org.junit.After
|
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.mockito.Mockito
|
|
||||||
import org.robolectric.RobolectricTestRunner
|
|
||||||
import org.robolectric.annotation.Config
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.random.Random
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock web server based tests for ok http json api client
|
|
||||||
*/
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
|
||||||
@Config(sdk = [23], application = TestCommonsApplication::class)
|
|
||||||
class OkHttpJsonApiClientTest {
|
|
||||||
|
|
||||||
private lateinit var testObject: OkHttpJsonApiClient
|
|
||||||
private lateinit var toolsForgeServer: MockWebServer
|
|
||||||
private lateinit var sparqlServer: MockWebServer
|
|
||||||
private lateinit var campaignsServer: MockWebServer
|
|
||||||
private lateinit var server: MockWebServer
|
|
||||||
private lateinit var sharedPreferences: JsonKvStore
|
|
||||||
private lateinit var okHttpClient: OkHttpClient
|
|
||||||
|
|
||||||
/**
|
|
||||||
* - make instances of mock web server
|
|
||||||
* - create instance of OkHttpJsonApiClient
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
fun setUp() {
|
|
||||||
server = MockWebServer()
|
|
||||||
toolsForgeServer = MockWebServer()
|
|
||||||
sparqlServer = MockWebServer()
|
|
||||||
campaignsServer = MockWebServer()
|
|
||||||
okHttpClient = OkHttpClient.Builder().build()
|
|
||||||
sharedPreferences = Mockito.mock(JsonKvStore::class.java)
|
|
||||||
val toolsForgeUrl = "http://" + toolsForgeServer.hostName + ":" + toolsForgeServer.port + "/"
|
|
||||||
val sparqlUrl = "http://" + sparqlServer.hostName + ":" + sparqlServer.port + "/"
|
|
||||||
val campaignsUrl = "http://" + campaignsServer.hostName + ":" + campaignsServer.port + "/"
|
|
||||||
val serverUrl = "http://" + server.hostName + ":" + server.port + "/"
|
|
||||||
testObject = OkHttpJsonApiClient(okHttpClient, HttpUrl.get(toolsForgeUrl), sparqlUrl, campaignsUrl, serverUrl, Gson())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shutdown server after tests
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
fun teardown() {
|
|
||||||
server.shutdown()
|
|
||||||
toolsForgeServer.shutdown()
|
|
||||||
sparqlServer.shutdown()
|
|
||||||
campaignsServer.shutdown()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a MockResponse object which contains a list of media pages
|
|
||||||
*/
|
|
||||||
private fun getMediaList(queryContinueType: String,
|
|
||||||
queryContinueValue: String,
|
|
||||||
continueVal: String,
|
|
||||||
numberOfPages: Int): MockResponse {
|
|
||||||
val mockResponse = MockResponse()
|
|
||||||
mockResponse.setResponseCode(200)
|
|
||||||
var continueJson = ""
|
|
||||||
|
|
||||||
if (queryContinueType != "" && queryContinueValue != "" && continueVal != "") {
|
|
||||||
continueJson = ",\"continue\":{\"$queryContinueType\":\"$queryContinueValue\",\"continue\":\"$continueVal\"}"
|
|
||||||
}
|
|
||||||
|
|
||||||
val mediaList = mutableListOf<String>()
|
|
||||||
val random = Random(1000)
|
|
||||||
for (i in 0 until numberOfPages) {
|
|
||||||
mediaList.add(getMediaPage(random))
|
|
||||||
}
|
|
||||||
|
|
||||||
val pagesString = mediaList.joinToString()
|
|
||||||
val responseBody = "{\"batchcomplete\":\"\"$continueJson,\"query\":{\"pages\":[$pagesString]}}"
|
|
||||||
mockResponse.setBody(responseBody)
|
|
||||||
return mockResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate test media json object
|
|
||||||
*/
|
|
||||||
private fun getMediaPage(random: Random): String {
|
|
||||||
val pageID = random.nextInt()
|
|
||||||
val id = random.nextInt()
|
|
||||||
val fileName = "Test$id"
|
|
||||||
val id1 = random.nextInt()
|
|
||||||
val id2 = random.nextInt()
|
|
||||||
val categories = "cat$id1|cat$id2"
|
|
||||||
return "{\"pageid\":$pageID,\"ns\":6,\"title\":\"File:$fileName\",\"imagerepository\":\"local\",\"imageinfo\":[{\"url\":\"https://upload.wikimedia.org/$fileName\",\"descriptionurl\":\"https://commons.wikimedia.org/wiki/File:$fileName\",\"descriptionshorturl\":\"https://commons.wikimedia.org/w/index.php?curid=4406048\",\"extmetadata\":{\"DateTime\":{\"value\":\"2013-04-13 15:12:11\",\"source\":\"mediawiki-metadata\",\"hidden\":\"\"},\"Categories\":{\"value\":\"$categories\",\"source\":\"commons-categories\",\"hidden\":\"\"},\"Artist\":{\"value\":\"<bdi><a href=\\\"https://en.wikipedia.org/wiki/en:Raphael\\\" class=\\\"extiw\\\" title=\\\"w:en:Raphael\\\">Raphael</a>\\n</bdi>\",\"source\":\"commons-desc-page\"},\"ImageDescription\":{\"value\":\"test desc\",\"source\":\"commons-desc-page\"},\"DateTimeOriginal\":{\"value\":\"1511<div style=\\\"display: none;\\\">date QS:P571,+1511-00-00T00:00:00Z/9</div>\",\"source\":\"commons-desc-page\"},\"LicenseShortName\":{\"value\":\"Public domain\",\"source\":\"commons-desc-page\",\"hidden\":\"\"}}}]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check request params
|
|
||||||
*/
|
|
||||||
private fun assertBasicRequestParameters(server: MockWebServer, method: String): RecordedRequest = server.takeRequest().let {
|
|
||||||
Assert.assertEquals("/", it.requestUrl.encodedPath())
|
|
||||||
Assert.assertEquals(method, it.method)
|
|
||||||
return it
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check request params with encoded path
|
|
||||||
*/
|
|
||||||
private fun assertBasicRequestParameters(server: MockWebServer, method: String,encodedPath: String): RecordedRequest = server.takeRequest().let {
|
|
||||||
Assert.assertEquals(encodedPath, it.requestUrl.encodedPath())
|
|
||||||
Assert.assertEquals(method, it.method)
|
|
||||||
return it
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse query params
|
|
||||||
*/
|
|
||||||
private fun parseQueryParams(request: RecordedRequest) = HashMap<String, String?>().apply {
|
|
||||||
request.requestUrl.let {
|
|
||||||
it.queryParameterNames().forEach { name -> put(name, it.queryParameter(name)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test getUploadCount posititive and negative cases
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun testGetUploadCount(){
|
|
||||||
//Positive
|
|
||||||
assertEquals(testBaseCasesAndGetUploadCount(true), 20)
|
|
||||||
//Negative
|
|
||||||
assertEquals(testBaseCasesAndGetUploadCount(false), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test getUploadCount base cases
|
|
||||||
*/
|
|
||||||
private fun testBaseCasesAndGetUploadCount(shouldAddResponse: Boolean): Int? {
|
|
||||||
val mockResponse = MockResponse()
|
|
||||||
mockResponse.setResponseCode(200)
|
|
||||||
if(shouldAddResponse) {
|
|
||||||
val responseBody = "20"
|
|
||||||
mockResponse.setBody(responseBody)
|
|
||||||
}
|
|
||||||
toolsForgeServer.enqueue(mockResponse)
|
|
||||||
|
|
||||||
val uploadCount=testObject.getUploadCount("ashishkumar294").blockingGet()
|
|
||||||
assertBasicRequestParameters(toolsForgeServer, "GET","/uploadsbyuser.py").let { request ->
|
|
||||||
parseQueryParams(request).let { body ->
|
|
||||||
Assert.assertEquals("ashishkumar294", body["user"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uploadCount
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -50,25 +50,6 @@ class UploadPresenterTest {
|
||||||
`when`(uploadableFile?.filePath).thenReturn("data://test")
|
`when`(uploadableFile?.filePath).thenReturn("data://test")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* unit test case for method UploadPresenter.handleSubmit
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun handleSubmitTest() {
|
|
||||||
uploadPresenter?.handleSubmit()
|
|
||||||
verify(view)?.isLoggedIn
|
|
||||||
verify(view)?.showProgress(true)
|
|
||||||
verify(repository)?.buildContributions()
|
|
||||||
val buildContributions = repository?.buildContributions()
|
|
||||||
buildContributions?.test()?.assertNoErrors()?.assertValue {
|
|
||||||
verify(repository)?.prepareService()
|
|
||||||
verify(view)?.showProgress(false)
|
|
||||||
verify(view)?.showMessage(ArgumentMatchers.any(Int::class.java))
|
|
||||||
verify(view)?.finish()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unit test for UploadMediaPresenter.deletePictureAtIndex
|
* unit test for UploadMediaPresenter.deletePictureAtIndex
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue