TransformationEngine { CompletableFuture<TransformationResult> perform(TransformationRequest transformationRequest) { return CompletableFuture.supplyAsync( Transformer.createTransformer(transformationRequest, transformationListeners, manualInstructionsHandler, validator), executor ); }    }
@Test public void basicTest() throws ExecutionException, InterruptedException { Application application = new ApplicationImpl(transformedAppFolder); Configuration configuration = new ConfigurationImpl(null); TransformationTemplate transformationTemplate = getNewTestTransformationTemplate(); transformationTemplate.add(getNewTestTransformationUtility()); AbstractTransformationRequest transformation = new TemplateTransformationRequest(application, transformationTemplate, configuration); TransformationResult transformationResult = transformationEngine.perform(transformation).get(); assertNotNull(transformationResult); assertTrue(transformationResult.isSuccessful()); assertEquals(transformationResult.getTransformationRequest().getConfiguration(), configuration); assertFalse(transformationResult.hasManualInstructions()); assertNull(transformationResult.getManualInstructionsFile()); assertEquals(transformationResult.getTransformedApplicationDir(), transformedAppFolder); assertNull(transformationResult.getAbortDetails()); List<TransformationMetrics> metricsList = transformationResult.getMetrics(); assertNotNull(metricsList); assertEquals(metricsList.size(), 1); TransformationMetrics metrics = metricsList.get(0); assertNull(metrics.getFromVersion()); TransformationStatistics statistics = metrics.getStatistics(); assertEquals(statistics.getManualInstructionsCount(), 0); assertEquals(statistics.getOperationsCount(), 0); assertEquals(statistics.getPerformResultErrorCount(), 0); assertEquals(statistics.getPerformResultExecutionResultCount(), 1); assertEquals(statistics.getPerformResultSkippedConditionCount(), 0); assertEquals(statistics.getPerformResultSkippedDependencyCount(), 0); assertEquals(statistics.getTOExecutionResultErrorCount(), 0); assertEquals(statistics.getTOExecutionResultNoOpCount(), 0); assertEquals(statistics.getTOExecutionResultSuccessCount(), 0); assertEquals(statistics.getTOExecutionResultWarningCount(), 0); assertEquals(statistics.getUtilitiesCount(), 1); assertEquals(statistics.getTUExecutionResultErrorCount(), 0); assertEquals(statistics.getTUExecutionResultNullCount(), 0); assertEquals(statistics.getTUExecutionResultValueCount(), 1); assertEquals(statistics.getTUExecutionResultWarningCount(), 0); }
@Test public void javaEEToSpringBootTest() throws IOException, ExecutionException, InterruptedException { File appFolder = new File("../tests/sample-apps/echo"); File transformedAppFolder = new File("./out/test/resources/echo-transformed"); FileUtils.deleteDirectory(transformedAppFolder); FileUtils.copyDirectory(appFolder, transformedAppFolder); System.out.printf("Transformed sample app folder: %s\n", transformedAppFolder.getAbsolutePath()); Application application = new ApplicationImpl(transformedAppFolder); Properties properties = new Properties(); properties.put("changeReadme", "true"); properties.put("validate", "false"); Configuration configuration = new ConfigurationImpl(properties); TransformationTemplate transformationTemplate = new JavaEEToSpringBoot(); AbstractTransformationRequest transformation = new TemplateTransformationRequest(application, transformationTemplate, configuration); TransformationResult transformationResult = transformationEngine.perform(transformation).get(); assertNotNull(transformationResult); assertTrue(transformationResult.isSuccessful()); assertEquals(transformationResult.getTransformationRequest().getConfiguration(), configuration); assertFalse(transformationResult.hasManualInstructions()); assertNull(transformationResult.getManualInstructionsFile()); assertEquals(transformationResult.getTransformedApplicationDir(), transformedAppFolder); assertNull(transformationResult.getAbortDetails()); List<TransformationMetrics> metricsList = transformationResult.getMetrics(); assertNotNull(metricsList); assertEquals(metricsList.size(), 1); TransformationMetrics metrics = metricsList.get(0); assertNull(metrics.getFromVersion()); assertNull(metrics.getToVersion()); TransformationStatistics statistics = metrics.getStatistics(); assertEquals(statistics.getPerformResultErrorCount(), 0); assertEquals(statistics.getPerformResultSkippedConditionCount(), 2); assertEquals(statistics.getPerformResultSkippedDependencyCount(), 0); assertEquals(statistics.getTUExecutionResultWarningCount(), 0); assertEquals(statistics.getTUExecutionResultErrorCount(), 0); assertEquals(statistics.getTOExecutionResultWarningCount(), 0); assertEquals(statistics.getTOExecutionResultErrorCount(), 0); assertEquals(statistics.getManualInstructionsCount(), 0); }
@Test(dependsOnMethods = "javaEEToSpringBootTest") public void springBootUpgradeTest() throws ExecutionException, InterruptedException { File appFolder = new File("./out/test/resources/echo-transformed"); Application application = new ApplicationImpl(appFolder); Configuration configuration = new ConfigurationImpl(null); UpgradePath upgradePath = new UpgradePath(SpringBootUpgrade_1_5_6_to_1_5_7.class); AbstractTransformationRequest transformation = new UpgradePathTransformationRequest(application, upgradePath, configuration); TransformationResult transformationResult = transformationEngine.perform(transformation).get(); assertNotNull(transformationResult); assertTrue(transformationResult.isSuccessful()); assertEquals(transformationResult.getTransformationRequest().getConfiguration(), configuration); assertFalse(transformationResult.hasManualInstructions()); assertNull(transformationResult.getManualInstructionsFile()); assertEquals(transformationResult.getTransformedApplicationDir(), appFolder); assertNull(transformationResult.getAbortDetails()); List<TransformationMetrics> metricsList = transformationResult.getMetrics(); assertNotNull(metricsList); assertEquals(metricsList.size(), 1); TransformationMetrics metrics = metricsList.get(0); assertEquals(metrics.getFromVersion(), "1.5.6"); assertEquals(metrics.getToVersion(), "1.5.7"); TransformationStatistics statistics = metrics.getStatistics(); assertEquals(statistics.getManualInstructionsCount(), 0); assertEquals(statistics.getPerformResultErrorCount(), 0); assertEquals(statistics.getPerformResultSkippedConditionCount(), 1); assertEquals(statistics.getPerformResultSkippedDependencyCount(), 0); assertEquals(statistics.getTOExecutionResultErrorCount(), 0); assertEquals(statistics.getTOExecutionResultWarningCount(), 0); assertEquals(statistics.getTUExecutionResultErrorCount(), 0); assertEquals(statistics.getTUExecutionResultWarningCount(), 0); }
@Test public void abortTest() throws IOException, URISyntaxException, ExecutionException, InterruptedException { File appFolder = new File(getClass().getResource("/test-app-2").toURI()); File transformedAppFolder = Files.createTempDir(); FileUtils.copyDirectory(appFolder, transformedAppFolder); System.out.printf("Transformed sample app folder: %s\n", transformedAppFolder.getAbsolutePath()); Application application = new ApplicationImpl(transformedAppFolder); Configuration configuration = new ConfigurationImpl(null); TransformationTemplate transformationTemplate = new JavaEEToSpringBoot(); AbstractTransformationRequest transformation = new TemplateTransformationRequest(application, transformationTemplate, configuration); TransformationResult transformationResult = transformationEngine.perform(transformation).get(); assertNotNull(transformationResult); assertFalse(transformationResult.isSuccessful()); assertEquals(transformationResult.getTransformationRequest().getConfiguration(), configuration); assertFalse(transformationResult.hasManualInstructions()); assertNull(transformationResult.getManualInstructionsFile()); assertEquals(transformationResult.getTransformedApplicationDir(), transformedAppFolder); assertNotNull(transformationResult.getAbortDetails()); List<TransformationMetrics> metricsList = transformationResult.getMetrics(); assertNotNull(metricsList); assertEquals(metricsList.size(), 1); TransformationMetrics metrics = metricsList.get(0); assertNull(metrics.getFromVersion()); assertNull(metrics.getToVersion()); TransformationStatistics statistics = metrics.getStatistics(); assertEquals(statistics.getTUExecutionResultValueCount(), 1); assertEquals(statistics.getManualInstructionsCount(), 0); assertEquals(statistics.getPerformResultErrorCount(), 0); assertEquals(statistics.getPerformResultSkippedConditionCount(), 0); assertEquals(statistics.getPerformResultSkippedDependencyCount(), 0); assertEquals(statistics.getTOExecutionResultErrorCount(), 0); assertEquals(statistics.getTOExecutionResultWarningCount(), 0); assertEquals(statistics.getTUExecutionResultErrorCount(), 1); assertEquals(statistics.getTUExecutionResultWarningCount(), 0); AbortDetails abortDetails = transformationResult.getAbortDetails(); assertTrue(abortDetails.toString().startsWith("{\n" + " \"templateName\": \"ButterflySpringBootExtension:JavaEEToSpringBoot\",\n" + " \"templateClassName\": \"com.paypal.butterfly.extensions.springboot.JavaEEToSpringBoot\",\n" + " \"utilityName\": \"ButterflySpringBootExtension:JavaEEToSpringBoot-2-Abort\",\n" + " \"utilityClassName\": \"com.paypal.butterfly.extensions.api.utilities.Abort\",\n" + " \"abortMessage\": \"This application does not have a root pom.xml file\",\n" + " \"exceptionClassName\": \"com.paypal.butterfly.extensions.api.exception.TransformationUtilityException\",\n" + " \"exceptionMessage\": \"Abort transformation utility has been executed\",\n" + " \"exceptionStackTrace\": \"com.paypal.butterfly.extensions.api.exception.TransformationUtilityException: Abort transformation utility has been executed")); assertEquals(abortDetails.getTemplateName(), ButterflySpringBootExtension.class.getSimpleName() + ":" + JavaEEToSpringBoot.class.getSimpleName()); assertEquals(abortDetails.getTemplateClassName(), JavaEEToSpringBoot.class.getName()); assertEquals(abortDetails.getUtilityName(), "ButterflySpringBootExtension:JavaEEToSpringBoot-2-Abort"); assertEquals(abortDetails.getUtilityClassName(), Abort.class.getName()); assertEquals(abortDetails.getAbortMessage(), "This application does not have a root pom.xml file"); assertEquals(abortDetails.getExceptionClassName(), TransformationUtilityException.class.getName()); assertEquals(abortDetails.getExceptionMessage(), "Abort transformation utility has been executed"); assertNotNull(abortDetails.getExceptionStackTrace()); assertTrue(abortDetails.getExceptionStackTrace().startsWith(TransformationUtilityException.class.getName() + ": Abort transformation utility has been executed\n\tat " + Abort.class.getName() + ".execution(")); }
@Test public void pendingManualChangesTest() throws IOException, URISyntaxException, InterruptedException { File appFolder = new File(getClass().getResource("/test-app-3").toURI()); File transformedAppFolder = Files.createTempDir(); FileUtils.copyDirectory(appFolder, transformedAppFolder); System.out.printf("Transformed sample app folder: %s\n", transformedAppFolder.getAbsolutePath()); Application application = new ApplicationImpl(transformedAppFolder); Configuration configuration = new ConfigurationImpl(null); TransformationTemplate transformationTemplate = new JavaEEToSpringBoot(); AbstractTransformationRequest transformation = new TemplateTransformationRequest(application, transformationTemplate, configuration); try { transformationEngine.perform(transformation).get(); fail("An ApplicationValidationException was supposed to be thrown (since application had a pending manual instruction) but was not"); } catch (ExecutionException executionException) { Throwable cause = executionException.getCause(); assertTrue(cause instanceof ApplicationValidationException); String exceptionMessage = String.format("This application has pending manual instructions. Perform manual instructions at the following file first, then remove it, and run Butterfly again: %s/%s", transformedAppFolder.getAbsolutePath(), ManualInstructionsHandler.MANUAL_INSTRUCTIONS_MAIN_FILE); assertEquals(cause.getMessage(), exceptionMessage); } }