-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
180 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
changelog: | ||
sections: | ||
- title: ":rocket: Enhancements & Features" | ||
labels: [ "Type: enhancement", "Type: documentation", "Type: example" ] | ||
- title: ":bug: Bug Fixes" | ||
labels: [ "Type: bug" ] | ||
- title: ":hammer_and_wrench: Chore" | ||
labels: [ "Type: dependencies", "Type: build", "Type: codacy" ] | ||
issues: | ||
exclude: | ||
labels: [ "Type: question" ] | ||
contributors: | ||
exclude: | ||
names: [ "dependabot[bot]" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
changelog: | ||
sections: | ||
- title: ":rocket: Enhancements & Features" | ||
labels: [ "Type: enhancement", "Type: documentation", "Type: example" ] | ||
- title: ":bug: Bug Fixes" | ||
labels: [ "Type: bug" ] | ||
- title: ":hammer_and_wrench: Chore" | ||
labels: [ "Type: dependencies", "Type: build", "Type: codacy" ] | ||
issues: | ||
exclude: | ||
labels: [ "Type: question" ] | ||
contributors: | ||
exclude: | ||
names: [ "dependabot[bot]" ] | ||
# Trigger the workflow on milestone events | ||
on: | ||
milestone: | ||
types: [closed] | ||
name: Milestone Closure | ||
jobs: | ||
create-release-notes: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@master | ||
- name: Create Release Notes Markdown | ||
uses: docker://decathlon/release-notes-generator-action:3.1.5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | ||
OUTPUT_FOLDER: temp_release_notes | ||
USE_MILESTONE_TITLE: "true" | ||
- name: Get the name of the created Release Notes file and extract Version | ||
run: | | ||
RELEASE_NOTES_FILE=$(ls temp_release_notes/*.md | head -n 1) | ||
echo "RELEASE_NOTES_FILE=$RELEASE_NOTES_FILE" >> $GITHUB_ENV | ||
VERSION=$(echo ${{ github.event.milestone.title }} | cut -d' ' -f2) | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
- name: Create a Draft Release Notes on GitHub | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | ||
with: | ||
tag_name: ${{ env.VERSION }} | ||
release_name: ${{ env.VERSION }} | ||
body_path: ${{ env.RELEASE_NOTES_FILE }} | ||
draft: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
extension/upcaster-test-core/src/test/kotlin/AccountCreatedV0V1UpcasterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package io.holixon.axon.testing.upcaster | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.databind.node.ObjectNode | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import io.holixon.axon.testing.upcaster.UpcasterTestSupport.Companion.initialEvent | ||
import io.holixon.axon.testing.upcaster.UpcasterTestSupport.Companion.jsonTestEventData | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.axonframework.serialization.Revision | ||
import org.axonframework.serialization.SerializedObject | ||
import org.axonframework.serialization.SimpleSerializedType | ||
import org.axonframework.serialization.json.JacksonSerializer | ||
import org.axonframework.serialization.upcasting.event.EventUpcasterChain | ||
import org.axonframework.serialization.upcasting.event.IntermediateEventRepresentation | ||
import org.axonframework.serialization.upcasting.event.SingleEventUpcaster | ||
import org.junit.jupiter.api.Test | ||
import kotlin.streams.toList | ||
|
||
/** | ||
* Let's assume we had a revision "0" of accountCreated which had different field names and one missing required field. | ||
*/ | ||
class AccountCreatedV0V1UpcasterTest { | ||
private val om = jacksonObjectMapper() | ||
private val jsonSerializer = JacksonSerializer.builder().objectMapper(om).build() | ||
|
||
@Test | ||
fun `upcast v0 to v1`() { | ||
// GIVEN: a new event with accountId and required field maximalBalance | ||
@Revision("1") | ||
data class AccountCreatedEvent( | ||
val accountId: String, | ||
val customerId: String, | ||
val initialBalance: Int, | ||
val maximalBalance: Int | ||
) | ||
|
||
val payloadType = AccountCreatedEvent::class.java.name | ||
val targetRevision = AccountCreatedEvent::class.java.getAnnotation(Revision::class.java).value | ||
|
||
// AND GIVEN: an old event with revision "0" with bankAccountId (has to be renamed to accountId), and maximalBalance is missing! | ||
val eventData = jsonTestEventData( | ||
payloadJson = """{"bankAccountId":"1","customerId":"3","initialBalance":0}""", | ||
payloadTypeName = payloadType, | ||
revisionNumber = "0" | ||
) | ||
|
||
// AND an upcaster we wrote for this usecase | ||
val upcaster = upcaster(payloadType = payloadType, sourceRevision = eventData.payload.type.revision, targetRevision = targetRevision) { | ||
(it as ObjectNode).apply { | ||
put("accountId", get("bankAccountId").asText()) | ||
remove("bankAccountId") | ||
put("maximalBalance", 1000) | ||
} | ||
} | ||
|
||
// WHEN we run the upcaster chain on a stream with a single event | ||
val serializedResult: SerializedObject<*> = EventUpcasterChain(upcaster) | ||
.upcast(initialEvent(entry = eventData, serializer = jsonSerializer)) | ||
.toList() | ||
.first().data | ||
|
||
// AND deserialize to target data class | ||
val revision1data: AccountCreatedEvent = jsonSerializer.deserialize(serializedResult) | ||
|
||
// THEN the fields are renamed and set | ||
assertThat(revision1data.accountId).isEqualTo("1") | ||
assertThat(revision1data.customerId).isEqualTo("3") | ||
assertThat(revision1data.initialBalance).isEqualTo(0) | ||
assertThat(revision1data.maximalBalance).isEqualTo(1000) | ||
} | ||
|
||
private fun upcaster(payloadType: String, sourceRevision: String, targetRevision: String, upcastFunction: (JsonNode) -> JsonNode) = | ||
object : SingleEventUpcaster() { | ||
override fun canUpcast(representation: IntermediateEventRepresentation): Boolean = | ||
representation.type.name == payloadType && representation.type.revision == sourceRevision | ||
|
||
override fun doUpcast(intermediateRepresentation: IntermediateEventRepresentation): IntermediateEventRepresentation = | ||
intermediateRepresentation.upcastPayload( | ||
SimpleSerializedType(payloadType, targetRevision), | ||
JsonNode::class.java, | ||
upcastFunction | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.