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);
}
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);
}
}
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());
}
}
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");
}
}
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");
}
}
Aggregations