From 98a2e9e8e16e094d5cffed9430ef78fb6fe6cd13 Mon Sep 17 00:00:00 2001 From: theghost5800 Date: Tue, 14 Oct 2025 16:24:09 +0300 Subject: [PATCH 1/4] Add tests for flowable engine JIRA:LMCROSSITXSADEPLOY-3320 --- .../test/TestDataSourceProvider.java | 9 +- multiapps-controller-process/pom.xml | 27 +- .../process/flowable/FlowableEngineTest.java | 562 ++++++++++++++++++ .../test/resources/META-INF/persistence.xml | 18 + 4 files changed, 612 insertions(+), 4 deletions(-) create mode 100644 multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java create mode 100644 multiapps-controller-process/src/test/resources/META-INF/persistence.xml diff --git a/multiapps-controller-persistence-test/src/main/java/org/cloudfoundry/multiapps/controller/persistence/test/TestDataSourceProvider.java b/multiapps-controller-persistence-test/src/main/java/org/cloudfoundry/multiapps/controller/persistence/test/TestDataSourceProvider.java index 65e4b37eef..ab9fe0a9b8 100644 --- a/multiapps-controller-persistence-test/src/main/java/org/cloudfoundry/multiapps/controller/persistence/test/TestDataSourceProvider.java +++ b/multiapps-controller-persistence-test/src/main/java/org/cloudfoundry/multiapps/controller/persistence/test/TestDataSourceProvider.java @@ -3,16 +3,14 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; - import javax.sql.DataSource; -import org.springframework.jdbc.datasource.SingleConnectionDataSource; - import liquibase.Liquibase; import liquibase.database.Database; import liquibase.database.DatabaseFactory; import liquibase.database.jvm.JdbcConnection; import liquibase.resource.ClassLoaderResourceAccessor; +import org.springframework.jdbc.datasource.SingleConnectionDataSource; public final class TestDataSourceProvider { @@ -20,6 +18,11 @@ private TestDataSourceProvider() { } + public static DataSource getDataSource() throws Exception { + Connection connection = createH2InMemoryConnection(); + return new SingleConnectionDataSource(connection, true); + } + public static DataSource getDataSource(String liquibaseChangelogLocation) throws Exception { // Liquibase closes the connection after it's done, so we need a separate one for it. Connection connectionForLiquibase = createH2InMemoryConnection(); diff --git a/multiapps-controller-process/pom.xml b/multiapps-controller-process/pom.xml index 06d5c2d465..95c71842f3 100644 --- a/multiapps-controller-process/pom.xml +++ b/multiapps-controller-process/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 multiapps-controller-process @@ -96,5 +96,30 @@ jakarta.xml.bind jakarta.xml.bind-api + + org.cloudfoundry.multiapps + multiapps-controller-persistence-test + test + + + org.apache.derby + derby + test + + + org.apache.derby + derbyclient + test + + + org.apache.derby + derbynet + test + + + com.h2database + h2 + test + \ No newline at end of file diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java new file mode 100644 index 0000000000..78fdc0395d --- /dev/null +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java @@ -0,0 +1,562 @@ +package org.cloudfoundry.multiapps.controller.process.flowable; + +import java.time.Duration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.sql.DataSource; + +import org.cloudfoundry.multiapps.common.util.JsonSerializationStrategy; +import org.cloudfoundry.multiapps.common.util.JsonUtil; +import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudRoute; +import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudServiceKey; +import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableCloudServiceKey; +import org.cloudfoundry.multiapps.controller.core.cf.apps.ApplicationStateAction; +import org.cloudfoundry.multiapps.controller.core.model.DeployedMta; +import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; +import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaService; +import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMta; +import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaApplication; +import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaService; +import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationURI; +import org.cloudfoundry.multiapps.controller.persistence.test.TestDataSourceProvider; +import org.cloudfoundry.multiapps.controller.process.steps.StepPhase; +import org.cloudfoundry.multiapps.controller.process.variables.Serializer; +import org.cloudfoundry.multiapps.controller.process.variables.Variable; +import org.cloudfoundry.multiapps.controller.process.variables.Variables; +import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; +import org.cloudfoundry.multiapps.mta.model.ExtensionDescriptor; +import org.cloudfoundry.multiapps.mta.model.ExtensionModule; +import org.cloudfoundry.multiapps.mta.model.ExtensionResource; +import org.cloudfoundry.multiapps.mta.model.Module; +import org.cloudfoundry.multiapps.mta.model.ProvidedDependency; +import org.cloudfoundry.multiapps.mta.model.RequiredDependency; +import org.cloudfoundry.multiapps.mta.model.Resource; +import org.cloudfoundry.multiapps.mta.model.Version; +import org.flowable.engine.ProcessEngine; +import org.flowable.engine.ProcessEngineConfiguration; +import org.flowable.engine.RepositoryService; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.flowable.engine.repository.ProcessDefinition; +import org.flowable.engine.runtime.ProcessInstance; +import org.flowable.mail.common.api.client.FlowableMailClient; +import org.junit.jupiter.api.AfterEach; +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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +/** + * Integration test for Flowable engine with in-memory H2 database. Tests real BPMN process creation, variable setting and retrieval using + * the multiapps-controller variable handling system. + */ +//@FlowableTest +//@ConfigurationResource("flowable-config.xml") +class FlowableEngineTest { + + private static final String TEST_PROCESS_KEY = "mtaDeploymentTest"; + private static final String TEST_BPMN_CONTENT = """ + + + + + + + + + + + """; + + @Mock + private FlowableMailClient flowableMailClient; + + private ProcessEngine processEngine; + private RepositoryService repositoryService; + private RuntimeService runtimeService; + private String deploymentId; + private TestVariableTask testVariableTask; + + @BeforeEach + void setUp() throws Exception { + MockitoAnnotations.openMocks(this); + testVariableTask = new TestVariableTask(); + DataSource dataSource = TestDataSourceProvider.getDataSource(); + ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration(); + configuration.setDataSource(dataSource); + configuration.setDefaultMailClient(flowableMailClient); + configuration.setDatabaseSchemaUpdate("create-drop"); + configuration.setBeans(Map.of("testVariableTask", testVariableTask)); + configuration.setAsyncExecutorActivate(false); + processEngine = configuration.buildProcessEngine(); + repositoryService = processEngine.getRepositoryService(); + runtimeService = processEngine.getRuntimeService(); + + // Deploy test process + deploymentId = repositoryService.createDeployment() + .name("MTA Deployment Test") + .addString("mta-deployment-test.bpmn20.xml", TEST_BPMN_CONTENT) + .deploy() + .getId(); + } + + @AfterEach + void tearDown() { + if (deploymentId != null) { + repositoryService.deleteDeployment(deploymentId, true); + } + if (processEngine != null) { + processEngine.close(); + } + } + + @Test + void testProcessDeployment() { + List processDefinitions = repositoryService.createProcessDefinitionQuery() + .processDefinitionKey(TEST_PROCESS_KEY) + .list(); + + assertEquals(1, processDefinitions.size()); + assertEquals(TEST_PROCESS_KEY, processDefinitions.get(0) + .getKey()); + assertEquals("MTA Deployment Test Process", processDefinitions.get(0) + .getName()); + } + + @Test + void testProcessWithPredefinedVariables() { + String correlationId = UUID.randomUUID() + .toString(); + String spaceGuid = UUID.randomUUID() + .toString(); + String orgGuid = UUID.randomUUID() + .toString(); + String userName = "test-user@example.com"; + String userGuid = UUID.randomUUID() + .toString(); + String mtaId = "test-mta"; + String mtaVersion = "1.0.0"; + boolean keepFiles = true; + Duration appsStageTimeout = Duration.ofMinutes(15); + int modulesCount = 5; + DeploymentDescriptor smallDeploymentDescriptor = createSmallDeploymentDescriptor(mtaId, mtaVersion); + DeploymentDescriptor bigDeploymentDescriptor = createBigDeploymentDescriptor(mtaId, mtaVersion); + DeployedMta deployedMta = createDeployedMta(mtaId, mtaVersion); + List cloudRoutes = createCloudRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com"); + StepPhase stepPhase = StepPhase.DONE; + List appStateActionsToExecute = List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START); + List serviceKeysToCreate = createServiceKeysToCreate(); + List modulesForDeployment = List.of("module-1", "module-2", "module-3"); + List extensionDescriptors = createExtensionDescriptorsWithNullValues(mtaId); + + // Start process instance with variables using multiapps-controller variable names + Map variables = new HashMap<>(); + setSerializedValueInMap(variables, Variables.CORRELATION_ID, correlationId); + setSerializedValueInMap(variables, Variables.SPACE_GUID, spaceGuid); + setSerializedValueInMap(variables, Variables.ORGANIZATION_GUID, orgGuid); + setSerializedValueInMap(variables, Variables.USER, userName); + setSerializedValueInMap(variables, Variables.USER_GUID, userGuid); + setSerializedValueInMap(variables, Variables.MTA_ID, mtaId); + setSerializedValueInMap(variables, Variables.KEEP_FILES, keepFiles); + setSerializedValueInMap(variables, Variables.APPS_STAGE_TIMEOUT_PROCESS_VARIABLE, appsStageTimeout); + setSerializedValueInMap(variables, Variables.MODULES_COUNT, modulesCount); + setSerializedValueInMap(variables, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS, smallDeploymentDescriptor); + setSerializedValueInMap(variables, Variables.DEPLOYMENT_DESCRIPTOR, bigDeploymentDescriptor); + setSerializedValueInMap(variables, Variables.DEPLOYED_MTA, deployedMta); + setSerializedValueInMap(variables, Variables.CURRENT_ROUTES, cloudRoutes); + setSerializedValueInMap(variables, Variables.STEP_PHASE, stepPhase); + setSerializedValueInMap(variables, Variables.APP_STATE_ACTIONS_TO_EXECUTE, appStateActionsToExecute); + setSerializedValueInMap(variables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); + setSerializedValueInMap(variables, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); + setSerializedValueInMap(variables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); + + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY, variables); + + assertEquals(TEST_PROCESS_KEY, processInstance.getProcessDefinitionKey()); + + // Verify variables are set and retrievable using multiapps variable system + assertEquals(correlationId, getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID)); + assertEquals(spaceGuid, getDeserializedValue(testVariableTask.capturedVariables, Variables.SPACE_GUID)); + assertEquals(orgGuid, getDeserializedValue(testVariableTask.capturedVariables, Variables.ORGANIZATION_GUID)); + assertEquals(userName, getDeserializedValue(testVariableTask.capturedVariables, Variables.USER)); + assertEquals(userGuid, getDeserializedValue(testVariableTask.capturedVariables, Variables.USER_GUID)); + assertEquals(mtaId, getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID)); + assertEquals(keepFiles, getDeserializedValue(testVariableTask.capturedVariables, Variables.KEEP_FILES)); + assertEquals(appsStageTimeout, + getDeserializedValue(testVariableTask.capturedVariables, Variables.APPS_STAGE_TIMEOUT_PROCESS_VARIABLE)); + assertEquals(modulesCount, getDeserializedValue(testVariableTask.capturedVariables, Variables.MODULES_COUNT)); + assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson( + getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS))); + assertEquals(JsonUtil.toJson(bigDeploymentDescriptor), + JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR))); + assertEquals(deployedMta, getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA)); + assertEquals(cloudRoutes, getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES)); + assertEquals(stepPhase, getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE)); + assertEquals(appStateActionsToExecute, + getDeserializedValue(testVariableTask.capturedVariables, Variables.APP_STATE_ACTIONS_TO_EXECUTE)); + assertEquals(serviceKeysToCreate, getDeserializedValue(testVariableTask.capturedVariables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE)); + assertEquals(modulesForDeployment, getDeserializedValue(testVariableTask.capturedVariables, Variables.MODULES_FOR_DEPLOYMENT)); + assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), + JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN), + JsonSerializationStrategy.ALLOW_NULLS)); + } + + @Test + void testVariableUpdateAndRetrieval() { + String correlationId = UUID.randomUUID() + .toString(); + Boolean deleteServices = true; + String mtaId = "test-mta-2"; + String mtaVersion = "2.0.0"; + DeploymentDescriptor smallDeploymentDescriptor = createSmallDeploymentDescriptor(mtaId, mtaVersion); + DeploymentDescriptor bigDeploymentDescriptor = createBigDeploymentDescriptor(mtaId, mtaVersion); + DeploymentDescriptor modifiedBigDeploymentDescriptor = DeploymentDescriptor.copyOf(bigDeploymentDescriptor) + .setParameters(Map.of("new-param", "new-value")); + DeployedMta oldDeployedMta = createDeployedMta(mtaId, "1.0.0"); + DeployedMta newDeployedMta = createDeployedMta(mtaId, mtaVersion); + List idleRoutes = createCloudRoutes("route-1-idle.example.com/bar-foo", "route-2-idle.example.com", + "route-3-idle.example.com"); + List liveRoutes = createCloudRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com"); + StepPhase pollingPhase = StepPhase.POLL; + StepPhase donePhase = StepPhase.DONE; + List idleAppStateActionsToExecute = List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START); + List liveAppStateActionsToExecute = List.of(ApplicationStateAction.EXECUTE, ApplicationStateAction.STOP); + List serviceKeysToCreate = createServiceKeysToCreate(); + List modulesForDeployment = List.of("module-1", "module-2", "module-3"); + List extensionDescriptors = createExtensionDescriptorsWithNullValues(mtaId); + + Map initialVariables = new HashMap<>(); + setSerializedValueInMap(initialVariables, Variables.CORRELATION_ID, correlationId); + setSerializedValueInMap(initialVariables, Variables.DELETE_SERVICES, deleteServices); + setSerializedValueInMap(initialVariables, Variables.MTA_ID, mtaId); + setSerializedValueInMap(initialVariables, Variables.DEPLOYMENT_DESCRIPTOR, bigDeploymentDescriptor); + setSerializedValueInMap(initialVariables, Variables.DEPLOYED_MTA, oldDeployedMta); + setSerializedValueInMap(initialVariables, Variables.CURRENT_ROUTES, idleRoutes); + setSerializedValueInMap(initialVariables, Variables.STEP_PHASE, pollingPhase); + setSerializedValueInMap(initialVariables, Variables.APP_STATE_ACTIONS_TO_EXECUTE, idleAppStateActionsToExecute); + setSerializedValueInMap(initialVariables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); + setSerializedValueInMap(initialVariables, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); + setSerializedValueInMap(initialVariables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); + + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CORRELATION_ID, correlationId); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DELETE_SERVICES, deleteServices); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_ID, mtaId); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS, + smallDeploymentDescriptor); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR, modifiedBigDeploymentDescriptor); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYED_MTA, newDeployedMta); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CURRENT_ROUTES, liveRoutes); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.STEP_PHASE, donePhase); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.APP_STATE_ACTIONS_TO_EXECUTE, + liveAppStateActionsToExecute); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); + + runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY, initialVariables); + + String retrievedCorrelationId = getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID); + Boolean retrievedDeleteServices = getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES); + String retrievedMtaId = getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID); + DeploymentDescriptor retrievedSmallDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, + Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS); + DeploymentDescriptor retrievedBigDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, + Variables.DEPLOYMENT_DESCRIPTOR); + DeployedMta retrievedDeployedMta = getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA); + List retrievedCloudRoutes = getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES); + StepPhase retrievedStepPhase = getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE); + List retrievedAppStateActionsToExecute = getDeserializedValue(testVariableTask.capturedVariables, + Variables.APP_STATE_ACTIONS_TO_EXECUTE); + List retrievedServiceKeysToCreate = getDeserializedValue(testVariableTask.capturedVariables, + Variables.CLOUD_SERVICE_KEYS_TO_CREATE); + List retrievedModulesForDeployment = getDeserializedValue(testVariableTask.capturedVariables, + Variables.MODULES_FOR_DEPLOYMENT); + List retrievedExtensionDescriptors = getDeserializedValue(testVariableTask.capturedVariables, + Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN); + + assertEquals(correlationId, retrievedCorrelationId); + assertEquals(deleteServices, retrievedDeleteServices); + assertEquals(mtaId, retrievedMtaId); + assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson(retrievedSmallDeploymentDescriptor)); + // This assertion intentionally checks that the modified deployment descriptor is different from the initially set one because of flowable caching regression + // https://github.com/flowable/flowable-engine/issues/4130 + // The original behaviour must be to have same deployment descriptor as it was set in the task. Modify the test to assert for matching values when the issue is fixed. + assertNotEquals(JsonUtil.toJson(modifiedBigDeploymentDescriptor), JsonUtil.toJson(retrievedBigDeploymentDescriptor)); + assertEquals(newDeployedMta, retrievedDeployedMta); + assertEquals(liveRoutes, retrievedCloudRoutes); + assertEquals(donePhase, retrievedStepPhase); + assertEquals(liveAppStateActionsToExecute, retrievedAppStateActionsToExecute); + assertEquals(serviceKeysToCreate, retrievedServiceKeysToCreate); + assertEquals(modulesForDeployment, retrievedModulesForDeployment); + assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), + JsonUtil.toJson(retrievedExtensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS)); + } + + @Test + void testSetVariablesInsideStep() { + String correlationId = UUID.randomUUID() + .toString(); + Boolean deleteServices = true; + String mtaId = "test-mta-2"; + String mtaVersion = "2.0.0"; + DeploymentDescriptor smallDeploymentDescriptor = createSmallDeploymentDescriptor(mtaId, mtaVersion); + DeploymentDescriptor bigDeploymentDescriptor = createBigDeploymentDescriptor(mtaId, mtaVersion); + DeployedMta deployedMta = createDeployedMta(mtaId, mtaVersion); + List cloudRoutes = createCloudRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com"); + StepPhase stepPhase = StepPhase.DONE; + List appStateActionsToExecute = List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START); + List serviceKeysToCreate = createServiceKeysToCreate(); + List modulesForDeployment = List.of("module-1", "module-2", "module-3"); + List extensionDescriptors = createExtensionDescriptorsWithNullValues(mtaId); + + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CORRELATION_ID, correlationId); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DELETE_SERVICES, deleteServices); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_ID, mtaId); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS, + smallDeploymentDescriptor); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR, bigDeploymentDescriptor); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYED_MTA, deployedMta); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CURRENT_ROUTES, cloudRoutes); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.STEP_PHASE, stepPhase); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.APP_STATE_ACTIONS_TO_EXECUTE, appStateActionsToExecute); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); + setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); + + runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY); + + String retrievedCorrelationId = getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID); + Boolean retrievedDeleteServices = getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES); + String retrievedMtaId = getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID); + DeploymentDescriptor retrievedSmallDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, + Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS); + DeploymentDescriptor retrievedBigDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, + Variables.DEPLOYMENT_DESCRIPTOR); + DeployedMta retrievedDeployedMta = getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA); + List retrievedCloudRoutes = getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES); + StepPhase retrievedStepPhase = getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE); + List retrievedAppStateActionsToExecute = getDeserializedValue(testVariableTask.capturedVariables, + Variables.APP_STATE_ACTIONS_TO_EXECUTE); + List retrievedServiceKeysToCreate = getDeserializedValue(testVariableTask.capturedVariables, + Variables.CLOUD_SERVICE_KEYS_TO_CREATE); + List retrievedModulesForDeployment = getDeserializedValue(testVariableTask.capturedVariables, + Variables.MODULES_FOR_DEPLOYMENT); + List retrievedExtensionDescriptors = getDeserializedValue(testVariableTask.capturedVariables, + Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN); + + assertEquals(correlationId, retrievedCorrelationId); + assertEquals(deleteServices, retrievedDeleteServices); + assertEquals(mtaId, retrievedMtaId); + assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson(retrievedSmallDeploymentDescriptor)); + assertEquals(JsonUtil.toJson(bigDeploymentDescriptor), JsonUtil.toJson(retrievedBigDeploymentDescriptor)); + assertEquals(deployedMta, retrievedDeployedMta); + assertEquals(cloudRoutes, retrievedCloudRoutes); + assertEquals(stepPhase, retrievedStepPhase); + assertEquals(appStateActionsToExecute, retrievedAppStateActionsToExecute); + assertEquals(serviceKeysToCreate, retrievedServiceKeysToCreate); + assertEquals(modulesForDeployment, retrievedModulesForDeployment); + assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), + JsonUtil.toJson(retrievedExtensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS)); + } + + private void setSerializedValueInMap(Map variables, Variable variable, T value) { + if (value == null) { + variables.put(variable.getName(), null); + return; + } + Serializer serializer = variable.getSerializer(); + variables.put(variable.getName(), serializer.serialize(value)); + } + + private T getDeserializedValue(Map variables, Variable variable) { + Object serializedValue = variables.get(variable.getName()); + if (serializedValue == null) { + return variable.getDefaultValue(); + } + Serializer serializer = variable.getSerializer(); + return serializer.deserialize(serializedValue); + } + + private DeploymentDescriptor createSmallDeploymentDescriptor(String mtaId, String mtaVersion) { + return DeploymentDescriptor.createV3() + .setId(mtaId) + .setVersion(mtaVersion) + .setModules(List.of(Module.createV3() + .setName("module-1") + .setType("javascript") + .setParameters( + Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, + "256M", SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-1-route.example.com"))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"))))) + .setResources(List.of(Resource.createV3() + .setName("db") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", + SupportedParameters.SERVICE_PLAN, "free")))); + } + + private DeploymentDescriptor createBigDeploymentDescriptor(String mtaId, String mtaVersion) { + return DeploymentDescriptor.createV3() + .setId(mtaId) + .setVersion(mtaVersion) + .setParameters(Map.of(SupportedParameters.ENABLE_PARALLEL_DEPLOYMENTS, true)) + .setModules(List.of(Module.createV3() + .setName("module-1") + .setType("javascript") + .setParameters( + Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, + "256M", SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-1-route.example.com"), + SupportedParameters.TASKS, + List.of(Map.of("name", "task-1", "command", "migrate-db.sh")))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"), + RequiredDependency.createV3() + .setName( + "application-logs"))), + Module.createV3() + .setName("module-2") + .setType("java") + .setParameters( + Map.of(SupportedParameters.MEMORY, "1G", SupportedParameters.DISK_QUOTA, + "4096M", SupportedParameters.INSTANCES, 2, + SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-2-route.example.com"))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"), + RequiredDependency.createV3() + .setName("cache"), + RequiredDependency.createV3() + .setName("autoscaler"), + RequiredDependency.createV3() + .setName( + "application-logs"))), + Module.createV3() + .setName("module-3") + .setType("javascript") + .setParameters( + Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, + "256M", SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-3-route.example.com"))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"), + RequiredDependency.createV3() + .setName("cache"), + RequiredDependency.createV3() + .setName("autoscaler"), + RequiredDependency.createV3() + .setName( + "application-logs"))) + .setProvidedDependencies(List.of(ProvidedDependency.createV3() + .setName("my-api") + .setProperties(Map.of("url", + "https://api.example.com")))))) + .setResources(List.of(Resource.createV3() + .setName("db") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", + SupportedParameters.SERVICE_PLAN, "free")), + Resource.createV3() + .setName("cache") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "test-cache-service", + SupportedParameters.SERVICE_PLAN, "free")), + Resource.createV3() + .setName("autoscaler") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "app-autoscaler", + SupportedParameters.SERVICE_PLAN, "default")), + Resource.createV3() + .setName("application-logs") + .setType("org.cloudfoundry.user-provided-service") + .setParameters(Map.of(SupportedParameters.SYSLOG_DRAIN_URL, + "syslog://logs.example.com:514")))); + } + + private DeployedMta createDeployedMta(String mtaId, String mtaVersion) { + List deployedMtaApplications = List.of("app-1", "app-2", "app-3") + .stream() + .map(appName -> ImmutableDeployedMtaApplication.builder() + .name(appName) + .moduleName(appName) + .build()) + .collect(Collectors.toList()); + List deployedMtaServices = List.of("service-1", "service-2", "service-3") + .stream() + .map(serviceName -> ImmutableDeployedMtaService.builder() + .name(serviceName) + .build()) + .collect(Collectors.toList()); + return ImmutableDeployedMta.builder() + .metadata(org.cloudfoundry.multiapps.controller.core.cf.metadata.ImmutableMtaMetadata.builder() + .id(mtaId) + .version( + Version.parseVersion( + mtaVersion)) + .build()) + .applications(deployedMtaApplications) + .services(deployedMtaServices) + .build(); + } + + private List createCloudRoutes(String... routes) { + // return List.of("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com") + return Stream.of(routes) + .map(route -> new ApplicationURI(route, false, null).toCloudRoute()) + .collect(Collectors.toList()); + } + + private List createServiceKeysToCreate() { + return List.of(ImmutableCloudServiceKey.builder() + .name("service-key-1") + .build(), ImmutableCloudServiceKey.builder() + .name("service-key-2") + .build()); + } + + private List createExtensionDescriptorsWithNullValues(String mtaId) { + Map moduleParams = new HashMap<>(); + moduleParams.put(SupportedParameters.MEMORY, null); + moduleParams.put(SupportedParameters.DISK_QUOTA, "256M"); + moduleParams.put(SupportedParameters.ROUTES, List.of(SupportedParameters.ROUTE, "module-1-route.example.com")); + + Map resourceParams = new HashMap<>(); + resourceParams.put("test-parameter", null); + return List.of(ExtensionDescriptor.createV3() + .setId("test-extension") + .setParentId(mtaId) + .setModules(List.of(ExtensionModule.createV3() + .setName("module-1") + .setParameters(moduleParams))) + .setResources(List.of(ExtensionResource.createV3() + .setName("db") + .setParameters(resourceParams)))); + } + + private class TestVariableTask implements JavaDelegate { + + Map variablesToSetInContext = new HashMap<>(); + Map capturedVariables = new HashMap<>(); + + @Override + public void execute(DelegateExecution execution) { + execution.setVariables(variablesToSetInContext); + capturedVariables = execution.getVariables(); + } + } + +} diff --git a/multiapps-controller-process/src/test/resources/META-INF/persistence.xml b/multiapps-controller-process/src/test/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..cda667cd28 --- /dev/null +++ b/multiapps-controller-process/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,18 @@ + + + + org.eclipse.persistence.jpa.PersistenceProvider + + + + + + + + + + + \ No newline at end of file From 0c57e201948b42dd15d7ae5b2b26a8b64460e2c0 Mon Sep 17 00:00:00 2001 From: theghost5800 Date: Tue, 21 Oct 2025 12:44:36 +0300 Subject: [PATCH 2/4] Refactor tests first step --- multiapps-controller-process/pom.xml | 15 --- .../process/flowable/FlowableEngineTest.java | 121 ++++++------------ .../process/flowable/test-bpmn-diagram.bpmn | 13 ++ 3 files changed, 50 insertions(+), 99 deletions(-) create mode 100644 multiapps-controller-process/src/test/resources/org/cloudfoundry/multiapps/controller/process/flowable/test-bpmn-diagram.bpmn diff --git a/multiapps-controller-process/pom.xml b/multiapps-controller-process/pom.xml index 95c71842f3..9066ec03b5 100644 --- a/multiapps-controller-process/pom.xml +++ b/multiapps-controller-process/pom.xml @@ -101,21 +101,6 @@ multiapps-controller-persistence-test test - - org.apache.derby - derby - test - - - org.apache.derby - derbyclient - test - - - org.apache.derby - derbynet - test - com.h2database h2 diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java index 78fdc0395d..2a6419491a 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java @@ -59,26 +59,9 @@ * Integration test for Flowable engine with in-memory H2 database. Tests real BPMN process creation, variable setting and retrieval using * the multiapps-controller variable handling system. */ -//@FlowableTest -//@ConfigurationResource("flowable-config.xml") class FlowableEngineTest { private static final String TEST_PROCESS_KEY = "mtaDeploymentTest"; - private static final String TEST_BPMN_CONTENT = """ - - - - - - - - - - - """; @Mock private FlowableMailClient flowableMailClient; @@ -99,15 +82,13 @@ void setUp() throws Exception { configuration.setDefaultMailClient(flowableMailClient); configuration.setDatabaseSchemaUpdate("create-drop"); configuration.setBeans(Map.of("testVariableTask", testVariableTask)); - configuration.setAsyncExecutorActivate(false); processEngine = configuration.buildProcessEngine(); repositoryService = processEngine.getRepositoryService(); runtimeService = processEngine.getRuntimeService(); - - // Deploy test process deploymentId = repositoryService.createDeployment() .name("MTA Deployment Test") - .addString("mta-deployment-test.bpmn20.xml", TEST_BPMN_CONTENT) + .addClasspathResource( + "org/cloudfoundry/multiapps/controller/process/flowable/test-bpmn-diagram.bpmn") .deploy() .getId(); } @@ -267,41 +248,26 @@ void testVariableUpdateAndRetrieval() { runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY, initialVariables); - String retrievedCorrelationId = getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID); - Boolean retrievedDeleteServices = getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES); - String retrievedMtaId = getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID); - DeploymentDescriptor retrievedSmallDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, - Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS); - DeploymentDescriptor retrievedBigDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, - Variables.DEPLOYMENT_DESCRIPTOR); - DeployedMta retrievedDeployedMta = getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA); - List retrievedCloudRoutes = getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES); - StepPhase retrievedStepPhase = getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE); - List retrievedAppStateActionsToExecute = getDeserializedValue(testVariableTask.capturedVariables, - Variables.APP_STATE_ACTIONS_TO_EXECUTE); - List retrievedServiceKeysToCreate = getDeserializedValue(testVariableTask.capturedVariables, - Variables.CLOUD_SERVICE_KEYS_TO_CREATE); - List retrievedModulesForDeployment = getDeserializedValue(testVariableTask.capturedVariables, - Variables.MODULES_FOR_DEPLOYMENT); - List retrievedExtensionDescriptors = getDeserializedValue(testVariableTask.capturedVariables, - Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN); - - assertEquals(correlationId, retrievedCorrelationId); - assertEquals(deleteServices, retrievedDeleteServices); - assertEquals(mtaId, retrievedMtaId); - assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson(retrievedSmallDeploymentDescriptor)); + assertEquals(correlationId, getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID)); + assertEquals(deleteServices, getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES)); + assertEquals(mtaId, getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID)); + assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson( + getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS))); // This assertion intentionally checks that the modified deployment descriptor is different from the initially set one because of flowable caching regression // https://github.com/flowable/flowable-engine/issues/4130 // The original behaviour must be to have same deployment descriptor as it was set in the task. Modify the test to assert for matching values when the issue is fixed. - assertNotEquals(JsonUtil.toJson(modifiedBigDeploymentDescriptor), JsonUtil.toJson(retrievedBigDeploymentDescriptor)); - assertEquals(newDeployedMta, retrievedDeployedMta); - assertEquals(liveRoutes, retrievedCloudRoutes); - assertEquals(donePhase, retrievedStepPhase); - assertEquals(liveAppStateActionsToExecute, retrievedAppStateActionsToExecute); - assertEquals(serviceKeysToCreate, retrievedServiceKeysToCreate); - assertEquals(modulesForDeployment, retrievedModulesForDeployment); + assertNotEquals(JsonUtil.toJson(modifiedBigDeploymentDescriptor), + JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR))); + assertEquals(newDeployedMta, getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA)); + assertEquals(liveRoutes, getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES)); + assertEquals(donePhase, getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE)); + assertEquals(liveAppStateActionsToExecute, + getDeserializedValue(testVariableTask.capturedVariables, Variables.APP_STATE_ACTIONS_TO_EXECUTE)); + assertEquals(serviceKeysToCreate, getDeserializedValue(testVariableTask.capturedVariables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE)); + assertEquals(modulesForDeployment, getDeserializedValue(testVariableTask.capturedVariables, Variables.MODULES_FOR_DEPLOYMENT)); assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), - JsonUtil.toJson(retrievedExtensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS)); + JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN), + JsonSerializationStrategy.ALLOW_NULLS)); } @Test @@ -337,38 +303,26 @@ void testSetVariablesInsideStep() { runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY); - String retrievedCorrelationId = getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID); - Boolean retrievedDeleteServices = getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES); - String retrievedMtaId = getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID); - DeploymentDescriptor retrievedSmallDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, - Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS); - DeploymentDescriptor retrievedBigDeploymentDescriptor = getDeserializedValue(testVariableTask.capturedVariables, - Variables.DEPLOYMENT_DESCRIPTOR); - DeployedMta retrievedDeployedMta = getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA); - List retrievedCloudRoutes = getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES); - StepPhase retrievedStepPhase = getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE); - List retrievedAppStateActionsToExecute = getDeserializedValue(testVariableTask.capturedVariables, - Variables.APP_STATE_ACTIONS_TO_EXECUTE); - List retrievedServiceKeysToCreate = getDeserializedValue(testVariableTask.capturedVariables, - Variables.CLOUD_SERVICE_KEYS_TO_CREATE); - List retrievedModulesForDeployment = getDeserializedValue(testVariableTask.capturedVariables, - Variables.MODULES_FOR_DEPLOYMENT); - List retrievedExtensionDescriptors = getDeserializedValue(testVariableTask.capturedVariables, - Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN); - - assertEquals(correlationId, retrievedCorrelationId); - assertEquals(deleteServices, retrievedDeleteServices); - assertEquals(mtaId, retrievedMtaId); - assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson(retrievedSmallDeploymentDescriptor)); - assertEquals(JsonUtil.toJson(bigDeploymentDescriptor), JsonUtil.toJson(retrievedBigDeploymentDescriptor)); - assertEquals(deployedMta, retrievedDeployedMta); - assertEquals(cloudRoutes, retrievedCloudRoutes); - assertEquals(stepPhase, retrievedStepPhase); - assertEquals(appStateActionsToExecute, retrievedAppStateActionsToExecute); - assertEquals(serviceKeysToCreate, retrievedServiceKeysToCreate); - assertEquals(modulesForDeployment, retrievedModulesForDeployment); + assertEquals(correlationId, getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID)); + assertEquals(deleteServices, getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES)); + assertEquals(mtaId, getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID)); + assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, + Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS))); + assertEquals(JsonUtil.toJson(bigDeploymentDescriptor), JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, + Variables.DEPLOYMENT_DESCRIPTOR))); + assertEquals(deployedMta, getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA)); + assertEquals(cloudRoutes, getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES)); + assertEquals(stepPhase, getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE)); + assertEquals(appStateActionsToExecute, getDeserializedValue(testVariableTask.capturedVariables, + Variables.APP_STATE_ACTIONS_TO_EXECUTE)); + assertEquals(serviceKeysToCreate, getDeserializedValue(testVariableTask.capturedVariables, + Variables.CLOUD_SERVICE_KEYS_TO_CREATE)); + assertEquals(modulesForDeployment, getDeserializedValue(testVariableTask.capturedVariables, + Variables.MODULES_FOR_DEPLOYMENT)); assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), - JsonUtil.toJson(retrievedExtensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS)); + JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, + Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN), + JsonSerializationStrategy.ALLOW_NULLS)); } private void setSerializedValueInMap(Map variables, Variable variable, T value) { @@ -514,7 +468,6 @@ private DeployedMta createDeployedMta(String mtaId, String mtaVersion) { } private List createCloudRoutes(String... routes) { - // return List.of("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com") return Stream.of(routes) .map(route -> new ApplicationURI(route, false, null).toCloudRoute()) .collect(Collectors.toList()); diff --git a/multiapps-controller-process/src/test/resources/org/cloudfoundry/multiapps/controller/process/flowable/test-bpmn-diagram.bpmn b/multiapps-controller-process/src/test/resources/org/cloudfoundry/multiapps/controller/process/flowable/test-bpmn-diagram.bpmn new file mode 100644 index 0000000000..736d665177 --- /dev/null +++ b/multiapps-controller-process/src/test/resources/org/cloudfoundry/multiapps/controller/process/flowable/test-bpmn-diagram.bpmn @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file From 512fd55fd4957793472a67be201c2035a2ffcabe Mon Sep 17 00:00:00 2001 From: theghost5800 Date: Tue, 21 Oct 2025 16:42:30 +0300 Subject: [PATCH 3/4] Refactor tests second step --- .../process/flowable/FlowableEngineTest.java | 443 +++--------------- .../flowable/FlowableProcessTestData.java | 67 +++ .../FlowableProcessTestDataUtils.java | 274 +++++++++++ 3 files changed, 411 insertions(+), 373 deletions(-) create mode 100644 multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestData.java create mode 100644 multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java index 2a6419491a..c149e74167 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java @@ -1,42 +1,16 @@ package org.cloudfoundry.multiapps.controller.process.flowable; -import java.time.Duration; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; -import java.util.stream.Stream; import javax.sql.DataSource; import org.cloudfoundry.multiapps.common.util.JsonSerializationStrategy; import org.cloudfoundry.multiapps.common.util.JsonUtil; -import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudRoute; -import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudServiceKey; -import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableCloudServiceKey; -import org.cloudfoundry.multiapps.controller.core.cf.apps.ApplicationStateAction; -import org.cloudfoundry.multiapps.controller.core.model.DeployedMta; -import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; -import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaService; -import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMta; -import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaApplication; -import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaService; -import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters; -import org.cloudfoundry.multiapps.controller.core.util.ApplicationURI; import org.cloudfoundry.multiapps.controller.persistence.test.TestDataSourceProvider; -import org.cloudfoundry.multiapps.controller.process.steps.StepPhase; import org.cloudfoundry.multiapps.controller.process.variables.Serializer; import org.cloudfoundry.multiapps.controller.process.variables.Variable; import org.cloudfoundry.multiapps.controller.process.variables.Variables; -import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; -import org.cloudfoundry.multiapps.mta.model.ExtensionDescriptor; -import org.cloudfoundry.multiapps.mta.model.ExtensionModule; -import org.cloudfoundry.multiapps.mta.model.ExtensionResource; -import org.cloudfoundry.multiapps.mta.model.Module; -import org.cloudfoundry.multiapps.mta.model.ProvidedDependency; -import org.cloudfoundry.multiapps.mta.model.RequiredDependency; -import org.cloudfoundry.multiapps.mta.model.Resource; -import org.cloudfoundry.multiapps.mta.model.Version; import org.flowable.engine.ProcessEngine; import org.flowable.engine.ProcessEngineConfiguration; import org.flowable.engine.RepositoryService; @@ -44,7 +18,6 @@ import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.JavaDelegate; import org.flowable.engine.repository.ProcessDefinition; -import org.flowable.engine.runtime.ProcessInstance; import org.flowable.mail.common.api.client.FlowableMailClient; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -62,6 +35,7 @@ class FlowableEngineTest { private static final String TEST_PROCESS_KEY = "mtaDeploymentTest"; + private static final String MTA_DEPLOYMENT_TEST_PROCESS = "MTA Deployment Test Process"; @Mock private FlowableMailClient flowableMailClient; @@ -112,217 +86,58 @@ void testProcessDeployment() { assertEquals(1, processDefinitions.size()); assertEquals(TEST_PROCESS_KEY, processDefinitions.get(0) .getKey()); - assertEquals("MTA Deployment Test Process", processDefinitions.get(0) - .getName()); + assertEquals(MTA_DEPLOYMENT_TEST_PROCESS, processDefinitions.get(0) + .getName()); } @Test void testProcessWithPredefinedVariables() { - String correlationId = UUID.randomUUID() - .toString(); - String spaceGuid = UUID.randomUUID() - .toString(); - String orgGuid = UUID.randomUUID() - .toString(); - String userName = "test-user@example.com"; - String userGuid = UUID.randomUUID() - .toString(); - String mtaId = "test-mta"; - String mtaVersion = "1.0.0"; - boolean keepFiles = true; - Duration appsStageTimeout = Duration.ofMinutes(15); - int modulesCount = 5; - DeploymentDescriptor smallDeploymentDescriptor = createSmallDeploymentDescriptor(mtaId, mtaVersion); - DeploymentDescriptor bigDeploymentDescriptor = createBigDeploymentDescriptor(mtaId, mtaVersion); - DeployedMta deployedMta = createDeployedMta(mtaId, mtaVersion); - List cloudRoutes = createCloudRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com"); - StepPhase stepPhase = StepPhase.DONE; - List appStateActionsToExecute = List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START); - List serviceKeysToCreate = createServiceKeysToCreate(); - List modulesForDeployment = List.of("module-1", "module-2", "module-3"); - List extensionDescriptors = createExtensionDescriptorsWithNullValues(mtaId); - - // Start process instance with variables using multiapps-controller variable names - Map variables = new HashMap<>(); - setSerializedValueInMap(variables, Variables.CORRELATION_ID, correlationId); - setSerializedValueInMap(variables, Variables.SPACE_GUID, spaceGuid); - setSerializedValueInMap(variables, Variables.ORGANIZATION_GUID, orgGuid); - setSerializedValueInMap(variables, Variables.USER, userName); - setSerializedValueInMap(variables, Variables.USER_GUID, userGuid); - setSerializedValueInMap(variables, Variables.MTA_ID, mtaId); - setSerializedValueInMap(variables, Variables.KEEP_FILES, keepFiles); - setSerializedValueInMap(variables, Variables.APPS_STAGE_TIMEOUT_PROCESS_VARIABLE, appsStageTimeout); - setSerializedValueInMap(variables, Variables.MODULES_COUNT, modulesCount); - setSerializedValueInMap(variables, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS, smallDeploymentDescriptor); - setSerializedValueInMap(variables, Variables.DEPLOYMENT_DESCRIPTOR, bigDeploymentDescriptor); - setSerializedValueInMap(variables, Variables.DEPLOYED_MTA, deployedMta); - setSerializedValueInMap(variables, Variables.CURRENT_ROUTES, cloudRoutes); - setSerializedValueInMap(variables, Variables.STEP_PHASE, stepPhase); - setSerializedValueInMap(variables, Variables.APP_STATE_ACTIONS_TO_EXECUTE, appStateActionsToExecute); - setSerializedValueInMap(variables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); - setSerializedValueInMap(variables, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); - setSerializedValueInMap(variables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); - - ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY, variables); - - assertEquals(TEST_PROCESS_KEY, processInstance.getProcessDefinitionKey()); - - // Verify variables are set and retrievable using multiapps variable system - assertEquals(correlationId, getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID)); - assertEquals(spaceGuid, getDeserializedValue(testVariableTask.capturedVariables, Variables.SPACE_GUID)); - assertEquals(orgGuid, getDeserializedValue(testVariableTask.capturedVariables, Variables.ORGANIZATION_GUID)); - assertEquals(userName, getDeserializedValue(testVariableTask.capturedVariables, Variables.USER)); - assertEquals(userGuid, getDeserializedValue(testVariableTask.capturedVariables, Variables.USER_GUID)); - assertEquals(mtaId, getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID)); - assertEquals(keepFiles, getDeserializedValue(testVariableTask.capturedVariables, Variables.KEEP_FILES)); - assertEquals(appsStageTimeout, - getDeserializedValue(testVariableTask.capturedVariables, Variables.APPS_STAGE_TIMEOUT_PROCESS_VARIABLE)); - assertEquals(modulesCount, getDeserializedValue(testVariableTask.capturedVariables, Variables.MODULES_COUNT)); - assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson( - getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS))); - assertEquals(JsonUtil.toJson(bigDeploymentDescriptor), - JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR))); - assertEquals(deployedMta, getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA)); - assertEquals(cloudRoutes, getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES)); - assertEquals(stepPhase, getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE)); - assertEquals(appStateActionsToExecute, - getDeserializedValue(testVariableTask.capturedVariables, Variables.APP_STATE_ACTIONS_TO_EXECUTE)); - assertEquals(serviceKeysToCreate, getDeserializedValue(testVariableTask.capturedVariables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE)); - assertEquals(modulesForDeployment, getDeserializedValue(testVariableTask.capturedVariables, Variables.MODULES_FOR_DEPLOYMENT)); - assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), - JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN), - JsonSerializationStrategy.ALLOW_NULLS)); + FlowableProcessTestData data = FlowableProcessTestDataUtils.predefinedScenario(); + runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY, buildVariablesMap(data)); + assertCapturedVariables(data, true); } @Test void testVariableUpdateAndRetrieval() { - String correlationId = UUID.randomUUID() - .toString(); - Boolean deleteServices = true; - String mtaId = "test-mta-2"; - String mtaVersion = "2.0.0"; - DeploymentDescriptor smallDeploymentDescriptor = createSmallDeploymentDescriptor(mtaId, mtaVersion); - DeploymentDescriptor bigDeploymentDescriptor = createBigDeploymentDescriptor(mtaId, mtaVersion); - DeploymentDescriptor modifiedBigDeploymentDescriptor = DeploymentDescriptor.copyOf(bigDeploymentDescriptor) - .setParameters(Map.of("new-param", "new-value")); - DeployedMta oldDeployedMta = createDeployedMta(mtaId, "1.0.0"); - DeployedMta newDeployedMta = createDeployedMta(mtaId, mtaVersion); - List idleRoutes = createCloudRoutes("route-1-idle.example.com/bar-foo", "route-2-idle.example.com", - "route-3-idle.example.com"); - List liveRoutes = createCloudRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com"); - StepPhase pollingPhase = StepPhase.POLL; - StepPhase donePhase = StepPhase.DONE; - List idleAppStateActionsToExecute = List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START); - List liveAppStateActionsToExecute = List.of(ApplicationStateAction.EXECUTE, ApplicationStateAction.STOP); - List serviceKeysToCreate = createServiceKeysToCreate(); - List modulesForDeployment = List.of("module-1", "module-2", "module-3"); - List extensionDescriptors = createExtensionDescriptorsWithNullValues(mtaId); - - Map initialVariables = new HashMap<>(); - setSerializedValueInMap(initialVariables, Variables.CORRELATION_ID, correlationId); - setSerializedValueInMap(initialVariables, Variables.DELETE_SERVICES, deleteServices); - setSerializedValueInMap(initialVariables, Variables.MTA_ID, mtaId); - setSerializedValueInMap(initialVariables, Variables.DEPLOYMENT_DESCRIPTOR, bigDeploymentDescriptor); - setSerializedValueInMap(initialVariables, Variables.DEPLOYED_MTA, oldDeployedMta); - setSerializedValueInMap(initialVariables, Variables.CURRENT_ROUTES, idleRoutes); - setSerializedValueInMap(initialVariables, Variables.STEP_PHASE, pollingPhase); - setSerializedValueInMap(initialVariables, Variables.APP_STATE_ACTIONS_TO_EXECUTE, idleAppStateActionsToExecute); - setSerializedValueInMap(initialVariables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); - setSerializedValueInMap(initialVariables, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); - setSerializedValueInMap(initialVariables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); - - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CORRELATION_ID, correlationId); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DELETE_SERVICES, deleteServices); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_ID, mtaId); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS, - smallDeploymentDescriptor); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR, modifiedBigDeploymentDescriptor); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYED_MTA, newDeployedMta); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CURRENT_ROUTES, liveRoutes); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.STEP_PHASE, donePhase); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.APP_STATE_ACTIONS_TO_EXECUTE, - liveAppStateActionsToExecute); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); - - runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY, initialVariables); - - assertEquals(correlationId, getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID)); - assertEquals(deleteServices, getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES)); - assertEquals(mtaId, getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID)); - assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson( - getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS))); + FlowableProcessTestDataUtils.UpdateScenario updateScenario = FlowableProcessTestDataUtils.updateScenario(); + testVariableTask.variablesToSetInContext = buildVariablesMap(updateScenario.updated()); + runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY, buildVariablesMap(updateScenario.initial())); // This assertion intentionally checks that the modified deployment descriptor is different from the initially set one because of flowable caching regression // https://github.com/flowable/flowable-engine/issues/4130 // The original behaviour must be to have same deployment descriptor as it was set in the task. Modify the test to assert for matching values when the issue is fixed. - assertNotEquals(JsonUtil.toJson(modifiedBigDeploymentDescriptor), - JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYMENT_DESCRIPTOR))); - assertEquals(newDeployedMta, getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA)); - assertEquals(liveRoutes, getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES)); - assertEquals(donePhase, getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE)); - assertEquals(liveAppStateActionsToExecute, - getDeserializedValue(testVariableTask.capturedVariables, Variables.APP_STATE_ACTIONS_TO_EXECUTE)); - assertEquals(serviceKeysToCreate, getDeserializedValue(testVariableTask.capturedVariables, Variables.CLOUD_SERVICE_KEYS_TO_CREATE)); - assertEquals(modulesForDeployment, getDeserializedValue(testVariableTask.capturedVariables, Variables.MODULES_FOR_DEPLOYMENT)); - assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), - JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN), - JsonSerializationStrategy.ALLOW_NULLS)); + assertCapturedVariables(updateScenario.updated(), false); } @Test void testSetVariablesInsideStep() { - String correlationId = UUID.randomUUID() - .toString(); - Boolean deleteServices = true; - String mtaId = "test-mta-2"; - String mtaVersion = "2.0.0"; - DeploymentDescriptor smallDeploymentDescriptor = createSmallDeploymentDescriptor(mtaId, mtaVersion); - DeploymentDescriptor bigDeploymentDescriptor = createBigDeploymentDescriptor(mtaId, mtaVersion); - DeployedMta deployedMta = createDeployedMta(mtaId, mtaVersion); - List cloudRoutes = createCloudRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com"); - StepPhase stepPhase = StepPhase.DONE; - List appStateActionsToExecute = List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START); - List serviceKeysToCreate = createServiceKeysToCreate(); - List modulesForDeployment = List.of("module-1", "module-2", "module-3"); - List extensionDescriptors = createExtensionDescriptorsWithNullValues(mtaId); - - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CORRELATION_ID, correlationId); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DELETE_SERVICES, deleteServices); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_ID, mtaId); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS, - smallDeploymentDescriptor); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYMENT_DESCRIPTOR, bigDeploymentDescriptor); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.DEPLOYED_MTA, deployedMta); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CURRENT_ROUTES, cloudRoutes); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.STEP_PHASE, stepPhase); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.APP_STATE_ACTIONS_TO_EXECUTE, appStateActionsToExecute); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, serviceKeysToCreate); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MODULES_FOR_DEPLOYMENT, modulesForDeployment); - setSerializedValueInMap(testVariableTask.variablesToSetInContext, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, extensionDescriptors); - + FlowableProcessTestData data = FlowableProcessTestDataUtils.insideStepScenario(); + testVariableTask.variablesToSetInContext = buildVariablesMap(data); runtimeService.startProcessInstanceByKey(TEST_PROCESS_KEY); + assertCapturedVariables(data, true); + } - assertEquals(correlationId, getDeserializedValue(testVariableTask.capturedVariables, Variables.CORRELATION_ID)); - assertEquals(deleteServices, getDeserializedValue(testVariableTask.capturedVariables, Variables.DELETE_SERVICES)); - assertEquals(mtaId, getDeserializedValue(testVariableTask.capturedVariables, Variables.MTA_ID)); - assertEquals(JsonUtil.toJson(smallDeploymentDescriptor), JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, - Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS))); - assertEquals(JsonUtil.toJson(bigDeploymentDescriptor), JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, - Variables.DEPLOYMENT_DESCRIPTOR))); - assertEquals(deployedMta, getDeserializedValue(testVariableTask.capturedVariables, Variables.DEPLOYED_MTA)); - assertEquals(cloudRoutes, getDeserializedValue(testVariableTask.capturedVariables, Variables.CURRENT_ROUTES)); - assertEquals(stepPhase, getDeserializedValue(testVariableTask.capturedVariables, Variables.STEP_PHASE)); - assertEquals(appStateActionsToExecute, getDeserializedValue(testVariableTask.capturedVariables, - Variables.APP_STATE_ACTIONS_TO_EXECUTE)); - assertEquals(serviceKeysToCreate, getDeserializedValue(testVariableTask.capturedVariables, - Variables.CLOUD_SERVICE_KEYS_TO_CREATE)); - assertEquals(modulesForDeployment, getDeserializedValue(testVariableTask.capturedVariables, - Variables.MODULES_FOR_DEPLOYMENT)); - assertEquals(JsonUtil.toJson(extensionDescriptors, JsonSerializationStrategy.ALLOW_NULLS), - JsonUtil.toJson(getDeserializedValue(testVariableTask.capturedVariables, - Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN), - JsonSerializationStrategy.ALLOW_NULLS)); + private Map buildVariablesMap(FlowableProcessTestData flowableProcessTestData) { + Map vars = new HashMap<>(); + setSerializedValueInMap(vars, Variables.CORRELATION_ID, flowableProcessTestData.getCorrelationId()); + setSerializedValueInMap(vars, Variables.SPACE_GUID, flowableProcessTestData.getSpaceGuid()); + setSerializedValueInMap(vars, Variables.ORGANIZATION_GUID, flowableProcessTestData.getOrgGuid()); + setSerializedValueInMap(vars, Variables.USER, flowableProcessTestData.getUsername()); + setSerializedValueInMap(vars, Variables.USER_GUID, flowableProcessTestData.getUserGuid()); + setSerializedValueInMap(vars, Variables.MTA_ID, flowableProcessTestData.getMtaId()); + setSerializedValueInMap(vars, Variables.KEEP_FILES, flowableProcessTestData.keepFiles()); + setSerializedValueInMap(vars, Variables.DELETE_SERVICES, flowableProcessTestData.deleteServices()); + setSerializedValueInMap(vars, Variables.APPS_STAGE_TIMEOUT_PROCESS_VARIABLE, flowableProcessTestData.getAppsStageTimeout()); + setSerializedValueInMap(vars, Variables.MODULES_COUNT, flowableProcessTestData.getModulesCount()); + setSerializedValueInMap(vars, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS, flowableProcessTestData.getSmallDescriptor()); + setSerializedValueInMap(vars, Variables.DEPLOYMENT_DESCRIPTOR, flowableProcessTestData.getBigDescriptor()); + setSerializedValueInMap(vars, Variables.DEPLOYED_MTA, flowableProcessTestData.getDeployedMta()); + setSerializedValueInMap(vars, Variables.CURRENT_ROUTES, flowableProcessTestData.getRoutes()); + setSerializedValueInMap(vars, Variables.STEP_PHASE, flowableProcessTestData.getStepPhase()); + setSerializedValueInMap(vars, Variables.APP_STATE_ACTIONS_TO_EXECUTE, flowableProcessTestData.getAppActions()); + setSerializedValueInMap(vars, Variables.CLOUD_SERVICE_KEYS_TO_CREATE, flowableProcessTestData.getServiceKeys()); + setSerializedValueInMap(vars, Variables.MODULES_FOR_DEPLOYMENT, flowableProcessTestData.getModulesForDeployment()); + setSerializedValueInMap(vars, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN, flowableProcessTestData.getExtensionDescriptors()); + return vars; } private void setSerializedValueInMap(Map variables, Variable variable, T value) { @@ -343,161 +158,43 @@ private T getDeserializedValue(Map variables, Variable va return serializer.deserialize(serializedValue); } - private DeploymentDescriptor createSmallDeploymentDescriptor(String mtaId, String mtaVersion) { - return DeploymentDescriptor.createV3() - .setId(mtaId) - .setVersion(mtaVersion) - .setModules(List.of(Module.createV3() - .setName("module-1") - .setType("javascript") - .setParameters( - Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, - "256M", SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-1-route.example.com"))) - .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"))))) - .setResources(List.of(Resource.createV3() - .setName("db") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", - SupportedParameters.SERVICE_PLAN, "free")))); - } - - private DeploymentDescriptor createBigDeploymentDescriptor(String mtaId, String mtaVersion) { - return DeploymentDescriptor.createV3() - .setId(mtaId) - .setVersion(mtaVersion) - .setParameters(Map.of(SupportedParameters.ENABLE_PARALLEL_DEPLOYMENTS, true)) - .setModules(List.of(Module.createV3() - .setName("module-1") - .setType("javascript") - .setParameters( - Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, - "256M", SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-1-route.example.com"), - SupportedParameters.TASKS, - List.of(Map.of("name", "task-1", "command", "migrate-db.sh")))) - .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"), - RequiredDependency.createV3() - .setName( - "application-logs"))), - Module.createV3() - .setName("module-2") - .setType("java") - .setParameters( - Map.of(SupportedParameters.MEMORY, "1G", SupportedParameters.DISK_QUOTA, - "4096M", SupportedParameters.INSTANCES, 2, - SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-2-route.example.com"))) - .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"), - RequiredDependency.createV3() - .setName("cache"), - RequiredDependency.createV3() - .setName("autoscaler"), - RequiredDependency.createV3() - .setName( - "application-logs"))), - Module.createV3() - .setName("module-3") - .setType("javascript") - .setParameters( - Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, - "256M", SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-3-route.example.com"))) - .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"), - RequiredDependency.createV3() - .setName("cache"), - RequiredDependency.createV3() - .setName("autoscaler"), - RequiredDependency.createV3() - .setName( - "application-logs"))) - .setProvidedDependencies(List.of(ProvidedDependency.createV3() - .setName("my-api") - .setProperties(Map.of("url", - "https://api.example.com")))))) - .setResources(List.of(Resource.createV3() - .setName("db") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", - SupportedParameters.SERVICE_PLAN, "free")), - Resource.createV3() - .setName("cache") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "test-cache-service", - SupportedParameters.SERVICE_PLAN, "free")), - Resource.createV3() - .setName("autoscaler") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "app-autoscaler", - SupportedParameters.SERVICE_PLAN, "default")), - Resource.createV3() - .setName("application-logs") - .setType("org.cloudfoundry.user-provided-service") - .setParameters(Map.of(SupportedParameters.SYSLOG_DRAIN_URL, - "syslog://logs.example.com:514")))); - } - - private DeployedMta createDeployedMta(String mtaId, String mtaVersion) { - List deployedMtaApplications = List.of("app-1", "app-2", "app-3") - .stream() - .map(appName -> ImmutableDeployedMtaApplication.builder() - .name(appName) - .moduleName(appName) - .build()) - .collect(Collectors.toList()); - List deployedMtaServices = List.of("service-1", "service-2", "service-3") - .stream() - .map(serviceName -> ImmutableDeployedMtaService.builder() - .name(serviceName) - .build()) - .collect(Collectors.toList()); - return ImmutableDeployedMta.builder() - .metadata(org.cloudfoundry.multiapps.controller.core.cf.metadata.ImmutableMtaMetadata.builder() - .id(mtaId) - .version( - Version.parseVersion( - mtaVersion)) - .build()) - .applications(deployedMtaApplications) - .services(deployedMtaServices) - .build(); - } - - private List createCloudRoutes(String... routes) { - return Stream.of(routes) - .map(route -> new ApplicationURI(route, false, null).toCloudRoute()) - .collect(Collectors.toList()); - } - - private List createServiceKeysToCreate() { - return List.of(ImmutableCloudServiceKey.builder() - .name("service-key-1") - .build(), ImmutableCloudServiceKey.builder() - .name("service-key-2") - .build()); + private void assertCapturedVariables(FlowableProcessTestData expected, boolean expectBigDescriptorMatch) { + Map actual = testVariableTask.capturedVariables; + assertEquals(expected.getCorrelationId(), getDeserializedValue(actual, Variables.CORRELATION_ID)); + assertEquals(expected.getSpaceGuid(), getDeserializedValue(actual, Variables.SPACE_GUID)); + assertEquals(expected.getOrgGuid(), getDeserializedValue(actual, Variables.ORGANIZATION_GUID)); + assertEquals(expected.getUsername(), getDeserializedValue(actual, Variables.USER)); + assertEquals(expected.getUserGuid(), getDeserializedValue(actual, Variables.USER_GUID)); + assertEquals(expected.getMtaId(), getDeserializedValue(actual, Variables.MTA_ID)); + assertEquals(expected.keepFiles(), getDeserializedValue(actual, Variables.KEEP_FILES)); + assertEquals(expected.deleteServices(), getDeserializedValue(actual, Variables.DELETE_SERVICES)); + assertEquals(expected.getAppsStageTimeout(), getDeserializedValue(actual, Variables.APPS_STAGE_TIMEOUT_PROCESS_VARIABLE)); + assertEquals(expected.getModulesCount(), getDeserializedValue(actual, Variables.MODULES_COUNT)); + assertEquals(JsonUtil.toJson(expected.getSmallDescriptor()), + JsonUtil.toJson(getDeserializedValue(actual, Variables.DEPLOYMENT_DESCRIPTOR_WITH_SYSTEM_PARAMETERS))); + + String expectedBigDescriptor = JsonUtil.toJson(expected.getBigDescriptor()); + String actualBigDescriptor = JsonUtil.toJson(getDeserializedValue(actual, Variables.DEPLOYMENT_DESCRIPTOR)); + assertBigDescriptor(expectBigDescriptorMatch, expectedBigDescriptor, actualBigDescriptor); + + assertEquals(expected.getDeployedMta(), getDeserializedValue(actual, Variables.DEPLOYED_MTA)); + assertEquals(expected.getRoutes(), getDeserializedValue(actual, Variables.CURRENT_ROUTES)); + assertEquals(expected.getStepPhase(), getDeserializedValue(actual, Variables.STEP_PHASE)); + assertEquals(expected.getAppActions(), getDeserializedValue(actual, Variables.APP_STATE_ACTIONS_TO_EXECUTE)); + assertEquals(expected.getServiceKeys(), getDeserializedValue(actual, Variables.CLOUD_SERVICE_KEYS_TO_CREATE)); + assertEquals(expected.getModulesForDeployment(), getDeserializedValue(actual, Variables.MODULES_FOR_DEPLOYMENT)); + assertEquals(JsonUtil.toJson(expected.getExtensionDescriptors(), JsonSerializationStrategy.ALLOW_NULLS), + JsonUtil.toJson(getDeserializedValue(actual, Variables.MTA_EXTENSION_DESCRIPTOR_CHAIN), + JsonSerializationStrategy.ALLOW_NULLS)); } - private List createExtensionDescriptorsWithNullValues(String mtaId) { - Map moduleParams = new HashMap<>(); - moduleParams.put(SupportedParameters.MEMORY, null); - moduleParams.put(SupportedParameters.DISK_QUOTA, "256M"); - moduleParams.put(SupportedParameters.ROUTES, List.of(SupportedParameters.ROUTE, "module-1-route.example.com")); + private static void assertBigDescriptor(boolean expectBigDescriptorMatch, String expectedBigDescriptor, String actualBigDescriptor) { + if (expectBigDescriptorMatch) { + assertEquals(expectedBigDescriptor, actualBigDescriptor); + return; + } + assertNotEquals(expectedBigDescriptor, actualBigDescriptor); - Map resourceParams = new HashMap<>(); - resourceParams.put("test-parameter", null); - return List.of(ExtensionDescriptor.createV3() - .setId("test-extension") - .setParentId(mtaId) - .setModules(List.of(ExtensionModule.createV3() - .setName("module-1") - .setParameters(moduleParams))) - .setResources(List.of(ExtensionResource.createV3() - .setName("db") - .setParameters(resourceParams)))); } private class TestVariableTask implements JavaDelegate { diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestData.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestData.java new file mode 100644 index 0000000000..dc1db91811 --- /dev/null +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestData.java @@ -0,0 +1,67 @@ +package org.cloudfoundry.multiapps.controller.process.flowable; + +import java.time.Duration; +import java.util.List; + +import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudRoute; +import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudServiceKey; +import org.cloudfoundry.multiapps.controller.core.cf.apps.ApplicationStateAction; +import org.cloudfoundry.multiapps.controller.core.model.DeployedMta; +import org.cloudfoundry.multiapps.controller.process.steps.StepPhase; +import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; +import org.cloudfoundry.multiapps.mta.model.ExtensionDescriptor; +import org.immutables.value.Value; + +@Value.Immutable +public interface FlowableProcessTestData { + + String getCorrelationId(); + + String getSpaceGuid(); + + String getOrgGuid(); + + String getUsername(); + + String getUserGuid(); + + String getMtaId(); + + String getMtaVersion(); + + @Value.Default + default boolean keepFiles() { + return false; + } + + @Value.Default + default boolean deleteServices() { + return false; + } + + Duration getAppsStageTimeout(); + + @Value.Default + default int getModulesCount() { + return 0; + } + + DeploymentDescriptor getSmallDescriptor(); + + DeploymentDescriptor getBigDescriptor(); + + DeployedMta getDeployedMta(); + + List getRoutes(); + + StepPhase getStepPhase(); + + List getAppActions(); + + List getServiceKeys(); + + List getModulesForDeployment(); + + List getExtensionDescriptors(); + +} diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java new file mode 100644 index 0000000000..3769106f25 --- /dev/null +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java @@ -0,0 +1,274 @@ +package org.cloudfoundry.multiapps.controller.process.flowable; + +import java.time.Duration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudRoute; +import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudServiceKey; +import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableCloudServiceKey; +import org.cloudfoundry.multiapps.controller.core.cf.apps.ApplicationStateAction; +import org.cloudfoundry.multiapps.controller.core.cf.metadata.ImmutableMtaMetadata; +import org.cloudfoundry.multiapps.controller.core.model.DeployedMta; +import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication; +import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaService; +import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMta; +import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaApplication; +import org.cloudfoundry.multiapps.controller.core.model.ImmutableDeployedMtaService; +import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters; +import org.cloudfoundry.multiapps.controller.core.util.ApplicationURI; +import org.cloudfoundry.multiapps.controller.process.steps.StepPhase; +import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor; +import org.cloudfoundry.multiapps.mta.model.ExtensionDescriptor; +import org.cloudfoundry.multiapps.mta.model.ExtensionModule; +import org.cloudfoundry.multiapps.mta.model.ExtensionResource; +import org.cloudfoundry.multiapps.mta.model.Module; +import org.cloudfoundry.multiapps.mta.model.ProvidedDependency; +import org.cloudfoundry.multiapps.mta.model.RequiredDependency; +import org.cloudfoundry.multiapps.mta.model.Resource; +import org.cloudfoundry.multiapps.mta.model.Version; + +public class FlowableProcessTestDataUtils { + private FlowableProcessTestDataUtils() { + } + + public record UpdateScenario(FlowableProcessTestData initial, FlowableProcessTestData updated) { + } + + public static FlowableProcessTestData predefinedScenario() { + String mtaId = "test-mta"; + String mtaVersion = "1.0.0"; + return baseBuilder(mtaId, mtaVersion).keepFiles(true) + .modulesCount(5) + .bigDescriptor(createBigDescriptor(mtaId, mtaVersion)) + .routes( + createRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com")) + .stepPhase(StepPhase.DONE) + .appActions(List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START)) + .build(); + } + + public static UpdateScenario updateScenario() { + String id = "test-mta-2"; + DeploymentDescriptor bigDescriptorV1 = createBigDescriptor(id, "1.0.0"); + DeploymentDescriptor bigDescriptorV2 = DeploymentDescriptor.copyOf(createBigDescriptor(id, "2.0.0")) + .setParameters(Map.of("new-param", "new-value")); + FlowableProcessTestData initial = baseBuilder(id, "1.0.0").deleteServices(true) + .bigDescriptor(bigDescriptorV1) + .deployedMta(createDeployed(id, "1.0.0")) + .routes( + createRoutes("route-1-idle.example.com/bar-foo", + "route-2-idle.example.com")) + .stepPhase( + org.cloudfoundry.multiapps.controller.process.steps.StepPhase.POLL) + .appActions( + List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START)) + .build(); + FlowableProcessTestData updated = baseBuilder(id, "2.0.0").deleteServices(true) + .smallDescriptor(createSmallDescriptor(id, "2.0.0")) + .bigDescriptor(bigDescriptorV2) + .deployedMta(createDeployed(id, "2.0.0")) + .routes(createRoutes("route-1.example.com/foo-bar", "route-2.example.com", + "route-3.example.com")) + .stepPhase( + org.cloudfoundry.multiapps.controller.process.steps.StepPhase.DONE) + .appActions( + List.of(ApplicationStateAction.EXECUTE, ApplicationStateAction.STOP)) + .build(); + return new UpdateScenario(initial, updated); + } + + public static FlowableProcessTestData insideStepScenario() { + String id = "test-mta-2"; + String mtaVersion = "2.0.0"; + return baseBuilder(id, mtaVersion).deleteServices(true) + .smallDescriptor(createSmallDescriptor(id, mtaVersion)) + .bigDescriptor(createBigDescriptor(id, mtaVersion)) + .deployedMta(createDeployed(id, mtaVersion)) + .routes(createRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com")) + .stepPhase(org.cloudfoundry.multiapps.controller.process.steps.StepPhase.DONE) + .appActions(List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START)) + .build(); + } + + private static ImmutableFlowableProcessTestData.Builder baseBuilder(String mtaId, String mtaVersion) { + return ImmutableFlowableProcessTestData.builder() + .correlationId(UUID.randomUUID() + .toString()) + .spaceGuid(UUID.randomUUID() + .toString()) + .orgGuid(UUID.randomUUID() + .toString()) + .username("test-user@example.com") + .userGuid(UUID.randomUUID() + .toString()) + .mtaId(mtaId) + .mtaVersion(mtaVersion) + .appsStageTimeout(Duration.ofMinutes(15)) + .smallDescriptor(createSmallDescriptor(mtaId, mtaVersion)) + .deployedMta(createDeployed(mtaId, mtaVersion)) + .stepPhase(StepPhase.DONE) + .serviceKeys(createServiceKeys()) + .modulesForDeployment(List.of("module-1", "module-2", "module-3")) + .extensionDescriptors(createExtensionDescriptorsWithNullValues(mtaId)); + } + + private static DeploymentDescriptor createSmallDescriptor(String id, String mtaVersion) { + return DeploymentDescriptor.createV3() + .setId(id) + .setVersion(mtaVersion) + .setModules(List.of(Module.createV3() + .setName("module-1") + .setType("javascript") + .setParameters( + Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, + "256M", SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-1-route.example.com"))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"))))) + .setResources(List.of(Resource.createV3() + .setName("db") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", + SupportedParameters.SERVICE_PLAN, "free")))); + } + + private static DeploymentDescriptor createBigDescriptor(String id, String mtaVersion) { + return DeploymentDescriptor.createV3() + .setId(id) + .setVersion(mtaVersion) + .setParameters(Map.of(SupportedParameters.ENABLE_PARALLEL_DEPLOYMENTS, true)) + .setModules(List.of(Module.createV3() + .setName("module-1") + .setType("javascript") + .setParameters( + Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, + "256M", SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-1-route.example.com"), + SupportedParameters.TASKS, + List.of(Map.of("name", "task-1", "command", "migrate-db.sh")))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"), + RequiredDependency.createV3() + .setName( + "application-logs"))), + Module.createV3() + .setName("module-2") + .setType("java") + .setParameters( + Map.of(SupportedParameters.MEMORY, "1G", SupportedParameters.DISK_QUOTA, + "4096M", SupportedParameters.INSTANCES, 2, + SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-2-route.example.com"))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"), + RequiredDependency.createV3() + .setName("cache"), + RequiredDependency.createV3() + .setName("autoscaler"), + RequiredDependency.createV3() + .setName( + "application-logs"))), + Module.createV3() + .setName("module-3") + .setType("javascript") + .setParameters( + Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, + "256M", SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, "module-3-route.example.com"))) + .setRequiredDependencies(List.of(RequiredDependency.createV3() + .setName("db"), + RequiredDependency.createV3() + .setName("cache"), + RequiredDependency.createV3() + .setName("autoscaler"), + RequiredDependency.createV3() + .setName( + "application-logs"))) + .setProvidedDependencies(List.of(ProvidedDependency.createV3() + .setName("my-api") + .setProperties(Map.of("url", + "https://api.example.com")))))) + .setResources(List.of(Resource.createV3() + .setName("db") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", + SupportedParameters.SERVICE_PLAN, "free")), + Resource.createV3() + .setName("cache") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "test-cache-service", + SupportedParameters.SERVICE_PLAN, "free")), + Resource.createV3() + .setName("autoscaler") + .setType("org.cloudfoundry.managed-service") + .setParameters(Map.of(SupportedParameters.SERVICE, "app-autoscaler", + SupportedParameters.SERVICE_PLAN, "default")), + Resource.createV3() + .setName("application-logs") + .setType("org.cloudfoundry.user-provided-service") + .setParameters(Map.of(SupportedParameters.SYSLOG_DRAIN_URL, + "syslog://logs.example.com:514")))); + } + + private static DeployedMta createDeployed(String id, String mtaVersion) { + List apps = Stream.of("app-1", "app-2", "app-3") + .map(app -> ImmutableDeployedMtaApplication.builder() + .name(app) + .moduleName(app) + .build()) + .collect(Collectors.toList()); + List services = Stream.of("service-1", "service-2", "service-3") + .map(service -> ImmutableDeployedMtaService.builder() + .name(service) + .build()) + .collect(Collectors.toList()); + return ImmutableDeployedMta.builder() + .metadata(ImmutableMtaMetadata.builder() + .id(id) + .version( + Version.parseVersion( + mtaVersion)) + .build()) + .applications(apps) + .services(services) + .build(); + } + + private static List createRoutes(String... routes) { + return Stream.of(routes) + .map(route -> new ApplicationURI(route, false, null).toCloudRoute()) + .collect(Collectors.toList()); + } + + private static List createServiceKeys() { + return List.of(ImmutableCloudServiceKey.builder() + .name("service-key-1") + .build(), ImmutableCloudServiceKey.builder() + .name("service-key-2") + .build()); + } + + private static List createExtensionDescriptorsWithNullValues(String mtaId) { + Map moduleParams = new HashMap<>(); + moduleParams.put(SupportedParameters.MEMORY, null); + moduleParams.put(SupportedParameters.DISK_QUOTA, "256M"); + moduleParams.put(SupportedParameters.ROUTES, List.of(SupportedParameters.ROUTE, "module-1-route.example.com")); + Map resourceParams = new HashMap<>(); + resourceParams.put("test-parameter", null); + return List.of(ExtensionDescriptor.createV3() + .setId("test-extension") + .setParentId(mtaId) + .setModules(List.of(ExtensionModule.createV3() + .setName("module-1") + .setParameters(moduleParams))) + .setResources(List.of(ExtensionResource.createV3() + .setName("db") + .setParameters(resourceParams)))); + } + +} From 7b6bcbaf90cdfd6c4436c229332f44f7537d6c7f Mon Sep 17 00:00:00 2001 From: theghost5800 Date: Tue, 21 Oct 2025 17:44:55 +0300 Subject: [PATCH 4/4] Use constants for variables in tests --- .../process/flowable/FlowableEngineTest.java | 13 +- .../FlowableProcessTestDataUtils.java | 346 ++++++++++++------ 2 files changed, 235 insertions(+), 124 deletions(-) diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java index c149e74167..6dd2381b84 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableEngineTest.java @@ -36,6 +36,11 @@ class FlowableEngineTest { private static final String TEST_PROCESS_KEY = "mtaDeploymentTest"; private static final String MTA_DEPLOYMENT_TEST_PROCESS = "MTA Deployment Test Process"; + private static final String FLOWABLE_DB_SCHEMA_STRATEGY_CREATE_DROP = "create-drop"; + private static final String TEST_VARIABLE_TASK_BEAN_NAME = "testVariableTask"; + private static final String DEPLOYMENT_NAME_OF_DIAGRAM = "MTA Deployment Test"; + private static final String TEST_BPMN_DIAGRAM_RESOURCE = + "org/cloudfoundry/multiapps/controller/process/flowable/test-bpmn-diagram.bpmn"; @Mock private FlowableMailClient flowableMailClient; @@ -54,15 +59,15 @@ void setUp() throws Exception { ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration(); configuration.setDataSource(dataSource); configuration.setDefaultMailClient(flowableMailClient); - configuration.setDatabaseSchemaUpdate("create-drop"); - configuration.setBeans(Map.of("testVariableTask", testVariableTask)); + configuration.setDatabaseSchemaUpdate(FLOWABLE_DB_SCHEMA_STRATEGY_CREATE_DROP); + configuration.setBeans(Map.of(TEST_VARIABLE_TASK_BEAN_NAME, testVariableTask)); processEngine = configuration.buildProcessEngine(); repositoryService = processEngine.getRepositoryService(); runtimeService = processEngine.getRuntimeService(); deploymentId = repositoryService.createDeployment() - .name("MTA Deployment Test") + .name(DEPLOYMENT_NAME_OF_DIAGRAM) .addClasspathResource( - "org/cloudfoundry/multiapps/controller/process/flowable/test-bpmn-diagram.bpmn") + TEST_BPMN_DIAGRAM_RESOURCE) .deploy() .getId(); } diff --git a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java index 3769106f25..82909fdd58 100644 --- a/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java +++ b/multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/flowable/FlowableProcessTestDataUtils.java @@ -33,6 +33,86 @@ import org.cloudfoundry.multiapps.mta.model.Version; public class FlowableProcessTestDataUtils { + + // MTA and test identifiers + private static final String DEFAULT_MTA_ID = "test-mta"; + private static final String DEFAULT_MTA_VERSION = "1.0.0"; + private static final String UPDATE_SCENARIO_MTA_ID = "test-mta-2"; + private static final String UPDATE_SCENARIO_VERSION_V2 = "2.0.0"; + private static final String TEST_USER_EMAIL = "test-user@example.com"; + + // Module names and types + private static final String MODULE_1_NAME = "module-1"; + private static final String MODULE_2_NAME = "module-2"; + private static final String MODULE_3_NAME = "module-3"; + private static final String MEMORY_1G = "1G"; + private static final String MODULE_TYPE_JAVASCRIPT = "javascript"; + private static final String MODULE_TYPE_JAVA = "java"; + private static final int MODULES_COUNT = 5; + + // Memory and disk quota values + private static final String MEMORY_512M = "512M"; + private static final String DISK_QUOTA_256M = "256M"; + private static final String DISK_QUOTA_4096M = "4096M"; + private static final int INSTANCES_COUNT_2 = 2; + + // Route configurations + private static final String ROUTE_1_EXAMPLE_COM = "route-1.example.com/foo-bar"; + private static final String ROUTE_2_EXAMPLE_COM = "route-2.example.com"; + private static final String ROUTE_3_EXAMPLE_COM = "route-3.example.com"; + private static final String ROUTE_1_IDLE_EXAMPLE_COM = "route-1-idle.example.com/bar-foo"; + private static final String ROUTE_2_IDLE_EXAMPLE_COM = "route-2-idle.example.com"; + private static final String MODULE_1_ROUTE_EXAMPLE_COM = "module-1-route.example.com"; + private static final String MODULE_2_ROUTE_EXAMPLE_COM = "module-2-route.example.com"; + private static final String MODULE_3_ROUTE_EXAMPLE_COM = "module-3-route.example.com"; + + // Resource names + private static final String RESOURCE_DB_NAME = "db"; + private static final String RESOURCE_CACHE_NAME = "cache"; + private static final String RESOURCE_AUTOSCALER_NAME = "autoscaler"; + private static final String RESOURCE_APPLICATION_LOGS_NAME = "application-logs"; + + // Service configurations + private static final String SERVICE_TYPE_MANAGED = "org.cloudfoundry.managed-service"; + private static final String SERVICE_TYPE_USER_PROVIDED = "org.cloudfoundry.user-provided-service"; + private static final String TEST_DB_SERVICE = "test-db-service"; + private static final String TEST_CACHE_SERVICE = "test-cache-service"; + private static final String APP_AUTOSCALER_SERVICE = "app-autoscaler"; + private static final String SERVICE_PLAN_FREE = "free"; + private static final String SERVICE_PLAN_DEFAULT = "default"; + + // Task configurations + private static final String TASK_1_NAME = "task-1"; + private static final String TASK_1_COMMAND = "migrate-db.sh"; + private static final String TASK_NAME_KEY = "name"; + private static final String TASK_COMMAND_KEY = "command"; + + // Application and service names + private static final String APP_1_NAME = "app-1"; + private static final String APP_2_NAME = "app-2"; + private static final String APP_3_NAME = "app-3"; + private static final String SERVICE_1_NAME = "service-1"; + private static final String SERVICE_2_NAME = "service-2"; + private static final String SERVICE_3_NAME = "service-3"; + + // Service key names + private static final String SERVICE_KEY_1_NAME = "service-key-1"; + private static final String SERVICE_KEY_2_NAME = "service-key-2"; + + // Extension descriptor configurations + private static final String TEST_EXTENSION_ID = "test-extension"; + private static final String TEST_PARAMETER_KEY = "test-parameter"; + + // API configurations + private static final String PROVIDED_DEPENDENCY_MY_API = "my-api"; + private static final String API_URL_KEY = "url"; + private static final String API_URL_VALUE = "https://api.example.com"; + + // Parameter values + private static final String NEW_PARAM_KEY = "new-param"; + private static final String NEW_PARAM_VALUE = "new-value"; + private static final String SYSLOG_DRAIN_URL_VALUE = "syslog://logs.example.com:514"; + private FlowableProcessTestDataUtils() { } @@ -40,59 +120,72 @@ public record UpdateScenario(FlowableProcessTestData initial, FlowableProcessTes } public static FlowableProcessTestData predefinedScenario() { - String mtaId = "test-mta"; - String mtaVersion = "1.0.0"; - return baseBuilder(mtaId, mtaVersion).keepFiles(true) - .modulesCount(5) - .bigDescriptor(createBigDescriptor(mtaId, mtaVersion)) - .routes( - createRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com")) - .stepPhase(StepPhase.DONE) - .appActions(List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START)) - .build(); + return baseBuilder(DEFAULT_MTA_ID, DEFAULT_MTA_VERSION).keepFiles(true) + .modulesCount(MODULES_COUNT) + .bigDescriptor(createBigDescriptor(DEFAULT_MTA_ID, DEFAULT_MTA_VERSION)) + .routes(createRoutes(ROUTE_1_EXAMPLE_COM, ROUTE_2_EXAMPLE_COM, + ROUTE_3_EXAMPLE_COM)) + .stepPhase(StepPhase.DONE) + .appActions( + List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START)) + .build(); } public static UpdateScenario updateScenario() { - String id = "test-mta-2"; - DeploymentDescriptor bigDescriptorV1 = createBigDescriptor(id, "1.0.0"); - DeploymentDescriptor bigDescriptorV2 = DeploymentDescriptor.copyOf(createBigDescriptor(id, "2.0.0")) - .setParameters(Map.of("new-param", "new-value")); - FlowableProcessTestData initial = baseBuilder(id, "1.0.0").deleteServices(true) - .bigDescriptor(bigDescriptorV1) - .deployedMta(createDeployed(id, "1.0.0")) - .routes( - createRoutes("route-1-idle.example.com/bar-foo", - "route-2-idle.example.com")) - .stepPhase( - org.cloudfoundry.multiapps.controller.process.steps.StepPhase.POLL) - .appActions( - List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START)) - .build(); - FlowableProcessTestData updated = baseBuilder(id, "2.0.0").deleteServices(true) - .smallDescriptor(createSmallDescriptor(id, "2.0.0")) - .bigDescriptor(bigDescriptorV2) - .deployedMta(createDeployed(id, "2.0.0")) - .routes(createRoutes("route-1.example.com/foo-bar", "route-2.example.com", - "route-3.example.com")) - .stepPhase( - org.cloudfoundry.multiapps.controller.process.steps.StepPhase.DONE) - .appActions( - List.of(ApplicationStateAction.EXECUTE, ApplicationStateAction.STOP)) - .build(); + DeploymentDescriptor bigDescriptorV1 = createBigDescriptor(UPDATE_SCENARIO_MTA_ID, DEFAULT_MTA_VERSION); + DeploymentDescriptor bigDescriptorV2 = DeploymentDescriptor.copyOf( + createBigDescriptor(UPDATE_SCENARIO_MTA_ID, UPDATE_SCENARIO_VERSION_V2)) + .setParameters(Map.of(NEW_PARAM_KEY, NEW_PARAM_VALUE)); + FlowableProcessTestData initial = baseBuilder(UPDATE_SCENARIO_MTA_ID, DEFAULT_MTA_VERSION).deleteServices(true) + .bigDescriptor(bigDescriptorV1) + .deployedMta( + createDeployed(UPDATE_SCENARIO_MTA_ID, + DEFAULT_MTA_VERSION)) + .routes( + createRoutes(ROUTE_1_IDLE_EXAMPLE_COM, + ROUTE_2_IDLE_EXAMPLE_COM)) + .stepPhase( + org.cloudfoundry.multiapps.controller.process.steps.StepPhase.POLL) + .appActions( + List.of(ApplicationStateAction.STAGE, + ApplicationStateAction.START)) + .build(); + FlowableProcessTestData updated = baseBuilder(UPDATE_SCENARIO_MTA_ID, UPDATE_SCENARIO_VERSION_V2).deleteServices(true) + .smallDescriptor( + createSmallDescriptor( + UPDATE_SCENARIO_MTA_ID, + UPDATE_SCENARIO_VERSION_V2)) + .bigDescriptor(bigDescriptorV2) + .deployedMta(createDeployed( + UPDATE_SCENARIO_MTA_ID, + UPDATE_SCENARIO_VERSION_V2)) + .routes(createRoutes( + ROUTE_1_EXAMPLE_COM, + ROUTE_2_EXAMPLE_COM, + ROUTE_3_EXAMPLE_COM)) + .stepPhase( + org.cloudfoundry.multiapps.controller.process.steps.StepPhase.DONE) + .appActions(List.of( + ApplicationStateAction.EXECUTE, + ApplicationStateAction.STOP)) + .build(); return new UpdateScenario(initial, updated); } public static FlowableProcessTestData insideStepScenario() { - String id = "test-mta-2"; - String mtaVersion = "2.0.0"; - return baseBuilder(id, mtaVersion).deleteServices(true) - .smallDescriptor(createSmallDescriptor(id, mtaVersion)) - .bigDescriptor(createBigDescriptor(id, mtaVersion)) - .deployedMta(createDeployed(id, mtaVersion)) - .routes(createRoutes("route-1.example.com/foo-bar", "route-2.example.com", "route-3.example.com")) - .stepPhase(org.cloudfoundry.multiapps.controller.process.steps.StepPhase.DONE) - .appActions(List.of(ApplicationStateAction.STAGE, ApplicationStateAction.START)) - .build(); + return baseBuilder(UPDATE_SCENARIO_MTA_ID, UPDATE_SCENARIO_VERSION_V2).deleteServices(true) + .smallDescriptor(createSmallDescriptor(UPDATE_SCENARIO_MTA_ID, + UPDATE_SCENARIO_VERSION_V2)) + .bigDescriptor(createBigDescriptor(UPDATE_SCENARIO_MTA_ID, + UPDATE_SCENARIO_VERSION_V2)) + .deployedMta(createDeployed(UPDATE_SCENARIO_MTA_ID, + UPDATE_SCENARIO_VERSION_V2)) + .routes(createRoutes(ROUTE_1_EXAMPLE_COM, ROUTE_2_EXAMPLE_COM, + ROUTE_3_EXAMPLE_COM)) + .stepPhase(StepPhase.DONE) + .appActions(List.of(ApplicationStateAction.STAGE, + ApplicationStateAction.START)) + .build(); } private static ImmutableFlowableProcessTestData.Builder baseBuilder(String mtaId, String mtaVersion) { @@ -103,7 +196,7 @@ private static ImmutableFlowableProcessTestData.Builder baseBuilder(String mtaId .toString()) .orgGuid(UUID.randomUUID() .toString()) - .username("test-user@example.com") + .username(TEST_USER_EMAIL) .userGuid(UUID.randomUUID() .toString()) .mtaId(mtaId) @@ -113,7 +206,7 @@ private static ImmutableFlowableProcessTestData.Builder baseBuilder(String mtaId .deployedMta(createDeployed(mtaId, mtaVersion)) .stepPhase(StepPhase.DONE) .serviceKeys(createServiceKeys()) - .modulesForDeployment(List.of("module-1", "module-2", "module-3")) + .modulesForDeployment(List.of(MODULE_1_NAME, MODULE_2_NAME, MODULE_3_NAME)) .extensionDescriptors(createExtensionDescriptorsWithNullValues(mtaId)); } @@ -122,19 +215,22 @@ private static DeploymentDescriptor createSmallDescriptor(String id, String mtaV .setId(id) .setVersion(mtaVersion) .setModules(List.of(Module.createV3() - .setName("module-1") - .setType("javascript") - .setParameters( - Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, - "256M", SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-1-route.example.com"))) + .setName(MODULE_1_NAME) + .setType(MODULE_TYPE_JAVASCRIPT) + .setParameters(Map.of(SupportedParameters.MEMORY, MEMORY_512M, + SupportedParameters.DISK_QUOTA, DISK_QUOTA_256M, + SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, + MODULE_1_ROUTE_EXAMPLE_COM))) .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"))))) + .setName( + RESOURCE_DB_NAME))))) .setResources(List.of(Resource.createV3() - .setName("db") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", - SupportedParameters.SERVICE_PLAN, "free")))); + .setName(RESOURCE_DB_NAME) + .setType(SERVICE_TYPE_MANAGED) + .setParameters(Map.of(SupportedParameters.SERVICE, TEST_DB_SERVICE, + SupportedParameters.SERVICE_PLAN, + SERVICE_PLAN_FREE)))); } private static DeploymentDescriptor createBigDescriptor(String id, String mtaVersion) { @@ -143,86 +239,98 @@ private static DeploymentDescriptor createBigDescriptor(String id, String mtaVer .setVersion(mtaVersion) .setParameters(Map.of(SupportedParameters.ENABLE_PARALLEL_DEPLOYMENTS, true)) .setModules(List.of(Module.createV3() - .setName("module-1") - .setType("javascript") - .setParameters( - Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, - "256M", SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-1-route.example.com"), - SupportedParameters.TASKS, - List.of(Map.of("name", "task-1", "command", "migrate-db.sh")))) + .setName(MODULE_1_NAME) + .setType(MODULE_TYPE_JAVASCRIPT) + .setParameters(Map.of(SupportedParameters.MEMORY, MEMORY_512M, + SupportedParameters.DISK_QUOTA, DISK_QUOTA_256M, + SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, + MODULE_1_ROUTE_EXAMPLE_COM), + SupportedParameters.TASKS, List.of( + Map.of(TASK_NAME_KEY, TASK_1_NAME, TASK_COMMAND_KEY, TASK_1_COMMAND)))) .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"), + .setName(RESOURCE_DB_NAME), RequiredDependency.createV3() .setName( - "application-logs"))), + RESOURCE_APPLICATION_LOGS_NAME))), Module.createV3() - .setName("module-2") - .setType("java") - .setParameters( - Map.of(SupportedParameters.MEMORY, "1G", SupportedParameters.DISK_QUOTA, - "4096M", SupportedParameters.INSTANCES, 2, - SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-2-route.example.com"))) + .setName(MODULE_2_NAME) + .setType(MODULE_TYPE_JAVA) + .setParameters(Map.of(SupportedParameters.MEMORY, MEMORY_1G, + SupportedParameters.DISK_QUOTA, DISK_QUOTA_4096M, + SupportedParameters.INSTANCES, INSTANCES_COUNT_2, + SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, + MODULE_2_ROUTE_EXAMPLE_COM))) .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"), + .setName(RESOURCE_DB_NAME), RequiredDependency.createV3() - .setName("cache"), + .setName( + RESOURCE_CACHE_NAME), RequiredDependency.createV3() - .setName("autoscaler"), + .setName( + RESOURCE_AUTOSCALER_NAME), RequiredDependency.createV3() .setName( - "application-logs"))), + RESOURCE_APPLICATION_LOGS_NAME))), Module.createV3() - .setName("module-3") - .setType("javascript") + .setName(MODULE_3_NAME) + .setType(MODULE_TYPE_JAVASCRIPT) .setParameters( - Map.of(SupportedParameters.MEMORY, "512M", SupportedParameters.DISK_QUOTA, - "256M", SupportedParameters.ROUTES, - List.of(SupportedParameters.ROUTE, "module-3-route.example.com"))) + Map.of(SupportedParameters.MEMORY, MEMORY_512M, + SupportedParameters.DISK_QUOTA, + DISK_QUOTA_256M, SupportedParameters.ROUTES, + List.of(SupportedParameters.ROUTE, MODULE_3_ROUTE_EXAMPLE_COM))) .setRequiredDependencies(List.of(RequiredDependency.createV3() - .setName("db"), + .setName(RESOURCE_DB_NAME), RequiredDependency.createV3() - .setName("cache"), + .setName( + RESOURCE_CACHE_NAME), RequiredDependency.createV3() - .setName("autoscaler"), + .setName( + RESOURCE_AUTOSCALER_NAME), RequiredDependency.createV3() .setName( - "application-logs"))) + RESOURCE_APPLICATION_LOGS_NAME))) .setProvidedDependencies(List.of(ProvidedDependency.createV3() - .setName("my-api") - .setProperties(Map.of("url", - "https://api.example.com")))))) + .setName( + PROVIDED_DEPENDENCY_MY_API) + .setProperties( + Map.of(API_URL_KEY, + API_URL_VALUE)))))) .setResources(List.of(Resource.createV3() - .setName("db") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "test-db-service", - SupportedParameters.SERVICE_PLAN, "free")), + .setName(RESOURCE_DB_NAME) + .setType(SERVICE_TYPE_MANAGED) + .setParameters(Map.of(SupportedParameters.SERVICE, TEST_DB_SERVICE, + SupportedParameters.SERVICE_PLAN, + SERVICE_PLAN_FREE)), Resource.createV3() - .setName("cache") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "test-cache-service", - SupportedParameters.SERVICE_PLAN, "free")), + .setName(RESOURCE_CACHE_NAME) + .setType(SERVICE_TYPE_MANAGED) + .setParameters(Map.of(SupportedParameters.SERVICE, TEST_CACHE_SERVICE, + SupportedParameters.SERVICE_PLAN, + SERVICE_PLAN_FREE)), Resource.createV3() - .setName("autoscaler") - .setType("org.cloudfoundry.managed-service") - .setParameters(Map.of(SupportedParameters.SERVICE, "app-autoscaler", - SupportedParameters.SERVICE_PLAN, "default")), + .setName(RESOURCE_AUTOSCALER_NAME) + .setType(SERVICE_TYPE_MANAGED) + .setParameters(Map.of(SupportedParameters.SERVICE, APP_AUTOSCALER_SERVICE, + SupportedParameters.SERVICE_PLAN, + SERVICE_PLAN_DEFAULT)), Resource.createV3() - .setName("application-logs") - .setType("org.cloudfoundry.user-provided-service") + .setName(RESOURCE_APPLICATION_LOGS_NAME) + .setType(SERVICE_TYPE_USER_PROVIDED) .setParameters(Map.of(SupportedParameters.SYSLOG_DRAIN_URL, - "syslog://logs.example.com:514")))); + SYSLOG_DRAIN_URL_VALUE)))); } private static DeployedMta createDeployed(String id, String mtaVersion) { - List apps = Stream.of("app-1", "app-2", "app-3") + List apps = Stream.of(APP_1_NAME, APP_2_NAME, APP_3_NAME) .map(app -> ImmutableDeployedMtaApplication.builder() .name(app) .moduleName(app) .build()) .collect(Collectors.toList()); - List services = Stream.of("service-1", "service-2", "service-3") + List services = Stream.of(SERVICE_1_NAME, SERVICE_2_NAME, SERVICE_3_NAME) .map(service -> ImmutableDeployedMtaService.builder() .name(service) .build()) @@ -230,9 +338,7 @@ private static DeployedMta createDeployed(String id, String mtaVersion) { return ImmutableDeployedMta.builder() .metadata(ImmutableMtaMetadata.builder() .id(id) - .version( - Version.parseVersion( - mtaVersion)) + .version(Version.parseVersion(mtaVersion)) .build()) .applications(apps) .services(services) @@ -247,27 +353,27 @@ private static List createRoutes(String... routes) { private static List createServiceKeys() { return List.of(ImmutableCloudServiceKey.builder() - .name("service-key-1") + .name(SERVICE_KEY_1_NAME) .build(), ImmutableCloudServiceKey.builder() - .name("service-key-2") + .name(SERVICE_KEY_2_NAME) .build()); } private static List createExtensionDescriptorsWithNullValues(String mtaId) { Map moduleParams = new HashMap<>(); moduleParams.put(SupportedParameters.MEMORY, null); - moduleParams.put(SupportedParameters.DISK_QUOTA, "256M"); - moduleParams.put(SupportedParameters.ROUTES, List.of(SupportedParameters.ROUTE, "module-1-route.example.com")); + moduleParams.put(SupportedParameters.DISK_QUOTA, DISK_QUOTA_256M); + moduleParams.put(SupportedParameters.ROUTES, List.of(SupportedParameters.ROUTE, MODULE_1_ROUTE_EXAMPLE_COM)); Map resourceParams = new HashMap<>(); - resourceParams.put("test-parameter", null); + resourceParams.put(TEST_PARAMETER_KEY, null); return List.of(ExtensionDescriptor.createV3() - .setId("test-extension") + .setId(TEST_EXTENSION_ID) .setParentId(mtaId) .setModules(List.of(ExtensionModule.createV3() - .setName("module-1") + .setName(MODULE_1_NAME) .setParameters(moduleParams))) .setResources(List.of(ExtensionResource.createV3() - .setName("db") + .setName(RESOURCE_DB_NAME) .setParameters(resourceParams)))); }