Search in sources :

Example 11 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class UpdateProjectParentTest method executeWithoutProjectParentGavAndWithParent.

@Test
public void executeWithoutProjectParentGavAndWithParent() throws URISyntaxException, IOException, XmlPullParserException {
    UpdateProjectParent updateProjectParent = new UpdateProjectParent();
    final ApplicationModel applicationModelMock = mock(ApplicationModel.class);
    when(applicationModelMock.getProjectPomParent()).thenReturn(Optional.empty());
    updateProjectParent.setApplicationModel(applicationModelMock);
    Path pomPath = Paths.get(getClass().getResource(PARENT_POM).toURI());
    PomModel model = new PomModel.PomModelBuilder().withPom(pomPath).build();
    try {
        updateProjectParent.execute(model, report.getReport());
        assertTrue(model.getParent().isPresent());
        assertEquals("com.mule.parent", model.getParent().get().getGroupId());
        assertEquals("parent-rest", model.getParent().get().getArtifactId());
        assertEquals("1.0.0", model.getParent().get().getVersion());
    } catch (RuntimeException e) {
        fail("no exception have to be thrown");
    }
}
Also used : Path(java.nio.file.Path) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) Test(org.junit.Test)

Example 12 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class UpdateProjectParentTest method executeWithProjectParentGavAndWithoutParent.

@Test
public void executeWithProjectParentGavAndWithoutParent() throws URISyntaxException, IOException, XmlPullParserException {
    UpdateProjectParent updateProjectParent = new UpdateProjectParent();
    final ApplicationModel applicationModelMock = mock(ApplicationModel.class);
    Parent parent = new Parent.ParentBuilder().withGroupId("com.mule").withArtifactId("rest-parent").withVersion("2.0.0").build();
    when(applicationModelMock.getProjectPomParent()).thenReturn(Optional.of(parent));
    updateProjectParent.setApplicationModel(applicationModelMock);
    Path pomPath = Paths.get(getClass().getResource(POM).toURI());
    PomModel model = new PomModel.PomModelBuilder().withPom(pomPath).build();
    try {
        updateProjectParent.execute(model, report.getReport());
        assertTrue(!model.getParent().isPresent());
    } catch (RuntimeException e) {
        fail("no exception have to be thrown");
    }
}
Also used : Path(java.nio.file.Path) Parent(com.mulesoft.tools.migration.project.model.pom.Parent) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) Test(org.junit.Test)

Example 13 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class SoapkitMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    final ApplicationModel applicationModel = getApplicationModel();
    final SoapkitMigrationTask soapkitMigrationTask = new SoapkitMigrationTask();
    steps = soapkitMigrationTask.getSteps().stream().filter(step -> step instanceof AbstractSoapkitMigrationStep).collect(toList());
    steps.forEach(step -> ((AbstractSoapkitMigrationStep) step).setApplicationModel(applicationModel));
}
Also used : SoapkitMigrationTask(com.mulesoft.tools.migration.library.soapkit.tasks.SoapkitMigrationTask) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) AbstractSoapkitMigrationStep(com.mulesoft.tools.migration.library.soapkit.steps.AbstractSoapkitMigrationStep) Before(org.junit.Before)

Example 14 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class MockApplicationModelSupplier method mockApplicationModel.

public static ApplicationModel mockApplicationModel(Document doc, TemporaryFolder temp) throws IOException {
    ApplicationModel appModel = mock(ApplicationModel.class);
    when(appModel.getNodes(any(String.class))).thenAnswer(invocation -> getElementsFromDocument(doc, (String) invocation.getArguments()[0]));
    when(appModel.getNode(any(String.class))).thenAnswer(invocation -> {
        List<Element> nodes = getElementsFromDocument(doc, (String) invocation.getArguments()[0]);
        if (nodes.size() != 1) {
            throw new IllegalStateException(format("Found %d nodes for xpath expression '%s'", nodes.size(), invocation.getArguments()[0]));
        }
        return nodes.stream().findFirst().orElse(null);
    });
    when(appModel.getNodeOptional(any(String.class))).thenAnswer(invocation -> {
        List<Element> elementsFromDocument = getElementsFromDocument(doc, (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)));
    return appModel;
}
Also used : Element(org.jdom2.Element) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel)

Example 15 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class AbstractAmqpEndpoint method migrateAmqpConfig.

public static String migrateAmqpConfig(Element object, MigrationReport report, Optional<Element> connector, ApplicationModel appModel) {
    String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "AmqpConfig");
    Optional<Element> config = appModel.getNodeOptional("*/*[(namespace-uri()='" + AMQP_NAMESPACE_URI + "' or namespace-uri()='" + AMQPS_NAMESPACE_URI + "') and local-name()='config' and @name='" + configName + "']");
    config.orElseGet(() -> {
        final Element amqpConfig = new Element("config", AMQP_NAMESPACE);
        amqpConfig.setAttribute("name", configName);
        connector.ifPresent(conn -> {
            addConnectionToConfig(amqpConfig, conn, appModel, report);
            if (hasAttribute(conn, "fallbackAddresses")) {
                report.report("amqp.fallbackAddresses", conn, amqpConfig);
            }
            if (hasAttribute(conn, "default-return-endpoint-ref")) {
                report.report("amqp.returnListener", conn, amqpConfig);
            }
            if (mustAddConsumerConfig(conn)) {
                addConsumerConfigToConfig(amqpConfig, conn, appModel, report);
            }
            if (mustAddPublisherConfig(conn)) {
                addPublisherConfigToConfig(amqpConfig, conn, appModel, report);
            }
            if (mustAddQoSConfig(conn)) {
                addQoSConfigToConfig(amqpConfig, conn, appModel, report);
            }
            if (hasAttribute(conn, "activeDeclarationsOnly")) {
                String fallbackQueueActionValue = Boolean.toString(!parseBoolean(conn.getAttribute("activeDeclarationsOnly").getValue()));
                amqpConfig.setAttribute("createFallbackQueue", fallbackQueueActionValue);
                amqpConfig.setAttribute("createFallbackExchange", fallbackQueueActionValue);
                report.report("activeDeclarationsOnly", conn, amqpConfig);
            }
        });
        addTopLevelElement(amqpConfig, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
        return amqpConfig;
    });
    return configName;
}
Also used : DeliveryModeAttributeMapper(com.mulesoft.tools.migration.library.mule.steps.amqp.values.DeliveryModeAttributeMapper) Optional.of(java.util.Optional.of) Set(java.util.Set) HashMap(java.util.HashMap) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) List(java.util.List) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) AckModeAttributeMapper(com.mulesoft.tools.migration.library.mule.steps.amqp.values.AckModeAttributeMapper) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) XPATH_SELECTOR(com.mulesoft.tools.migration.library.mule.steps.amqp.AmqpConnector.XPATH_SELECTOR) SimpleAttributeMapper(com.mulesoft.tools.migration.library.mule.steps.amqp.values.SimpleAttributeMapper) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Map(java.util.Map) XmlDslUtils.hasAttribute(com.mulesoft.tools.migration.step.util.XmlDslUtils.hasAttribute) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Aggregations

ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)28 Path (java.nio.file.Path)9 Namespace (org.jdom2.Namespace)9 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)8 Document (org.jdom2.Document)8 Before (org.junit.Before)8 Test (org.junit.Test)7 Element (org.jdom2.Element)6 PomModel (com.mulesoft.tools.migration.project.model.pom.PomModel)5 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)4 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)4 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)4 List (java.util.List)4 Optional (java.util.Optional)4 XMLOutputter (org.jdom2.output.XMLOutputter)4 ApplicationModelBuilder (com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder)3 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)3 NamespaceContribution (com.mulesoft.tools.migration.step.category.NamespaceContribution)3 Map (java.util.Map)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2