From 4169bbc14b924105ce4c88305b57d8613af6fa1a Mon Sep 17 00:00:00 2001
From: Reiner Jung <reiner.jung@email.uni-kiel.de>
Date: Thu, 13 Jul 2023 09:43:50 +0200
Subject: [PATCH] Started adding test.

---
 analysis/build.gradle                         |   2 +
 .../BasicArchitectureModelUtils.java          | 101 ++++++++++++++++++
 .../stages/CountUniqueCallsStageTest.java     |  42 +++++++-
 3 files changed, 143 insertions(+), 2 deletions(-)
 create mode 100644 analysis/src/test/java/org/oceandsl/analysis/architecture/BasicArchitectureModelUtils.java

diff --git a/analysis/build.gradle b/analysis/build.gradle
index 929a6f5d..e9f4bc2c 100644
--- a/analysis/build.gradle
+++ b/analysis/build.gradle
@@ -16,6 +16,8 @@ dependencies {
 
 	implementation 'org.yaml:snakeyaml:2.0'
 	implementation 'org.csveed:csveed:0.7.4'
+	
+	testImplementation 'org.hamcrest:hamcrest-core:2.2'
 }
 
 java {
diff --git a/analysis/src/test/java/org/oceandsl/analysis/architecture/BasicArchitectureModelUtils.java b/analysis/src/test/java/org/oceandsl/analysis/architecture/BasicArchitectureModelUtils.java
new file mode 100644
index 00000000..f271d936
--- /dev/null
+++ b/analysis/src/test/java/org/oceandsl/analysis/architecture/BasicArchitectureModelUtils.java
@@ -0,0 +1,101 @@
+/***************************************************************************
+ * Copyright (C) 2023 OceanDSL (https://oceandsl.uni-kiel.de)
+ *
+ * Licensed 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.oceandsl.analysis.architecture;
+
+import kieker.analysis.architecture.repository.ModelRepository;
+import kieker.model.analysismodel.assembly.AssemblyComponent;
+import kieker.model.analysismodel.assembly.AssemblyFactory;
+import kieker.model.analysismodel.assembly.AssemblyModel;
+import kieker.model.analysismodel.assembly.AssemblyPackage;
+import kieker.model.analysismodel.deployment.DeploymentModel;
+import kieker.model.analysismodel.type.ComponentType;
+import kieker.model.analysismodel.type.OperationType;
+import kieker.model.analysismodel.type.TypeFactory;
+import kieker.model.analysismodel.type.TypeModel;
+import kieker.model.analysismodel.type.TypePackage;
+
+/**
+ * @author Reiner Jung
+ * @since 1.3.0
+ *
+ */
+public final class BasicArchitectureModelUtils {
+
+    public static final String COMPONENT_A = "A";
+    public static final String COMPONENT_B = "B";
+    public static final String OPERATION_A_A = "a()";
+    public static final String OPERATION_B_A = "b()";
+    public static final String BASE = "base";
+
+    private BasicArchitectureModelUtils() {
+        // do not instantiate
+    }
+
+    public static ModelRepository createMinimalModelRepository() {
+        final ModelRepository repository = ArchitectureModelRepositoryFactory.createEmptyModelRepository("test");
+
+        final TypeModel typeModel = createTypeModel(repository);
+        final AssemblyModel assemblyModel = createAssemblyModel(repository, typeModel);
+        final DeploymentModel deploymentModel = createDeploymentModel(repository, assemblyModel, typeModel);
+
+        return repository;
+    }
+
+    private static TypeModel createTypeModel(final ModelRepository repository) {
+        final TypeModel typeModel = repository.getModel(TypePackage.Literals.TYPE_MODEL);
+
+        final ComponentType componentA = createComponent(COMPONENT_A);
+        createOperation(componentA, OPERATION_A_A);
+        final ComponentType componentB = createComponent(COMPONENT_B);
+        createOperation(componentB, OPERATION_B_A);
+
+        typeModel.getComponentTypes().put(COMPONENT_A, componentA);
+        typeModel.getComponentTypes().put(COMPONENT_B, componentB);
+
+        return typeModel;
+    }
+
+    private static void createOperation(final ComponentType component, final String operation) {
+        final OperationType operationType = TypeFactory.eINSTANCE.createOperationType();
+        operationType.setName(operation);
+        operationType.setReturnType("int");
+        operationType.setSignature("int " + operation);
+
+        component.getProvidedOperations().put(operation, operationType);
+    }
+
+    private static ComponentType createComponent(final String component) {
+        final ComponentType componentType = TypeFactory.eINSTANCE.createComponentType();
+        componentType.setName(component);
+        componentType.setPackage(BASE);
+
+        return componentType;
+    }
+
+    private static AssemblyModel createAssemblyModel(final ModelRepository repository, final TypeModel typeModel) {
+        final AssemblyModel assemblyModel = repository.getModel(AssemblyPackage.Literals.ASSEMBLY_MODEL);
+
+        final AssemblyComponent componentA = AssemblyFactory.eINSTANCE.createAssemblyComponent();
+        componentA.setComponentType(typeModel.getComponentTypes().get(COMPONENT_A));
+        assemblyModel.getComponents().put(COMPONENT_A, componentA);
+        final AssemblyComponent componentB = AssemblyFactory.eINSTANCE.createAssemblyComponent();
+        componentB.setComponentType(typeModel.getComponentTypes().get(COMPONENT_B));
+        assemblyModel.getComponents().put(COMPONENT_B, componentB);
+
+        return assemblyModel;
+    }
+
+}
diff --git a/analysis/src/test/java/org/oceandsl/analysis/architecture/stages/CountUniqueCallsStageTest.java b/analysis/src/test/java/org/oceandsl/analysis/architecture/stages/CountUniqueCallsStageTest.java
index cd7aa437..ec2fdb83 100644
--- a/analysis/src/test/java/org/oceandsl/analysis/architecture/stages/CountUniqueCallsStageTest.java
+++ b/analysis/src/test/java/org/oceandsl/analysis/architecture/stages/CountUniqueCallsStageTest.java
@@ -15,14 +15,52 @@
  ***************************************************************************/
 package org.oceandsl.analysis.architecture.stages;
 
-import org.junit.jupiter.api.Assertions;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+
 import org.junit.jupiter.api.Test;
 
+import kieker.analysis.architecture.recovery.events.DeployedOperationCallEvent;
+import kieker.analysis.architecture.repository.ModelRepository;
+import kieker.model.analysismodel.deployment.DeployedOperation;
+import kieker.model.analysismodel.deployment.DeploymentPackage;
+import kieker.model.analysismodel.execution.ExecutionFactory;
+import kieker.model.analysismodel.execution.ExecutionModel;
+import kieker.model.analysismodel.execution.ExecutionPackage;
+import kieker.model.analysismodel.execution.Tuple;
+import kieker.model.analysismodel.statistics.StatisticsModel;
+import kieker.model.analysismodel.statistics.StatisticsPackage;
+
+import teetime.framework.test.StageTester;
+
+import org.oceandsl.analysis.architecture.BasicArchitectureModelUtils;
+
+/**
+ *
+ * @author Reiner Jung
+ * @since 1.3.0
+ */
 class CountUniqueCallsStageTest {
 
     @Test
     public void test() {
-        Assertions.fail("Not yet implemented");
+        final ModelRepository repository = BasicArchitectureModelUtils.createMinimalModelRepository();
+
+        final StatisticsModel statisticsModel = repository.getModel(StatisticsPackage.Literals.STATISTICS_MODEL);
+        final ExecutionModel executionModel = repository.getModel(ExecutionPackage.Literals.EXECUTION_MODEL);
+        final ExecutionModel deployedModel = repository.getModel(DeploymentPackage.Literals.DEPLOYMENT_MODEL);
+
+        final CountUniqueCallsStage stage = new CountUniqueCallsStage(statisticsModel, executionModel);
+
+        final Duration duration = Duration.of(10, ChronoUnit.SECONDS);
+        final Tuple<DeployedOperation, DeployedOperation> tuple = ExecutionFactory.eINSTANCE.createTuple();
+
+        final DeployedOperationCallEvent event = new DeployedOperationCallEvent(tuple, duration);
+
+        StageTester.test(stage).send(event).to(stage.getInputPort()).start();
+        assertThat(stage.getOutputPort(), StageTester.produces(event));
     }
 
 }
-- 
GitLab