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

Kotlin | Add ConfigureRequiredPullRequestReviews #3

Open
wants to merge 1 commit into
base: workshop/start
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.application

import com.eventstore.dbclient.EventStoreDBClient
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import pl.zycienakodach.eventmodeling.githubclone.shared.application.EventMapper
import pl.zycienakodach.eventmodeling.githubclone.shared.infrastructure.EventStoreApplicationService
import pl.zycienakodach.eventmodeling.githubclone.shared.infrastructure.JsonEventMapper
import pl.zycienakodach.eventmodeling.githubclone.slices.write.addsinglepullrequestcomment.domain.CommentDomainEvent
import pl.zycienakodach.eventmodeling.githubclone.slices.write.addsinglepullrequestcomment.domain.SingleCommentWasAdded
import pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain.PullRequestReviewingDomainEvent
import pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain.RequiredPullRequestReviewsWereConfigured
import kotlin.reflect.KClass

@Configuration
class ConfigureRequiredApprovesApplication(
private val objectMapper: ObjectMapper,
private val eventStore: EventStoreDBClient
) {

@Bean
fun pullRequestReviewingEventMapper(): EventMapper<PullRequestReviewingDomainEvent> {
val eventTypesMapping = mapOf<String, KClass<out PullRequestReviewingDomainEvent>>(
"RequiredPullRequestReviewsWereConfigured" to RequiredPullRequestReviewsWereConfigured::class
)
return JsonEventMapper(objectMapper, eventTypesMapping)
}

@Bean
fun pullRequestReviewingApplicationService(eventMapper: EventMapper<PullRequestReviewingDomainEvent>): EventStoreApplicationService<PullRequestReviewingDomainEvent> =
EventStoreApplicationService(eventStore, eventMapper)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain

import java.time.Instant
import java.util.*

data class ConfigureRequiredPullRequestReviews(
val commandId: UUID,
val issuedAt: Instant,
val repositoryId: String,
val branch: String,
val requiredApprovingReviews: Int
)

fun configureRequiredPullRequestReviews(history: List<PullRequestReviewingDomainEvent>, command: ConfigureRequiredPullRequestReviews): List<PullRequestReviewingDomainEvent> {
return listOf(
RequiredPullRequestReviewsWereConfigured(
eventId = command.commandId,
occurredAt = command.issuedAt,
repositoryId = command.repositoryId,
branch = command.branch,
requiredApprovingReviews = command.requiredApprovingReviews
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain

import pl.zycienakodach.eventmodeling.githubclone.shared.domain.DomainEvent
import java.time.Instant
import java.util.*


sealed class PullRequestReviewingDomainEvent : DomainEvent

data class RequiredPullRequestReviewsWereConfigured(
override val eventId: UUID,
override val occurredAt: Instant,
val repositoryId: String,
val branch: String,
val requiredApprovingReviews: Int
) : PullRequestReviewingDomainEvent() {
override val type: String = "RequiredPullRequestReviewsWereConfigured"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves

import assertk.assertThat
import assertk.assertions.isEqualTo
import com.eventstore.dbclient.EventStoreDBClient
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import pl.zycienakodach.eventmodeling.githubclone.shared.application.ApplicationService
import pl.zycienakodach.eventmodeling.githubclone.shared.application.EventMapper
import pl.zycienakodach.eventmodeling.githubclone.shared.domain.RepositoryId
import pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain.ConfigureRequiredPullRequestReviews
import pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain.PullRequestReviewingDomainEvent
import pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain.RequiredPullRequestReviewsWereConfigured
import pl.zycienakodach.eventmodeling.githubclone.slices.write.configurerequiredapproves.domain.configureRequiredPullRequestReviews

import pl.zycienakodach.eventmodeling.githubclone.testsupport.WriteSliceTestSupport
import java.time.Instant
import java.util.*

@SpringBootTest
class ConfigureRequiredPullRequestReviewsIntegrationTest
@Autowired constructor(
val applicationService: ApplicationService<PullRequestReviewingDomainEvent>,
override val eventStore: EventStoreDBClient,
override val eventDeserializer: EventMapper<PullRequestReviewingDomainEvent>
) : WriteSliceTestSupport {

@Test
fun `configure required pull request reviews`() {
//Given
val currentTime = Instant.now()
val randomOwner = UUID.randomUUID().toString()
val randomRepository = UUID.randomUUID().toString()
val repositoryId = RepositoryId(randomOwner, randomRepository)
val commandId = UUID.randomUUID()

//When
val command = ConfigureRequiredPullRequestReviews(
commandId = commandId,
issuedAt = currentTime,
repositoryId = repositoryId.toString(),
branch = "develop",
requiredApprovingReviews = 2
)
val streamName = "PullRequestReviewing-${repositoryId}"
applicationService.execute(streamName)
{ history -> configureRequiredPullRequestReviews(history, command) }.join()

//Then
assertThat(eventStore.eventsInStream(streamName)).isEqualTo(1);
assertThat(eventStore.streamLastEvent(streamName)).isEqualTo(
RequiredPullRequestReviewsWereConfigured(
eventId = commandId,
occurredAt = currentTime,
repositoryId = repositoryId.toString(),
branch = "develop",
requiredApprovingReviews = 2
)
)
}
}
Loading