Skip to content
Merged
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
Expand Up @@ -18,40 +18,40 @@
import io.flamingock.internal.common.core.preview.PreviewPipeline;

public class FlamingockMetadata {

private PreviewPipeline pipeline;
private String setup;
private String configFile;

public FlamingockMetadata() {
}

public FlamingockMetadata(PreviewPipeline pipeline, String setup, String configFile) {
this.pipeline = pipeline;
this.setup = setup;
this.configFile = configFile;
}

public PreviewPipeline getPipeline() {
return pipeline;
}

public void setPipeline(PreviewPipeline pipeline) {
this.pipeline = pipeline;
}

public String getSetup() {
return setup;
}

public void setSetup(String setup) {
this.setup = setup;
}

public String getPipelineFile() {
return configFile;
}

public void setPipelineFile(String configFile) {
this.configFile = configFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ public abstract class AbstractTargetSystem<HOLDER extends AbstractTargetSystem<H
ContextConfigurable<HOLDER> {
private final String id;

protected Context targetSystemContext = new SimpleContext();
protected final Context targetSystemContext = new SimpleContext();

public AbstractTargetSystem(String id) {
this.id = id;
targetSystemContext.setProperty("change.targetSystem.id", id);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.flamingock.common.test.pipeline.CodeChangeTestDefinition;
import io.flamingock.common.test.pipeline.PipelineTestHelper;
import io.flamingock.core.e2e.changes._008__TargetSystemManagerInjectionChange;
import io.flamingock.core.e2e.changes._009__TargetSystemIdInjectionChange;
import io.flamingock.core.e2e.helpers.Counter;
import io.flamingock.core.kit.audit.AuditTestHelper;
import io.flamingock.core.kit.inmemory.InMemoryTestKit;
Expand All @@ -30,9 +31,11 @@
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.Collections;

import static io.flamingock.core.kit.audit.AuditEntryExpectation.APPLIED;
import static io.flamingock.core.kit.audit.AuditEntryExpectation.STARTED;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;


Expand Down Expand Up @@ -76,4 +79,44 @@ void shouldInjectTargetSystemManagerInChange() {
APPLIED("test8-target-system-manager-injection")
);
}

@Test
@DisplayName("Should inject target system ID as dependency in change via @Named annotation")
void shouldInjectTargetSystemIdInChange() {
// Given - Create isolated test kit with domain-separated helpers
InMemoryTestKit testKit = InMemoryTestKit.create();
AuditTestHelper auditHelper = testKit.getAuditHelper();

Counter counter = new Counter();

NonTransactionalTargetSystem targetSystem = new NonTransactionalTargetSystem("kafka")
.addDependency(counter);

try (MockedStatic<Deserializer> mocked = Mockito.mockStatic(Deserializer.class)) {
mocked.when(Deserializer::readPreviewPipelineFromFile).thenReturn(
PipelineTestHelper.getPreviewPipeline(
new CodeChangeTestDefinition(
_009__TargetSystemIdInjectionChange.class,
Collections.singletonList(Counter.class)
)
)
);

// When - Execute using test builder
testKit.createBuilder()
.addTargetSystem(targetSystem)
.build()
.run();
}

// Then - Verify that target system ID was successfully injected
assertTrue(counter.isExecuted(), "Counter.executed should be true, indicating target system ID was injected");
assertEquals("kafka", counter.getTargetSystemId(), "Target system ID should match the configured ID");

// Verify complete audit flow
auditHelper.verifyAuditSequenceStrict(
STARTED("test9-target-system-id-injection"),
APPLIED("test9-target-system-id-injection")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2025 Flamingock (https://www.flamingock.io)
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.flamingock.core.e2e.changes;

import io.flamingock.api.annotations.Change;
import io.flamingock.api.annotations.Apply;
import io.flamingock.api.annotations.NonLockGuarded;
import io.flamingock.api.annotations.TargetSystem;
import io.flamingock.core.e2e.helpers.Counter;

import javax.inject.Named;

/**
* Change that receives the target system ID as a dependency to verify
* that it can be injected via @Named("change.targetSystem.id").
*/
@Change(id = "test9-target-system-id-injection", transactional = false, author = "aperezdieppa")
@TargetSystem(id = "kafka")
public class _009__TargetSystemIdInjectionChange {

@Apply
public void apply(@Named("change.targetSystem.id") String targetSystemId, @NonLockGuarded Counter counter) {
if (targetSystemId != null && !targetSystemId.isEmpty()) {
counter.setTargetSystemId(targetSystemId);
counter.setExecuted(true);
System.out.println("Target system ID successfully injected: " + targetSystemId);
} else {
throw new RuntimeException("Target system ID was not injected");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class Counter {
private boolean executed = false;
private boolean rollbacked = false;
private String targetSystemId;

public boolean isExecuted() {
return executed;
Expand All @@ -34,5 +35,13 @@ public boolean isRollbacked() {
public void setRollbacked(boolean rollbacked) {
this.rollbacked = rollbacked;
}

public String getTargetSystemId() {
return targetSystemId;
}

public void setTargetSystemId(String targetSystemId) {
this.targetSystemId = targetSystemId;
}
}

Loading