This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new bbce64b1bf Test:Implement unit tests for pipeline element 
'MathOpProcessor' (#3300)
bbce64b1bf is described below

commit bbce64b1bf9a71d15fbc986e1bba1615a585eb97
Author: liu xinhao <[email protected]>
AuthorDate: Wed Nov 13 22:29:41 2024 +0800

    Test:Implement unit tests for pipeline element 'MathOpProcessor' (#3300)
    
    * Test:Implement unit tests for pipeline element 'MathOpProcessor'
    
    * Test:Implement unit tests for pipeline element 'MathOpProcessor'
    
    * update
    
    * update code style
    
    * update code
    
    * update code
    
    * update code
---
 .../jvm/processor/math/MathOpProcessor.java        |   8 +-
 .../jvm/processor/math/MathOpProcessorTest.java    | 121 +++++++++++++++++++++
 2 files changed, 125 insertions(+), 4 deletions(-)

diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/math/MathOpProcessor.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/math/MathOpProcessor.java
index 7a2409d1b2..0571496f6b 100644
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/math/MathOpProcessor.java
+++ 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/math/MathOpProcessor.java
@@ -47,10 +47,10 @@ import 
org.apache.streampipes.wrapper.standalone.StreamPipesDataProcessor;
 
 public class MathOpProcessor extends StreamPipesDataProcessor {
 
-  private static final String RESULT_FIELD = "calculationResult";
-  private static final String LEFT_OPERAND = "leftOperand";
-  private static final String RIGHT_OPERAND = "rightOperand";
-  private static final String OPERATION = "operation";
+  protected static final String RESULT_FIELD = "calculationResult";
+  protected static final String LEFT_OPERAND = "leftOperand";
+  protected static final String RIGHT_OPERAND = "rightOperand";
+  protected static final String OPERATION = "operation";
 
   Operation arithmeticOperation = null;
   String leftOperand;
diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/test/java/org/apache/streampipes/processors/enricher/jvm/processor/math/MathOpProcessorTest.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/test/java/org/apache/streampipes/processors/enricher/jvm/processor/math/MathOpProcessorTest.java
new file mode 100644
index 0000000000..fb2a1d5666
--- /dev/null
+++ 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/test/java/org/apache/streampipes/processors/enricher/jvm/processor/math/MathOpProcessorTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.streampipes.processors.enricher.jvm.processor.math;
+
+import org.apache.streampipes.test.executors.ProcessingElementTestExecutor;
+import org.apache.streampipes.test.executors.TestConfiguration;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.Map;
+
+public class MathOpProcessorTest{
+  private MathOpProcessor processor;
+
+  @BeforeEach
+  public void setup(){
+    processor = new MathOpProcessor();
+  }
+
+  @Test
+  public void detectAdditionOperator(){
+    TestConfiguration leftOperandConfiguration = TestConfiguration.builder()
+            .configWithDefaultPrefix(MathOpProcessor.LEFT_OPERAND, 
"leftOperand")
+            .configWithDefaultPrefix(MathOpProcessor.RIGHT_OPERAND, 
"rightOperand")
+            .config(MathOpProcessor.OPERATION, "+").build();
+
+    List<Map<String, Object>> inputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d));
+    List<Map<String, Object>> outputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d, 
"calculationResult", 10.0d));
+    ProcessingElementTestExecutor testExecutor = new 
ProcessingElementTestExecutor(
+            processor, leftOperandConfiguration);
+
+    testExecutor.run(inputEvents, outputEvents);
+  }
+
+  @Test
+  public void detectSubtractionOperator(){
+    TestConfiguration leftOperandConfiguration = TestConfiguration.builder()
+            .configWithDefaultPrefix(MathOpProcessor.LEFT_OPERAND, 
"leftOperand")
+            .configWithDefaultPrefix(MathOpProcessor.RIGHT_OPERAND, 
"rightOperand")
+            .config(MathOpProcessor.OPERATION, "-").build();
+
+    List<Map<String, Object>> inputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d));
+    List<Map<String, Object>> outputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d, 
"calculationResult", 0.0d));
+    ProcessingElementTestExecutor testExecutor = new 
ProcessingElementTestExecutor(
+            processor, leftOperandConfiguration);
+
+    testExecutor.run(inputEvents, outputEvents);
+  }
+
+  @Test
+  public void detectMultiplicationOperator(){
+    TestConfiguration leftOperandConfiguration = TestConfiguration.builder()
+            .configWithDefaultPrefix(MathOpProcessor.LEFT_OPERAND, 
"leftOperand")
+            .configWithDefaultPrefix(MathOpProcessor.RIGHT_OPERAND, 
"rightOperand")
+            .config(MathOpProcessor.OPERATION, "*").build();
+
+    List<Map<String, Object>> inputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d));
+    List<Map<String, Object>> outputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d, 
"calculationResult", 25.0d));
+    ProcessingElementTestExecutor testExecutor = new 
ProcessingElementTestExecutor(
+            processor, leftOperandConfiguration);
+
+    testExecutor.run(inputEvents, outputEvents);
+  }
+
+  @Test
+  public void detectDivisionOperator(){
+    TestConfiguration leftOperandConfiguration = TestConfiguration.builder()
+            .configWithDefaultPrefix(MathOpProcessor.LEFT_OPERAND, 
"leftOperand")
+            .configWithDefaultPrefix(MathOpProcessor.RIGHT_OPERAND, 
"rightOperand")
+            .config(MathOpProcessor.OPERATION, "/").build();
+
+    List<Map<String, Object>> inputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d));
+    List<Map<String, Object>> outputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d, 
"calculationResult", 1.0d));
+    ProcessingElementTestExecutor testExecutor = new 
ProcessingElementTestExecutor(
+            processor, leftOperandConfiguration);
+
+    testExecutor.run(inputEvents, outputEvents);
+  }
+
+  @Test
+  public void detectModulusOperator(){
+    TestConfiguration leftOperandConfiguration = TestConfiguration.builder()
+            .configWithDefaultPrefix(MathOpProcessor.LEFT_OPERAND, 
"leftOperand")
+            .configWithDefaultPrefix(MathOpProcessor.RIGHT_OPERAND, 
"rightOperand")
+            .config(MathOpProcessor.OPERATION, "%").build();
+
+    List<Map<String, Object>> inputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d));
+    List<Map<String, Object>> outputEvents = List.of(
+            Map.of("leftOperand", 5.0d, "rightOperand", 5.0d, 
"calculationResult", 0.0d));
+    ProcessingElementTestExecutor testExecutor = new 
ProcessingElementTestExecutor(
+            processor, leftOperandConfiguration);
+
+    testExecutor.run(inputEvents, outputEvents);
+  }
+}
\ No newline at end of file

Reply via email to