You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2021/08/18 14:30:00 UTC
[incubator-streampipes] branch dev updated: [STREAMPIPES-319]
Improve tests for TestPipelineManagment
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/incubator-streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 676d065 [STREAMPIPES-319] Improve tests for TestPipelineManagment
676d065 is described below
commit 676d06598009a8e679f3732df775961f8ed9e6f1
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Wed Aug 18 16:29:31 2021 +0200
[STREAMPIPES-319] Improve tests for TestPipelineManagment
---
streampipes-pipeline-management/pom.xml | 6 ++
.../manager/pipeline/PipelineManager.java | 22 ++++---
.../manager/pipeline/TestPipelineManager.java | 67 ++++------------------
.../generator/pipeline/DummyPipelineGenerator.java | 45 +++++++++++++++
.../pipelineelement/DummyProcessorGenerator.java | 31 ++++++++++
.../pipelineelement/DummySinkGenerator.java | 30 ++++++++++
6 files changed, 138 insertions(+), 63 deletions(-)
diff --git a/streampipes-pipeline-management/pom.xml b/streampipes-pipeline-management/pom.xml
index 0f90493..1324eb9 100644
--- a/streampipes-pipeline-management/pom.xml
+++ b/streampipes-pipeline-management/pom.xml
@@ -139,6 +139,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.streampipes</groupId>
+ <artifactId>streampipes-test-utils</artifactId>
+ <version>0.69.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
diff --git a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java
index 56b7e3e..833ed88 100644
--- a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java
+++ b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/pipeline/PipelineManager.java
@@ -57,18 +57,15 @@ public class PipelineManager {
*/
public static String addPipeline(String username, Pipeline pipeline) {
+ // call by reference bad smell
String pipelineId = UUID.randomUUID().toString();
- pipeline.setPipelineId(pipelineId);
- pipeline.setRunning(false);
- pipeline.setCreatedByUser(username);
- pipeline.setCreatedAt(new Date().getTime());
- pipeline.getSepas().forEach(processor -> processor.setCorrespondingUser(username));
- pipeline.getActions().forEach(action -> action.setCorrespondingUser(username));
+ preparePipelineBasics(username, pipeline, pipelineId);
Operations.storePipeline(pipeline);
return pipelineId;
}
+
/**
* Starts all processing elements of the pipeline with the pipelineId
* @param pipelineId
@@ -102,7 +99,18 @@ public class PipelineManager {
getPipelineStorage().deletePipeline(pipelineId);
}
- public static IPipelineStorage getPipelineStorage() {
+ private static void preparePipelineBasics(String username,
+ Pipeline pipeline,
+ String pipelineId) {
+ pipeline.setPipelineId(pipelineId);
+ pipeline.setRunning(false);
+ pipeline.setCreatedByUser(username);
+ pipeline.setCreatedAt(new Date().getTime());
+ pipeline.getSepas().forEach(processor -> processor.setCorrespondingUser(username));
+ pipeline.getActions().forEach(action -> action.setCorrespondingUser(username));
+ }
+
+ private static IPipelineStorage getPipelineStorage() {
return StorageDispatcher.INSTANCE.getNoSqlStore().getPipelineStorageAPI();
}
}
diff --git a/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/pipeline/TestPipelineManager.java b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/pipeline/TestPipelineManager.java
index 2f4190b..5d128ec 100644
--- a/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/pipeline/TestPipelineManager.java
+++ b/streampipes-pipeline-management/src/test/java/org/apache/streampipes/manager/pipeline/TestPipelineManager.java
@@ -19,10 +19,9 @@ package org.apache.streampipes.manager.pipeline;
import org.apache.streampipes.manager.operations.Operations;
import org.apache.streampipes.manager.storage.UserManagementService;
-import org.apache.streampipes.manager.storage.UserService;
import org.apache.streampipes.model.pipeline.Pipeline;
import org.apache.streampipes.model.pipeline.PipelineOperationStatus;
-import org.apache.streampipes.storage.couchdb.impl.PipelineStorageImpl;
+import org.apache.streampipes.test.generator.pipeline.DummyPipelineGenerator;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,13 +30,10 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import static com.sun.prism.GraphicsPipeline.getPipeline;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({
@@ -53,42 +49,6 @@ public class TestPipelineManager {
}
@Test
- public void testGetOwnPipelines() {
- // Prepare
- Pipeline expectedPipeline = this.getPipeline();
- List<Pipeline> expected = Arrays.asList(expectedPipeline);
-
- UserService userService = mock(UserService.class);
- when(userService.getOwnPipelines(any(String.class))).thenReturn(expected);
- when(UserManagementService.getUserService()).thenReturn(userService);
-
- // Test
- List<Pipeline> result = PipelineManager.getOwnPipelines("user@test.com");
-
- // Assertions
- assertEquals(1, result.size());
- assertEquals(this.getPipelineName(), result.get(0).getName());
- }
-
- @Test
- public void testGetPipeline() {
- // Prepare
- Pipeline expectedPipeline = this.getPipeline();
-
- PipelineStorageImpl pipelineStorageImpl = mock(PipelineStorageImpl.class);
- when(pipelineStorageImpl.getPipeline(any(String.class))).thenReturn(expectedPipeline);
- PowerMockito.stub(PowerMockito.method(PipelineManager.class, "getPipelineStorage")).toReturn(pipelineStorageImpl);
-
- // Test
- Pipeline result = PipelineManager.getPipeline("pipelineid");
-
- // Assertions
- assertNotNull(result);
- assertEquals(this.getPipelineName(), result.getName());
- }
-
-
- @Test
public void testStartPipeline() {
// Prepare
PipelineOperationStatus expectedPipelineOperationStatus = getPipelineOperationStatus();
@@ -121,28 +81,23 @@ public class TestPipelineManager {
@Test
public void testAddPipeline() {
// Prepare
- PipelineOperationStatus expectedPipelineOperationStatus = getPipelineOperationStatus();
PowerMockito.mockStatic(Operations.class);
+ Pipeline pipeline = DummyPipelineGenerator.makePipelineWithProcessorAndSink();
+
+ String username = "test@user.com";
// Test
- String result = PipelineManager.addPipeline("test@user.com", getPipeline());
+ String result = PipelineManager.addPipeline(username, pipeline);
// Assertions
assertNotNull(result);
- }
-
- private String getPipelineName() {
- return "Test Pipeline";
- }
-
- private Pipeline getPipeline() {
- Pipeline pipeline = new Pipeline();
- pipeline.setPipelineId("testId");
- pipeline.setName(this.getPipelineName());
- return pipeline;
+ assertNotNull(pipeline.getPipelineId());
+ assertEquals(username, pipeline.getCreatedByUser());
+ pipeline.getSepas().forEach(processor -> assertEquals(username, processor.getCorrespondingUser()));
+ pipeline.getActions().forEach(sink -> assertEquals(username, sink.getCorrespondingUser()));
}
private PipelineOperationStatus getPipelineOperationStatus() {
- return new PipelineOperationStatus("", getPipelineName(),"", new ArrayList<>());
+ return new PipelineOperationStatus("", DummyPipelineGenerator.PIPELINE_NAME,"", new ArrayList<>());
}
}
\ No newline at end of file
diff --git a/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipeline/DummyPipelineGenerator.java b/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipeline/DummyPipelineGenerator.java
new file mode 100644
index 0000000..afba691
--- /dev/null
+++ b/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipeline/DummyPipelineGenerator.java
@@ -0,0 +1,45 @@
+/*
+ * 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.test.generator.pipeline;
+
+import org.apache.streampipes.model.pipeline.Pipeline;
+import org.apache.streampipes.test.generator.pipelineelement.DummyProcessorGenerator;
+import org.apache.streampipes.test.generator.pipelineelement.DummySinkGenerator;
+
+import java.util.Collections;
+
+public class DummyPipelineGenerator {
+ public static String PIPELINE_NAME = "Test Pipeline";
+
+ public static Pipeline makePipelineWithPipelineName() {
+ Pipeline pipeline = new Pipeline();
+ pipeline.setName(PIPELINE_NAME);
+
+ return pipeline;
+ }
+
+ public static Pipeline makePipelineWithProcessorAndSink() {
+ Pipeline pipeline = makePipelineWithPipelineName();
+
+ pipeline.setSepas(Collections.singletonList(DummyProcessorGenerator.makeDummyProcessor()));
+ pipeline.setActions(Collections.singletonList(DummySinkGenerator.makeDummySink()));
+
+ return pipeline;
+ }
+}
diff --git a/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipelineelement/DummyProcessorGenerator.java b/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipelineelement/DummyProcessorGenerator.java
new file mode 100644
index 0000000..871b840
--- /dev/null
+++ b/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipelineelement/DummyProcessorGenerator.java
@@ -0,0 +1,31 @@
+/*
+ * 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.test.generator.pipelineelement;
+
+import org.apache.streampipes.model.graph.DataProcessorInvocation;
+
+public class DummyProcessorGenerator {
+
+ public static DataProcessorInvocation makeDummyProcessor() {
+
+ DataProcessorInvocation dataProcessorInvocation = new DataProcessorInvocation();
+
+ return dataProcessorInvocation;
+ }
+}
diff --git a/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipelineelement/DummySinkGenerator.java b/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipelineelement/DummySinkGenerator.java
new file mode 100644
index 0000000..15a58a4
--- /dev/null
+++ b/streampipes-test-utils/src/main/java/org/apache/streampipes/test/generator/pipelineelement/DummySinkGenerator.java
@@ -0,0 +1,30 @@
+/*
+ * 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.test.generator.pipelineelement;
+
+import org.apache.streampipes.model.graph.DataSinkInvocation;
+
+public class DummySinkGenerator {
+ public static DataSinkInvocation makeDummySink() {
+
+ DataSinkInvocation dataSinkInvocation = new DataSinkInvocation();
+
+ return dataSinkInvocation;
+ }
+}