Skip to content

Commit f13a23d

Browse files
committed
[axon-system-plugin] Add test for CommitCommandFixturesLineRunner
1 parent 5573453 commit f13a23d

2 files changed

Lines changed: 62 additions & 5 deletions

File tree

axon-system-plugin/src/main/java/ai/stapi/axonsystemplugin/commandpersisting/CommitCommandFixturesLineRunner.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ public CommitCommandFixturesLineRunner(
2121
}
2222

2323
@Override
24-
public void run(String... args) throws Exception {
24+
public void run(String... args) {
25+
var outputDirectoryPath = getOutputDirectoryPath(args);
26+
this.commandGateway.sendAndWait(new CommitCommandFixtures(outputDirectoryPath));
27+
var exitCode = SpringApplication.exit(this.applicationContext, () -> 0);
28+
System.exit(exitCode);
29+
}
30+
31+
public static String getOutputDirectoryPath(String... args) {
2532
if (args.length == 0) {
2633
throw new RuntimeException("Please specify path where to commit persisted commands as command line argument.");
2734
}
2835
var path = Arrays.stream(args)
2936
.filter(arg -> arg.startsWith("_outputPath:"))
3037
.map(arg -> arg.replace("_outputPath:", ""))
3138
.findFirst();
32-
33-
this.commandGateway.sendAndWait(new CommitCommandFixtures(path.orElse(args[0])));
34-
var exitCode = SpringApplication.exit(this.applicationContext, () -> 0);
35-
System.exit(exitCode);
39+
40+
return path.orElse(args[0]);
3641
}
3742
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package ai.stapi.axonsystemplugin.commandpersisting;
2+
3+
import ai.stapi.axonsystem.commandpersisting.CommandMessageStore;
4+
import ai.stapi.axonsystemplugin.exampleimplmentation.CreateNewExampleNodeCommand;
5+
import ai.stapi.identity.UniversallyUniqueIdentifier;
6+
import ai.stapi.test.domain.DomainTestCase;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.test.context.ActiveProfiles;
13+
14+
15+
@ActiveProfiles("dev")
16+
class CommitCommandFixturesLineRunnerTest extends DomainTestCase {
17+
18+
private final CommandMessageStore commandMessageStore;
19+
20+
public CommitCommandFixturesLineRunnerTest(
21+
@Autowired CommandMessageStore commandMessageStore
22+
) {
23+
this.commandMessageStore = commandMessageStore;
24+
}
25+
26+
@BeforeEach
27+
void before() {
28+
this.commandMessageStore.wipeAll();
29+
}
30+
31+
@Test
32+
public void itWorks() {
33+
this.givenCommandIsDispatched(
34+
new CreateNewExampleNodeCommand(
35+
UniversallyUniqueIdentifier.randomUUID(),
36+
"ExampleNodeType",
37+
"Example Name"
38+
)
39+
);
40+
41+
var actualPath = this.getActualOutputDirectoryPath();
42+
var actualOutputPath = CommitCommandFixturesLineRunner.getOutputDirectoryPath(
43+
String.format("_outputPath:%s", actualPath)
44+
);
45+
Assertions.assertEquals(actualPath, actualOutputPath);
46+
}
47+
48+
@NotNull
49+
private String getActualOutputDirectoryPath() {
50+
return this.getLocationFilePath() + "/output";
51+
}
52+
}

0 commit comments

Comments
 (0)