Skip to content
Snippets Groups Projects
Commit 53e7f383 authored by as's avatar as
Browse files

fiex: AnomalyDetectionFilterTests and NoAnomalyDetectionFilterTests

parent d44f9dd8
No related branches found
No related tags found
No related merge requests found
......@@ -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));
}
}
/**
* 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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment