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 8e7d262d7e feat: Implement visit for mapping property nary in pipeline
element templates (#3029)
8e7d262d7e is described below
commit 8e7d262d7ec6c5df6b7b11930f242b8069a44335
Author: Philipp Zehnder <[email protected]>
AuthorDate: Mon Jul 15 17:52:25 2024 +0200
feat: Implement visit for mapping property nary in pipeline element
templates (#3029)
---
.../template/PipelineElementTemplateVisitor.java | 5 +-
.../PipelineElementTemplateVisitorTest.java | 75 ++++++++++++++++++++++
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
index 62e037c146..b301a5243a 100644
---
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
+++
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
@@ -105,7 +105,10 @@ public class PipelineElementTemplateVisitor implements
StaticPropertyVisitor {
@Override
public void visit(MappingPropertyNary mappingPropertyNary) {
- // Do nothing, not supported by pipeline element templates
+ if (hasKey(mappingPropertyNary)) {
+ var selectedProperties = getValueAsList(mappingPropertyNary);
+ mappingPropertyNary.setSelectedProperties(selectedProperties);
+ }
}
@Override
diff --git
a/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitorTest.java
b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitorTest.java
new file mode 100644
index 0000000000..672817786c
--- /dev/null
+++
b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitorTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.manager.template;
+
+import org.apache.streampipes.model.staticproperty.MappingPropertyNary;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class PipelineElementTemplateVisitorTest {
+ private static final String PROPERTY_NAME = "propertyName";
+
+ private PipelineElementTemplateVisitor visitor;
+ private Map<String, Object> configs;
+ private MappingPropertyNary mappingPropertyNary;
+
+ @BeforeEach
+ void setUp() {
+ configs = new HashMap<>();
+ visitor = new PipelineElementTemplateVisitor(configs);
+ mappingPropertyNary = mock(MappingPropertyNary.class);
+ when(mappingPropertyNary.getInternalName()).thenReturn(PROPERTY_NAME);
+ }
+
+ @Test
+ void visitMappingPropertyNary_SetsSelectedPropertiesWhenKeyExists() {
+ List<String> expectedValues = List.of("value1", "value2");
+ configs.put(PROPERTY_NAME, expectedValues);
+ visitor.visit(mappingPropertyNary);
+
+ verify(mappingPropertyNary).setSelectedProperties(expectedValues);
+ }
+
+ @Test
+ void visitMappingPropertyNary_DoesNothingWhenKeyDoesNotExist() {
+ visitor.visit(mappingPropertyNary);
+
+ verify(mappingPropertyNary, never()).setSelectedProperties(anyList());
+ }
+
+ @Test
+ void visitMappingPropertyNary_HandlesEmptySelectedPropertiesCorrectly() {
+ List<String> expectedValues = List.of();
+ configs.put(PROPERTY_NAME, expectedValues);
+ visitor.visit(mappingPropertyNary);
+
+ verify(mappingPropertyNary).setSelectedProperties(expectedValues);
+ }
+}