diff --git a/githubAppUpdate/build.gradle b/githubAppUpdate/build.gradle index 74d2616..1eb5c11 100644 --- a/githubAppUpdate/build.gradle +++ b/githubAppUpdate/build.gradle @@ -33,6 +33,9 @@ dependencies { api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4" api "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1" implementation "com.squareup.okhttp3:logging-interceptor:4.10.0" + + testImplementation 'junit:junit:4.13.2' + testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4" } project.afterEvaluate { diff --git a/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt b/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt index 856096c..7babc31 100644 --- a/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt +++ b/githubAppUpdate/src/main/java/info/hannes/github/AppUpdateHelper.kt @@ -26,6 +26,11 @@ import org.jfrog.artifactory.client.ArtifactoryClientBuilder import retrofit2.Response import java.util.concurrent.TimeUnit +import org.jfrog.artifactory.client.model.impl.RepositoryTypeImpl.LOCAL +import org.jfrog.artifactory.client.model.impl.RepositoryTypeImpl.REMOTE +import org.jfrog.artifactory.client.model.impl.RepositoryTypeImpl.VIRTUAL +import org.jfrog.artifactory.client.model.impl.RepositoryTypeImpl.FEDERATED + object AppUpdateHelper { @@ -45,7 +50,7 @@ object AppUpdateHelper { } // silently in background - fun checkForNewVersion(activity: AppCompatActivity, gitRepoUrl: String, repeatTime : Long = 6, timeUnit: TimeUnit = TimeUnit.HOURS) { + fun checkForNewVersion(activity: AppCompatActivity, gitRepoUrl: String, repeatTime: Long = 6, timeUnit: TimeUnit = TimeUnit.HOURS) { val currentVersionName = activity.getVersionName() DownloadWorker.run(activity, currentVersionName, gitRepoUrl, repeatTime, timeUnit) } @@ -124,7 +129,7 @@ object AppUpdateHelper { appContext: Context, currentVersionName: String, gitRepoUrl: String - ){ + ) { try { val versionList = requestVersionsSync(gitRepoUrl) @@ -148,15 +153,34 @@ object AppUpdateHelper { return client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute() } - private suspend fun requestArtifactoryVersions(artifactoryRepoUrl: String): Response>? { + suspend fun requestArtifactoryVersions(artifactoryRepoUrl: String): Response>? { val artifactory: Artifactory = ArtifactoryClientBuilder.create() .setUrl(artifactoryRepoUrl) //.setUsername("username") //.setPassword("password") .build() // TODO runtime error with "No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier" val versionList = withContext(Dispatchers.Default) { - artifactory.repositories() + val repositories = artifactory.repositories() + +// val allBuilds = artifactory.builds().allBuilds +// Log.d("allBuilds", allBuilds.toString()) + + val localRepoList = repositories.list(LOCAL) + val remoteRepoList = repositories.list(REMOTE) + val virtualRepoList = repositories.list(VIRTUAL) + val federatedRepoList = repositories.list(FEDERATED) + + Log.d("data", localRepoList.toString()) +// val list = artifactory.storage().storageInfo.repositoriesSummaryList +// Log.d("list", list.toString()) + val dataA = artifactory.repository("AppStore") + .download("/AppStore/AutonomousCar/app/1.2/app-1.2.pom") + .doDownload() + Log.d("dataA", dataA.toString()) + Log.d("data", repositories.toString()) + Log.d("data", repositories.replicationApi) } + Log.d("data", versionList.toString()) return null } diff --git a/githubAppUpdate/src/test/java/info/hannes/github/AppUpdateHelperTest.kt b/githubAppUpdate/src/test/java/info/hannes/github/AppUpdateHelperTest.kt new file mode 100644 index 0000000..41a0804 --- /dev/null +++ b/githubAppUpdate/src/test/java/info/hannes/github/AppUpdateHelperTest.kt @@ -0,0 +1,41 @@ +package info.hannes.github + +import junit.framework.Assert.assertEquals +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.delay +import kotlinx.coroutines.test.runTest +import org.junit.Test + +@OptIn(ExperimentalCoroutinesApi::class) +class AppUpdateHelperTest { + + @org.junit.Before + fun setUp() { + } + + @org.junit.After + fun tearDown() { + } + + @org.junit.Test + fun getPackageInfo() { + } + + @org.junit.Test + fun requestArtifactoryVersions() = runTest { + val data = AppUpdateHelper.requestArtifactoryVersions("https://artifactory.mxtracks.info") + assertEquals("Hello world", data) + } + + @Test + fun dataShouldBeHelloWorld() = runTest { + val data = fetchData() + assertEquals("Hello world", data) + } + + suspend fun fetchData(): String { + delay(1000L) + return "Hello world" + } + +} \ No newline at end of file