diff --git a/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt b/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt index 96324c00..93818ab5 100644 --- a/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt +++ b/datacapturing/src/androidTest/kotlin/de/cyface/datacapturing/DataCapturingServiceTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023 Cyface GmbH + * Copyright 2017-2024 Cyface GmbH * * This file is part of the Cyface SDK for Android. * @@ -46,13 +46,11 @@ 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.DefaultSynchronizationSettings 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 @@ -70,8 +68,6 @@ import java.util.concurrent.locks.ReentrantLock * * @author Klemens Muthmann * @author Armin Schnabel - * @version 5.7.8 - * @since 2.0.0 */ @RunWith(AndroidJUnit4::class) @LargeTest @@ -224,7 +220,7 @@ class DataCapturingServiceTest { * @throws DataCapturingException If the asynchronous background service did not start successfully or no valid * Android context was available. * @throws MissingPermissionException If no Android `ACCESS_FINE_LOCATION` has been granted. You may - * register a [de.cyface.datacapturing.ui.UIListener] to ask the user for this permission and prevent the + * register a `de.cyface.datacapturing.ui.UIListener` to ask the user for this permission and prevent the * `Exception`. If the `Exception` was thrown the service does not start. */ @Throws( diff --git a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt index 898679c4..5abcca4e 100644 --- a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt +++ b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/MockedUploader.kt @@ -18,10 +18,11 @@ */ package de.cyface.synchronization -import de.cyface.model.RequestMetaData import de.cyface.uploader.Result import de.cyface.uploader.UploadProgressListener import de.cyface.uploader.Uploader +import de.cyface.uploader.model.Attachment +import de.cyface.uploader.model.Measurement import java.io.File import java.net.MalformedURLException import java.net.URL @@ -51,7 +52,7 @@ internal class MockedUploader : Uploader { override fun uploadMeasurement( jwtToken: String, - metaData: RequestMetaData, + uploadable: Measurement, file: File, progressListener: UploadProgressListener ): Result { @@ -61,7 +62,7 @@ internal class MockedUploader : Uploader { override fun uploadAttachment( jwtToken: String, - metaData: RequestMetaData, + uploadable: Attachment, file: File, fileName: String, progressListener: UploadProgressListener diff --git a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt index 8ece3d10..1b62eba8 100644 --- a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt +++ b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest.kt @@ -24,7 +24,6 @@ import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.platform.app.InstrumentationRegistry -import de.cyface.model.RequestMetaData import de.cyface.persistence.DefaultPersistenceBehaviour import de.cyface.persistence.DefaultPersistenceLayer import de.cyface.persistence.exception.NoSuchMeasurementException @@ -56,6 +55,13 @@ import de.cyface.uploader.exception.UnauthorizedException import de.cyface.uploader.exception.UnexpectedResponseCode import de.cyface.uploader.exception.UploadFailed import de.cyface.uploader.exception.UploadSessionExpired +import de.cyface.uploader.model.Attachment +import de.cyface.uploader.model.MeasurementIdentifier +import de.cyface.uploader.model.metadata.ApplicationMetaData +import de.cyface.uploader.model.metadata.AttachmentMetaData +import de.cyface.uploader.model.metadata.DeviceMetaData +import de.cyface.uploader.model.metadata.GeoLocation +import de.cyface.uploader.model.metadata.MeasurementMetaData import de.cyface.utils.CursorIsNullException import kotlinx.coroutines.runBlocking import org.hamcrest.CoreMatchers @@ -68,6 +74,7 @@ import java.io.File import java.net.URL import java.nio.file.Files import java.nio.file.Path +import java.util.UUID /** * Tests the data transmission code. @@ -153,7 +160,7 @@ class SyncPerformerTest { } } val fileName = - "${metaData.deviceIdentifier}_${metaData.measurementIdentifier}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}" + "${metaData.identifier.deviceIdentifier}_${metaData.identifier.measurementIdentifier}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}" val uploader = MockedUploader() // Prepare transmission @@ -269,28 +276,28 @@ class SyncPerformerTest { val startLocation = tracks[0].geoLocations[0]!! val lastTrack = tracks[tracks.size - 1].geoLocations val endLocation = lastTrack[lastTrack.size - 1]!! - val deviceId = "testDevi-ce00-42b6-a840-1b70d30094b8" // Must be a valid UUID - val startRecord = RequestMetaData.MeasurementMetaData.GeoLocation( + val deviceId = UUID.randomUUID() + val startRecord = GeoLocation( startLocation.timestamp, startLocation.lat, startLocation.lon ) - val endRecord = RequestMetaData.MeasurementMetaData.GeoLocation( + val endRecord = GeoLocation( endLocation.timestamp, endLocation.lat, endLocation.lon ) - val metaData = RequestMetaData( - RequestMetaData.MeasurementIdentifier(deviceId, measurementIdentifier.toString()), - RequestMetaData.DeviceMetaData("testOsVersion", "testDeviceType"), - RequestMetaData.ApplicationMetaData("testAppVersion", 3), - RequestMetaData.MeasurementMetaData( + val metaData = de.cyface.uploader.model.Measurement( + MeasurementIdentifier(deviceId, measurementIdentifier), + DeviceMetaData("testOsVersion", "testDeviceType"), + ApplicationMetaData("testAppVersion", 3), + MeasurementMetaData( distance, locationCount.toLong(), startRecord, endRecord, Modality.BICYCLE.databaseIdentifier, ), - RequestMetaData.AttachmentMetaData(0, 0, 0, 0), + AttachmentMetaData(0, 0, 0, 0), ) val progressListener = object : UploadProgressListener { override fun updatedProgress(percent: Float) { @@ -298,7 +305,7 @@ class SyncPerformerTest { } } val fileName = - "${metaData.identifier.deviceId}_${metaData.identifier.measurementId}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}" + "${metaData.identifier.deviceIdentifier}_${metaData.identifier.measurementIdentifier}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}" // Mock the actual post request val mockedUploader = object : Uploader { @@ -312,7 +319,7 @@ class SyncPerformerTest { override fun uploadMeasurement( jwtToken: String, - metaData: RequestMetaData, + uploadable: de.cyface.uploader.model.Measurement, file: File, progressListener: UploadProgressListener ): Result { @@ -321,7 +328,7 @@ class SyncPerformerTest { override fun uploadAttachment( jwtToken: String, - metaData: RequestMetaData, + uploadable: Attachment, file: File, fileName: String, progressListener: UploadProgressListener diff --git a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest_withoutAuth.kt b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest_withoutAuth.kt index 89c4406d..b9c32964 100644 --- a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest_withoutAuth.kt +++ b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/SyncPerformerTest_withoutAuth.kt @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 Cyface GmbH + * Copyright 2018-2024 Cyface GmbH * * This file is part of the Cyface SDK for Android. * @@ -23,7 +23,6 @@ import android.content.Context import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import androidx.test.platform.app.InstrumentationRegistry -import de.cyface.model.RequestMetaData import de.cyface.persistence.DefaultPersistenceBehaviour import de.cyface.persistence.DefaultPersistenceLayer import de.cyface.persistence.exception.NoSuchMeasurementException @@ -72,8 +71,6 @@ import java.io.IOException * * @author Klemens Muthmann * @author Armin Schnabel - * @version 2.1.3 - * @since 2.0.0 * @see [Testing documentation](http://d.android.com/tools/testing) */ @RunWith(AndroidJUnit4::class) @@ -148,7 +145,7 @@ class SyncPerformerTestWithoutAuth { ) ) file = loadSerializedCompressed(persistence, measurementIdentifier) - val metaData: RequestMetaData = + val metaData = loadMetaData(persistence, measurement, locationCount, 0, 0, 0, 0) val url = "$TEST_API_URL/api/v3/measurements" diff --git a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/TestUtils.kt b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/TestUtils.kt index 4639d558..1cbcc487 100644 --- a/synchronization/src/androidTest/kotlin/de/cyface/synchronization/TestUtils.kt +++ b/synchronization/src/androidTest/kotlin/de/cyface/synchronization/TestUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019 Cyface GmbH + * Copyright 2019-2024 Cyface GmbH * * This file is part of the Cyface SDK for Android. * @@ -19,24 +19,25 @@ package de.cyface.synchronization import android.util.Log -import de.cyface.model.MeasurementIdentifier -import de.cyface.model.RequestMetaData import de.cyface.persistence.DefaultPersistenceLayer import de.cyface.persistence.model.Measurement import de.cyface.persistence.model.Modality import de.cyface.persistence.serialization.MeasurementSerializer import de.cyface.serializer.DataSerializable +import de.cyface.uploader.model.metadata.ApplicationMetaData +import de.cyface.uploader.model.metadata.AttachmentMetaData +import de.cyface.uploader.model.metadata.DeviceMetaData +import de.cyface.uploader.model.metadata.GeoLocation +import de.cyface.uploader.model.metadata.MeasurementMetaData import de.cyface.utils.CursorIsNullException import java.io.File -import kotlin.math.log +import java.util.UUID /** * Contains utility methods and constants required by the tests within the synchronization project. * * @author Klemens Muthmann * @author Armin Schnabel - * @version 2.4.2 - * @since 2.1.0 */ object TestUtils { /** @@ -85,27 +86,33 @@ object TestUtils { imageCount: Int, videoCount: Int, filesSize: Long - ): RequestMetaData { + ): de.cyface.uploader.model.Measurement { // Load meta data val tracks = persistence.loadTracks(measurement.id) val startLocation = tracks[0].geoLocations[0]!! val lastTrack = tracks[tracks.size - 1].geoLocations val endLocation = lastTrack[lastTrack.size - 1]!! - val deviceId = "testDevi-ce00-42b6-a840-1b70d30094b8" // Must be a valid UUID - val id = MeasurementIdentifier(deviceId, measurement.id) - val startRecord = RequestMetaData.GeoLocation( + val deviceId = UUID.randomUUID() + val startRecord = GeoLocation( startLocation.timestamp, startLocation.lat, startLocation.lon ) - val endRecord = RequestMetaData.GeoLocation( + val endRecord = GeoLocation( endLocation.timestamp, endLocation.lat, endLocation.lon ) - return RequestMetaData( - deviceId, id.measurementIdentifier.toString(), - "testOsVersion", "testDeviceType", "testAppVersion", - measurement.distance, locationCount.toLong(), startRecord, endRecord, - Modality.BICYCLE.databaseIdentifier, 3, logCount, imageCount, videoCount, filesSize + return de.cyface.uploader.model.Measurement( + de.cyface.uploader.model.MeasurementIdentifier(deviceId, measurement.id), + DeviceMetaData("testOsVersion", "testDeviceType"), + ApplicationMetaData("testAppVersion", 3), + MeasurementMetaData( + measurement.distance, + locationCount.toLong(), + startRecord, + endRecord, + Modality.BICYCLE.databaseIdentifier, + ), + AttachmentMetaData(logCount, imageCount, videoCount, filesSize), ) }