diff --git a/src/test/java/teetime/stage/opad/filter/AnomalyDetectionFilterTest.java b/src/test/java/teetime/stage/opad/filter/AnomalyDetectionFilterTest.java index 5a2619bd84deaa0bda742583b17b1443b81bd740..d74e49f392ac0c6b13dd3457aeeca125fa6068c8 100644 --- a/src/test/java/teetime/stage/opad/filter/AnomalyDetectionFilterTest.java +++ b/src/test/java/teetime/stage/opad/filter/AnomalyDetectionFilterTest.java @@ -44,8 +44,7 @@ public class AnomalyDetectionFilterTest { private StorableDetectionResult input3; private StorableDetectionResult input4; private List<StorableDetectionResult> inputElements; - private List<StorableDetectionResult> resultsNormalPort; - private List<StorableDetectionResult> resultsAnnormalPort; + private List<StorableDetectionResult> results; @Before public void initializeAnomalyDetectionFilterAndInputs() { @@ -56,44 +55,37 @@ public class AnomalyDetectionFilterTest { input4 = new StorableDetectionResult("Test4", 7, 1, 1, 1); inputElements = Arrays.asList(input1, input2, input3, input4); - resultsNormalPort = new ArrayList<StorableDetectionResult>(); - resultsAnnormalPort = new ArrayList<StorableDetectionResult>(); + results = new ArrayList<StorableDetectionResult>(); } @Test - public void theOutputPortNormalShouldForwardElements() { + public void theOutputPortShouldForwardZeroElements() { Collection<Pair<Thread, Throwable>> exceptions; exceptions = test(adf).and().send(input1, input2).to(adf.getInputPort()) - .and().receive(resultsNormalPort).from(adf.getOutputPortNormal()) - .and().receive(resultsAnnormalPort).from(adf.getOutputPortAnnormal()) + .and().receive(results).from(adf.getOutputPort()) .start(); assertThat(exceptions, is(empty())); - assertThat(resultsNormalPort, contains(input1, input2)); - assertThat(resultsAnnormalPort, is(empty())); + assertThat(results, is(empty())); } @Test - public void theOutputPortAnnormalShouldForwardElements() { + public void theOutputPortShouldForwardTwoElements() { Collection<Pair<Thread, Throwable>> exceptions; exceptions = test(adf).and().send(input3, input4).to(adf.getInputPort()) - .and().receive(resultsNormalPort).from(adf.getOutputPortNormal()) - .and().receive(resultsAnnormalPort).from(adf.getOutputPortAnnormal()) + .and().receive(results).from(adf.getOutputPort()) .start(); assertThat(exceptions, is(empty())); - assertThat(resultsNormalPort, is(empty())); - assertThat(resultsAnnormalPort, contains(input3, input4)); + assertThat(results, contains(input3, input4)); } @Test - public void bothOutputPortsShouldForwardElements() { + public void theOutputPortsShouldForwardElements() { Collection<Pair<Thread, Throwable>> exceptions; exceptions = test(adf).and().send(inputElements).to(adf.getInputPort()) - .and().receive(resultsNormalPort).from(adf.getOutputPortNormal()) - .and().receive(resultsAnnormalPort).from(adf.getOutputPortAnnormal()) + .and().receive(results).from(adf.getOutputPort()) .start(); assertThat(exceptions, is(empty())); - assertThat(resultsNormalPort, contains(input1, input2)); - assertThat(resultsAnnormalPort, contains(input3, input4)); + assertThat(results, contains(input3, input4)); } } diff --git a/src/test/java/teetime/stage/opad/filter/NoAnomalyDetectionFilterTest.java b/src/test/java/teetime/stage/opad/filter/NoAnomalyDetectionFilterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bbd34ca451ceb21c27b44125c110db1440b2ccac --- /dev/null +++ b/src/test/java/teetime/stage/opad/filter/NoAnomalyDetectionFilterTest.java @@ -0,0 +1,89 @@ +/** + * 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.opad.filter; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +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.Arrays; +import java.util.Collection; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import teetime.util.Pair; + +import kieker.tools.opad.record.StorableDetectionResult; + +/** + * @author Arne Jan Salveter + */ +public class NoAnomalyDetectionFilterTest { + + private NoAnomalyDetectionFilter adf; + private StorableDetectionResult input1; + private StorableDetectionResult input2; + private StorableDetectionResult input3; + private StorableDetectionResult input4; + private List<StorableDetectionResult> inputElements; + private List<StorableDetectionResult> results; + + @Before + public void initializeAnomalyDetectionFilterAndInputs() { + adf = new NoAnomalyDetectionFilter(6); + input1 = new StorableDetectionResult("Test1", 1, 1, 1, 1); + input2 = new StorableDetectionResult("Test2", 2, 1, 1, 1); + input3 = new StorableDetectionResult("Test3", 6, 1, 1, 1); + input4 = new StorableDetectionResult("Test4", 7, 1, 1, 1); + inputElements = Arrays.asList(input1, input2, input3, input4); + results = new ArrayList<StorableDetectionResult>(); + } + + @Test + public void theOutputPortShouldForwardTwoElements() { + Collection<Pair<Thread, Throwable>> exceptions; + exceptions = test(adf).and().send(input1, input2).to(adf.getInputPort()) + .and().receive(results).from(adf.getOutputPort()) + .start(); + assertThat(exceptions, is(empty())); + assertThat(results, contains(input1, input2)); + } + + @Test + public void theOutputPortShouldForwardZeroElements() { + Collection<Pair<Thread, Throwable>> exceptions; + exceptions = test(adf).and().send(input3, input4).to(adf.getInputPort()) + .and().receive(results).from(adf.getOutputPort()) + .start(); + assertThat(exceptions, is(empty())); + assertThat(results, is(empty())); + } + + @Test + public void theOutputPortsShouldForwardElements() { + Collection<Pair<Thread, Throwable>> exceptions; + exceptions = test(adf).and().send(inputElements).to(adf.getInputPort()) + .and().receive(results).from(adf.getOutputPort()) + .start(); + assertThat(exceptions, is(empty())); + assertThat(results, contains(input1, input2)); + } +}