Skip to content

Commit

Permalink
Fix: OONIAPIClientTest using failing API endpoint and incorrect testi…
Browse files Browse the repository at this point in the history
…ng logic (#784)

Fixes ooni/probe#2778

## Proposed Changes

- Switch testing endpoint from `ams-pg.ooni.org` to
`https://backend-hel.ooni.org`
  - Refactor `OONIAPIClientTest` to Kotlin
  - Execute API calls synchronously to fix incorrect async logic
- Remove database operations that were irrelevant to the
`testSelectMeasurementsWithJson` test
- Remove the test `getMeasurementJsonError` because it was only testing
external libraries logic (retrofit and gson) and not the `OONIAPIClient`
  • Loading branch information
sdsantos authored Jul 16, 2024
1 parent a638d43 commit fffcea6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ public OONICheckInConfig getOONICheckInConfig() {

public ActivityComponent getActivityComponent() { return component.activityComponent(); }

public OkHttpClient getOkHttpClient() {
return _okHttpClient;
}

public OONIAPIClient getApiClient() {
return _apiClient;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.openobservatory.ooniprobe.client

import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.openobservatory.ooniprobe.RobolectricAbstractTest

class OONIAPIClientTest : RobolectricAbstractTest() {

@Test
fun measurementSuccess() {
val response = apiClient.getMeasurement(EXISTING_REPORT_ID, null).execute()

assertTrue(response.isSuccessful)
response.body().use { body ->
assertNotNull(body)
assertNotNull(body!!.string())
}
}

@Test
fun measurementError() {
val response = apiClient.getMeasurement(NON_EXISTING_REPORT_ID, null).execute()

assertFalse(response.isSuccessful)
}

@Test
fun testSelectMeasurementsWithJson() {
val response = apiClient.checkReportId(EXISTING_REPORT_ID).execute()

assertTrue(response.isSuccessful)
with(response.body()) {
assertNotNull(this)
assertTrue(this!!.found)
}
}

private val apiClient get() = a.apiClient

companion object {
private const val EXISTING_REPORT_ID =
"20190113T202156Z_AS327931_CgoC3KbgM6zKajvIIt1AxxybJ1HbjwwWJjsJnlxy9rpcGY54VH"
private const val NON_EXISTING_REPORT_ID = "EMPTY"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Module
public class TestAppModule extends ApplicationModule {

private static final String CLIENT_URL = "https://ams-pg.ooni.org";
private static final String CLIENT_URL = "https://backend-hel.ooni.org";

public TestAppModule(Application application) {
super(application);
Expand Down

0 comments on commit fffcea6

Please sign in to comment.