Search in sources :

Example 11 with MigrationStep

use of com.mulesoft.tools.migration.step.MigrationStep in project mule-migration-assistant by mulesoft.

the class AbstractMigrationTaskTest method executeWithPlainMigrationStep.

@Test
public void executeWithPlainMigrationStep() throws Exception {
    MigrationStep stepMock = mock(MigrationStep.class);
    List<MigrationStep> steps = new ArrayList<>();
    steps.add(stepMock);
    migrationTask.setApplicationModel(applicationModelMock);
    ((MigrationTaskImpl) migrationTask).setMigrationSteps(steps);
    migrationTask.execute(mock(MigrationReport.class));
    verify(stepMock, times(0)).execute(eq(applicationModelMock), any(MigrationReport.class));
}
Also used : MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Test(org.junit.Test)

Example 12 with MigrationStep

use of com.mulesoft.tools.migration.step.MigrationStep in project mule-migration-assistant by mulesoft.

the class BasicStructureMigrationTask method getSteps.

@Override
public List<MigrationStep> getSteps() {
    PolicyFileRenameMigrationStep policyFileRenameMigrationStep = new PolicyFileRenameMigrationStep();
    policyFileRenameMigrationStep.setApplicationModel(getApplicationModel());
    List<MigrationStep> steps = new ArrayList<>();
    steps.add(new PolicyTagMigrationStep());
    steps.add(new BeforeTagMigrationStep());
    steps.add(new AfterTagMigrationStep());
    steps.add(new BeforeExceptionTagMigrationStep());
    steps.add(new AfterExceptionTagMigrationStep());
    steps.add(new PointcutTagMigrationStep());
    steps.add(new DataTagMigrationStep());
    steps.add(new CleanupAttributesMigrationStep());
    steps.add(policyFileRenameMigrationStep);
    return steps;
}
Also used : BeforeExceptionTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.BeforeExceptionTagMigrationStep) AfterExceptionTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.AfterExceptionTagMigrationStep) BeforeTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.BeforeTagMigrationStep) AfterExceptionTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.AfterExceptionTagMigrationStep) PolicyFileRenameMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.PolicyFileRenameMigrationStep) AfterTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.AfterTagMigrationStep) PointcutTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.PointcutTagMigrationStep) BeforeTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.BeforeTagMigrationStep) BeforeExceptionTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.BeforeExceptionTagMigrationStep) PolicyTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.PolicyTagMigrationStep) CleanupAttributesMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.CleanupAttributesMigrationStep) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) DataTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.DataTagMigrationStep) ArrayList(java.util.ArrayList) DataTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.DataTagMigrationStep) PolicyFileRenameMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.PolicyFileRenameMigrationStep) PolicyTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.PolicyTagMigrationStep) AfterTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.AfterTagMigrationStep) CleanupAttributesMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.CleanupAttributesMigrationStep) PointcutTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.basicstructure.PointcutTagMigrationStep)

Example 13 with MigrationStep

use of com.mulesoft.tools.migration.step.MigrationStep in project mule-migration-assistant by mulesoft.

the class ThrottlingMigrationTask method getSteps.

@Override
public List<MigrationStep> getSteps() {
    FixedTimeFrameAlgorithmMigrationStep fixedTimeFrameAlgorithmMigrationStep = new FixedTimeFrameAlgorithmMigrationStep();
    fixedTimeFrameAlgorithmMigrationStep.setApplicationModel(getApplicationModel());
    SlaBasedAlgorithmMigrationStep slaBasedAlgorithmMigrationStep = new SlaBasedAlgorithmMigrationStep();
    slaBasedAlgorithmMigrationStep.setApplicationModel(getApplicationModel());
    List<MigrationStep> steps = new ArrayList<>();
    steps.add(fixedTimeFrameAlgorithmMigrationStep);
    steps.add(slaBasedAlgorithmMigrationStep);
    steps.add(new RateLimitTagMigrationStep());
    steps.add(new DelayResponseTagMigrationStep());
    steps.add(new DiscardResponseTagMigrationStep());
    steps.add(new PolicyTagMigrationStep());
    steps.add(new ThrottleTagMigrationStep());
    return steps;
}
Also used : RateLimitTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.RateLimitTagMigrationStep) DiscardResponseTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.DiscardResponseTagMigrationStep) PolicyTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.PolicyTagMigrationStep) FixedTimeFrameAlgorithmMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.FixedTimeFrameAlgorithmMigrationStep) DelayResponseTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.DelayResponseTagMigrationStep) ThrottleTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.ThrottleTagMigrationStep) SlaBasedAlgorithmMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.SlaBasedAlgorithmMigrationStep) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) RateLimitTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.RateLimitTagMigrationStep) DiscardResponseTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.DiscardResponseTagMigrationStep) ArrayList(java.util.ArrayList) DelayResponseTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.DelayResponseTagMigrationStep) FixedTimeFrameAlgorithmMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.FixedTimeFrameAlgorithmMigrationStep) PolicyTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.PolicyTagMigrationStep) ThrottleTagMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.ThrottleTagMigrationStep) SlaBasedAlgorithmMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.throttling.SlaBasedAlgorithmMigrationStep)

Example 14 with MigrationStep

use of com.mulesoft.tools.migration.step.MigrationStep in project mule-migration-assistant by mulesoft.

the class DomainTest method execute.

@Test
public void execute() throws Exception {
    for (MigrationStep domainStep : domainSteps) {
        if (domainStep instanceof ApplicationModelContribution) {
            getElementsFromDocument(domainDoc, ((ApplicationModelContribution) domainStep).getAppliedTo().getExpression(), "domain").forEach(node -> domainStep.execute(node, report.getReport()));
        }
    }
    for (MigrationStep appStep : appSteps) {
        if (appStep instanceof ApplicationModelContribution) {
            getElementsFromDocument(originalDomainDoc, ((ApplicationModelContribution) appStep).getAppliedTo().getExpression(), "domain").forEach(node -> appStep.execute(node, report.getReport()));
            getElementsFromDocument(appDoc, ((ApplicationModelContribution) appStep).getAppliedTo().getExpression()).forEach(node -> appStep.execute(node, report.getReport()));
        }
    }
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    String domainXmlString = outputter.outputString(domainDoc);
    String appXmlString = outputter.outputString(appDoc);
    assertThat(domainXmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(domainTargetPath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
    assertThat(appXmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(appTargetPath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) ApplicationModelContribution(com.mulesoft.tools.migration.step.category.ApplicationModelContribution) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 15 with MigrationStep

use of com.mulesoft.tools.migration.step.MigrationStep in project mule-migration-assistant by mulesoft.

the class DomainTest method setUp.

@Before
public void setUp() throws Exception {
    originalDomainDoc = getDocument(this.getClass().getClassLoader().getResource(domainConfigPath.toString()).toURI().getPath());
    domainDoc = getDocument(this.getClass().getClassLoader().getResource(domainConfigPath.toString()).toURI().getPath());
    appDoc = getDocument(this.getClass().getClassLoader().getResource(appConfigPath.toString()).toURI().getPath());
    MelToDwExpressionMigrator expressionMigrator = new MelToDwExpressionMigrator(report.getReport(), mock(ApplicationModel.class));
    domainModel = mock(ApplicationModel.class);
    when(domainModel.getNodes(any(String.class))).thenAnswer(invocation -> getElementsFromDocument(domainDoc, (String) invocation.getArguments()[0], "domain"));
    when(domainModel.getNode(any(String.class))).thenAnswer(invocation -> getElementsFromDocument(domainDoc, (String) invocation.getArguments()[0], "domain").iterator().next());
    when(domainModel.getNodeOptional(any(String.class))).thenAnswer(invocation -> {
        List<Element> elementsFromDocument = getElementsFromDocument(domainDoc, (String) invocation.getArguments()[0], "domain");
        if (elementsFromDocument.isEmpty()) {
            return empty();
        } else {
            return of(elementsFromDocument.iterator().next());
        }
    });
    when(domainModel.getProjectBasePath()).thenReturn(temp.newFolder().toPath());
    when(domainModel.getPomModel()).thenReturn(of(mock(PomModel.class)));
    final Map<Path, Document> domainModelDocs = new HashMap<>();
    domainModelDocs.put(domainConfigPath, domainDoc);
    when(domainModel.getApplicationDocuments()).thenReturn(domainModelDocs);
    doAnswer(invocation -> {
        String prefix = invocation.getArgument(0);
        String uri = invocation.getArgument(1);
        String schemaLocation = invocation.getArgument(2);
        Namespace namespace = Namespace.getNamespace(prefix, uri);
        addNameSpace(namespace, schemaLocation, domainDoc);
        return null;
    }).when(domainModel).addNameSpace(anyString(), anyString(), anyString());
    appModel = mock(ApplicationModel.class);
    when(appModel.getNodes(any(String.class))).thenAnswer(invocation -> getElementsFromDocuments((String) invocation.getArguments()[0]));
    when(appModel.getNode(any(String.class))).thenAnswer(invocation -> getElementsFromDocuments((String) invocation.getArguments()[0]).iterator().next());
    when(appModel.getNodeOptional(any(String.class))).thenAnswer(invocation -> {
        List<Element> elementsFromDocument = getElementsFromDocuments((String) invocation.getArguments()[0]);
        if (elementsFromDocument.isEmpty()) {
            return empty();
        } else {
            return of(elementsFromDocument.iterator().next());
        }
    });
    when(appModel.getProjectBasePath()).thenReturn(temp.newFolder().toPath());
    when(appModel.getPomModel()).thenReturn(of(mock(PomModel.class)));
    final Map<Path, Document> appDomainModelDocs = new HashMap<>();
    appDomainModelDocs.put(domainConfigPath, originalDomainDoc);
    when(appModel.getDomainDocuments()).thenReturn(appDomainModelDocs);
    doAnswer(invocation -> {
        String prefix = invocation.getArgument(0);
        String uri = invocation.getArgument(1);
        String schemaLocation = invocation.getArgument(2);
        Namespace namespace = Namespace.getNamespace(prefix, uri);
        addNameSpace(namespace, schemaLocation, originalDomainDoc);
        addNameSpace(namespace, schemaLocation, appDoc);
        return null;
    }).when(appModel).addNameSpace(anyString(), anyString(), anyString());
    List<AbstractMigrationTask> coreMigrationTasks = new ArrayList<>();
    coreMigrationTasks.add(new MuleCoreComponentsMigrationTask());
    coreMigrationTasks.add(new HTTPMigrationTask());
    coreMigrationTasks.add(new DbMigrationTask());
    coreMigrationTasks.add(new EndpointsMigrationTask());
    coreMigrationTasks.add(new JmsDomainMigrationTask());
    coreMigrationTasks.add(new JmsMigrationTask());
    coreMigrationTasks.add(new DomainAppMigrationTask());
    coreMigrationTasks.add(new SpringMigrationTask());
    coreMigrationTasks.add(new HTTPCleanupTask());
    coreMigrationTasks.add(new MigrationCleanTask());
    coreMigrationTasks.add(new PostprocessGeneral());
    coreMigrationTasks.add(new PostprocessMuleApplication());
    appSteps = new ArrayList<>();
    domainSteps = new ArrayList<>();
    for (AbstractMigrationTask task : coreMigrationTasks) {
        if (task.getApplicableProjectTypes().contains(MULE_FOUR_DOMAIN)) {
            for (MigrationStep step : task.getSteps()) {
                if (step instanceof ExpressionMigratorAware) {
                    ((ExpressionMigratorAware) step).setExpressionMigrator(expressionMigrator);
                }
                if (step instanceof ApplicationModelContribution) {
                    ((ApplicationModelContribution) step).setApplicationModel(domainModel);
                }
                domainSteps.add(step);
            }
        }
        if (task.getApplicableProjectTypes().contains(MULE_FOUR_APPLICATION)) {
            for (MigrationStep step : task.getSteps()) {
                if (step instanceof ExpressionMigratorAware) {
                    ((ExpressionMigratorAware) step).setExpressionMigrator(expressionMigrator);
                }
                if (step instanceof ApplicationModelContribution) {
                    ((ApplicationModelContribution) step).setApplicationModel(appModel);
                }
                appSteps.add(step);
            }
        }
    }
}
Also used : DbMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.DbMigrationTask) EndpointsMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.EndpointsMigrationTask) HashMap(java.util.HashMap) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) SpringMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.SpringMigrationTask) MigrationCleanTask(com.mulesoft.tools.migration.library.mule.tasks.MigrationCleanTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Document(org.jdom2.Document) DocumentHelper.getElementsFromDocument(com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument) DocumentHelper.getDocument(com.mulesoft.tools.migration.helper.DocumentHelper.getDocument) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) ApplicationModelContribution(com.mulesoft.tools.migration.step.category.ApplicationModelContribution) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) JmsMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.JmsMigrationTask) JmsDomainMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.JmsDomainMigrationTask) Path(java.nio.file.Path) PostprocessGeneral(com.mulesoft.tools.migration.library.mule.tasks.PostprocessGeneral) PostprocessMuleApplication(com.mulesoft.tools.migration.library.mule.tasks.PostprocessMuleApplication) DomainAppMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.DomainAppMigrationTask) AbstractMigrationTask(com.mulesoft.tools.migration.task.AbstractMigrationTask) HTTPCleanupTask(com.mulesoft.tools.migration.library.mule.tasks.HTTPCleanupTask) Namespace(org.jdom2.Namespace) MelToDwExpressionMigrator(com.mulesoft.tools.migration.library.tools.MelToDwExpressionMigrator) HTTPMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.HTTPMigrationTask) MuleCoreComponentsMigrationTask(com.mulesoft.tools.migration.library.mule.tasks.MuleCoreComponentsMigrationTask) Before(org.junit.Before)

Aggregations

MigrationStep (com.mulesoft.tools.migration.step.MigrationStep)17 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)11 Test (org.junit.Test)11 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)10 ArrayList (java.util.ArrayList)9 XMLOutputter (org.jdom2.output.XMLOutputter)9 Path (java.nio.file.Path)8 List (java.util.List)8 Document (org.jdom2.Document)8 Before (org.junit.Before)8 POLICY_APPLICATION_MODEL_PATH (com.mulesoft.tools.migration.library.gateway.TestConstants.POLICY_APPLICATION_MODEL_PATH)7 POLICY_EXAMPLES_PATH (com.mulesoft.tools.migration.library.gateway.TestConstants.POLICY_EXAMPLES_PATH)7 BasicStructureMigrationTask (com.mulesoft.tools.migration.library.gateway.tasks.BasicStructureMigrationTask)7 DocumentHelper.getDocument (com.mulesoft.tools.migration.library.gateway.tasks.DocumentHelper.getDocument)7 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.library.gateway.tasks.DocumentHelper.getElementsFromDocument)7 ProjectType (com.mulesoft.tools.migration.project.ProjectType)7 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)7 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)7 Arrays.asList (java.util.Arrays.asList)7 Collection (java.util.Collection)7