Skip to content

Commit

Permalink
Fixed #101 NoSuchElementException with custom action container in tes…
Browse files Browse the repository at this point in the history
…t runner
  • Loading branch information
christophd committed May 23, 2016
1 parent 51d53ea commit fd57627
Show file tree
Hide file tree
Showing 19 changed files with 474 additions and 6 deletions.
@@ -0,0 +1,54 @@
/*
* Copyright 2006-2016 the original author or authors.
*
* 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 com.consol.citrus.javadsl.design;

import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.container.AbstractActionContainer;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.dsl.builder.AbstractTestContainerBuilder;
import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
import org.testng.annotations.Test;

/**
* @author Christoph Deppisch
* @since 2.6
*/
@Test
public class CustomContainerJavaIT extends TestNGCitrusTestDesigner {

@CitrusTest
public void shouldExecuteReverseContainer() {
reverse().actions(
echo("${text}"),
echo("Does it work?"),
createVariable("text", "Yes it works!")
);
}

public AbstractTestContainerBuilder<ReverseActionContainer> reverse() {
return container(new ReverseActionContainer());
}

private class ReverseActionContainer extends AbstractActionContainer {
@Override
public void doExecute(TestContext context) {
for (int i = getActions().size(); i > 0; i--) {
getActions().get(i - 1).execute(context);
}
}
}
}
@@ -0,0 +1,54 @@
/*
* Copyright 2006-2016 the original author or authors.
*
* 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 com.consol.citrus.javadsl.runner;

import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.container.AbstractActionContainer;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.dsl.builder.AbstractTestContainerBuilder;
import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;
import org.testng.annotations.Test;

/**
* @author Christoph Deppisch
* @since 2.6
*/
@Test
public class CustomContainerTestRunnerIT extends TestNGCitrusTestRunner {

@CitrusTest
public void shouldExecuteReverseContainer() {
reverse().actions(
echo("${text}"),
echo("Does it work?"),
createVariable("text", "Yes it works!")
);
}

public AbstractTestContainerBuilder<ReverseActionContainer> reverse() {
return container(new ReverseActionContainer());
}

private class ReverseActionContainer extends AbstractActionContainer {
@Override
public void doExecute(TestContext context) {
for (int i = getActions().size(); i > 0; i--) {
getActions().get(i - 1).execute(context);
}
}
}
}
Expand Up @@ -34,6 +34,21 @@ public class DelegatingTestAction<T extends TestAction> extends AbstractTestActi
/** Delegate */
private T delegate;

/**
* Default constructor.
*/
public DelegatingTestAction() {
super();
}

/**
* Constructor using the delegate test action.
* @param delegate
*/
public DelegatingTestAction(T delegate) {
this.delegate = delegate;
}

@Override
public void doExecute(TestContext context) {
if (delegate != null) {
Expand Down
Expand Up @@ -50,7 +50,7 @@ public AbstractExceptionContainerBuilder(TestDesigner designer, T container) {
* @param actions
* @return
*/
public TestActionContainer when(TestAction... actions) {
public T when(TestAction... actions) {
return actions(actions);
}
}
Expand Up @@ -38,7 +38,7 @@ public abstract class AbstractTestContainerBuilder<T extends TestActionContainer
protected TestDesigner designer;

/** The action container */
protected final TestActionContainer container;
protected final T container;

/**
* Default constructor with test runner and test action.
Expand Down Expand Up @@ -67,7 +67,7 @@ public AbstractTestContainerBuilder(TestDesigner designer, T container) {
* @param actions
* @return
*/
public TestActionContainer actions(TestAction ... actions) {
public T actions(TestAction ... actions) {
if (runner != null) {
for (int i = 0; i < actions.length; i++) {
if (actions[i] instanceof com.consol.citrus.dsl.runner.ApplyTestBehaviorAction) {
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.consol.citrus.dsl.builder;

import com.consol.citrus.TestAction;
import com.consol.citrus.container.TestActionContainer;
import com.consol.citrus.dsl.container.FinallySequence;
import com.consol.citrus.dsl.design.TestDesigner;
import com.consol.citrus.dsl.runner.TestRunner;
Expand Down Expand Up @@ -63,7 +62,7 @@ public FinallySequenceBuilder(TestRunner runner) {
}

@Override
public TestActionContainer actions(TestAction... actions) {
public FinallySequence actions(TestAction... actions) {
if (runner != null) {
return super.actions(actions);
} else {
Expand Down
Expand Up @@ -172,6 +172,12 @@ public ApplyTestBehaviorAction applyBehavior(TestBehavior behavior) {
return action;
}

@Override
public <T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container) {
AbstractTestContainerBuilder<T> containerBuilder = new AbstractTestContainerBuilder<T>(this, container) {};
return containerBuilder;
}

@Override
public void action(TestAction testAction) {
List<TestAction> actions = null;
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.consol.citrus.*;
import com.consol.citrus.actions.*;
import com.consol.citrus.container.AbstractActionContainer;
import com.consol.citrus.dsl.builder.*;
import com.consol.citrus.dsl.util.PositionHandle;
import com.consol.citrus.endpoint.Endpoint;
Expand Down Expand Up @@ -116,6 +117,13 @@ public interface TestDesigner extends ApplicationContextAware {
*/
ApplyTestBehaviorAction applyBehavior(TestBehavior behavior);

/**
* Prepare and add a custom container implementation.
* @param container
* @return
*/
<T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container);

/**
* Action creating a new test variable during a test.
*
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.consol.citrus.*;
import com.consol.citrus.actions.*;
import com.consol.citrus.container.AbstractActionContainer;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.dsl.builder.*;
import com.consol.citrus.dsl.design.*;
Expand Down Expand Up @@ -170,6 +171,11 @@ public ApplyTestBehaviorAction applyBehavior(TestBehavior behavior) {
return testDesigner.applyBehavior(behavior);
}

@Override
public <T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container) {
return testDesigner.container(container);
}

@Override
public AntRunBuilder antrun(String buildFilePath) {
return testDesigner.antrun(buildFilePath);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.consol.citrus.*;
import com.consol.citrus.actions.*;
import com.consol.citrus.camel.actions.AbstractCamelRouteAction;
import com.consol.citrus.container.AbstractActionContainer;
import com.consol.citrus.container.Template;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.docker.actions.DockerExecuteAction;
Expand Down Expand Up @@ -139,6 +140,11 @@ public ApplyTestBehaviorAction applyBehavior(com.consol.citrus.dsl.runner.TestBe
return testRunner.applyBehavior(behavior);
}

@Override
public <T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container) {
return testRunner.container(container);
}

@Override
public CreateVariablesAction createVariable(String variableName, String value) {
return testRunner.createVariable(variableName, value);
Expand Down
Expand Up @@ -207,6 +207,13 @@ public ApplyTestBehaviorAction applyBehavior(TestBehavior behavior) {
return run(new ApplyTestBehaviorAction(this, behavior));
}

@Override
public <T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container) {
AbstractTestContainerBuilder<T> containerBuilder = new AbstractTestContainerBuilder<T>(this, container) {};
this.containers.push(containerBuilder.build());
return containerBuilder;
}

@Override
public CreateVariablesAction createVariable(String variableName, String value) {
CreateVariablesAction action = new CreateVariablesAction();
Expand Down
Expand Up @@ -19,7 +19,7 @@
import com.consol.citrus.*;
import com.consol.citrus.actions.*;
import com.consol.citrus.camel.actions.AbstractCamelRouteAction;
import com.consol.citrus.container.Template;
import com.consol.citrus.container.*;
import com.consol.citrus.docker.actions.DockerExecuteAction;
import com.consol.citrus.dsl.builder.*;
import com.consol.citrus.jms.actions.PurgeJmsQueuesAction;
Expand Down Expand Up @@ -123,6 +123,13 @@ public interface TestRunner extends ApplicationContextAware {
*/
ApplyTestBehaviorAction applyBehavior(TestBehavior behavior);

/**
* Prepare and add a custom container implementation.
* @param container
* @return
*/
<T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container);

/**
* Action creating a new test variable during a test.
*
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.consol.citrus.*;
import com.consol.citrus.actions.*;
import com.consol.citrus.container.AbstractActionContainer;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.dsl.builder.*;
import com.consol.citrus.dsl.design.*;
Expand Down Expand Up @@ -170,6 +171,11 @@ public ApplyTestBehaviorAction applyBehavior(TestBehavior behavior) {
return testDesigner.applyBehavior(behavior);
}

@Override
public <T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container) {
return testDesigner.container(container);
}

@Override
public AntRunBuilder antrun(String buildFilePath) {
return testDesigner.antrun(buildFilePath);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.consol.citrus.*;
import com.consol.citrus.actions.*;
import com.consol.citrus.camel.actions.AbstractCamelRouteAction;
import com.consol.citrus.container.AbstractActionContainer;
import com.consol.citrus.container.Template;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.docker.actions.DockerExecuteAction;
Expand Down Expand Up @@ -138,6 +139,11 @@ public ApplyTestBehaviorAction applyBehavior(TestBehavior behavior) {
return testRunner.applyBehavior(behavior);
}

@Override
public <T extends AbstractActionContainer> AbstractTestContainerBuilder<T> container(T container) {
return testRunner.container(container);
}

@Override
public CreateVariablesAction createVariable(String variableName, String value) {
return testRunner.createVariable(variableName, value);
Expand Down

0 comments on commit fd57627

Please sign in to comment.