From b211f34b8e40a3d5492b5fe7ee6e907939116040 Mon Sep 17 00:00:00 2001
From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de>
Date: Thu, 2 Jul 2015 14:00:07 +0200
Subject: [PATCH] added nested stages test

---
 src/changes/changes.xml                       |  3 +-
 src/main/java/teetime/framework/Stage.java    |  2 +-
 .../framework/AbstractCompositeStageTest.java | 55 +++++++++++++++++++
 3 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6ed7a57d..5f4f3953 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -21,8 +21,7 @@
 			</action>
 			<action dev="ntd" type="add" issue="171">
 				Configurations are now
-				built within the Configuration class which is passed on to nested
-				CompositeStages.
+				built within the Configuration class.
 				This removes any constraints on CompositeStages and
 				enables therefore multiple connections and multithreading.
 			</action>
diff --git a/src/main/java/teetime/framework/Stage.java b/src/main/java/teetime/framework/Stage.java
index 7b9398ca..4625f610 100644
--- a/src/main/java/teetime/framework/Stage.java
+++ b/src/main/java/teetime/framework/Stage.java
@@ -48,7 +48,7 @@ public abstract class Stage {
 	/** The owning thread of this stage if this stage is directly executed by a {@link AbstractRunnableStage}, <code>null</code> otherwise. */
 	protected Thread owningThread;
 
-	protected ConfigurationContext owningContext = EmptyContext.getInstance();
+	public ConfigurationContext owningContext = EmptyContext.getInstance();
 
 	protected Stage() {
 		this.id = this.createId();
diff --git a/src/test/java/teetime/framework/AbstractCompositeStageTest.java b/src/test/java/teetime/framework/AbstractCompositeStageTest.java
index 3ca971fb..2d8848e2 100644
--- a/src/test/java/teetime/framework/AbstractCompositeStageTest.java
+++ b/src/test/java/teetime/framework/AbstractCompositeStageTest.java
@@ -15,7 +15,62 @@
  */
 package teetime.framework;
 
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+import teetime.stage.Counter;
+import teetime.stage.InitialElementProducer;
+import teetime.stage.basic.Sink;
 
 public class AbstractCompositeStageTest {
 
+	@Test
+	public void testNestedStages() {
+		Execution<NestesConfig> exec = new Execution<NestesConfig>(new NestesConfig());
+		assertThat(exec.getConfiguration().getContext().getThreadableStages().size(), is(3));
+	}
+
+	private class NestesConfig extends Configuration {
+
+		private final InitialElementProducer<Object> init;
+		private final Sink sink;
+		private final TestNestingCompositeStage compositeStage;
+
+		public NestesConfig() {
+			init = new InitialElementProducer<Object>(new Object());
+			sink = new Sink();
+			compositeStage = new TestNestingCompositeStage();
+			connectPorts(init.getOutputPort(), compositeStage.firstCompositeStage.firstCounter.getInputPort());
+			connectPorts(compositeStage.secondCompositeStage.secondCounter.getOutputPort(), sink.getInputPort());
+
+		}
+	}
+
+	private class TestCompositeStage extends AbstractCompositeStage {
+
+		private final Counter firstCounter = new Counter();
+		private final Counter secondCounter = new Counter();
+
+		public TestCompositeStage() {
+			addThreadableStage(firstCounter);
+			connectPorts(firstCounter.getOutputPort(), secondCounter.getInputPort());
+		}
+
+	}
+
+	private class TestNestingCompositeStage extends AbstractCompositeStage {
+
+		public TestCompositeStage firstCompositeStage;
+		public TestCompositeStage secondCompositeStage;
+
+		public TestNestingCompositeStage() {
+			firstCompositeStage = new TestCompositeStage();
+			secondCompositeStage = new TestCompositeStage();
+			connectPorts(firstCompositeStage.secondCounter.getOutputPort(), secondCompositeStage.firstCounter.getInputPort());
+		}
+
+	}
+
 }
-- 
GitLab