-
Notifications
You must be signed in to change notification settings - Fork 2
More on generated routing #183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bc46045
Bump version -> `2.0.0-SNAPSHOT.265`
alexander-yevsyukov f9dded9
Bump local dependencies
alexander-yevsyukov 98d0658
Update dependency reports
alexander-yevsyukov 0b5f903
Add documentation
alexander-yevsyukov 0be93a3
Detect duplicated route functions
alexander-yevsyukov 3c23de0
Improve code layout
alexander-yevsyukov d490600
Extract `lineNumber` property
alexander-yevsyukov 4592990
Simplify code flow
alexander-yevsyukov 9cbbf02
Turn the function into extension
alexander-yevsyukov 6cec723
Improve documentation
alexander-yevsyukov 0110691
Test generated command routing
alexander-yevsyukov a3204dc
Add codegen for state update routing setup
alexander-yevsyukov 0246160
Introduce an abstract base for multicast setup generators
alexander-yevsyukov 6e314ad
Fix the dependency on `AutoService.annotations`
alexander-yevsyukov cf7ee03
Update build time
alexander-yevsyukov bac82ed
Improve documentation
alexander-yevsyukov b0a2dab
Bump local dependencies
alexander-yevsyukov 0052047
Update dependency report
alexander-yevsyukov adeeaf6
Bump Base -> `2.0.0-SNAPSHOT.244`
alexander-yevsyukov cbd1cc1
Improve code layout
alexander-yevsyukov cec3e81
Improve doc language
alexander-yevsyukov 8d04894
Improve function name
alexander-yevsyukov 5035eda
Improve doc language
alexander-yevsyukov 89d0d11
Fix package name
alexander-yevsyukov f6bb9a6
Update config
alexander-yevsyukov c0c03e8
Suppress warnings
alexander-yevsyukov 84455e5
Improve doc wording
alexander-yevsyukov a04627a
Update dependency reports
alexander-yevsyukov 336f351
Improve comment language
alexander-yevsyukov 1b57492
Remove redundant (c) statement
alexander-yevsyukov 3e73626
Remove redundant word in docs
alexander-yevsyukov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Submodule config
updated
1 files
| +12 −11 | buildSrc/src/main/kotlin/io/spine/gradle/report/pom/PomGenerator.kt |
Large diffs are not rendered by default.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
...ng-tests/src/test/kotlin/io/spine/tools/mc/java/routing/tests/CommandRoutingSetupITest.kt
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * Copyright 2025, TeamDev. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Redistribution and use in source and/or binary forms, with or without | ||
| * modification, must retain the above copyright notice and the following | ||
| * disclaimer. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package io.spine.tools.mc.java.routing.tests | ||
|
|
||
| import io.spine.given.home.Device | ||
| import io.spine.given.home.DeviceAggregate | ||
| import io.spine.given.home.DeviceId | ||
| import io.kotest.matchers.shouldBe | ||
| import io.spine.given.home.State | ||
| import io.spine.given.home.commands.addDevice | ||
| import io.spine.given.home.commands.setState | ||
| import io.spine.given.home.homeAutomation | ||
| import io.spine.testing.server.blackbox.BlackBox | ||
| import io.spine.testing.server.blackbox.assertEntity | ||
| import org.junit.jupiter.api.DisplayName | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| @DisplayName("Generated `CommandRoutingSetup` should") | ||
| internal class CommandRoutingSetupITest { | ||
|
|
||
| @Test | ||
| fun `apply generated routes`() { | ||
| BlackBox.from(homeAutomation()).use { context -> | ||
| val l1 = DeviceId.generate() | ||
|
|
||
| context.receivesCommand( | ||
| addDevice { | ||
| device = l1 | ||
| name = "First Lamp" | ||
| } | ||
| ) | ||
|
|
||
| // The first command is handled using the standard routing | ||
| // via the first command field. | ||
| var lamp = context.readState(l1) | ||
| lamp.state shouldBe State.OFF | ||
|
|
||
| context.receivesCommand( | ||
| setState { | ||
| device = l1 | ||
| state = State.ON | ||
| } | ||
| ) | ||
|
|
||
| // The command was handled via custom routing declared in the class. | ||
| lamp = context.readState(l1) | ||
| lamp.state shouldBe State.ON | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Reads the state of the [DeviceAggregate] with the given ID. | ||
| */ | ||
| private fun BlackBox.readState(id: DeviceId) = | ||
| assertEntity<DeviceAggregate, DeviceId>(id).actual()?.state() as Device |
This file contains hidden or 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
71 changes: 71 additions & 0 deletions
71
...ting-tests/src/test/kotlin/io/spine/tools/mc/java/routing/tests/StateRoutingSetupITest.kt
This file contains hidden or 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,71 @@ | ||
| /* | ||
| * Copyright 2025, TeamDev. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Redistribution and use in source and/or binary forms, with or without | ||
| * modification, must retain the above copyright notice and the following | ||
| * disclaimer. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package io.spine.tools.mc.java.routing.tests | ||
|
|
||
| import io.kotest.matchers.shouldBe | ||
| import io.spine.given.home.Home | ||
| import io.spine.given.home.HomeProjection | ||
| import io.spine.given.home.HomeProjection.Companion.SINGLETON_ID | ||
| import io.spine.given.home.RoomId | ||
| import io.spine.given.home.events.roomAdded | ||
| import io.spine.given.home.homeAutomation | ||
| import io.spine.testing.server.blackbox.BlackBox | ||
| import io.spine.testing.server.blackbox.assertEntity | ||
| import org.junit.jupiter.api.DisplayName | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| @DisplayName("Generated `StateRoutingSetup` should") | ||
| internal class StateRoutingSetupITest { | ||
|
|
||
| @Test | ||
| fun `apply generated routes`() { | ||
| BlackBox.from(homeAutomation()).use { context -> | ||
| val r1 = RoomId.generate() | ||
| val r2 = RoomId.generate() | ||
|
|
||
| context.receivesEvent( | ||
| roomAdded { | ||
| room = r1 | ||
| name = "Living Room" | ||
| } | ||
| ) | ||
| context.receivesEvent( | ||
| roomAdded { | ||
| room = r2 | ||
| name = "Bedroom" | ||
| } | ||
| ) | ||
|
|
||
| val home = context.assertEntity<HomeProjection, String>(SINGLETON_ID) | ||
| .actual()?.state() as Home | ||
|
|
||
| // This means that two `Room` instances were routed by the routing | ||
| // function directing all the updates to the singleton. | ||
| home.roomList.map { it.name } shouldBe listOf("Living Room", "Bedroom") | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why to have them on the same line? The methods below don't do that.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because these functions generate events, while appliers update the state.
Also, I'm experimenting with the compact style for code which merely transforms a command into an event without doing much work.