use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class UpdateProjectParentTest method executeWithoutProjectParentGavAndWithParent.
@Test
public void executeWithoutProjectParentGavAndWithParent() throws URISyntaxException, IOException, XmlPullParserException {
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(PARENT_POM).toURI());
PomModel model = new PomModel.PomModelBuilder().withPom(pomPath).build();
try {
updateProjectParent.execute(model, report.getReport());
assertTrue(model.getParent().isPresent());
assertEquals("com.mule.parent", model.getParent().get().getGroupId());
assertEquals("parent-rest", model.getParent().get().getArtifactId());
assertEquals("1.0.0", model.getParent().get().getVersion());
} 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 executeWithProjectParentGavAndWithoutParent.
@Test
public void executeWithProjectParentGavAndWithoutParent() 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(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 SoapkitMigrationTest method setUp.
@Before
public void setUp() throws Exception {
final ApplicationModel applicationModel = getApplicationModel();
final SoapkitMigrationTask soapkitMigrationTask = new SoapkitMigrationTask();
steps = soapkitMigrationTask.getSteps().stream().filter(step -> step instanceof AbstractSoapkitMigrationStep).collect(toList());
steps.forEach(step -> ((AbstractSoapkitMigrationStep) step).setApplicationModel(applicationModel));
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class MockApplicationModelSupplier method mockApplicationModel.
public static ApplicationModel mockApplicationModel(Document doc, TemporaryFolder temp) throws IOException {
ApplicationModel appModel = mock(ApplicationModel.class);
when(appModel.getNodes(any(String.class))).thenAnswer(invocation -> getElementsFromDocument(doc, (String) invocation.getArguments()[0]));
when(appModel.getNode(any(String.class))).thenAnswer(invocation -> {
List<Element> nodes = getElementsFromDocument(doc, (String) invocation.getArguments()[0]);
if (nodes.size() != 1) {
throw new IllegalStateException(format("Found %d nodes for xpath expression '%s'", nodes.size(), invocation.getArguments()[0]));
}
return nodes.stream().findFirst().orElse(null);
});
when(appModel.getNodeOptional(any(String.class))).thenAnswer(invocation -> {
List<Element> elementsFromDocument = getElementsFromDocument(doc, (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)));
return appModel;
}
use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.
the class AbstractAmqpEndpoint method migrateAmqpConfig.
public static String migrateAmqpConfig(Element object, MigrationReport report, Optional<Element> connector, ApplicationModel appModel) {
String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "AmqpConfig");
Optional<Element> config = appModel.getNodeOptional("*/*[(namespace-uri()='" + AMQP_NAMESPACE_URI + "' or namespace-uri()='" + AMQPS_NAMESPACE_URI + "') and local-name()='config' and @name='" + configName + "']");
config.orElseGet(() -> {
final Element amqpConfig = new Element("config", AMQP_NAMESPACE);
amqpConfig.setAttribute("name", configName);
connector.ifPresent(conn -> {
addConnectionToConfig(amqpConfig, conn, appModel, report);
if (hasAttribute(conn, "fallbackAddresses")) {
report.report("amqp.fallbackAddresses", conn, amqpConfig);
}
if (hasAttribute(conn, "default-return-endpoint-ref")) {
report.report("amqp.returnListener", conn, amqpConfig);
}
if (mustAddConsumerConfig(conn)) {
addConsumerConfigToConfig(amqpConfig, conn, appModel, report);
}
if (mustAddPublisherConfig(conn)) {
addPublisherConfigToConfig(amqpConfig, conn, appModel, report);
}
if (mustAddQoSConfig(conn)) {
addQoSConfigToConfig(amqpConfig, conn, appModel, report);
}
if (hasAttribute(conn, "activeDeclarationsOnly")) {
String fallbackQueueActionValue = Boolean.toString(!parseBoolean(conn.getAttribute("activeDeclarationsOnly").getValue()));
amqpConfig.setAttribute("createFallbackQueue", fallbackQueueActionValue);
amqpConfig.setAttribute("createFallbackExchange", fallbackQueueActionValue);
report.report("activeDeclarationsOnly", conn, amqpConfig);
}
});
addTopLevelElement(amqpConfig, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
return amqpConfig;
});
return configName;
}
Aggregations