Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove kotlin-test and use atrium for test assertions #52

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ val ktlintVersion: String by project
val mockkVersion: String by project
val quarkusAwsS3Version: String by project
val quarkusMockkVersion: String by project
val atriumVersion: String by project
val awsSdkKotlinVersion: String by project
val jacksonDatatypeJsr310Version: String by project
val okhttp3Version: String by project
Expand All @@ -45,8 +46,8 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test")
testImplementation("ch.tutteli.atrium:atrium-fluent:$atriumVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("io.quarkiverse.amazonservices:quarkus-amazon-s3:$quarkusAwsS3Version")
testImplementation("io.quarkiverse.mockk:quarkus-junit5-mockk:$quarkusMockkVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.nxcloudce.api.domain.organization.interactor

import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import io.mockk.coEvery
import io.mockk.coVerify
import io.quarkiverse.test.junit.mockk.InjectMock
import io.quarkus.test.junit.QuarkusTest
import jakarta.inject.Inject
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.nxcloudce.api.domain.organization.gateway.OrganizationRepository
import org.nxcloudce.api.domain.organization.model.Organization
import org.nxcloudce.api.domain.organization.model.OrganizationId
import org.nxcloudce.api.domain.organization.usecase.CreateOrganizationRequest
import org.nxcloudce.api.domain.organization.usecase.CreateOrganizationResponse
import kotlin.test.Test
import kotlin.test.assertEquals

@QuarkusTest
class CreateOrganizationImplTest {
Expand All @@ -36,7 +37,7 @@ class CreateOrganizationImplTest {
val result = createOrganization.create(dummyRequest) { it }

// Then
assertEquals(dummyResponse, result)
expect(result).toEqual(dummyResponse)
coVerify(exactly = 1) { mockOrgRepository.create(dummyRequest) }
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package org.nxcloudce.api.domain.run.interactor

import ch.tutteli.atrium.api.fluent.en_GB.notToEqualNull
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import io.mockk.coEvery
import io.quarkiverse.test.junit.mockk.InjectMock
import io.quarkus.test.junit.QuarkusTest
import jakarta.inject.Inject
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.nxcloudce.api.domain.run.gateway.ArtifactRepository
import org.nxcloudce.api.domain.run.gateway.RunRepository
import org.nxcloudce.api.domain.run.gateway.TaskRepository
import org.nxcloudce.api.domain.run.model.*
import org.nxcloudce.api.domain.run.usecase.EndRunRequest
import org.nxcloudce.api.domain.workspace.model.WorkspaceId
import java.time.LocalDateTime
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

@QuarkusTest
class EndRunImplTest {
Expand Down Expand Up @@ -66,9 +67,8 @@ class EndRunImplTest {
val response = endRunImpl.end(request) { it.run }

// Then
assertEquals(RunStatus.SUCCESS, response.status)
assertNotNull(remoteArtifactSize)
assertEquals(1, remoteArtifactSize)
expect(response.status).toEqual(RunStatus.SUCCESS)
expect(remoteArtifactSize).notToEqualNull().toEqual(1)
}

@Test
Expand Down Expand Up @@ -105,7 +105,7 @@ class EndRunImplTest {
val response = endRunImpl.end(request) { it.run }

// Then
assertEquals(RunStatus.FAILURE, response.status)
expect(response.status).toEqual(RunStatus.FAILURE)
}

private fun buildRequestRun(): EndRunRequest.Run =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.nxcloudce.api.domain.run.interactor

import ch.tutteli.atrium.api.fluent.en_GB.its
import ch.tutteli.atrium.api.fluent.en_GB.toBeAnInstanceOf
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import io.mockk.coEvery
import io.mockk.coVerify
import io.quarkiverse.test.junit.mockk.InjectMock
Expand All @@ -14,9 +18,6 @@ import org.nxcloudce.api.domain.run.model.ArtifactId
import org.nxcloudce.api.domain.run.model.Hash
import org.nxcloudce.api.domain.run.usecase.StartRunRequest
import org.nxcloudce.api.domain.workspace.model.WorkspaceId
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue

@QuarkusTest
class StartRunImplTest {
Expand Down Expand Up @@ -59,10 +60,13 @@ class StartRunImplTest {
val result = startRunImpl.start(dummyRequest) { it }

// Then
assertTrue(result.artifacts.first() is Artifact.Exist)
val resultArtifact = result.artifacts.first() as Artifact.Exist
assertEquals("test-get-url", resultArtifact.get)
assertEquals("test-put-url", resultArtifact.put)
val firstArtifact = result.artifacts.first()
expect(firstArtifact).toBeAnInstanceOf<Artifact.Exist>()
val resultArtifact = firstArtifact as Artifact.Exist
expect(resultArtifact) {
its { get }.toEqual("test-get-url")
its { put }.toEqual("test-put-url")
}
coVerify(exactly = 1) { mockArtifactRepository.createWithHash(emptyList(), dummyWorkspaceId) }
}

Expand Down Expand Up @@ -95,9 +99,10 @@ class StartRunImplTest {
val result = startRunImpl.start(dummyRequest) { it }

// Then
assertTrue(result.artifacts.first() is Artifact.New)
val firstArtifact = result.artifacts.first()
expect(firstArtifact).toBeAnInstanceOf<Artifact.New>()
val resultArtifact = result.artifacts.first() as Artifact.New
assertEquals("test-put-url", resultArtifact.put)
expect(resultArtifact.put).toEqual("test-put-url")
coVerify(exactly = 0) { mockStorageService.generateGetUrl(dummyArtifact.id, dummyWorkspaceId) }
}

Expand Down Expand Up @@ -131,10 +136,13 @@ class StartRunImplTest {
val result = startRunImpl.start(dummyRequest) { it }

// Then
assertTrue(result.artifacts.first() is Artifact.Exist)
val firstArtifact = result.artifacts.first()
expect(firstArtifact).toBeAnInstanceOf<Artifact.Exist>()
val resultArtifact = result.artifacts.first() as Artifact.Exist
assertEquals("test-get-url", resultArtifact.get)
assertNull(resultArtifact.put)
expect(resultArtifact) {
its { get }.toEqual("test-get-url")
its { put }.toEqual(null)
}
coVerify(exactly = 1) { mockArtifactRepository.createWithHash(emptyList(), dummyWorkspaceId) }
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.nxcloudce.api.domain.run.model

import ch.tutteli.atrium.api.fluent.en_GB.its
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import org.junit.jupiter.api.Test
import org.nxcloudce.api.domain.workspace.model.WorkspaceId
import java.time.LocalDateTime
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class RunTest {
@Test
Expand Down Expand Up @@ -33,23 +34,25 @@ class RunTest {
hashedContributors = null
}

assertEquals("run-id", run.id.value)
assertEquals("workspace-id", run.workspaceId.value)
assertEquals("nx test apps/api", run.command)
assertEquals(RunStatus.SUCCESS, run.status)
assertEquals(dummyStartTime, run.startTime)
assertEquals(dummyEndTime, run.endTime)
assertEquals("main", run.branch)
assertEquals("default", run.runGroup)
assertEquals(false, run.inner)
assertEquals(null, run.distributedExecutionId)
assertEquals(null, run.ciExecutionId)
assertEquals(null, run.ciExecutionEnv)
assertEquals(MachineInfo("machine-id", "linux", "1.0", 4), run.machineInfo)
assertEquals("https://github.com/example/repo.git", run.vcsContext)
assertEquals(emptyList(), run.tasks)
assertEquals("link-id", run.linkId)
assertEquals("project-graph", run.projectGraph)
assertNull(run.hashedContributors)
expect(run) {
its { id.value }.toEqual("run-id")
its { workspaceId.value }.toEqual("workspace-id")
its { command }.toEqual("nx test apps/api")
its { status }.toEqual(RunStatus.SUCCESS)
its { startTime }.toEqual(dummyStartTime)
its { endTime }.toEqual(dummyEndTime)
its { branch }.toEqual("main")
its { runGroup }.toEqual("default")
its { inner }.toEqual(false)
its { distributedExecutionId }.toEqual(null)
its { ciExecutionId }.toEqual(null)
its { ciExecutionEnv }.toEqual(null)
its { machineInfo }.toEqual(MachineInfo("machine-id", "linux", "1.0", 4))
its { vcsContext }.toEqual("https://github.com/example/repo.git")
its { tasks }.toEqual(emptyList())
its { linkId }.toEqual("link-id")
its { projectGraph }.toEqual("project-graph")
its { hashedContributors }.toEqual(null)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.nxcloudce.api.domain.run.model

import ch.tutteli.atrium.api.fluent.en_GB.its
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import org.junit.jupiter.api.Test
import org.nxcloudce.api.domain.workspace.model.WorkspaceId
import java.time.LocalDateTime
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class TaskTest {
@Test
Expand All @@ -29,19 +30,21 @@ class TaskTest {
artifactId = ArtifactId("artifact-id")
}

assertEquals("task-id", task.taskId.value)
assertEquals("run-id", task.runId.value)
assertEquals("workspace-id", task.workspaceId.value)
assertEquals("hash-value", task.hash.value)
assertEquals("apps/api", task.projectName)
assertEquals("test", task.target)
assertEquals(dummyStartTime, task.startTime)
assertEquals(dummyEndTime, task.endTime)
assertEquals(CacheStatus.CACHE_MISS, task.cacheStatus)
assertEquals(0, task.status)
assertTrue(task.uploadedToStorage)
assertEquals("params", task.params)
assertEquals("terminal-output", task.terminalOutput)
assertEquals("artifact-id", task.artifactId?.value)
expect(task) {
its { taskId.value }.toEqual("task-id")
its { runId.value }.toEqual("run-id")
its { workspaceId.value }.toEqual("workspace-id")
its { hash.value }.toEqual("hash-value")
its { projectName }.toEqual("apps/api")
its { target }.toEqual("test")
its { startTime }.toEqual(dummyStartTime)
its { endTime }.toEqual(dummyEndTime)
its { cacheStatus }.toEqual(CacheStatus.CACHE_MISS)
its { status }.toEqual(0)
its { uploadedToStorage }.toEqual(true)
its { params }.toEqual("params")
its { terminalOutput }.toEqual("terminal-output")
its { artifactId?.value }.toEqual("artifact-id")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.nxcloudce.api.domain.workspace.interactor

import ch.tutteli.atrium.api.fluent.en_GB.its
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import io.mockk.every
import io.quarkiverse.test.junit.mockk.InjectMock
import io.quarkus.test.junit.QuarkusTest
import io.quarkus.test.vertx.RunOnVertxContext
import io.quarkus.test.vertx.UniAsserter
import io.smallrye.mutiny.Uni
import jakarta.inject.Inject
import org.junit.jupiter.api.Test
import org.nxcloudce.api.domain.organization.model.Organization
import org.nxcloudce.api.domain.organization.model.OrganizationId
import org.nxcloudce.api.domain.workspace.gateway.AccessTokenRepository
Expand All @@ -15,8 +19,6 @@ import org.nxcloudce.api.domain.workspace.gateway.WorkspaceRepository
import org.nxcloudce.api.domain.workspace.model.*
import org.nxcloudce.api.domain.workspace.usecase.CreateOrgAndWorkspaceRequest
import java.time.LocalDateTime
import kotlin.test.Test
import kotlin.test.assertEquals

@QuarkusTest
class CreateOrgAndWorkspaceImplTest {
Expand Down Expand Up @@ -66,10 +68,12 @@ class CreateOrgAndWorkspaceImplTest {
{ createOrgAndWorkspace.create(dummyRequest) { it } },
{ response ->
// Then
assertEquals("test workspace", response.workspace.name)
assertEquals(dummyWorkspaceId, response.workspace.id)
assertEquals("default", response.accessToken.name)
assertEquals(AccessLevel.READ_WRITE, response.accessToken.accessLevel)
expect(response) {
its { workspace.name }.toEqual("test workspace")
its { workspace.id }.toEqual(dummyWorkspaceId)
its { accessToken.name }.toEqual("default")
its { accessToken.accessLevel }.toEqual(AccessLevel.READ_WRITE)
}
},
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package org.nxcloudce.api.domain.workspace.interactor

import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
import ch.tutteli.atrium.api.verbs.expect
import io.mockk.coEvery
import io.mockk.coVerify
import io.quarkiverse.test.junit.mockk.InjectMock
import io.quarkus.test.junit.QuarkusTest
import jakarta.inject.Inject
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.nxcloudce.api.domain.organization.model.OrganizationId
import org.nxcloudce.api.domain.workspace.exception.OrganizationNotFoundException
import org.nxcloudce.api.domain.workspace.gateway.OrganizationValidationService
Expand All @@ -14,9 +19,6 @@ import org.nxcloudce.api.domain.workspace.model.Workspace
import org.nxcloudce.api.domain.workspace.model.WorkspaceId
import org.nxcloudce.api.domain.workspace.usecase.CreateWorkspaceRequest
import org.nxcloudce.api.domain.workspace.usecase.CreateWorkspaceResponse
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

@QuarkusTest
class CreateWorkspaceImplTest {
Expand All @@ -39,9 +41,9 @@ class CreateWorkspaceImplTest {
coEvery { mockOrgValidationService.isValidOrgId(dummyOrgId) } returns false

// When and then
assertFailsWith<OrganizationNotFoundException> {
createWorkspace.create(dummyRequest) {}
}
expect {
runBlocking { createWorkspace.create(dummyRequest) {} }
}.toThrow<OrganizationNotFoundException>()
}

@Test
Expand All @@ -67,7 +69,7 @@ class CreateWorkspaceImplTest {
val result = createWorkspace.create(dummyRequest) { it }

// Then
assertEquals(dummyResponse, result)
expect(result).toEqual(dummyResponse)
coVerify(exactly = 1) { mockWorkspaceRepository.create(dummyRequest) }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.nxcloudce.api.domain.workspace.interactor

import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import io.mockk.*
import io.quarkiverse.test.junit.mockk.InjectMock
import io.quarkus.test.junit.QuarkusTest
import jakarta.inject.Inject
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.nxcloudce.api.domain.workspace.gateway.AccessTokenRepository
import org.nxcloudce.api.domain.workspace.model.AccessToken
import org.nxcloudce.api.domain.workspace.usecase.GetWorkspaceAccessTokenRequest
import kotlin.test.Test
import kotlin.test.assertEquals

@QuarkusTest
class GetWorkspaceAccessTokenImplTest {
Expand All @@ -32,7 +33,7 @@ class GetWorkspaceAccessTokenImplTest {
val result = getWorkspaceAccessToken.getAccessToken(dummyRequest) { it }

// Then
assertEquals(dummyAccessToken, result.accessToken)
expect(result.accessToken).toEqual(dummyAccessToken)
coVerify(exactly = 1) { mockAccessTokenRepository.findByEncodedValue("test-token") }
}
}
Loading