blob: 9e072efc521f2d36c924ab01fd68118c8a5f3a5a [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.apex.malhar.contrib.misc.algo;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.apache.apex.malhar.lib.algo.MatchMap;
import org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink;
/**
* @deprecated
* Functional tests for {@link org.apache.apex.malhar.lib.algo.MatchMap}<p>
*
*/
@Deprecated
public class MatchMapTest
{
/**
* Test node logic emits correct results
*/
@Test
public void testNodeProcessing() throws Exception
{
testNodeProcessingSchema(new MatchMap<String, Integer>());
testNodeProcessingSchema(new MatchMap<String, Double>());
testNodeProcessingSchema(new MatchMap<String, Float>());
testNodeProcessingSchema(new MatchMap<String, Short>());
testNodeProcessingSchema(new MatchMap<String, Long>());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(MatchMap oper)
{
CountAndLastTupleTestSink matchSink = new CountAndLastTupleTestSink();
oper.match.setSink(matchSink);
oper.setKey("a");
oper.setValue(3.0);
oper.setTypeNEQ();
oper.beginWindow(0);
HashMap<String, Number> input = new HashMap<String, Number>();
input.put("a", 2);
input.put("b", 20);
input.put("c", 1000);
oper.data.process(input);
input.clear();
input.put("a", 3);
oper.data.process(input);
oper.endWindow();
// One for each key
Assert.assertEquals("number emitted tuples", 1, matchSink.count);
for (Map.Entry<String, Number> e : ((HashMap<String, Number>)matchSink.tuple).entrySet()) {
if (e.getKey().equals("a")) {
Assert.assertEquals("emitted value for 'a' was ", new Double(2), new Double(e.getValue().doubleValue()));
} else if (e.getKey().equals("b")) {
Assert.assertEquals("emitted tuple for 'b' was ", new Double(20), new Double(e.getValue().doubleValue()));
} else if (e.getKey().equals("c")) {
Assert.assertEquals("emitted tuple for 'c' was ", new Double(1000), new Double(e.getValue().doubleValue()));
}
}
}
}