Skip to content

Commit

Permalink
Unit test for artifactory
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesa2 committed Feb 3, 2023
1 parent ae596c2 commit 51197e0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
3 changes: 3 additions & 0 deletions githubAppUpdate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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)
}
Expand Down Expand Up @@ -124,7 +129,7 @@ object AppUpdateHelper {
appContext: Context,
currentVersionName: String,
gitRepoUrl: String
){
) {
try {
val versionList = requestVersionsSync(gitRepoUrl)

Expand All @@ -148,15 +153,34 @@ object AppUpdateHelper {
return client.github.getGithubVersions(gitRepoUrl.user(), gitRepoUrl.repo()).execute()
}

private suspend fun requestArtifactoryVersions(artifactoryRepoUrl: String): Response<MutableList<GithubVersion>>? {
suspend fun requestArtifactoryVersions(artifactoryRepoUrl: String): Response<MutableList<GithubVersion>>? {
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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}

}

0 comments on commit 51197e0

Please sign in to comment.