use of com.mulesoft.tools.migration.step.category.ApplicationModelContribution in project mule-migration-assistant by mulesoft.
the class AbstractMigrationTaskTest method shouldExecuteAllStepsAppModelContributionAndElementPresent.
@Test
public void shouldExecuteAllStepsAppModelContributionAndElementPresent() {
doReturn(newArrayList(mock(Element.class))).when(applicationModelMock).getNodes(any(XPathExpression.class));
MigrationStepSelector selectorMock = mock(MigrationStepSelector.class);
ApplicationModelContribution contrib = mock(ApplicationModelContribution.class);
doReturn(mock(XPathExpression.class)).when(contrib).getAppliedTo();
doReturn(newArrayList(contrib)).when(selectorMock).getApplicationModelContributionSteps();
AbstractMigrationTask taskSpy = spy(AbstractMigrationTask.class);
taskSpy.setApplicationModel(applicationModelMock);
assertThat("It should return true", taskSpy.shouldExecuteAllSteps(selectorMock));
}
use of com.mulesoft.tools.migration.step.category.ApplicationModelContribution in project mule-migration-assistant by mulesoft.
the class AbstractMigrationTaskTest method execute.
@Test
public void execute() throws Exception {
NamespaceContribution namespaceContributionMock = mock(NamespaceContribution.class);
ApplicationModelContribution applicationModelContributionMock = mock(ApplicationModelContribution.class);
ProjectStructureContribution projectStructureContributionMock = mock(ProjectStructureContribution.class);
PomContribution pomContributionMock = mock(PomContribution.class);
List<MigrationStep> steps = new ArrayList<>();
steps.add(namespaceContributionMock);
steps.add(applicationModelContributionMock);
steps.add(projectStructureContributionMock);
steps.add(pomContributionMock);
InOrder inOrder = Mockito.inOrder(steps.toArray());
migrationTask.setApplicationModel(applicationModelMock);
((MigrationTaskImpl) migrationTask).setMigrationSteps(new ArrayList<>(steps));
migrationTask.execute(mock(MigrationReport.class));
verify(namespaceContributionMock, times(1)).execute(any(ApplicationModel.class), any(MigrationReport.class));
verify(applicationModelContributionMock, times(2)).getAppliedTo();
verify(projectStructureContributionMock, times(1)).execute(isNull(), any(MigrationReport.class));
verify(pomContributionMock, times(1)).execute(any(PomModel.class), any(MigrationReport.class));
inOrder.verify(namespaceContributionMock).execute(any(ApplicationModel.class), any(MigrationReport.class));
inOrder.verify(projectStructureContributionMock).execute(isNull(), any(MigrationReport.class));
inOrder.verify(pomContributionMock).execute(any(PomModel.class), any(MigrationReport.class));
}
use of com.mulesoft.tools.migration.step.category.ApplicationModelContribution in project mule-migration-assistant by mulesoft.
the class AbstractMigrationTask method fetchAndProcessNodes.
private void fetchAndProcessNodes(MigrationReport report, ApplicationModelContribution s, List<Element> alreadyProcessed) {
AtomicInteger processedElements = new AtomicInteger(0);
List<Element> nodes = applicationModel.getNodes(s.getAppliedTo());
nodes.stream().filter(n -> !alreadyProcessed.contains(n)).forEach(n -> {
try {
processedElements.incrementAndGet();
s.execute(n, report);
} catch (Exception e) {
throw new MigrationStepException("Task execution exception (" + e.getMessage() + ") migrating node:" + lineSeparator() + outp.outputString(n), e);
}
});
alreadyProcessed.addAll(nodes);
nodes.removeAll(applicationModel.getNodes(s.getAppliedTo()));
if (!nodes.isEmpty()) {
// This recursive calls is here so if any task adds nodes to the config that would be processed by this task, those are
// processed.
// Also, this is recursive rather than iterative so in the case of a bug, we get a StackOverflow rather than an infinite
// loop.
fetchAndProcessNodes(report, s, alreadyProcessed);
}
report.addProcessedElements(processedElements.get());
}
use of com.mulesoft.tools.migration.step.category.ApplicationModelContribution 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());
}
use of com.mulesoft.tools.migration.step.category.ApplicationModelContribution 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);
}
}
}
}
Aggregations