diff --git a/analysis/build.gradle b/analysis/build.gradle index 8ae46fc3023b061222b128d49580fd89c2a1ffb4..b733427d1f23a0a74428fe17931e6f5375bc2d21 100644 --- a/analysis/build.gradle +++ b/analysis/build.gradle @@ -21,7 +21,6 @@ java { withSourcesJar() } - publishing { publications { mavenJava(MavenPublication) { diff --git a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/AllSelector.java b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/AllSelector.java index 72d2450471ed3a8e2ed6a82614d865dc6348507c..300c531396154a1eb2d7436e27b1f8af18bfdedd 100644 --- a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/AllSelector.java +++ b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/AllSelector.java @@ -19,9 +19,12 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import kieker.analysis.architecture.repository.ModelRepository; +import kieker.analysis.exception.InternalErrorException; import kieker.model.analysismodel.execution.Invocation; import kieker.model.analysismodel.execution.OperationDataflow; import kieker.model.analysismodel.execution.StorageDataflow; +import kieker.model.analysismodel.source.SourceModel; +import kieker.model.analysismodel.source.SourcePackage; import org.oceandsl.analysis.graph.IGraphElementSelector; @@ -32,8 +35,11 @@ import org.oceandsl.analysis.graph.IGraphElementSelector; public class AllSelector implements IGraphElementSelector { @Override - public void setRepository(final ModelRepository repository) { - // nothing to do here + public void setRepository(final ModelRepository repository) throws InternalErrorException { + final SourceModel sourceModel = repository.getModel(SourcePackage.Literals.SOURCE_MODEL); + if (sourceModel == null) { + throw new InternalErrorException("Missing source model."); + } } @Override diff --git a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/DiffSelector.java b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/DiffSelector.java index f16ee473b3388e44c176de03c3e9034501b372e0..eb8811e53f28a4722e6558988e487daf87756b20 100644 --- a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/DiffSelector.java +++ b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/DiffSelector.java @@ -32,6 +32,9 @@ import kieker.model.analysismodel.source.SourcePackage; import org.oceandsl.analysis.graph.IGraphElementSelector; /** + * Selects a node or edge when the given object matches labels from either group. Further it selects + * the color group 0, 1, 2 when the object is in both groups, group A or group B, respectively. + * * @author Reiner Jung * @since 1.1 */ diff --git a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/IntersectSelector.java b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/IntersectSelector.java index c3d51bd4727934e8aa8ec825e74a8c5e6a0799bc..b39888816ce09c3662c7304863653379c9d9c945 100644 --- a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/IntersectSelector.java +++ b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/IntersectSelector.java @@ -22,6 +22,7 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import kieker.analysis.architecture.repository.ModelRepository; +import kieker.analysis.exception.InternalErrorException; import kieker.model.analysismodel.execution.Invocation; import kieker.model.analysismodel.execution.OperationDataflow; import kieker.model.analysismodel.execution.StorageDataflow; @@ -56,8 +57,11 @@ public class IntersectSelector implements IGraphElementSelector { } @Override - public void setRepository(final ModelRepository repository) { + public void setRepository(final ModelRepository repository) throws InternalErrorException { this.sourceModel = repository.getModel(SourcePackage.Literals.SOURCE_MODEL); + if (this.sourceModel == null) { + throw new InternalErrorException("Missing source model."); + } } @Override @@ -85,9 +89,7 @@ public class IntersectSelector implements IGraphElementSelector { } private boolean isSelected(final EList<String> sources) { - return this.groupA.stream().allMatch(element -> sources.stream().anyMatch(source -> source.equals(element))) - && this.groupB.stream() - .allMatch(element -> sources.stream().anyMatch(source -> source.equals(element))); + return this.isGroupSelected(sources, this.groupA) && this.isGroupSelected(sources, this.groupB); } @Override @@ -116,4 +118,5 @@ public class IntersectSelector implements IGraphElementSelector { } return false; } + } diff --git a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/SubtractSelector.java b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/SubtractSelector.java index d37ba3dcb2b92406489da80d265eca6a50095a7f..67cbb27383c5d74a17517ed3bd219b4061130e09 100644 --- a/analysis/src/main/java/org/oceandsl/analysis/graph/selector/SubtractSelector.java +++ b/analysis/src/main/java/org/oceandsl/analysis/graph/selector/SubtractSelector.java @@ -22,6 +22,7 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import kieker.analysis.architecture.repository.ModelRepository; +import kieker.analysis.exception.InternalErrorException; import kieker.model.analysismodel.execution.Invocation; import kieker.model.analysismodel.execution.OperationDataflow; import kieker.model.analysismodel.execution.StorageDataflow; @@ -49,8 +50,11 @@ public class SubtractSelector implements IGraphElementSelector { } @Override - public void setRepository(final ModelRepository repository) { + public void setRepository(final ModelRepository repository) throws InternalErrorException { this.sourceModel = repository.getModel(SourcePackage.Literals.SOURCE_MODEL); + if (this.sourceModel == null) { + throw new InternalErrorException("Missing source model."); + } } @Override diff --git a/analysis/src/test/java/org/oceandsl/analysis/architecture/ArchitectureModelManagementUtilsTest.java b/analysis/src/test/java/org/oceandsl/analysis/architecture/ArchitectureModelManagementUtilsTest.java index 33aa83267648e6d7b04822f146079462a8235d07..0e28065283156ce40aef68e191fa2ffade12d8c9 100644 --- a/analysis/src/test/java/org/oceandsl/analysis/architecture/ArchitectureModelManagementUtilsTest.java +++ b/analysis/src/test/java/org/oceandsl/analysis/architecture/ArchitectureModelManagementUtilsTest.java @@ -48,15 +48,35 @@ class ArchitectureModelManagementUtilsTest { final ModelRepository repository = ArchitectureModelManagementUtils .createModelRepository(ArchitectureModelManagementUtilsTest.EXPERIMENT_NAME); Assertions.assertEquals(ArchitectureModelManagementUtilsTest.EXPERIMENT_NAME, repository.getName()); - Assertions.assertEquals(TypeModel.class, repository.getModel(TypePackage.Literals.TYPE_MODEL).getClass()); - Assertions.assertEquals(AssemblyModel.class, - repository.getModel(AssemblyPackage.Literals.ASSEMBLY_MODEL).getClass()); - Assertions.assertEquals(DeploymentModel.class, - repository.getModel(DeploymentPackage.Literals.DEPLOYMENT_MODEL).getClass()); - Assertions.assertEquals(ExecutionModel.class, - repository.getModel(ExecutionPackage.Literals.EXECUTION_MODEL).getClass()); - Assertions.assertEquals(StatisticsModel.class, - repository.getModel(StatisticsPackage.Literals.STATISTICS_MODEL).getClass()); - Assertions.assertEquals(SourceModel.class, repository.getModel(SourcePackage.Literals.SOURCE_MODEL).getClass()); + Assertions.assertTrue(repository.getModel(TypePackage.Literals.TYPE_MODEL) instanceof TypeModel, + "must be a type model"); + Assertions.assertTrue(repository.getModel(AssemblyPackage.Literals.ASSEMBLY_MODEL) instanceof AssemblyModel, + "must be an assembly model"); + Assertions.assertTrue( + repository.getModel(DeploymentPackage.Literals.DEPLOYMENT_MODEL) instanceof DeploymentModel, + "must be an deployment model"); + Assertions.assertTrue(repository.getModel(ExecutionPackage.Literals.EXECUTION_MODEL) instanceof ExecutionModel, + "must be an execution model"); + Assertions.assertTrue( + repository.getModel(StatisticsPackage.Literals.STATISTICS_MODEL) instanceof StatisticsModel, + "must be a statistics model"); + Assertions.assertTrue(repository.getModel(SourcePackage.Literals.SOURCE_MODEL) instanceof SourceModel, + "must be a source model"); + } + + @Test + public void createModelRepositoryFileTest() { // NOPMD + final ModelRepository fileBasedModelRepository = ArchitectureModelManagementUtils + .createModelRepository(ArchitectureModelManagementUtilsTest.EXPERIMENT_NAME, false); + + Assertions.assertTrue(fileBasedModelRepository.getName().endsWith("file"), "name should end with file"); + } + + @Test + public void createModelRepositoryMapTest() { // NOPMD + final ModelRepository fileBasedModelRepository = ArchitectureModelManagementUtils + .createModelRepository(ArchitectureModelManagementUtilsTest.EXPERIMENT_NAME, true); + + Assertions.assertTrue(fileBasedModelRepository.getName().endsWith("map"), "name should end with file"); } } diff --git a/analysis/src/test/java/org/oceandsl/analysis/architecture/ArchitectureModelUtils.java b/analysis/src/test/java/org/oceandsl/analysis/architecture/ArchitectureModelUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..3066e4ce01125dcbb2068c225d89f77cc33d9d54 --- /dev/null +++ b/analysis/src/test/java/org/oceandsl/analysis/architecture/ArchitectureModelUtils.java @@ -0,0 +1,223 @@ +/*************************************************************************** + * 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.model.analysismodel.assembly.AssemblyComponent; +import kieker.model.analysismodel.assembly.AssemblyFactory; +import kieker.model.analysismodel.assembly.AssemblyModel; +import kieker.model.analysismodel.assembly.AssemblyOperation; +import kieker.model.analysismodel.deployment.DeployedComponent; +import kieker.model.analysismodel.deployment.DeployedOperation; +import kieker.model.analysismodel.deployment.DeploymentContext; +import kieker.model.analysismodel.deployment.DeploymentFactory; +import kieker.model.analysismodel.deployment.DeploymentModel; +import kieker.model.analysismodel.execution.ExecutionFactory; +import kieker.model.analysismodel.execution.ExecutionModel; +import kieker.model.analysismodel.execution.Invocation; +import kieker.model.analysismodel.execution.OperationDataflow; +import kieker.model.analysismodel.execution.Tuple; +import kieker.model.analysismodel.statistics.StatisticRecord; +import kieker.model.analysismodel.statistics.StatisticsFactory; +import kieker.model.analysismodel.statistics.StatisticsModel; +import kieker.model.analysismodel.type.ComponentType; +import kieker.model.analysismodel.type.OperationType; +import kieker.model.analysismodel.type.TypeFactory; +import kieker.model.analysismodel.type.TypeModel; + +/** + * @author Reiner Jung + * + */ +public final class ArchitectureModelUtils { + + public static final String CP_LEFT = "Left"; + public static final String PACKAGE = "test"; + public static final String CP_LEFT_FQN = PACKAGE + "." + CP_LEFT; + public static final String OP_LEFT = "op1"; + public static final String OP_LEFT_SIGNATURE = "V op1 (T, B)"; + public static final String OP_RETURN_TYPE = "V"; + public static final String OP_RIGHT = "op2"; + public static final String OP_RIGHT_SIGNATURE = "V op2 (T, B)"; + public static final String CP_RIGHT = "Right"; + public static final String CP_RIGHT_FQN = PACKAGE + "." + CP_RIGHT; + public static final String CONTEXT = "context"; + public static final String DATAFLOW = "dataflow"; + + private ArchitectureModelUtils() { + // private constructor to block instantiation of utility class + } + + public static TypeModel createTypeModel() { + final TypeModel model = TypeFactory.eINSTANCE.createTypeModel(); + + final ComponentType componentType = createComponentType(CP_LEFT, CP_LEFT_FQN); + + final OperationType operationType = createOperationType(OP_LEFT, OP_LEFT_SIGNATURE, OP_RETURN_TYPE); + componentType.getProvidedOperations().put(operationType.getSignature(), operationType); + + model.getComponentTypes().put(componentType.getSignature(), componentType); + + final ComponentType componentType2 = createComponentType(CP_RIGHT, CP_RIGHT_FQN); + + final OperationType operationType2 = createOperationType(OP_RIGHT, OP_RIGHT_SIGNATURE, OP_RETURN_TYPE); + componentType.getProvidedOperations().put(operationType2.getSignature(), operationType2); + + model.getComponentTypes().put(componentType2.getSignature(), componentType2); + + return model; + } + + private static ComponentType createComponentType(final String name, final String fqnName) { + final ComponentType componentType = TypeFactory.eINSTANCE.createComponentType(); + componentType.setName(name); + componentType.setPackage(PACKAGE); + componentType.setSignature(fqnName); + return componentType; + } + + private static OperationType createOperationType(final String name, final String signature, + final String returnType) { + final OperationType operationType = TypeFactory.eINSTANCE.createOperationType(); + operationType.setName(name); + operationType.setSignature(signature); + operationType.setReturnType(returnType); + + return operationType; + } + + /* + * assembly + */ + + public static AssemblyModel createAssemblyModel(final TypeModel typeModel) { + final AssemblyModel model = AssemblyFactory.eINSTANCE.createAssemblyModel(); + + final AssemblyComponent component = createAssemblyComponent(CP_LEFT_FQN, typeModel); + component.getOperations().put(OP_LEFT_SIGNATURE, + createAssemblyOperation(OP_LEFT_SIGNATURE, component.getComponentType())); + model.getComponents().put(CP_LEFT_FQN, component); + + final AssemblyComponent component2 = createAssemblyComponent(CP_RIGHT_FQN, typeModel); + component2.getOperations().put(OP_RIGHT_SIGNATURE, + createAssemblyOperation(OP_RIGHT_SIGNATURE, component2.getComponentType())); + model.getComponents().put(CP_RIGHT_FQN, component2); + + return model; + } + + private static AssemblyComponent createAssemblyComponent(final String fqnName, final TypeModel typeModel) { + final AssemblyComponent component = AssemblyFactory.eINSTANCE.createAssemblyComponent(); + final ComponentType componentType = typeModel.getComponentTypes().get(CP_LEFT_FQN); + component.setComponentType(componentType); + component.setSignature(fqnName); + + return component; + } + + private static AssemblyOperation createAssemblyOperation(final String signature, + final ComponentType componentType) { + final AssemblyOperation operation = AssemblyFactory.eINSTANCE.createAssemblyOperation(); + operation.setOperationType(componentType.getProvidedOperations().get(signature)); + + return operation; + } + + /* + * deployment + */ + + public static DeploymentModel createDeploymentModel(final AssemblyModel assemblyModel) { + final DeploymentModel model = DeploymentFactory.eINSTANCE.createDeploymentModel(); + + final DeploymentContext context = DeploymentFactory.eINSTANCE.createDeploymentContext(); + context.setName(CONTEXT); + + model.getContexts().put(CONTEXT, context); + + final DeployedComponent component = createComponent(CP_LEFT_FQN, assemblyModel); + component.getOperations().put(OP_LEFT_SIGNATURE, createDeployedOperation(OP_LEFT_SIGNATURE, component)); + + context.getComponents().put(CP_LEFT_FQN, component); + + final DeployedComponent component2 = createComponent(CP_RIGHT_FQN, assemblyModel); + component2.getOperations().put(OP_RIGHT_SIGNATURE, createDeployedOperation(OP_RIGHT_SIGNATURE, component2)); + context.getComponents().put(CP_RIGHT_FQN, component2); + + return model; + } + + private static DeployedComponent createComponent(final String fqnName, final AssemblyModel assemblyModel) { + final DeployedComponent component = DeploymentFactory.eINSTANCE.createDeployedComponent(); + component.setSignature(fqnName); + component.setAssemblyComponent(assemblyModel.getComponents().get(fqnName)); + + return component; + } + + private static DeployedOperation createDeployedOperation(final String signature, + final DeployedComponent component) { + final DeployedOperation operation = DeploymentFactory.eINSTANCE.createDeployedOperation(); + operation.setAssemblyOperation(component.getAssemblyComponent().getOperations().get(signature)); + + return operation; + } + + /* + * execution + */ + + public static ExecutionModel createExecutionModel(final DeploymentModel deploymentModel) { + final ExecutionModel model = ExecutionFactory.eINSTANCE.createExecutionModel(); + + final DeployedOperation caller = deploymentModel.getContexts().get(CONTEXT).getComponents().get(CP_LEFT_FQN) + .getOperations().get(OP_LEFT_SIGNATURE); + final DeployedOperation callee = deploymentModel.getContexts().get(CONTEXT).getComponents().get(CP_RIGHT_FQN) + .getOperations().get(OP_RIGHT_SIGNATURE); + + final Tuple<DeployedOperation, DeployedOperation> tuple = ExecutionFactory.eINSTANCE.createTuple(); + final OperationDataflow dataflow = ExecutionFactory.eINSTANCE.createOperationDataflow(); + dataflow.setCallee(callee); + dataflow.setCaller(caller); + + final Invocation invocation = ExecutionFactory.eINSTANCE.createInvocation(); + invocation.setCaller(caller); + invocation.setCallee(callee); + + model.getOperationDataflows().put(tuple, dataflow); + model.getInvocations().put(tuple, invocation); + + return model; + } + + /* + * statistics + */ + + public static StatisticsModel createEmptyStatisticsModel(final ExecutionModel executionModel) { + final StatisticsModel model = StatisticsFactory.eINSTANCE.createStatisticsModel(); + return model; + } + + public static StatisticsModel createStatisticsModel(final ExecutionModel executionModel) { + final StatisticsModel model = StatisticsFactory.eINSTANCE.createStatisticsModel(); + executionModel.getOperationDataflows().values().forEach(dataflow -> { + final StatisticRecord statisticRecord = StatisticsFactory.eINSTANCE.createStatisticRecord(); + statisticRecord.getProperties().put(DATAFLOW, 1); + model.getStatistics().put(dataflow, statisticRecord); + }); + return model; + } +} 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 cd7aa437ff133ba3831d5afbe97c2663fc446518..d6ef99781f1556025ec9b74265bf84ecbe12ad59 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,54 @@ ***************************************************************************/ package org.oceandsl.analysis.architecture.stages; +import java.time.Duration; +import java.time.temporal.ChronoUnit; + +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import kieker.analysis.architecture.recovery.events.OperationCallDurationEvent; +import kieker.model.analysismodel.assembly.AssemblyModel; +import kieker.model.analysismodel.deployment.DeployedOperation; +import kieker.model.analysismodel.deployment.DeploymentModel; +import kieker.model.analysismodel.execution.ExecutionModel; +import kieker.model.analysismodel.execution.Invocation; +import kieker.model.analysismodel.execution.Tuple; +import kieker.model.analysismodel.statistics.StatisticsModel; +import kieker.model.analysismodel.type.TypeModel; + +import teetime.framework.test.StageTester; + +import org.oceandsl.analysis.architecture.ArchitectureModelUtils; + class CountUniqueCallsStageTest { @Test public void test() { - Assertions.fail("Not yet implemented"); + final TypeModel typeModel = ArchitectureModelUtils.createTypeModel(); + final AssemblyModel assemblyModel = ArchitectureModelUtils.createAssemblyModel(typeModel); + final DeploymentModel deploymentModel = ArchitectureModelUtils.createDeploymentModel(assemblyModel); + final ExecutionModel executionModel = ArchitectureModelUtils.createExecutionModel(deploymentModel); + final StatisticsModel statisticsModel = ArchitectureModelUtils.createEmptyStatisticsModel(executionModel); + + final Tuple<DeployedOperation, DeployedOperation> invocationKey = executionModel.getInvocations().keySet() + .iterator().next(); + + final OperationCallDurationEvent sourceCall = new OperationCallDurationEvent(invocationKey, + Duration.of(5, ChronoUnit.NANOS)); + + final Invocation invocation = executionModel.getInvocations().get(invocationKey); + + final CountUniqueCallsStage stage = new CountUniqueCallsStage(statisticsModel, executionModel); + + StageTester.test(stage).and().send(sourceCall).to(stage.getInputPort()).start(); + MatcherAssert.assertThat(stage.getOutputPort(), StageTester.produces(sourceCall)); + + Assertions.assertEquals(1, statisticsModel.getStatistics().size(), "one entry should exist"); + Assertions.assertTrue(statisticsModel.getStatistics().containsKey(invocation), "missing entry"); + Assertions.assertEquals(1L, statisticsModel.getStatistics().get(invocation).getProperties().get("calls"), + "only one call"); } } diff --git a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/AllSelectorTest.java b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/AllSelectorTest.java index e28b0e56e004d4327e6a6657dba3428caf517256..9e5fa5a83843d0489cff6d737e6423e1bff3f815 100644 --- a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/AllSelectorTest.java +++ b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/AllSelectorTest.java @@ -15,14 +15,116 @@ ***************************************************************************/ package org.oceandsl.analysis.graph.selector; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import kieker.analysis.architecture.repository.ModelRepository; +import kieker.analysis.exception.InternalErrorException; +import kieker.model.analysismodel.execution.ExecutionFactory; +import kieker.model.analysismodel.execution.Invocation; +import kieker.model.analysismodel.execution.OperationDataflow; +import kieker.model.analysismodel.execution.StorageDataflow; +import kieker.model.analysismodel.source.SourceModel; +import kieker.model.analysismodel.source.SourcePackage; +import kieker.model.analysismodel.type.TypeFactory; + +import org.oceandsl.analysis.architecture.ArchitectureModelManagementUtils; + class AllSelectorTest { + private static final String EXP_1_D = "exp1-dynamic"; + private static final String EXP_2_D = "exp2-dynamic"; + private static final String EXP_1_S = "exp1-static"; + private static final String EXP_2_S = "exp2-static"; + + private final String[] groupA = { EXP_1_D, EXP_2_D }; + private final String[] groupB = { EXP_1_S, EXP_2_S }; + + private final EObject object1d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object1d1s = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2s = TypeFactory.eINSTANCE.createOperationType(); + + private final Invocation invocation = ExecutionFactory.eINSTANCE.createInvocation(); + private final OperationDataflow operationDataflow = ExecutionFactory.eINSTANCE.createOperationDataflow(); + private final StorageDataflow storageDataflow = ExecutionFactory.eINSTANCE.createStorageDataflow(); + + private ModelRepository repository; + + @BeforeEach + void setUp() { + this.repository = ArchitectureModelManagementUtils.createModelRepository("test"); + + final SourceModel sourceModel = this.repository.getModel(SourcePackage.Literals.SOURCE_MODEL); + + sourceModel.getSources().put(this.object1d, this.list(EXP_1_D)); + sourceModel.getSources().put(this.object2d, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.object1d1s, this.list(EXP_1_D, EXP_1_S)); + sourceModel.getSources().put(this.object2s, this.list(EXP_1_S, EXP_2_S)); + + sourceModel.getSources().put(this.invocation, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.operationDataflow, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.storageDataflow, this.list(EXP_1_D, EXP_2_D)); + } + @Test - void test() { - Assertions.fail("Not yet implemented"); + void testNodeSelected() throws InternalErrorException { + final AllSelector selector = new AllSelector(); + + selector.setRepository(this.repository); + + Assertions.assertTrue(selector.nodeIsSelected(this.object1d), "node must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.object2d), "node must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.object1d1s), "node must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.object2s), "node must be selected"); + } + + @Test + void testColorGroupSelected() throws InternalErrorException { + final AllSelector selector = new AllSelector(); + + selector.setRepository(this.repository); + + Assertions.assertTrue(selector.isColorGroup(this.list(this.groupA), 0), "must be group 0"); + Assertions.assertTrue(selector.isColorGroup(this.list(EXP_1_D, EXP_2_D, EXP_1_S, EXP_2_S), 0), + "must be group 0"); + Assertions.assertTrue(selector.isColorGroup(this.list(this.groupB), 0), "must be group 0"); + Assertions.assertFalse(selector.isColorGroup(this.list(this.groupA), 1), "must not be group 1"); + } + + @Test + void testEdgeSelected() throws InternalErrorException { + final AllSelector selector = new AllSelector(); + + selector.setRepository(this.repository); + + Assertions.assertTrue(selector.edgeIsSelected(this.invocation), "invocation must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.operationDataflow), "operation dataflow must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.storageDataflow), "storage dataflow must be selected"); + } + + @Test + void testMissingSourceModel() { + final AllSelector selector = new AllSelector(); + final ModelRepository localRepository = new ModelRepository("example"); + try { + selector.setRepository(localRepository); + Assertions.fail("Missing source model must cause failure."); + } catch (final InternalErrorException e) { + // correct behavior + } + } + + private EList<String> list(final String... elements) { + final BasicEList<String> list = new BasicEList<>(); + for (final String element : elements) { + list.add(element); + } + return list; } } diff --git a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/DiffSelectorTest.java b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/DiffSelectorTest.java index e622fa51a88b7d58fe31c73fd5fcae53901a8654..c2fba6a58029c1bf74b5e5eed6b65715fda7ce1b 100644 --- a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/DiffSelectorTest.java +++ b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/DiffSelectorTest.java @@ -15,14 +15,116 @@ ***************************************************************************/ package org.oceandsl.analysis.graph.selector; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import kieker.analysis.architecture.repository.ModelRepository; +import kieker.analysis.exception.InternalErrorException; +import kieker.model.analysismodel.execution.ExecutionFactory; +import kieker.model.analysismodel.execution.Invocation; +import kieker.model.analysismodel.execution.OperationDataflow; +import kieker.model.analysismodel.execution.StorageDataflow; +import kieker.model.analysismodel.source.SourceModel; +import kieker.model.analysismodel.source.SourcePackage; +import kieker.model.analysismodel.type.TypeFactory; + +import org.oceandsl.analysis.architecture.ArchitectureModelManagementUtils; + class DiffSelectorTest { + private static final String EXP_1_D = "exp1-dynamic"; + private static final String EXP_2_D = "exp2-dynamic"; + private static final String EXP_1_S = "exp1-static"; + private static final String EXP_2_S = "exp2-static"; + + private final String[] groupA = { EXP_1_D, EXP_2_D }; + private final String[] groupB = { EXP_1_S, EXP_2_S }; + + private final EObject object1d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object1d1s = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2s = TypeFactory.eINSTANCE.createOperationType(); + + private final Invocation invocation = ExecutionFactory.eINSTANCE.createInvocation(); + private final OperationDataflow operationDataflow = ExecutionFactory.eINSTANCE.createOperationDataflow(); + private final StorageDataflow storageDataflow = ExecutionFactory.eINSTANCE.createStorageDataflow(); + + private ModelRepository repository; + + @BeforeEach + void setUp() { + this.repository = ArchitectureModelManagementUtils.createModelRepository("test"); + + final SourceModel sourceModel = this.repository.getModel(SourcePackage.Literals.SOURCE_MODEL); + + sourceModel.getSources().put(this.object1d, this.list(EXP_1_D)); + sourceModel.getSources().put(this.object2d, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.object1d1s, this.list(EXP_1_D, EXP_1_S)); + sourceModel.getSources().put(this.object2s, this.list(EXP_1_S, EXP_2_S)); + + sourceModel.getSources().put(this.invocation, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.operationDataflow, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.storageDataflow, this.list(EXP_1_D, EXP_2_D)); + } + + @Test + void testNodeSelected() throws InternalErrorException { + final DiffSelector selector = new DiffSelector(this.groupA, this.groupB); + + selector.setRepository(this.repository); + + Assertions.assertFalse(selector.nodeIsSelected(this.object1d), "node must not be selected, only one label"); + Assertions.assertTrue(selector.nodeIsSelected(this.object2d), "node must be selected, both labels present"); + Assertions.assertFalse(selector.nodeIsSelected(this.object1d1s), + "node must not be selected, only one label matches"); + Assertions.assertTrue(selector.nodeIsSelected(this.object2s), "node must be selected, other group"); + } + + @Test + void testMissingSourceModel() { + final DiffSelector selector = new DiffSelector(this.groupA, this.groupB); + final ModelRepository localRepository = new ModelRepository("example"); + try { + selector.setRepository(localRepository); + Assertions.fail("Missing source model must cause failure."); + } catch (final InternalErrorException e) { + // correct behavior + } + } + + @Test + void testColorGroupSelected() throws InternalErrorException { + final DiffSelector selector = new DiffSelector(this.groupA, this.groupB); + + selector.setRepository(this.repository); + + Assertions.assertFalse(selector.isColorGroup(this.list(this.groupA), 0), "must not be group 0"); + Assertions.assertFalse(selector.isColorGroup(this.list(EXP_1_D, EXP_2_D, EXP_1_S, EXP_2_S), 0), + "must be group 0"); + Assertions.assertTrue(selector.isColorGroup(this.list(this.groupA), 1), "must be group 1"); + Assertions.assertTrue(selector.isColorGroup(this.list(this.groupB), 2), "must be group 2"); + } + @Test - void test() { - Assertions.fail("Not yet implemented"); + void testEdgeSelected() throws InternalErrorException { + final DiffSelector selector = new DiffSelector(this.groupA, this.groupB); + + selector.setRepository(this.repository); + + Assertions.assertTrue(selector.edgeIsSelected(this.invocation), "invocation must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.operationDataflow), "operation dataflow must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.storageDataflow), "storage dataflow must be selected"); } + private EList<String> list(final String... elements) { + final BasicEList<String> list = new BasicEList<>(); + for (final String element : elements) { + list.add(element); + } + return list; + } } diff --git a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/IntersectSelectorTest.java b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/IntersectSelectorTest.java index 96e4526c415633080d8199ed2c51f6a6d2d84abb..994213e96bb47c2efc91381487f47c554bf70c01 100644 --- a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/IntersectSelectorTest.java +++ b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/IntersectSelectorTest.java @@ -15,14 +15,117 @@ ***************************************************************************/ package org.oceandsl.analysis.graph.selector; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import kieker.analysis.architecture.repository.ModelRepository; +import kieker.analysis.exception.InternalErrorException; +import kieker.model.analysismodel.execution.ExecutionFactory; +import kieker.model.analysismodel.execution.Invocation; +import kieker.model.analysismodel.execution.OperationDataflow; +import kieker.model.analysismodel.execution.StorageDataflow; +import kieker.model.analysismodel.source.SourceModel; +import kieker.model.analysismodel.source.SourcePackage; +import kieker.model.analysismodel.type.TypeFactory; + +import org.oceandsl.analysis.architecture.ArchitectureModelManagementUtils; + class IntersectSelectorTest { + private static final String EXP_1_D = "exp1-dynamic"; + private static final String EXP_2_D = "exp2-dynamic"; + private static final String EXP_1_S = "exp1-static"; + private static final String EXP_2_S = "exp2-static"; + + private final String[] groupA = { EXP_1_D }; + private final String[] groupB = { EXP_1_S }; + + private final EObject object1d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object1d1s = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2s = TypeFactory.eINSTANCE.createOperationType(); + + private final Invocation invocation = ExecutionFactory.eINSTANCE.createInvocation(); + private final OperationDataflow operationDataflow = ExecutionFactory.eINSTANCE.createOperationDataflow(); + private final StorageDataflow storageDataflow = ExecutionFactory.eINSTANCE.createStorageDataflow(); + + private ModelRepository repository; + + @BeforeEach + void setUp() { + this.repository = ArchitectureModelManagementUtils.createModelRepository("test"); + + final SourceModel sourceModel = this.repository.getModel(SourcePackage.Literals.SOURCE_MODEL); + + sourceModel.getSources().put(this.object1d, this.list(EXP_1_D)); + sourceModel.getSources().put(this.object2d, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.object1d1s, this.list(EXP_1_D, EXP_1_S)); + sourceModel.getSources().put(this.object2s, this.list(EXP_1_S, EXP_2_S)); + + sourceModel.getSources().put(this.invocation, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.operationDataflow, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.storageDataflow, this.list(EXP_1_D, EXP_2_D)); + } + @Test - void test() { - Assertions.fail("Not yet implemented"); + void testNodeSelected() throws InternalErrorException { + final IntersectSelector selector = new IntersectSelector(this.groupA, this.groupB); + + selector.setRepository(this.repository); + + Assertions.assertFalse(selector.nodeIsSelected(this.object1d), "node must not be selected, only one label"); + Assertions.assertFalse(selector.nodeIsSelected(this.object2d), "node must be selected, both labels present"); + Assertions.assertTrue(selector.nodeIsSelected(this.object1d1s), + "node must not be selected, only one label matches"); + Assertions.assertFalse(selector.nodeIsSelected(this.object2s), "node must be selected, other group"); + } + + @Test + void testColorGroupSelected() throws InternalErrorException { + final IntersectSelector selector = new IntersectSelector(this.groupA, this.groupB); + + selector.setRepository(this.repository); + + Assertions.assertFalse(selector.isColorGroup(this.list(this.groupA), 0), "must not be group 0"); + Assertions.assertFalse(selector.isColorGroup(this.list(EXP_1_D, EXP_2_D, EXP_1_S, EXP_2_S), 0), + "must be group 0"); + Assertions.assertTrue(selector.isColorGroup(this.list(this.groupA), 1), "must be group 1"); + Assertions.assertTrue(selector.isColorGroup(this.list(this.groupB), 2), "must be group 2"); + } + + @Test + void testEdgeSelected() throws InternalErrorException { + final IntersectSelector selector = new IntersectSelector(this.groupA, this.groupB); + + selector.setRepository(this.repository); + + Assertions.assertFalse(selector.edgeIsSelected(this.invocation), "invocation must not be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.operationDataflow), "operation dataflow must be selected"); + Assertions.assertFalse(selector.nodeIsSelected(this.storageDataflow), "storage dataflow must not be selected"); + } + + @Test + void testMissingSourceModel() { + final IntersectSelector selector = new IntersectSelector(this.groupA, this.groupB); + final ModelRepository localRepository = new ModelRepository("example"); + try { + selector.setRepository(localRepository); + Assertions.fail("Missing source model must cause failure."); + } catch (final InternalErrorException e) { + // correct behavior + } + } + + private EList<String> list(final String... elements) { + final BasicEList<String> list = new BasicEList<>(); + for (final String element : elements) { + list.add(element); + } + return list; } } diff --git a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/SubtractSelectorTest.java b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/SubtractSelectorTest.java index 08e2eb2cabe75fede8251c835cd55e80ac20c909..03a106d04cea63a65cdd311b4844268a40f79fac 100644 --- a/analysis/src/test/java/org/oceandsl/analysis/graph/selector/SubtractSelectorTest.java +++ b/analysis/src/test/java/org/oceandsl/analysis/graph/selector/SubtractSelectorTest.java @@ -15,14 +15,115 @@ ***************************************************************************/ package org.oceandsl.analysis.graph.selector; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import kieker.analysis.architecture.repository.ModelRepository; +import kieker.analysis.exception.InternalErrorException; +import kieker.model.analysismodel.execution.ExecutionFactory; +import kieker.model.analysismodel.execution.Invocation; +import kieker.model.analysismodel.execution.OperationDataflow; +import kieker.model.analysismodel.execution.StorageDataflow; +import kieker.model.analysismodel.source.SourceModel; +import kieker.model.analysismodel.source.SourcePackage; +import kieker.model.analysismodel.type.TypeFactory; + +import org.oceandsl.analysis.architecture.ArchitectureModelManagementUtils; + class SubtractSelectorTest { + private static final String EXP_1_D = "exp1-dynamic"; + private static final String EXP_2_D = "exp2-dynamic"; + private static final String EXP_1_S = "exp1-static"; + private static final String EXP_2_S = "exp2-static"; + + private final String[] group = { EXP_1_D, EXP_2_D }; + + private final EObject object1d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2d = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object1d1s = TypeFactory.eINSTANCE.createOperationType(); + private final EObject object2s = TypeFactory.eINSTANCE.createOperationType(); + + private final Invocation invocation = ExecutionFactory.eINSTANCE.createInvocation(); + private final OperationDataflow operationDataflow = ExecutionFactory.eINSTANCE.createOperationDataflow(); + private final StorageDataflow storageDataflow = ExecutionFactory.eINSTANCE.createStorageDataflow(); + + private ModelRepository repository; + + @BeforeEach + void setUp() { + this.repository = ArchitectureModelManagementUtils.createModelRepository("test"); + + final SourceModel sourceModel = this.repository.getModel(SourcePackage.Literals.SOURCE_MODEL); + + sourceModel.getSources().put(this.object1d, this.list(EXP_1_D)); + sourceModel.getSources().put(this.object2d, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.object1d1s, this.list(EXP_1_D, EXP_1_S)); + sourceModel.getSources().put(this.object2s, this.list(EXP_1_S, EXP_2_S)); + + sourceModel.getSources().put(this.invocation, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.operationDataflow, this.list(EXP_1_D, EXP_2_D)); + sourceModel.getSources().put(this.storageDataflow, this.list(EXP_1_D, EXP_2_D)); + } + @Test - void test() { - Assertions.fail("Not yet implemented"); + void testNodeSelected() throws InternalErrorException { + final SubtractSelector selector = new SubtractSelector(this.group); + + selector.setRepository(this.repository); + + Assertions.assertFalse(selector.nodeIsSelected(this.object1d), "node must not be selected, only one label"); + Assertions.assertTrue(selector.nodeIsSelected(this.object2d), "node must be selected, both labels present"); + Assertions.assertFalse(selector.nodeIsSelected(this.object1d1s), + "node must not be selected, only one label matches"); + Assertions.assertTrue(selector.nodeIsSelected(this.object2s), "node must be selected, other group"); + } + + @Test + void testColorGroupSelected() throws InternalErrorException { + final SubtractSelector selector = new SubtractSelector(this.group); + + selector.setRepository(this.repository); + + Assertions.assertFalse(selector.isColorGroup(this.list(this.group), 0), "must not be group 0"); + Assertions.assertFalse(selector.isColorGroup(this.list(EXP_1_D, EXP_2_D, EXP_1_S, EXP_2_S), 0), + "must be group 0"); + Assertions.assertTrue(selector.isColorGroup(this.list(this.group), 1), "must be group 1"); + } + + @Test + void testEdgeSelected() throws InternalErrorException { + final SubtractSelector selector = new SubtractSelector(this.group); + + selector.setRepository(this.repository); + + Assertions.assertTrue(selector.edgeIsSelected(this.invocation), "invocation must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.operationDataflow), "operation dataflow must be selected"); + Assertions.assertTrue(selector.nodeIsSelected(this.storageDataflow), "storage dataflow must be selected"); + } + + @Test + void testMissingSourceModel() { + final SubtractSelector selector = new SubtractSelector(this.group); + final ModelRepository localRepository = new ModelRepository("example"); + try { + selector.setRepository(localRepository); + Assertions.fail("Missing source model must cause failure."); + } catch (final InternalErrorException e) { + // correct behavior + } + } + + private EList<String> list(final String... elements) { + final BasicEList<String> list = new BasicEList<>(); + for (final String element : elements) { + list.add(element); + } + return list; } } diff --git a/build.gradle b/build.gradle index 4414f21a0277e0a72ac27ca1e11a67810c3cd0ac..629c3c8d0e945e60b146bdcef8607674fc54b02f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,6 @@ * This is a general purpose Gradle build. * Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds */ - plugins { id 'java' id "com.diffplug.spotless" version "5.17.1" @@ -57,7 +56,17 @@ subprojects { testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' } + test { + useJUnitPlatform() + } + jacocoTestReport { + reports { + xml.required = false + csv.required = false + html.required = true + } + } apply plugin: 'pmd' pmd { // is represented by the groovy class "PmdExtension" diff --git a/tools/sar/build.gradle b/tools/sar/build.gradle index ddf55309b59142fe2e82b858ed48bcb0c053556d..70f40e1acfc4ebd9b6b550b9244fe76efc045ae6 100644 --- a/tools/sar/build.gradle +++ b/tools/sar/build.gradle @@ -27,6 +27,9 @@ dependencies { implementation 'com.sun.xml.bind:jaxb-impl:2.3.3' implementation 'org.apache.commons:commons-compress:1.20' +// testImplementation project(':analysis') + testImplementation project(":analysis").sourceSets.test.output + testImplementation 'junit:junit:4.13' testImplementation 'org.hamcrest:hamcrest-all:1.3' testImplementation "org.mockito:mockito-core:3.+" diff --git a/tools/sar/src/test/java/org/oceandsl/tools/sar/stages/dataflow/CountUniqueDataflowCallsStageTest.java b/tools/sar/src/test/java/org/oceandsl/tools/sar/stages/dataflow/CountUniqueDataflowCallsStageTest.java index 1316ba40a87f1df920847a6bff01b303c0d20d65..595db8073239f90407d75955f98e399a8c756db3 100644 --- a/tools/sar/src/test/java/org/oceandsl/tools/sar/stages/dataflow/CountUniqueDataflowCallsStageTest.java +++ b/tools/sar/src/test/java/org/oceandsl/tools/sar/stages/dataflow/CountUniqueDataflowCallsStageTest.java @@ -21,58 +21,31 @@ import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import kieker.analysis.architecture.recovery.events.OperationEvent; -import kieker.model.analysismodel.assembly.AssemblyComponent; -import kieker.model.analysismodel.assembly.AssemblyFactory; import kieker.model.analysismodel.assembly.AssemblyModel; -import kieker.model.analysismodel.assembly.AssemblyOperation; -import kieker.model.analysismodel.deployment.DeployedComponent; -import kieker.model.analysismodel.deployment.DeployedOperation; -import kieker.model.analysismodel.deployment.DeploymentContext; -import kieker.model.analysismodel.deployment.DeploymentFactory; import kieker.model.analysismodel.deployment.DeploymentModel; import kieker.model.analysismodel.execution.EDirection; -import kieker.model.analysismodel.execution.ExecutionFactory; import kieker.model.analysismodel.execution.ExecutionModel; -import kieker.model.analysismodel.execution.OperationDataflow; -import kieker.model.analysismodel.execution.Tuple; -import kieker.model.analysismodel.statistics.StatisticRecord; -import kieker.model.analysismodel.statistics.StatisticsFactory; import kieker.model.analysismodel.statistics.StatisticsModel; -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 teetime.framework.test.StageTester; -class CountUniqueDataflowCallsStageTest { +import org.oceandsl.analysis.architecture.ArchitectureModelUtils; - private static final String CP_LEFT = "Left"; - private static final String PACKAGE = "test"; - private static final String CP_LEFT_FQN = CountUniqueDataflowCallsStageTest.PACKAGE + "." - + CountUniqueDataflowCallsStageTest.CP_LEFT; - private static final String OP_LEFT = "op1"; - private static final String OP_LEFT_SIGNATURE = "V op1 (T, B)"; - private static final String OP_RETURN_TYPE = "V"; - private static final String OP_RIGHT = "op2"; - private static final String OP_RIGHT_SIGNATURE = "V op2 (T, B)"; - private static final String CP_RIGHT = "Right"; - private static final String CP_RIGHT_FQN = CountUniqueDataflowCallsStageTest.PACKAGE + "." - + CountUniqueDataflowCallsStageTest.CP_RIGHT; - private static final String CONTEXT = "context"; +class CountUniqueDataflowCallsStageTest { @Test void test() { - final TypeModel typeModel = this.createTypeModel(); - final AssemblyModel assemblyModel = this.createAssemblyModel(typeModel); - final DeploymentModel deploymentModel = this.createDeploymentModel(assemblyModel); - final ExecutionModel executionModel = this.createExecutionModel(deploymentModel); - final StatisticsModel statisticsModel = this.createStatisticsModel(executionModel); - - final OperationEvent op1 = new OperationEvent(CountUniqueDataflowCallsStageTest.CONTEXT, - CountUniqueDataflowCallsStageTest.CP_LEFT_FQN, CountUniqueDataflowCallsStageTest.CP_LEFT_FQN); - final OperationEvent op2 = new OperationEvent(CountUniqueDataflowCallsStageTest.CONTEXT, - CountUniqueDataflowCallsStageTest.CP_RIGHT_FQN, CountUniqueDataflowCallsStageTest.CP_RIGHT_FQN); + final TypeModel typeModel = ArchitectureModelUtils.createTypeModel(); + final AssemblyModel assemblyModel = ArchitectureModelUtils.createAssemblyModel(typeModel); + final DeploymentModel deploymentModel = ArchitectureModelUtils.createDeploymentModel(assemblyModel); + final ExecutionModel executionModel = ArchitectureModelUtils.createExecutionModel(deploymentModel); + final StatisticsModel statisticsModel = ArchitectureModelUtils.createStatisticsModel(executionModel); + + final OperationEvent op1 = new OperationEvent(ArchitectureModelUtils.CONTEXT, + ArchitectureModelUtils.CP_LEFT_FQN, ArchitectureModelUtils.CP_LEFT_FQN); + final OperationEvent op2 = new OperationEvent(ArchitectureModelUtils.CONTEXT, + ArchitectureModelUtils.CP_RIGHT_FQN, ArchitectureModelUtils.CP_RIGHT_FQN); final DataflowEvent sourceDataflow = new DataflowEvent(op1, op2, EDirection.BOTH, Duration.ofMillis(5)); final CountUniqueDataflowCallsStage stage = new CountUniqueDataflowCallsStage(statisticsModel, executionModel); @@ -81,148 +54,4 @@ class CountUniqueDataflowCallsStageTest { MatcherAssert.assertThat(stage.getOutputPort(), StageTester.produces(sourceDataflow)); } - private StatisticsModel createStatisticsModel(final ExecutionModel executionModel) { - final StatisticsModel model = StatisticsFactory.eINSTANCE.createStatisticsModel(); - executionModel.getOperationDataflows().values().forEach(dataflow -> { - final StatisticRecord statisticRecord = StatisticsFactory.eINSTANCE.createStatisticRecord(); - statisticRecord.getProperties().put(CountUniqueDataflowCallsStage.DATAFLOW, 1); - model.getStatistics().put(dataflow, statisticRecord); - }); - return model; - } - - private TypeModel createTypeModel() { - final TypeModel model = TypeFactory.eINSTANCE.createTypeModel(); - - final ComponentType componentType = this.createComponentType(CountUniqueDataflowCallsStageTest.CP_LEFT, - CountUniqueDataflowCallsStageTest.CP_LEFT_FQN); - - final OperationType operationType = this.createOperationType(CountUniqueDataflowCallsStageTest.OP_LEFT, - CountUniqueDataflowCallsStageTest.OP_LEFT_SIGNATURE, CountUniqueDataflowCallsStageTest.OP_RETURN_TYPE); - componentType.getProvidedOperations().put(operationType.getSignature(), operationType); - - model.getComponentTypes().put(componentType.getSignature(), componentType); - - final ComponentType componentType2 = this.createComponentType(CountUniqueDataflowCallsStageTest.CP_RIGHT, - CountUniqueDataflowCallsStageTest.CP_RIGHT_FQN); - - final OperationType operationType2 = this.createOperationType(CountUniqueDataflowCallsStageTest.OP_RIGHT, - CountUniqueDataflowCallsStageTest.OP_RIGHT_SIGNATURE, CountUniqueDataflowCallsStageTest.OP_RETURN_TYPE); - componentType.getProvidedOperations().put(operationType2.getSignature(), operationType2); - - model.getComponentTypes().put(componentType2.getSignature(), componentType2); - - return model; - } - - private ComponentType createComponentType(final String name, final String fqnName) { - final ComponentType componentType = TypeFactory.eINSTANCE.createComponentType(); - componentType.setName(name); - componentType.setPackage(CountUniqueDataflowCallsStageTest.PACKAGE); - componentType.setSignature(fqnName); - return componentType; - } - - private OperationType createOperationType(final String name, final String signature, final String returnType) { - final OperationType operationType = TypeFactory.eINSTANCE.createOperationType(); - operationType.setName(name); - operationType.setSignature(signature); - operationType.setReturnType(returnType); - - return operationType; - } - - private AssemblyModel createAssemblyModel(final TypeModel typeModel) { - final AssemblyModel model = AssemblyFactory.eINSTANCE.createAssemblyModel(); - - final AssemblyComponent component = this.createAssemblyComponent(CountUniqueDataflowCallsStageTest.CP_LEFT_FQN, - typeModel); - component.getOperations().put(CountUniqueDataflowCallsStageTest.OP_LEFT_SIGNATURE, this.createAssemblyOperation( - CountUniqueDataflowCallsStageTest.OP_LEFT_SIGNATURE, component.getComponentType())); - - final AssemblyComponent component2 = this - .createAssemblyComponent(CountUniqueDataflowCallsStageTest.CP_RIGHT_FQN, typeModel); - component2.getOperations().put(CountUniqueDataflowCallsStageTest.OP_RIGHT_SIGNATURE, - this.createAssemblyOperation(CountUniqueDataflowCallsStageTest.OP_RIGHT_SIGNATURE, - component2.getComponentType())); - - return model; - } - - private AssemblyComponent createAssemblyComponent(final String fqnName, final TypeModel typeModel) { - final AssemblyComponent component = AssemblyFactory.eINSTANCE.createAssemblyComponent(); - final ComponentType componentType = typeModel.getComponentTypes() - .get(CountUniqueDataflowCallsStageTest.CP_LEFT_FQN); - component.setComponentType(componentType); - component.setSignature(fqnName); - - return component; - } - - private AssemblyOperation createAssemblyOperation(final String signature, final ComponentType componentType) { - final AssemblyOperation operation = AssemblyFactory.eINSTANCE.createAssemblyOperation(); - operation.setOperationType(componentType.getProvidedOperations().get(signature)); - - return operation; - } - - private DeploymentModel createDeploymentModel(final AssemblyModel assemblyModel) { - final DeploymentModel model = DeploymentFactory.eINSTANCE.createDeploymentModel(); - - final DeploymentContext context = DeploymentFactory.eINSTANCE.createDeploymentContext(); - context.setName(CountUniqueDataflowCallsStageTest.CONTEXT); - - model.getContexts().put(CountUniqueDataflowCallsStageTest.CONTEXT, context); - - final DeployedComponent component = this.createComponent(CountUniqueDataflowCallsStageTest.CP_LEFT_FQN, - assemblyModel); - component.getOperations().put(CountUniqueDataflowCallsStageTest.OP_LEFT_SIGNATURE, - this.createDeployedOperation(CountUniqueDataflowCallsStageTest.OP_LEFT_SIGNATURE, component)); - - context.getComponents().put(CountUniqueDataflowCallsStageTest.CP_LEFT_FQN, component); - - final DeployedComponent component2 = this.createComponent(CountUniqueDataflowCallsStageTest.CP_RIGHT_FQN, - assemblyModel); - component2.getOperations().put(CountUniqueDataflowCallsStageTest.OP_RIGHT_SIGNATURE, - this.createDeployedOperation(CountUniqueDataflowCallsStageTest.OP_RIGHT_SIGNATURE, component2)); - context.getComponents().put(CountUniqueDataflowCallsStageTest.CP_RIGHT_FQN, component2); - - return model; - } - - private DeployedComponent createComponent(final String fqnName, final AssemblyModel assemblyModel) { - final DeployedComponent component = DeploymentFactory.eINSTANCE.createDeployedComponent(); - component.setSignature(fqnName); - component.setAssemblyComponent(assemblyModel.getComponents().get(fqnName)); - - return component; - } - - private DeployedOperation createDeployedOperation(final String signature, final DeployedComponent component) { - final DeployedOperation operation = DeploymentFactory.eINSTANCE.createDeployedOperation(); - operation.setAssemblyOperation(component.getAssemblyComponent().getOperations().get(signature)); - - return operation; - } - - private ExecutionModel createExecutionModel(final DeploymentModel deploymentModel) { - final ExecutionModel model = ExecutionFactory.eINSTANCE.createExecutionModel(); - - final DeployedOperation caller = deploymentModel.getContexts().get(CountUniqueDataflowCallsStageTest.CONTEXT) - .getComponents().get(CountUniqueDataflowCallsStageTest.CP_LEFT_FQN).getOperations() - .get(CountUniqueDataflowCallsStageTest.OP_LEFT_SIGNATURE); - final DeployedOperation callee = deploymentModel.getContexts().get(CountUniqueDataflowCallsStageTest.CONTEXT) - .getComponents().get(CountUniqueDataflowCallsStageTest.CP_RIGHT_FQN).getOperations() - .get(CountUniqueDataflowCallsStageTest.OP_RIGHT_SIGNATURE); - - final Tuple<DeployedOperation, DeployedOperation> tuple = ExecutionFactory.eINSTANCE.createTuple(); - final OperationDataflow dataflow = ExecutionFactory.eINSTANCE.createOperationDataflow(); - dataflow.setCallee(callee); - dataflow.setCaller(caller); - - model.getOperationDataflows().put(tuple, dataflow); - - return model; - } - }