Search in sources :

Example 6 with ApplicationModel

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

the class ProcessorChainReferenceTest method setUp.

@Before
public void setUp() throws Exception {
    ApplicationModel appModel = mock(ApplicationModel.class);
    processorChain = new ProcessorChain();
    processorChainReference = new ProcessorChainReference();
    processorChain.setApplicationModel(appModel);
    processorChainReference.setApplicationModel(appModel);
}
Also used : ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Before(org.junit.Before)

Example 7 with ApplicationModel

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

the class AbstractMigrationTask method execute.

@Override
public void execute(MigrationReport report) throws Exception {
    // TODO depending on the project type this may not be true
    checkState(applicationModel != null, "An application model must be provided.");
    List<MigrationStep> steps = enableReporting(getSteps());
    try {
        if (steps != null) {
            MigrationStepSelector stepSelector = new MigrationStepSelector(steps);
            if (shouldExecuteAllSteps(stepSelector)) {
                steps.stream().filter(s -> s instanceof ExpressionMigratorAware).forEach(s -> ((ExpressionMigratorAware) s).setExpressionMigrator(getExpressionMigrator()));
                stepSelector.getNameSpaceContributionSteps().forEach(s -> s.execute(applicationModel, report));
                stepSelector.getApplicationModelContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    fetchAndProcessNodes(report, s, new ArrayList<>());
                });
                stepSelector.getProjectStructureContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    s.execute(applicationModel.getProjectBasePath(), report);
                });
                stepSelector.getPomContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    s.execute(applicationModel.getPomModel().orElse(new PomModel()), report);
                });
            }
        }
    } catch (MigrationAbortException e) {
        throw e;
    } catch (Exception e) {
        throw new MigrationTaskException("Task execution exception. " + e.getMessage(), e);
    }
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Collectors(java.util.stream.Collectors) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Preconditions.checkState(com.google.common.base.Preconditions.checkState) XMLOutputter(org.jdom2.output.XMLOutputter) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) List(java.util.List) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) ReportingStep(com.mulesoft.tools.migration.step.ReportingStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) ApplicationModelContribution(com.mulesoft.tools.migration.step.category.ApplicationModelContribution) Element(org.jdom2.Element) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException)

Example 8 with ApplicationModel

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

the class SpringTest method execute.

@Test
public void execute() throws Exception {
    Path resolvedConfigPath = Paths.get(this.getClass().getClassLoader().getResource(configPath.toString()).toURI());
    ApplicationModel appModel = new ApplicationModelBuilder().withProjectBasePath(Paths.get(this.getClass().getClassLoader().getResource(SPRING_EXAMPLES_PATH.toString()).toURI())).withConfigurationFiles(asList(resolvedConfigPath)).withMuleVersion(muleVersion).withProjectType(MULE_FOUR_APPLICATION).build();
    Document doc = appModel.getApplicationDocuments().get(configPath.getFileName());
    springPropertiesPlaceholder.setApplicationModel(appModel);
    springConfigContainingMuleConfig.setApplicationModel(appModel);
    springConfigInMuleConfig.setApplicationModel(appModel);
    springBeans.setApplicationModel(appModel);
    springContext.setApplicationModel(appModel);
    springContributions.setApplicationModel(appModel);
    getElementsFromDocument(doc, springPropertiesPlaceholder.getAppliedTo().getExpression()).forEach(node -> springPropertiesPlaceholder.execute(node, report.getReport()));
    getElementsFromDocument(doc, springConfigContainingMuleConfig.getAppliedTo().getExpression(), "spring").forEach(node -> springConfigContainingMuleConfig.execute(node, report.getReport()));
    getElementsFromDocument(doc, springConfigInMuleConfig.getAppliedTo().getExpression()).forEach(node -> springConfigInMuleConfig.execute(node, report.getReport()));
    getElementsFromDocument(doc, springBeans.getAppliedTo().getExpression()).forEach(node -> springBeans.execute(node, report.getReport()));
    getElementsFromDocument(doc, springContext.getAppliedTo().getExpression()).forEach(node -> springContext.execute(node, report.getReport()));
    getElementsFromDocument(doc, springContributions.getAppliedTo().getExpression()).forEach(node -> springContributions.execute(node, report.getReport()));
    XMLOutputter muleOutputter = new XMLOutputter(Format.getPrettyFormat());
    String muleXmlString = muleOutputter.outputString(doc);
    assertThat(muleXmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(targetMulePath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
    Document springDoc = appModel.getApplicationDocuments().get(Paths.get("src/main/resources/spring", targetSpringPath.getFileName().toString()));
    if (this.getClass().getClassLoader().getResource(targetSpringPath.toString()) != null) {
        XMLOutputter springOutputter = new XMLOutputter(Format.getPrettyFormat());
        String springXmlString = springOutputter.outputString(springDoc);
        assertThat(springXmlString, isSimilarTo(IOUtils.toString(this.getClass().getClassLoader().getResource(targetSpringPath.toString()).toURI(), UTF_8)).ignoreComments().normalizeWhitespace());
    } else {
        assertThat(springDoc, nullValue());
    }
}
Also used : Path(java.nio.file.Path) XMLOutputter(org.jdom2.output.XMLOutputter) ApplicationModelBuilder(com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Document(org.jdom2.Document) DocumentHelper.getElementsFromDocument(com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument) Test(org.junit.Test)

Example 9 with ApplicationModel

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

the class UpdateProjectParentTest method executeWithoutProjectParentGavAndWithoutParent.

@Test
public void executeWithoutProjectParentGavAndWithoutParent() throws IOException, XmlPullParserException, URISyntaxException {
    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(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) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) Test(org.junit.Test)

Example 10 with ApplicationModel

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

the class UpdateProjectParentTest method executeWithGavAndParent.

@Test
public void executeWithGavAndParent() 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(PARENT_POM).toURI());
    PomModel model = new PomModel.PomModelBuilder().withPom(pomPath).build();
    parent = model.getParent().get();
    assertEquals(parent.getGroupId(), "com.mule.parent");
    assertEquals(parent.getArtifactId(), "parent-rest");
    assertEquals(parent.getVersion(), "1.0.0");
    try {
        updateProjectParent.execute(model, report.getReport());
        Parent afterParent = model.getParent().get();
        assertEquals(afterParent.getGroupId(), "com.mule");
        assertEquals(afterParent.getArtifactId(), "rest-parent");
        assertEquals(afterParent.getVersion(), "2.0.0");
    } 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)

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