Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Jul 15, 2024
1 parent 2940cdc commit 4c63dfd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Cyface GmbH
* Copyright 2017-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +52,7 @@ internal class MockedUploader : Uploader {

override fun uploadMeasurement(
jwtToken: String,
metaData: RequestMetaData<RequestMetaData.MeasurementIdentifier>,
uploadable: Measurement,
file: File,
progressListener: UploadProgressListener
): Result {
Expand All @@ -61,7 +62,7 @@ internal class MockedUploader : Uploader {

override fun uploadAttachment(
jwtToken: String,
metaData: RequestMetaData<RequestMetaData.AttachmentIdentifier>,
uploadable: Attachment,
file: File,
fileName: String,
progressListener: UploadProgressListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -269,36 +276,36 @@ 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) {
Log.d(TAG, String.format("Upload Progress %f", percent))
}
}
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 {
Expand All @@ -312,7 +319,7 @@ class SyncPerformerTest {

override fun uploadMeasurement(
jwtToken: String,
metaData: RequestMetaData<RequestMetaData.MeasurementIdentifier>,
uploadable: de.cyface.uploader.model.Measurement,
file: File,
progressListener: UploadProgressListener
): Result {
Expand All @@ -321,7 +328,7 @@ class SyncPerformerTest {

override fun uploadAttachment(
jwtToken: String,
metaData: RequestMetaData<RequestMetaData.AttachmentIdentifier>,
uploadable: Attachment,
file: File,
fileName: String,
progressListener: UploadProgressListener
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 Cyface GmbH
* Copyright 2018-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Cyface GmbH
* Copyright 2019-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand All @@ -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 {
/**
Expand Down Expand Up @@ -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),
)
}

Expand Down

0 comments on commit 4c63dfd

Please sign in to comment.