use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class SoapkitMigrationTest method getApplicationModel.
private static ApplicationModel getApplicationModel() throws Exception {
final ApplicationModel mock = mock(ApplicationModel.class);
doCallRealMethod().when(mock).removeNameSpace(any(Namespace.class), anyString(), any(Document.class));
final URI basePathURI = SoapkitMigrationTest.class.getClassLoader().getResource(BASE_PATH.toString()).toURI();
final Path projectBasePath = Paths.get(new File(basePathURI).getAbsolutePath());
doReturn(projectBasePath).when(mock).getProjectBasePath();
return mock;
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class PreprocessNamespaces method addReportEntries.
public void addReportEntries(Document document, MigrationReport report, ApplicationModel applicationModel) {
List<Namespace> unsupportedNamespaces = document.getRootElement().getAdditionalNamespaces().stream().filter(n -> !getElementsWithNamespace(document, n, applicationModel).isEmpty() && !containsNamespace(n, applicationModel.getSupportedNamespaces())).collect(toList());
AtomicInteger processedElements = new AtomicInteger(0);
unsupportedNamespaces.forEach(ns -> {
// Ignore nested elements of the same pass to not distort statistics or clutter the report
applicationModel.getNodes("//*[namespace-uri() = '" + ns.getURI() + "' and namespace-uri(..) != '" + ns.getURI() + "']").forEach(node -> {
processedElements.incrementAndGet();
if (ns.getURI().startsWith("http://www.mulesoft.org")) {
report.report("components.unsupported", node, node, ns.getPrefix());
} else {
report.report("components.unknown", node, node, ns.getPrefix(), ns.getURI(), ADDITIONAL_SPRING_NAMESPACES_PROP);
}
report.addComponentFailure(node);
});
});
report.addProcessedElements(processedElements.get());
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class CleanNamespaces method removeUnusedNamespacesAndSchemas.
public void removeUnusedNamespacesAndSchemas(Document document, ApplicationModel applicationModel) {
List<Namespace> unusedNamespaces = document.getRootElement().getAdditionalNamespaces().stream().filter(n -> getElementsWithNamespace(document, n, applicationModel).size() <= 0 && !nonRemovableNamespaces.contains(n.getPrefix())).collect(Collectors.toList());
unusedNamespaces.forEach(n -> document.getRootElement().removeNamespaceDeclaration(n));
Attribute schemaLocationAttribute = document.getRootElement().getAttribute("schemaLocation", document.getRootElement().getNamespace("xsi"));
Map<String, String> schemas = new HashMap<>();
if (schemaLocationAttribute != null) {
String[] schemaValue = schemaLocationAttribute.getValue().split("\\s+");
for (int i = 0; i < schemaValue.length; i++) {
if (!schemaValue[i].equals("")) {
schemas.put(schemaValue[i], schemaValue[i + 1]);
i++;
}
}
unusedNamespaces.forEach(n -> schemas.remove(n.getURI()));
StringBuilder usedSchemas = new StringBuilder();
schemas.forEach((url, schema) -> {
usedSchemas.append(url);
usedSchemas.append(" " + schema + " ");
});
schemaLocationAttribute.setValue(usedSchemas.toString().trim());
}
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class ApikitMigrationTest method getApplicationModel.
private static ApplicationModel getApplicationModel() {
final ApplicationModel mock = mock(ApplicationModel.class);
doCallRealMethod().when(mock).removeNameSpace(any(Namespace.class), anyString(), any(Document.class));
return mock;
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class ApikitMigrationTest method setUp.
@Before
public void setUp() {
final ApplicationModel applicationModel = getApplicationModel();
final ApikitMigrationTask apikitMigrationTask = new ApikitMigrationTask();
steps = apikitMigrationTask.getSteps().stream().filter(step -> step instanceof AbstractApikitMigrationStep).collect(toList());
steps.forEach(step -> ((AbstractApikitMigrationStep) step).setApplicationModel(applicationModel));
}
Aggregations