Search in sources :

Example 1 with ApplicationModelBuilder

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();
}
Also used : MuleProject(com.mulesoft.tools.migration.engine.project.structure.mule.MuleProject) MuleProjectFactory.getMuleProject(com.mulesoft.tools.migration.engine.project.MuleProjectFactory.getMuleProject) ApplicationModelBuilder(com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder) ProjectType(com.mulesoft.tools.migration.project.ProjectType) ProjectTypeFactory(com.mulesoft.tools.migration.engine.project.ProjectTypeFactory)

Example 2 with ApplicationModelBuilder

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());
    }
}
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 3 with ApplicationModelBuilder

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));
}
Also used : ApplicationModelBuilder(com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder) Test(org.junit.Test)

Example 4 with ApplicationModelBuilder

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);
}
Also used : ApplicationModelBuilder(com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) Namespace(org.jdom2.Namespace) Test(org.junit.Test)

Example 5 with ApplicationModelBuilder

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

Aggregations

ApplicationModelBuilder (com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder)6 Test (org.junit.Test)5 Document (org.jdom2.Document)4 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)3 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)3 Path (java.nio.file.Path)3 XMLOutputter (org.jdom2.output.XMLOutputter)3 MuleProjectFactory.getMuleProject (com.mulesoft.tools.migration.engine.project.MuleProjectFactory.getMuleProject)1 ProjectTypeFactory (com.mulesoft.tools.migration.engine.project.ProjectTypeFactory)1 MuleProject (com.mulesoft.tools.migration.engine.project.structure.mule.MuleProject)1 ProjectType (com.mulesoft.tools.migration.project.ProjectType)1 Element (org.jdom2.Element)1 Namespace (org.jdom2.Namespace)1