/**
 * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net)
 *
 * 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 teetime.framework;

import org.junit.Assert;
import org.junit.Test;

import teetime.stage.Cache;
import teetime.stage.Counter;

public class StageTest {

	@Test
	public void testId() {
		Stage.clearInstanceCounters();

		Counter<Object> counter0 = new Counter<Object>();
		Counter<Object> counter1 = new Counter<Object>();
		Assert.assertEquals("Counter-0", counter0.getId());
		Assert.assertEquals("Counter-1", counter1.getId());

		for (int i = 0; i < 100; i++) {
			Cache<Object> cache = new Cache<Object>();
			Assert.assertEquals("Cache-" + i, cache.getId());
		}
	}

}

@@ -697,49 +697,274 @@
 ort 
-org.junit.Assert;%0Aimport org.junit.Test;%0A
+static org.junit.Assert.assertEquals;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0Aimport teetime.framework.pipe.IPipeFactory;%0Aimport teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;%0Aimport teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
 %0Aimp
@@ -1017,16 +1017,61 @@
 Counter;
+%0Aimport teetime.stage.InitialElementProducer;
 %0A%0Apublic
@@ -1509,10 +1509,1115 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09@Test%0A%09public void testSetOwningThread() throws Exception %7B%0A%09%09TestConfig tc = new TestConfig();%0A%09%09new Analysis%3CTestConfig%3E(tc);%0A%09%09assertEquals(tc.init.owningThread, tc.delay.owningThread);%0A%09%7D%0A%0A%09private static class TestConfig extends AnalysisConfiguration %7B%0A%09%09final IPipeFactory intraFact = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false);%0A%09%09public final DelayAndTerminate delay;%0A%09%09public InitialElementProducer%3CString%3E init;%0A%0A%09%09public TestConfig() %7B%0A%09%09%09init = new InitialElementProducer%3CString%3E(%22Hello%22);%0A%09%09%09delay = new DelayAndTerminate(0);%0A%09%09%09intraFact.create(init.getOutputPort(), delay.getInputPort());%0A%09%09%09addThreadableStage(init);%0A%09%09%7D%0A%09%7D%0A%0A%09private static class DelayAndTerminate extends AbstractConsumerStage%3CString%3E %7B%0A%0A%09%09private final long delayInMs;%0A%0A%09%09public boolean finished;%0A%0A%09%09public DelayAndTerminate(final long delayInMs) %7B%0A%09%09%09super();%0A%09%09%09this.delayInMs = delayInMs;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09protected void execute(final String element) %7B%0A%09%09%09try %7B%0A%09%09%09%09Thread.sleep(delayInMs);%0A%09%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09%7D%0A%09%09%09finished = true;%0A%09%09%7D%0A%0A%09%7D%0A%0A
 %7D%0A

test for thread assignment