Search in sources :

Example 11 with AbstractApplicationModelMigrationStep

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

the class ProxyMigrationTaskTestCase method execute.

@Test
public void execute() throws Exception {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    steps.forEach(step -> migrate((AbstractApplicationModelMigrationStep) step));
    String xmlString = outputter.outputString(doc);
    assertThat(xmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(targetPath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
    PomModel pm = appModel.getPomModel().get();
    String filename = configPath.toFile().getName();
    if (filename.equals("wsdl-mule3.xml")) {
        assertThat(pm.getDependencies().size(), is(3));
        assertWsdlDependency(pm, 2);
    } else if (filename.equals("custom-processor-mule3.xml")) {
        assertThat(pm.getDependencies().size(), is(3));
        assertCustomProcessorDependency(pm);
    } else {
        assertThat(pm.getDependencies().size(), is(4));
        assertCustomProcessorDependency(pm);
        assertWsdlDependency(pm, 3);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) Test(org.junit.Test)

Example 12 with AbstractApplicationModelMigrationStep

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

the class InboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    object.getChildren("property", CORE_NAMESPACE).forEach(p -> {
        object.setAttribute(p.getAttributeValue("key"), p.getAttributeValue("value"));
    });
    object.removeChildren("property", CORE_NAMESPACE);
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    AbstractApplicationModelMigrationStep migrator = null;
    if (object.getAttribute("address") != null) {
        String address = object.getAttributeValue("address");
        // TODO MMT-132 make available migrators discoverable
        if (address.startsWith("file://")) {
            migrator = new FileInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(FILE_NS_PREFIX, FILE_NS_URI));
        } else if (address.startsWith("ftp://")) {
            migrator = new FtpEeInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(FTP_NS_PREFIX, FTP_NS_URI));
        } else if (address.startsWith("sftp://")) {
            migrator = new SftpInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(SFTP_NS_PREFIX, SFTP_NS_URI));
        } else if (address.startsWith("http://")) {
            migrator = new HttpInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(HTTP_NS_PREFIX, HTTP_NS_URI));
        } else if (address.startsWith("https://")) {
            migrator = new HttpsInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("https", "http://www.mulesoft.org/schema/mule/https"));
        } else if (address.startsWith("imap://")) {
            migrator = new ImapInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("imap", "http://www.mulesoft.org/schema/mule/imap"));
        } else if (address.startsWith("imaps://")) {
            migrator = new ImapsInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("imaps", "http://www.mulesoft.org/schema/mule/imaps"));
        } else if (address.startsWith("pop3://")) {
            migrator = new Pop3InboundEndpoint();
            object.setNamespace(Namespace.getNamespace("pop3", "http://www.mulesoft.org/schema/mule/pop3"));
        } else if (address.startsWith("pop3s://")) {
            migrator = new Pop3sInboundEndpoint();
            object.setNamespace(Namespace.getNamespace("pop3s", "http://www.mulesoft.org/schema/mule/pop3s"));
        } else if (address.startsWith("jms://")) {
            migrator = new JmsInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(JMS_NS_PREFIX, JMS_NS_URI));
        } else if (address.startsWith("vm://")) {
            migrator = new VmInboundEndpoint();
            object.setNamespace(Namespace.getNamespace(VM_NS_PREFIX, VM_NS_URI));
        }
        if (migrator != null) {
            migrator.setApplicationModel(getApplicationModel());
            if (migrator instanceof ExpressionMigratorAware) {
                ((ExpressionMigratorAware) migrator).setExpressionMigrator(getExpressionMigrator());
            }
            migrator.execute(object, report);
        }
        object.removeAttribute("address");
    } else if (object.getAttribute("ref") != null) {
        Element globalEndpoint = getApplicationModel().getNode("/*/*[@name = '" + object.getAttributeValue("ref") + "']");
        // TODO MMT-132 make available migrators discoverable
        if (globalEndpoint.getAttribute("address") != null) {
            String address = globalEndpoint.getAttributeValue("address");
            if (address.startsWith("file://")) {
                migrator = new FileInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(FILE_NS_PREFIX, FILE_NS_URI));
            } else if (address.startsWith("ftp://")) {
                migrator = new FtpEeInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(FTP_NS_PREFIX, FTP_NS_URI));
            } else if (address.startsWith("sftp://")) {
                migrator = new SftpInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(SFTP_NS_PREFIX, SFTP_NS_URI));
            } else if (address.startsWith("http://")) {
                migrator = new HttpInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(HTTP_NS_PREFIX, HTTP_NS_URI));
            } else if (address.startsWith("https://")) {
                migrator = new HttpsInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("https", "http://www.mulesoft.org/schema/mule/https"));
            } else if (address.startsWith("imap://")) {
                migrator = new ImapInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("imap", "http://www.mulesoft.org/schema/mule/imap"));
            } else if (address.startsWith("imaps://")) {
                migrator = new ImapsInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("imaps", "http://www.mulesoft.org/schema/mule/imaps"));
            } else if (address.startsWith("pop3://")) {
                migrator = new Pop3InboundEndpoint();
                object.setNamespace(Namespace.getNamespace("pop3", "http://www.mulesoft.org/schema/mule/pop3"));
            } else if (address.startsWith("pop3s://")) {
                migrator = new Pop3sInboundEndpoint();
                object.setNamespace(Namespace.getNamespace("pop3s", "http://www.mulesoft.org/schema/mule/pop3s"));
            } else if (address.startsWith("jms://")) {
                migrator = new JmsInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(JMS_NS_PREFIX, JMS_NS_URI));
            } else if (address.startsWith("vm://")) {
                migrator = new VmInboundEndpoint();
                object.setNamespace(Namespace.getNamespace(VM_NS_PREFIX, VM_NS_URI));
            }
            if (migrator != null) {
                migrator.setApplicationModel(getApplicationModel());
                if (migrator instanceof ExpressionMigratorAware) {
                    ((ExpressionMigratorAware) migrator).setExpressionMigrator(getExpressionMigrator());
                }
                for (Attribute attribute : globalEndpoint.getAttributes()) {
                    if (object.getAttribute(attribute.getName()) == null) {
                        object.setAttribute(attribute.getName(), attribute.getValue());
                    }
                }
                migrator.execute(object, report);
            }
        }
    }
    if (object.getAttribute("exchange-pattern") != null) {
        object.removeAttribute("exchange-pattern");
    }
}
Also used : ImapsInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.ImapsInboundEndpoint) ImapInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.ImapInboundEndpoint) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) Element(org.jdom2.Element) HttpsInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint) HttpInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint) FileInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.file.FileInboundEndpoint) Pop3InboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.Pop3InboundEndpoint) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) FtpEeInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.ftp.FtpEeInboundEndpoint) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) SftpInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.sftp.SftpInboundEndpoint) JmsInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.jms.JmsInboundEndpoint) VmInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.vm.VmInboundEndpoint) Pop3sInboundEndpoint(com.mulesoft.tools.migration.library.mule.steps.email.Pop3sInboundEndpoint)

Example 13 with AbstractApplicationModelMigrationStep

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

the class ProxyMigrationTaskTestCase method setUp.

@Before
public void setUp() throws Exception {
    ApplicationModel.ApplicationModelBuilder amb = new ApplicationModel.ApplicationModelBuilder();
    amb.withProjectType(ProjectType.MULE_THREE_POLICY);
    amb.withProjectBasePath(APPLICATION_MODEL_PATH);
    amb.withPom(POM_PATH);
    appModel = amb.build();
    doc = getDocument(this.getClass().getClassLoader().getResource(configPath.toString()).toURI().getPath());
    ProxyMigrationTask task = new ProxyMigrationTask();
    task.setApplicationModel(appModel);
    steps = task.getSteps().stream().filter(step -> step instanceof AbstractApplicationModelMigrationStep).collect(toList());
}
Also used : ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ProxyMigrationTask(com.mulesoft.tools.migration.library.gateway.tasks.ProxyMigrationTask) Before(org.junit.Before)

Example 14 with AbstractApplicationModelMigrationStep

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

the class ThrottlingPolicyMigrationTestCase method setUp.

@Before
public void setUp() throws Exception {
    ApplicationModel.ApplicationModelBuilder amb = new ApplicationModel.ApplicationModelBuilder();
    amb.withProjectType(ProjectType.MULE_THREE_POLICY);
    amb.withProjectBasePath(POLICY_APPLICATION_MODEL_PATH);
    amb.withPom(pomPath);
    appModel = amb.build();
    doc = getDocument(this.getClass().getClassLoader().getResource(configPath.toString()).toURI().getPath());
    ThrottlingMigrationTask throttlingMigrationTask = new ThrottlingMigrationTask();
    throttlingMigrationTask.setApplicationModel(appModel);
    steps = throttlingMigrationTask.getSteps().stream().filter(step -> step instanceof AbstractApplicationModelMigrationStep).collect(toList());
    BasicStructureMigrationTask basicStructureTask = new BasicStructureMigrationTask();
    basicStructureTask.setApplicationModel(appModel);
    List<MigrationStep> basicStructureSteps = basicStructureTask.getSteps().stream().filter(step -> step instanceof AbstractApplicationModelMigrationStep).collect(toList());
    steps.addAll(basicStructureSteps);
}
Also used : RunWith(org.junit.runner.RunWith) ThrottlingMigrationTask(com.mulesoft.tools.migration.library.gateway.tasks.ThrottlingMigrationTask) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) POLICY_APPLICATION_MODEL_PATH(com.mulesoft.tools.migration.library.gateway.TestConstants.POLICY_APPLICATION_MODEL_PATH) Document(org.jdom2.Document) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) Arrays.asList(java.util.Arrays.asList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) BasicStructureMigrationTask(com.mulesoft.tools.migration.library.gateway.tasks.BasicStructureMigrationTask) Path(java.nio.file.Path) DocumentHelper.getDocument(com.mulesoft.tools.migration.library.gateway.tasks.DocumentHelper.getDocument) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) Format(org.jdom2.output.Format) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Collection(java.util.Collection) Test(org.junit.Test) ProjectType(com.mulesoft.tools.migration.project.ProjectType) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) XMLOutputter(org.jdom2.output.XMLOutputter) CompareMatcher.isSimilarTo(org.xmlunit.matchers.CompareMatcher.isSimilarTo) IOUtils(org.apache.commons.io.IOUtils) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) DocumentHelper.getElementsFromDocument(com.mulesoft.tools.migration.library.gateway.tasks.DocumentHelper.getElementsFromDocument) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) POLICY_EXAMPLES_PATH(com.mulesoft.tools.migration.library.gateway.TestConstants.POLICY_EXAMPLES_PATH) Mockito.mock(org.mockito.Mockito.mock) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ThrottlingMigrationTask(com.mulesoft.tools.migration.library.gateway.tasks.ThrottlingMigrationTask) BasicStructureMigrationTask(com.mulesoft.tools.migration.library.gateway.tasks.BasicStructureMigrationTask) Before(org.junit.Before)

Example 15 with AbstractApplicationModelMigrationStep

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

the class FederationPolicyMigrationTestCase method execute.

@Test
public void execute() throws Exception {
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    steps.forEach(step -> migrate((AbstractApplicationModelMigrationStep) step));
    String xmlString = outputter.outputString(doc);
    assertThat(xmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(targetPath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) Test(org.junit.Test)

Aggregations

AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)18 XMLOutputter (org.jdom2.output.XMLOutputter)15 Test (org.junit.Test)15 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)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 MigrationStep (com.mulesoft.tools.migration.step.MigrationStep)7 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)7 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)7 Path (java.nio.file.Path)7 Arrays.asList (java.util.Arrays.asList)7 Collection (java.util.Collection)7 List (java.util.List)7 Collectors.toList (java.util.stream.Collectors.toList)7 IOUtils (org.apache.commons.io.IOUtils)7