You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streampipes.apache.org by "Aditi840 (via GitHub)" <gi...@apache.org> on 2023/09/17 19:01:20 UTC

[PR] Additional Tests

Aditi840 opened a new pull request, #1940:
URL: https://github.com/apache/streampipes/pull/1940

   <!--
     ~ 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.
     ~
     -->
     
     <!--
   Thanks for contributing! Here are some tips you can follow to help us incorporate your contribution quickly and easily:
   1. If this is your first time, please read our contributor guidelines:
       - https://streampipes.apache.org/getinvolved.html
       - https://cwiki.apache.org/confluence/display/STREAMPIPES/Getting+Started
   2. Make sure the PR title is formatted like: `[#<GitHub issue id>] PR title ...`
   3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., `[WIP][#<GitHub issue id>] PR title ...`.
   4. Please write your PR title to summarize what this PR proposes/fixes.
   5. Link the PR to the corresponding GitHub issue (if present) in the `Development` section in the right menu bar. 
   6. Be sure to keep the PR description updated to reflect all changes.
   7. If possible, provide a concise example to reproduce the issue for a faster review.
   8. Make sure tests pass via `mvn clean install`.
   9. (Optional) If the contribution is large, please file an Apache ICLA
       - http://apache.org/licenses/icla.pdf
   -->
   
   ### Purpose
   <!--
   Please clarify what changes you are proposing and describe how those changes will address the issue.
   Furthermore, describe potential consequences the changes might have.
   -->
   
   ### Remarks
   <!--
   Is there anything left we need to pay attention on?
   Are there some references that might be important? E.g. links to Confluence, or discussions
   on the mailing list or GitHub.
   -->
   PR introduces (a) breaking change(s): <yes/no>
   
   PR introduces (a) deprecation(s): <yes/no>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(#1902): Implement unit tests for pipeline element 'TextFilterProcessor'

Posted by "Aditi840 (via GitHub)" <gi...@apache.org>.
Aditi840 commented on PR #1940:
URL: https://github.com/apache/streampipes/pull/1940#issuecomment-1725786821

   @bossenti, I have made some changes to the file will you check them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(#1902): Implement unit tests for pipeline element 'TextFilterProcessor'

Posted by "dominikriemer (via GitHub)" <gi...@apache.org>.
dominikriemer commented on PR #1940:
URL: https://github.com/apache/streampipes/pull/1940#issuecomment-1729806032

   @Aditi840 I had a look at your test and want to give some feedback:
   * The test class is intended for the `TextFilterProcessor` class, but your code added is in a module that doesn't contain a dependency on the `processors-filters-jvm` module which provides the class to test.
   * The code you provided uses imports that cannot be resolved due to missing dependencies.
   * The code uses invented methods which are not present in our codebase, such as `resetCollectedEvents` from the `SpOutputCollector` class or a `ModelDeclaration` class which doesn't even exist.
   
   We are a friendly and open community and are willing to help non-experienced coders, but my general advise is that you don't provide contributions to open source projects that are based on ChatGPT and which are completely untested and wrong. Note that many people who provide real code to open source projects do that in their spare time. Reviewing PRs which come out to be mostly nonsense is a waste of time and just not nice.
   
   Having said that, I'll close this PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(#1902): Implement unit tests for pipeline element 'TextFilterProcessor'

Posted by "bossenti (via GitHub)" <gi...@apache.org>.
bossenti commented on code in PR #1940:
URL: https://github.com/apache/streampipes/pull/1940#discussion_r1329602383


##########
streampipes-extensions/streampipes-processors-transformation-jvm/src/test/java/org/apache/streampipes/processors/transformation/jvm/Additional Tests:
##########
@@ -0,0 +1,96 @@
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.extensions.api.pe.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.extensions.api.pe.routing.SpOutputCollector;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.wrapper.params.compat.ProcessorParams;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+public class TextFilterProcessorTest {
+
+    @Mock
+    private ProcessorParams processorParams;
+
+    @Mock
+    private SpOutputCollector spOutputCollector;
+
+    @Mock
+    private EventProcessorRuntimeContext eventProcessorRuntimeContext;
+
+    @BeforeEach
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void testConstructorInitialization() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        assertNull(processor.getKeyword());
+        assertNull(processor.getStringOperator());
+        assertNull(processor.getFilterProperty());
+    }
+
+    @Test
+    public void testModelDeclaration() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        assertNotNull(processor.declareModel());
+        // Add more assertions to validate the description

Review Comment:
   Are you willing to come up with some here? 



##########
streampipes-extensions/streampipes-processors-transformation-jvm/src/test/java/org/apache/streampipes/processors/transformation/jvm/Additional Tests:
##########


Review Comment:
   This is not a valid `java` class. Can you please give it a valid file name and put it in the corresponding package? 



##########
streampipes-extensions/streampipes-processors-transformation-jvm/src/test/java/org/apache/streampipes/processors/transformation/jvm/Additional Tests:
##########
@@ -0,0 +1,96 @@
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.extensions.api.pe.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.extensions.api.pe.routing.SpOutputCollector;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.wrapper.params.compat.ProcessorParams;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+public class TextFilterProcessorTest {
+
+    @Mock
+    private ProcessorParams processorParams;
+
+    @Mock
+    private SpOutputCollector spOutputCollector;
+
+    @Mock
+    private EventProcessorRuntimeContext eventProcessorRuntimeContext;
+
+    @BeforeEach
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void testConstructorInitialization() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        assertNull(processor.getKeyword());
+        assertNull(processor.getStringOperator());
+        assertNull(processor.getFilterProperty());
+    }
+
+    @Test
+    public void testModelDeclaration() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        assertNotNull(processor.declareModel());
+        // Add more assertions to validate the description
+    }
+
+    @Test
+    public void testOnInvocation() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        when(processorParams.extractor().singleValueParameter(anyString(), eq(String.class))).thenReturn("keyword");
+        when(processorParams.extractor().selectedSingleValue(anyString(), eq(String.class))).thenReturn("MATCHES");
+        when(processorParams.extractor().mappingPropertyValue(anyString())).thenReturn("text");
+
+        assertDoesNotThrow(() -> processor.onInvocation(processorParams, spOutputCollector, eventProcessorRuntimeContext));
+
+        assertEquals("keyword", processor.getKeyword());
+        assertEquals(TextFilterProcessor.StringOperator.MATCHES, processor.getStringOperator());
+        assertEquals("text", processor.getFilterProperty());
+    }
+
+    @Test
+    public void testOnEvent() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        when(processorParams.extractor().singleValueParameter(anyString(), eq(String.class))).thenReturn("keyword");
+        when(processorParams.extractor().selectedSingleValue(anyString(), eq(String.class))).thenReturn("MATCHES");
+        when(processorParams.extractor().mappingPropertyValue(anyString())).thenReturn("text");
+
+        processor.onInvocation(processorParams, spOutputCollector, eventProcessorRuntimeContext);
+
+        Event matchingEvent = createMockEvent("Some text that MATCHES the keyword");

Review Comment:
   This text only contains the keyword, doesn't it?
   If you would like to test for equality, your string should just be `keyword`.



##########
streampipes-extensions/streampipes-processors-transformation-jvm/src/test/java/org/apache/streampipes/processors/transformation/jvm/Additional Tests:
##########
@@ -0,0 +1,96 @@
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.extensions.api.pe.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.extensions.api.pe.routing.SpOutputCollector;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.wrapper.params.compat.ProcessorParams;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+public class TextFilterProcessorTest {
+
+    @Mock
+    private ProcessorParams processorParams;
+
+    @Mock
+    private SpOutputCollector spOutputCollector;
+
+    @Mock
+    private EventProcessorRuntimeContext eventProcessorRuntimeContext;
+
+    @BeforeEach
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void testConstructorInitialization() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        assertNull(processor.getKeyword());
+        assertNull(processor.getStringOperator());
+        assertNull(processor.getFilterProperty());
+    }
+
+    @Test
+    public void testModelDeclaration() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        assertNotNull(processor.declareModel());
+        // Add more assertions to validate the description
+    }
+
+    @Test
+    public void testOnInvocation() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        when(processorParams.extractor().singleValueParameter(anyString(), eq(String.class))).thenReturn("keyword");
+        when(processorParams.extractor().selectedSingleValue(anyString(), eq(String.class))).thenReturn("MATCHES");
+        when(processorParams.extractor().mappingPropertyValue(anyString())).thenReturn("text");
+
+        assertDoesNotThrow(() -> processor.onInvocation(processorParams, spOutputCollector, eventProcessorRuntimeContext));
+
+        assertEquals("keyword", processor.getKeyword());
+        assertEquals(TextFilterProcessor.StringOperator.MATCHES, processor.getStringOperator());
+        assertEquals("text", processor.getFilterProperty());
+    }
+
+    @Test
+    public void testOnEvent() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        when(processorParams.extractor().singleValueParameter(anyString(), eq(String.class))).thenReturn("keyword");
+        when(processorParams.extractor().selectedSingleValue(anyString(), eq(String.class))).thenReturn("MATCHES");
+        when(processorParams.extractor().mappingPropertyValue(anyString())).thenReturn("text");
+
+        processor.onInvocation(processorParams, spOutputCollector, eventProcessorRuntimeContext);
+
+        Event matchingEvent = createMockEvent("Some text that MATCHES the keyword");
+        Event containingEvent = createMockEvent("Some text that CONTAINS the keyword");
+        Event nonMatchingEvent = createMockEvent("Some text that does not match or contain the keyword");
+
+        spOutputCollector.resetCollectedEvents(); // Reset collected events for each test case
+
+        processor.onEvent(matchingEvent, spOutputCollector);
+        assertEquals(1, spOutputCollector.getCollectedEvents().size());
+
+        processor.onEvent(containingEvent, spOutputCollector);
+        assertEquals(1, spOutputCollector.getCollectedEvents().size());
+
+        processor.onEvent(nonMatchingEvent, spOutputCollector);
+        assertEquals(0, spOutputCollector.getCollectedEvents().size());
+    }
+
+    @Test
+    public void testOnDetach() {
+        TextFilterProcessor processor = new TextFilterProcessor();
+        assertDoesNotThrow(() -> processor.onDetach());
+        // Add assertions if there is any specific behavior to test

Review Comment:
   I think there is no more to test here, so you can safely remove this comment



##########
streampipes-extensions/streampipes-processors-transformation-jvm/src/test/java/org/apache/streampipes/processors/transformation/jvm/Additional Tests:
##########
@@ -0,0 +1,96 @@
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;

Review Comment:
   This file misses our Apache license header, see an example [here](https://github.com/apache/streampipes/blob/ca4e0c2d44c1a713caaee3e9c1bff46096f41c53/streampipes-extensions/streampipes-processors-transformation-jvm/src/test/java/org/apache/streampipes/processors/transformation/jvm/processor/value/change/TestChangedValueDetectionProcessor.java#L1).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(#1902): Implement unit tests for pipeline element 'TextFilterProcessor'

Posted by "dominikriemer (via GitHub)" <gi...@apache.org>.
dominikriemer closed pull request #1940: test(#1902): Implement unit tests for pipeline element 'TextFilterProcessor'
URL: https://github.com/apache/streampipes/pull/1940


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Additional Tests

Posted by "Aditi840 (via GitHub)" <gi...@apache.org>.
Aditi840 commented on PR #1940:
URL: https://github.com/apache/streampipes/pull/1940#issuecomment-1722543180

   @bossenti, will you check my pull request


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@streampipes.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org