Skip to content

Commit

Permalink
chore: Fix YAML finally actions
Browse files Browse the repository at this point in the history
  • Loading branch information
christophd committed Oct 2, 2024
1 parent 42830a2 commit 303651f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@

import org.citrusframework.actions.NoopTestAction;
import org.citrusframework.container.TestActionContainer;
import org.citrusframework.spi.ReferenceResolver;
import org.citrusframework.spi.ReferenceResolverAware;

/**
* Abstract container builder takes care on calling the container runner when actions are placed in the container.
* @author Christoph Deppisch
*/
public abstract class AbstractTestContainerBuilder<T extends TestActionContainer, S extends TestActionContainerBuilder<T, S>> extends AbstractTestActionBuilder<T, S> implements TestActionContainerBuilder<T, S> {
public abstract class AbstractTestContainerBuilder<T extends TestActionContainer, S extends TestActionContainerBuilder<T, S>> extends AbstractTestActionBuilder<T, S> implements TestActionContainerBuilder<T, S>, ReferenceResolverAware {

protected final List<TestActionBuilder<?>> actions = new ArrayList<>();

protected ReferenceResolver referenceResolver;

@Override
public S actions(TestAction... actions) {
return actions(Stream.of(actions)
Expand All @@ -46,8 +50,12 @@ public S actions(TestActionBuilder<?>... actions) {
for (int i = 0; i < actions.length; i++) {
TestActionBuilder<?> current = actions[i];

if (current.build() instanceof NoopTestAction) {
continue;
try {
if (current.build() instanceof NoopTestAction) {
continue;
}
} catch (Exception exception) {
// do nothing - possible that the action build is not able to perform build at this state
}

if (this.actions.size() == i) {
Expand Down Expand Up @@ -75,6 +83,14 @@ private TestActionBuilder<?> resolveActionBuilder(TestActionBuilder<?> builder)
public T build() {
T container = doBuild();

if (referenceResolver != null) {
for (TestActionBuilder<?> builder : actions) {
if (builder instanceof ReferenceResolverAware referenceResolverAware) {
referenceResolverAware.setReferenceResolver(referenceResolver);
}
}
}

container.setActions(actions.stream()
.map(TestActionBuilder::build)
.filter(action -> !(action instanceof NoopTestAction))
Expand All @@ -93,6 +109,11 @@ public List<TestActionBuilder<?>> getActions() {
return actions;
}

@Override
public void setReferenceResolver(ReferenceResolver referenceResolver) {
this.referenceResolver = referenceResolver;
}

/**
* Static Java DSL container builder using generics.
* @param container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void setActions(List<TestActions> actions) {
}

public void setFinally(List<TestActions> actions) {
actions.forEach(action -> delegate.addTestAction(action.get()));
actions.forEach(action -> delegate.addFinalAction(action.get()));
}

public static class Variable {
Expand Down

0 comments on commit 303651f

Please sign in to comment.