Skip to content

Commit a78584f

Browse files
authored
feat: TargetSystemManager available as dependency (#734)
1 parent 7cde119 commit a78584f

File tree

4 files changed

+122
-13
lines changed

4 files changed

+122
-13
lines changed

core/flamingock-core/src/main/java/io/flamingock/internal/core/builder/change/AbstractChangeRunnerBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ private LoadedPipeline loadPipeline() {
231231
private PriorityContext buildContext() {
232232
logger.trace("injecting internal configuration");
233233
addDependency(coreConfiguration);
234+
addDependency(targetSystemManager);
234235
updateContextSpecific();
235236
List<ContextResolver> dependencyContextsFromPlugins = pluginManager.getPlugins()
236237
.stream()

core/flamingock-core/src/main/java/io/flamingock/internal/core/targets/TargetSystemManager.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,6 @@ public void add(TargetSystem targetSystem) {
7171
}
7272

7373

74-
/**
75-
* Registers the default {@link TargetSystem} to be returned when a specific ID is not found.
76-
* <p>
77-
* Also adds it to the general registry.
78-
*
79-
* @param defaultTargetSystem the default target system
80-
* @throws IllegalArgumentException if the target system or its ID is null/blank
81-
*/
82-
public void setAuditStoreTargetSystem(TargetSystem defaultTargetSystem) {
83-
add(defaultTargetSystem);
84-
this.auditStoreTargetSystem = (AbstractTargetSystem<?>) defaultTargetSystem;
85-
}
86-
8774
/**
8875
* Returns the {@link TargetSystem} associated with the given descriptor.
8976
*
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2025 Flamingock (https://www.flamingock.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.flamingock.core.e2e;
17+
18+
import io.flamingock.common.test.pipeline.CodeChangeTestDefinition;
19+
import io.flamingock.common.test.pipeline.PipelineTestHelper;
20+
import io.flamingock.core.e2e.changes._008__TargetSystemManagerInjectionChange;
21+
import io.flamingock.core.e2e.helpers.Counter;
22+
import io.flamingock.core.kit.audit.AuditTestHelper;
23+
import io.flamingock.core.kit.inmemory.InMemoryTestKit;
24+
import io.flamingock.internal.common.core.util.Deserializer;
25+
import io.flamingock.internal.core.targets.TargetSystemManager;
26+
import io.flamingock.targetsystem.nontransactional.NonTransactionalTargetSystem;
27+
import org.junit.jupiter.api.DisplayName;
28+
import org.junit.jupiter.api.Test;
29+
import org.mockito.MockedStatic;
30+
import org.mockito.Mockito;
31+
32+
import java.util.Arrays;
33+
34+
import static io.flamingock.core.kit.audit.AuditEntryExpectation.APPLIED;
35+
import static io.flamingock.core.kit.audit.AuditEntryExpectation.STARTED;
36+
import static org.junit.jupiter.api.Assertions.assertTrue;
37+
38+
39+
class BuilderE2ETest {
40+
41+
@Test
42+
@DisplayName("Should inject TargetSystemManager as dependency in change")
43+
void shouldInjectTargetSystemManagerInChange() {
44+
// Given - Create isolated test kit with domain-separated helpers
45+
InMemoryTestKit testKit = InMemoryTestKit.create();
46+
AuditTestHelper auditHelper = testKit.getAuditHelper();
47+
48+
Counter counter = new Counter();
49+
50+
NonTransactionalTargetSystem targetSystem = new NonTransactionalTargetSystem("kafka")
51+
.addDependency(counter);
52+
53+
try (MockedStatic<Deserializer> mocked = Mockito.mockStatic(Deserializer.class)) {
54+
mocked.when(Deserializer::readPreviewPipelineFromFile).thenReturn(
55+
PipelineTestHelper.getPreviewPipeline(
56+
new CodeChangeTestDefinition(
57+
_008__TargetSystemManagerInjectionChange.class,
58+
Arrays.asList(TargetSystemManager.class, Counter.class)
59+
)
60+
)
61+
);
62+
63+
// When - Execute using test builder
64+
testKit.createBuilder()
65+
.addTargetSystem(targetSystem)
66+
.build()
67+
.run();
68+
}
69+
70+
// Then - Verify that TargetSystemManager was successfully injected
71+
assertTrue(counter.isExecuted(), "Counter.executed should be true, indicating TargetSystemManager was injected");
72+
73+
// Verify complete audit flow
74+
auditHelper.verifyAuditSequenceStrict(
75+
STARTED("test8-target-system-manager-injection"),
76+
APPLIED("test8-target-system-manager-injection")
77+
);
78+
}
79+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Flamingock (https://www.flamingock.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.flamingock.core.e2e.changes;
17+
18+
import io.flamingock.api.annotations.Change;
19+
import io.flamingock.api.annotations.Apply;
20+
import io.flamingock.api.annotations.NonLockGuarded;
21+
import io.flamingock.api.annotations.TargetSystem;
22+
import io.flamingock.core.e2e.helpers.Counter;
23+
import io.flamingock.internal.core.targets.TargetSystemManager;
24+
25+
/**
26+
* Change that receives TargetSystemManager as a dependency to verify
27+
* that it can be injected into changes.
28+
*/
29+
@Change(id = "test8-target-system-manager-injection", transactional = false, author = "aperezdieppa")
30+
@TargetSystem(id = "kafka")
31+
public class _008__TargetSystemManagerInjectionChange {
32+
33+
@Apply
34+
public void apply(TargetSystemManager targetSystemManager, @NonLockGuarded Counter counter) {
35+
if (targetSystemManager != null) {
36+
counter.setExecuted(true);
37+
System.out.println("TargetSystemManager successfully injected");
38+
} else {
39+
throw new RuntimeException("TargetSystemManager was not injected");
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)