diff --git a/src/test/java/teetime/stage/CipherByteArrayTest.java b/src/test/java/teetime/stage/CipherByteArrayTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8f8d7882cfb32615d84ccb8cb47b95b3d1dc4b25 --- /dev/null +++ b/src/test/java/teetime/stage/CipherByteArrayTest.java @@ -0,0 +1,69 @@ +/** + * Copyright (C) 2015 TeeTime (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.stage; + +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import teetime.framework.Analysis; +import teetime.framework.AnalysisConfiguration; +import teetime.framework.pipe.IPipeFactory; +import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering; +import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication; +import teetime.stage.CipherByteArray.CipherMode; + +/** + * @author Nils Christian Ehmke + */ +public class CipherByteArrayTest { + + @Test + public void decryptShouldInvertEncryption() { + final byte[] input = new byte[] { 1, 2, 3, 4, 5 }; + final List<byte[]> output = new ArrayList<byte[]>(); + + final Configuration configuration = new Configuration(input, output); + final Analysis analysis = new Analysis(configuration); + analysis.start(); + + assertThat(output, contains(input)); + } + + private class Configuration extends AnalysisConfiguration { + + public Configuration(final byte[] input, final List<byte[]> output) { + final IPipeFactory pipeFactory = PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false); + + final InitialElementProducer<byte[]> producer = new InitialElementProducer<byte[]>(input); + final CipherByteArray encryptStage = new CipherByteArray("somePassword", CipherMode.ENCRYPT); + final CipherByteArray decryptStage = new CipherByteArray("somePassword", CipherMode.DECRYPT); + final CollectorSink<byte[]> sink = new CollectorSink<byte[]>(output); + + pipeFactory.create(producer.getOutputPort(), encryptStage.getInputPort()); + pipeFactory.create(encryptStage.getOutputPort(), decryptStage.getInputPort()); + pipeFactory.create(decryptStage.getOutputPort(), sink.getInputPort()); + + super.addThreadableStage(producer); + } + + } + +} diff --git a/src/test/java/teetime/stage/string/ToLowerCaseTest.java b/src/test/java/teetime/stage/string/ToLowerCaseTest.java index c1bde929db1632e068346a92d028e12eec724a3d..02e6d9b028998ae8fbfe0797342cc46026e76d67 100644 --- a/src/test/java/teetime/stage/string/ToLowerCaseTest.java +++ b/src/test/java/teetime/stage/string/ToLowerCaseTest.java @@ -34,25 +34,25 @@ public class ToLowerCaseTest { @Before public void initializeFilter() { - filter = new ToLowerCase(); + this.filter = new ToLowerCase(); } @Test public void toLowerCaseShouldWork() { - List<String> results = new ArrayList<String>(); + final List<String> results = new ArrayList<String>(); - test(filter).and().send("Hello World").to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start(); + test(this.filter).and().send("Hello World").to(this.filter.getInputPort()).and().receive(results).from(this.filter.getOutputPort()).start(); assertThat(results, contains("hello world")); } @Test - public void toLowerCaseShouldRemoveNonWordCharacters() { - List<String> results = new ArrayList<String>(); + public void toLowerCaseShouldNotRemoveNonWordCharacters() { + final List<String> results = new ArrayList<String>(); - test(filter).and().send("Hello 1 2 3 World").to(filter.getInputPort()).and().receive(results).from(filter.getOutputPort()).start(); + test(this.filter).and().send("1 2 3").to(this.filter.getInputPort()).and().receive(results).from(this.filter.getOutputPort()).start(); - assertThat(results, contains("hello world")); + assertThat(results, contains("1 2 3")); } } diff --git a/src/test/java/teetime/stage/string/TokenizerTest.java b/src/test/java/teetime/stage/string/TokenizerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..cadbcb8a43c3cbce27eeba32bc586984df55516b --- /dev/null +++ b/src/test/java/teetime/stage/string/TokenizerTest.java @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2015 TeeTime (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.stage.string; + +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.junit.Assert.assertThat; +import static teetime.framework.test.StageTester.test; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +/** + * @author Nils Christian Ehmke + */ +public class TokenizerTest { + + private Tokenizer tokenizer; + + @Before + public void initializeTokenizer() { + tokenizer = new Tokenizer(";"); + } + + @Test + public void tokenizerShouldJustDelaySingleToken() { + List<String> results = new ArrayList<String>(); + + test(tokenizer).and().send("Hello World").to(tokenizer.getInputPort()).and().receive(results).from(tokenizer.getOutputPort()).start(); + + assertThat(results, contains("Hello World")); + } + + @Test + public void tokenizerShouldSplitMultipleToken() { + List<String> results = new ArrayList<String>(); + + test(tokenizer).and().send("Hello;World").to(tokenizer.getInputPort()).and().receive(results).from(tokenizer.getOutputPort()).start(); + + assertThat(results, contains("Hello", "World")); + } + +}