Skip to content

Commit

Permalink
Fix connectedTests
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Mar 23, 2024
1 parent 5d77084 commit 6f6d2c0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -138,7 +145,8 @@ class DataCapturingServiceTest {
//TestUtils.oauthConfig(),
IgnoreEventsStrategy(),
testListener!!,
100
100,
CyfaceAuthenticator(context!!)
)
} catch (e: SetupException) {
throw IllegalStateException(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -150,7 +157,8 @@ class PingPongTest {
//TestUtils.oauthConfig(),
IgnoreEventsStrategy(),
testListener,
100
100,
CyfaceAuthenticator(context!!)
)
} catch (e: SetupException) {
throw IllegalStateException(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal class MockedUploader : Uploader {
metaData: RequestMetaData,
measurementId: Long,
file: File,
fileName: String,
progressListener: UploadProgressListener
): Result {
progressListener.updatedProgress(1.0f) // 100%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class SyncPerformerTest {
metaData: RequestMetaData,
measurementId: Long,
file: File,
fileName: String,
progressListener: UploadProgressListener
): Result {
throw UploadFailed(ConflictException("Test ConflictException"))
Expand Down

0 comments on commit 6f6d2c0

Please sign in to comment.