From 6f6d2c044322122c3af4d7b198815694170dc532 Mon Sep 17 00:00:00 2001 From: Armin Date: Sat, 23 Mar 2024 14:05:11 +0100 Subject: [PATCH] Fix connectedTests --- ...CapturingServiceWithoutPermissionTest.java | 21 ++++++++++++++++--- .../datacapturing/DataCapturingServiceTest.kt | 10 ++++++++- .../de/cyface/datacapturing/PingPongTest.kt | 10 ++++++++- .../cyface/synchronization/MockedUploader.kt | 1 + .../synchronization/SyncPerformerTest.kt | 1 + 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/datacapturing/src/androidTest/java/de/cyface/datacapturing/DataCapturingServiceWithoutPermissionTest.java b/datacapturing/src/androidTest/java/de/cyface/datacapturing/DataCapturingServiceWithoutPermissionTest.java index 4311fa182..c662dab20 100644 --- a/datacapturing/src/androidTest/java/de/cyface/datacapturing/DataCapturingServiceWithoutPermissionTest.java +++ b/datacapturing/src/androidTest/java/de/cyface/datacapturing/DataCapturingServiceWithoutPermissionTest.java @@ -26,6 +26,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.json.JSONException; +import org.json.JSONObject; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -46,6 +48,7 @@ import de.cyface.datacapturing.ui.UIListener; import de.cyface.persistence.model.Modality; import de.cyface.synchronization.CyfaceAuthenticator; +import de.cyface.synchronization.settings.SynchronizationSettings; /** * Checks if missing permissions are correctly detected before starting a service. @@ -82,18 +85,30 @@ public class DataCapturingServiceWithoutPermissionTest { * Initializes the object of class under test. */ @Before - public void setUp() { + public void setUp() throws JSONException { context = InstrumentationRegistry.getInstrumentation().getTargetContext(); // The LOGIN_ACTIVITY is normally set to the LoginActivity of the SDK implementing app CyfaceAuthenticator.LOGIN_ACTIVITY = AccountAuthenticatorActivity.class; + CyfaceAuthenticator.settings = new SynchronizationSettings( + context, + "https://TEST_URL/", + new JSONObject().put("discovery_uri", "https://TEST_URL/") + ); //final String dataUploadServerAddress = "https://localhost:8080/api/v3"; final DataCapturingListener listener = new TestListener(); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { try { - oocut = new CyfaceDataCapturingService(context, TestUtils.AUTHORITY, TestUtils.ACCOUNT_TYPE, - /*dataUploadServerAddress, TestUtils.oauthConfig(),*/ new IgnoreEventsStrategy(), listener, 100); + oocut = new CyfaceDataCapturingService( + context, + TestUtils.AUTHORITY, + TestUtils.ACCOUNT_TYPE, + /*dataUploadServerAddress, TestUtils.oauthConfig(),*/ new IgnoreEventsStrategy(), + listener, + 100, + new CyfaceAuthenticator(context) + ); } catch (SetupException e) { throw new IllegalStateException(e); } diff --git a/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt b/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt index fdb6c6955..bd26eac46 100644 --- a/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt +++ b/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt @@ -46,11 +46,13 @@ import de.cyface.persistence.model.Measurement import de.cyface.persistence.model.MeasurementStatus import de.cyface.persistence.model.Modality import de.cyface.synchronization.CyfaceAuthenticator +import de.cyface.synchronization.settings.SynchronizationSettings import de.cyface.testutils.SharedTestUtils.clearPersistenceLayer import de.cyface.utils.Validate import kotlinx.coroutines.runBlocking import org.hamcrest.CoreMatchers import org.hamcrest.MatcherAssert.assertThat +import org.json.JSONObject import org.junit.After import org.junit.Before import org.junit.Ignore @@ -120,6 +122,11 @@ class DataCapturingServiceTest { // The LOGIN_ACTIVITY is normally set to the LoginActivity of the SDK implementing app CyfaceAuthenticator.LOGIN_ACTIVITY = Activity::class.java + CyfaceAuthenticator.settings = SynchronizationSettings( + context!!, + "https://TEST_URL/", + JSONObject().put("discovery_uri", "https://TEST_URL/") + ) // Add test account val requestAccount = Account(TestUtils.DEFAULT_USERNAME, TestUtils.ACCOUNT_TYPE) @@ -138,7 +145,8 @@ class DataCapturingServiceTest { //TestUtils.oauthConfig(), IgnoreEventsStrategy(), testListener!!, - 100 + 100, + CyfaceAuthenticator(context!!) ) } catch (e: SetupException) { throw IllegalStateException(e) diff --git a/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/PingPongTest.kt b/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/PingPongTest.kt index 747c59777..f0949ed82 100644 --- a/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/PingPongTest.kt +++ b/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/PingPongTest.kt @@ -37,10 +37,12 @@ import de.cyface.persistence.SetupException import de.cyface.persistence.exception.NoSuchMeasurementException import de.cyface.persistence.model.Modality import de.cyface.synchronization.CyfaceAuthenticator +import de.cyface.synchronization.settings.SynchronizationSettings import de.cyface.testutils.SharedTestUtils.clearPersistenceLayer import kotlinx.coroutines.runBlocking import org.hamcrest.CoreMatchers import org.hamcrest.MatcherAssert +import org.json.JSONObject import org.junit.After import org.junit.Before import org.junit.Rule @@ -140,6 +142,11 @@ class PingPongTest { val testListener: DataCapturingListener = TestListener() // The LOGIN_ACTIVITY is normally set to the LoginActivity of the SDK implementing app CyfaceAuthenticator.LOGIN_ACTIVITY = Activity::class.java + CyfaceAuthenticator.settings = SynchronizationSettings( + context!!, + "https://TEST_URL/", + JSONObject().put("discovery_uri", "https://TEST_URL/") + ) InstrumentationRegistry.getInstrumentation().runOnMainSync { dcs = try { CyfaceDataCapturingService( @@ -150,7 +157,8 @@ class PingPongTest { //TestUtils.oauthConfig(), IgnoreEventsStrategy(), testListener, - 100 + 100, + CyfaceAuthenticator(context!!) ) } catch (e: SetupException) { throw IllegalStateException(e) diff --git a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt index 123440b06..29c0a8ceb 100644 --- a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt +++ b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt @@ -66,6 +66,7 @@ internal class MockedUploader : Uploader { metaData: RequestMetaData, measurementId: Long, file: File, + fileName: String, progressListener: UploadProgressListener ): Result { progressListener.updatedProgress(1.0f) // 100% diff --git a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt index f36f633a0..382ae7358 100644 --- a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt +++ b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt @@ -311,6 +311,7 @@ class SyncPerformerTest { metaData: RequestMetaData, measurementId: Long, file: File, + fileName: String, progressListener: UploadProgressListener ): Result { throw UploadFailed(ConflictException("Test ConflictException"))