use of com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder in project mule-migration-assistant by mulesoft.
the class MigrationJob method generateSourceApplicationModel.
private ApplicationModel generateSourceApplicationModel(Path project) throws Exception {
ProjectTypeFactory projectFactory = new ProjectTypeFactory();
ProjectType type = projectFactory.getProjectType(project);
MuleProject muleProject = getMuleProject(project, type);
ApplicationModelBuilder builder = new ApplicationModelBuilder().withConfigurationFiles(getFiles(muleProject.srcMainConfiguration(), "xml")).withProjectType(type).withMuleVersion(muleVersion).withPom(muleProject.pom()).withProjectPomGAV(projectGAV).withProjectBasePath(muleProject.getBaseFolder()).withSupportedNamespaces(getTasksDeclaredNamespaces(migrationTasks));
if (muleProject.srcTestConfiguration().toFile().exists()) {
builder.withTestConfigurationFiles(getFiles(muleProject.srcTestConfiguration(), "xml"));
}
return builder.build();
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder 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.ApplicationModelBuilder in project mule-migration-assistant by mulesoft.
the class ApplicationModelTest method test1.
@Test
public void test1() throws Exception {
ApplicationModel applicationModel = new ApplicationModelBuilder().withProjectBasePath(originalProjectPath).withConfigurationFiles(getFiles(originalProjectPath.resolve("src").resolve("main").resolve("app"))).withMuleVersion(MULE_VERSION).withSupportedNamespaces(newArrayList()).withProjectType(MULE_THREE_APPLICATION).withPom(originalProjectPath.resolve("pom.xml")).build();
applicationModel.removeNameSpace("mock", "http://www.mulesoft.org/schema/mule/mock", "http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd");
applicationModel.addNameSpace("munit-tools", "http://www.mulesoft.org/schema/mule/munit-tools", "http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd");
applicationModel.getNodes(XPATH_SELECTOR).forEach(n -> changeNodeName("munit-tools", "assert-that").andThen(changeAttribute("condition", of("expression"), empty())).andThen(addAttribute("is", "#[equalTo(true)]")).apply(n));
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder in project mule-migration-assistant by mulesoft.
the class ApplicationModelTest method testremoveNameSpace_schemaLocationAttribute_isNull.
@Test
public void testremoveNameSpace_schemaLocationAttribute_isNull() throws Exception {
ApplicationModel applicationModel = new ApplicationModelBuilder().withProjectBasePath(originalProjectPath).withConfigurationFiles(getFiles(originalProjectPath.resolve("src").resolve("main").resolve("app"))).withMuleVersion(MULE_VERSION).withSupportedNamespaces(newArrayList()).withProjectType(MULE_THREE_APPLICATION).withPom(originalProjectPath.resolve("pom.xml")).build();
Document document = mock(Document.class);
Element element = mock(Element.class);
Namespace namespace = Namespace.getNamespace("mock", "http://www.mulesoft.org/schema/mule/mock");
when(document.getRootElement()).thenReturn(element);
applicationModel.removeNameSpace(namespace, "http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd", document);
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder in project mule-migration-assistant by mulesoft.
the class SpringSecurityTest 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_SECURITY_EXAMPLES_PATH.toString()).toURI())).withConfigurationFiles(asList(resolvedConfigPath)).withProjectType(MULE_FOUR_APPLICATION).build();
Document doc = appModel.getApplicationDocuments().get(configPath.getFileName());
springConfigInMuleConfig.setApplicationModel(appModel);
securityManager.setApplicationModel(appModel);
getElementsFromDocument(doc, springConfigInMuleConfig.getAppliedTo().getExpression()).forEach(node -> springConfigInMuleConfig.execute(node, report.getReport()));
getElementsFromDocument(doc, securityManager.getAppliedTo().getExpression()).forEach(node -> securityManager.execute(node, report.getReport()));
getElementsFromDocument(doc, authorizationFilter.getAppliedTo().getExpression()).forEach(node -> authorizationFilter.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());
}
}
Aggregations