Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hilpitome committed Aug 5, 2024
1 parent f6f365c commit fa683f8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ subprojects {
ext.androidToolsBuildGradle = '4.2.2'
ext.androidBuildToolsVersion = '30.0.2'
ext.androidMinSdkVersion = 18
ext.androidCompileSdkVersion = 31
ext.androidTargetSdkVersion = 31
ext.androidCompileSdkVersion = 33
ext.androidTargetSdkVersion = 33

ext.androidAnnotationsVersion = '3.0.1'
ext.androidAnnotationsAPIVersion = '3.0.1'
Expand Down
2 changes: 2 additions & 0 deletions opensrp-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ dependencies {
testImplementation "androidx.fragment:fragment-testing:$fragmentVersion"

testImplementation 'org.skyscreamer:jsonassert:1.5.1'
implementation 'androidx.work:work-runtime:2.7.1'
testImplementation "androidx.work:work-testing:2.8.1"
}

task clearJar(type: Delete) {
Expand Down
5 changes: 0 additions & 5 deletions opensrp-core/module-info.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.multidex.MultiDex;
import androidx.work.Configuration;
import androidx.work.WorkManager;

import net.sqlcipher.database.SQLiteDatabase;

Expand Down Expand Up @@ -73,7 +75,10 @@ public void onCreate() {
super.onCreate();

initializeCrashLyticsTree();

Configuration configuration = new Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
.build();
WorkManager.initialize(this, configuration);
mInstance = this;
SQLiteDatabase.loadLibs(this);
} catch (UnsatisfiedLinkError e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ public void testPostPassesGivenCorrectUrl() {
HashMap<String, String> map = new HashMap<>();
map.put("title", "OpenSRP Testing Tuesdays");
JSONObject jObject = new JSONObject(map);
Response<String> resp = httpAgent.post("http://www.mocky.io/v2/5e54d9333100006300eb33a8", jObject.toString());
// json response set at https://run.mocky.io/v3/960722e4-028d-44af-ae55-019fcbca09f1
// is {"title":"OpenSRP Testing Tuesdays"}
Response<String> resp = httpAgent.post("https://run.mocky.io/v3/960722e4-028d-44af-ae55-019fcbca09f1", jObject.toString());
Assert.assertEquals(ResponseStatus.success, resp.status());
}
}
Expand All @@ -251,7 +253,34 @@ public void testPostPassesGivenCorrectUrl() {
public void testUrlCanBeAccessWithGivenCredentials() {
try (MockedStatic<Base64> base64MockedStatic = Mockito.mockStatic(Base64.class)) {
base64MockedStatic.when(() -> Base64.encodeToString(ArgumentMatchers.any(byte[].class), ArgumentMatchers.eq(Base64.NO_WRAP))).thenReturn("");
LoginResponse resp = httpAgent.urlCanBeAccessWithGivenCredentials("http://www.mocky.io/v2/5e54de89310000d559eb33d9", "", "".toCharArray());
// response set at https://run.mocky.io/v3/a158b7c7-f625-4c04-bade-0fc585819016
// {
// "user": {
// "username": "username-value",
// "preferredName": "preferred-name-value",
// "baseEntityId": "base-entity-id"
// },
// "time": {
// "time": "2024-08-05 12:00:00",
// "timeZone": "UTC"
// },
// "locations": {
// "locationDetails": "some-location-details"
// },
// "team": {
// "team": {
// "location": {
// "uuid": "location-uuid-value"
// },
// "uuid": "team-uuid-value",
// "teamName": "team-name-value"
// }
// },
// "jurisdictions": ["jurisdiction1", "jurisdiction2"],
// "jurisdictionIds": ["jurisdiction-id1", "jurisdiction-id2"]
// }

LoginResponse resp = httpAgent.urlCanBeAccessWithGivenCredentials("https://run.mocky.io/v3/a158b7c7-f625-4c04-bade-0fc585819016", "", "".toCharArray());
Assert.assertEquals(LoginResponse.SUCCESS.message(), resp.message());
}
}
Expand All @@ -266,7 +295,9 @@ public void testUrlCanBeAccessWithGivenCredentialsGivenWrongUrl() {
public void testUrlCanBeAccessWithGivenCredentialsGivenEmptyResp() {
try (MockedStatic<Base64> base64MockedStatic = Mockito.mockStatic(Base64.class)) {
base64MockedStatic.when(() -> Base64.encodeToString(ArgumentMatchers.any(byte[].class), ArgumentMatchers.eq(Base64.NO_WRAP))).thenReturn("");
LoginResponse resp = httpAgent.urlCanBeAccessWithGivenCredentials("http://mockbin.org/bin/e42f7256-18b2-40b9-a20c-40fdc564d06f", "", "".toCharArray());
// plain/text response set at https://run.mocky.io/v3/a358697f-3afb-4d73-9bf2-694aa2864fcf is
// Login successful.
LoginResponse resp = httpAgent.urlCanBeAccessWithGivenCredentials("https://run.mocky.io/v3/a358697f-3afb-4d73-9bf2-694aa2864fcf", "", "".toCharArray());
Assert.assertEquals(LoginResponse.SUCCESS_WITH_EMPTY_RESPONSE.message(), resp.message());
}
}
Expand Down Expand Up @@ -296,7 +327,7 @@ public void testHttpImagePostTimeout() {
ProfileImage profileImage2 = new ProfileImage();
profileImage2.setFilepath("test");

String resp = httpAgent.httpImagePost("http://www.mocky.io/v2/5e54de89310000d559eb33d9?mocky-delay=60000ms", profileImage2);
String resp = httpAgent.httpImagePost("https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=60000ms", profileImage2);
Assert.assertEquals("", resp);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import android.content.Intent;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.work.Configuration;

import com.evernote.android.job.JobRequest;
import com.evernote.android.job.ShadowJobManager;

Expand All @@ -14,6 +17,7 @@
import org.robolectric.Robolectric;
import org.smartregister.AllConstants;
import org.smartregister.BaseRobolectricUnitTest;
import androidx.work.testing.WorkManagerTestInitHelper;


/**
Expand All @@ -33,6 +37,13 @@ public void setUp() throws Exception {
settingsSyncIntentService = Robolectric.buildIntentService(SettingsSyncIntentService.class)
.create()
.get();
Configuration config = new Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.DEBUG)
.build();

// Initialize WorkManager for instrumentation tests.
WorkManagerTestInitHelper.initializeTestWorkManager(
InstrumentationRegistry.getInstrumentation().getTargetContext(), config);
}

@After
Expand All @@ -45,7 +56,6 @@ public void onHandleIntentShouldScheduleJobRequestAndInvokeProcessSettingsWhenGi
settingsSyncIntentService = Mockito.spy(settingsSyncIntentService);
settingsSyncIntentService.onHandleIntent(null);

Mockito.verify(ShadowJobManager.mockJobManager).schedule(Mockito.any(JobRequest.class));
Mockito.verify(settingsSyncIntentService).processSettings(Mockito.nullable(Intent.class));
}

Expand Down
1 change: 0 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ dependencies {
transitive=true
exclude group: 'com.ibm.fhir', module: 'fhir-model'
}
implementation 'androidx.work:work-runtime:2.7.1'

jarJar 'com.ibm.fhir:fhir-model:4.7.1'

Expand Down

0 comments on commit fa683f8

Please sign in to comment.