@Test public void testMavenizeRuleProvider() throws IOException, InstantiationException, IllegalAccessException { try (GraphContext graphContext = factory.create(WindupTestUtilMethods.getTempDirectoryForGraph())) { final String inputDir = "../../test-files/jee-example-app-1.0.0.ear"; // rules-java/api final Class<MavenizeRuleProvider> ruleToRunUpTo = MavenizeRuleProvider.class; final Path outputDir = executeWindupAgainstAppUntilRule(inputDir, graphContext, ruleToRunUpTo); Iterable<IdentifiedArchiveModel> identifiedArchives = graphContext.service(IdentifiedArchiveModel.class).findAll(); Assume.assumeTrue(identifiedArchives.iterator().hasNext()); // Were the pom.xml's created? final Path baseMavenDir = outputDir.resolve("mavenized/jee-example-app"); Path resultRootPomPath = baseMavenDir.resolve("pom.xml"); Assert.assertTrue("Exists: " + resultRootPomPath, resultRootPomPath.toFile().exists()); checkPomExistence(baseMavenDir, "jee-example-app-bom", true); checkPomExistence(baseMavenDir, "jee-example-services-jar", true); checkPomExistence(baseMavenDir, "jee-example-services", false); checkPomExistence(baseMavenDir, "log4j", false); checkPomExistence(baseMavenDir, "log4j-jar", false); checkPomExistence(baseMavenDir, "unparsable-jar", false); // TODO: Load the POM tree with Maven? // ProjectBuilder pb = new DefaultProjectBuilder(); // pb.build(new ArrayList<File>(){{add(outputDir.toFile());}}, true, new // DefaultProjectBuildingRequest()); } }
@Test public void testRunWindup() throws Exception { final Path folder = File.createTempFile("windupGraph", "").toPath(); final GraphContext context = factory.create(folder); final ConfigurationLoader loader = ConfigurationLoader.create(context); final Configuration configuration = loader.loadConfiguration(context); final DefaultEvaluationContext evaluationContext = new DefaultEvaluationContext(); final DefaultParameterValueStore values = new DefaultParameterValueStore(); evaluationContext.put(ParameterValueStore.class, values); Subset.evaluate(configuration).perform(new GraphRewrite(context), evaluationContext); }
@Test public void testMetadataFound() throws Exception { String inputPath = "src/test/resources/NonNamespacedMavenDiscoveryTest"; final Path outputPath = getDefaultPath(); FileUtils.deleteDirectory(outputPath.toFile()); Files.createDirectories(outputPath); try (GraphContext context = factory.create(outputPath)) { final WindupConfiguration processorConfig = new WindupConfiguration(); processorConfig.setOptionValue(SourceModeOption.NAME, true); Predicate<RuleProvider> ruleFilter = new AndPredicate(new RuleProviderWithDependenciesPredicate(MigrationRulesPhase.class)); processorConfig.setRuleProviderFilter(ruleFilter); processorConfig.setGraphContext(context); processorConfig.addInputPath(Paths.get(inputPath)); processorConfig.setOutputDirectory(outputPath); processorConfig.setOptionValue(ScanPackagesOption.NAME, Collections.singletonList("")); processor.execute(processorConfig); ProjectModel project = WindupConfigurationService.getConfigurationModel(context) .getInputPaths() .iterator() .next() .getProjectModel(); Assert.assertTrue("Maven Project Expected", project instanceof MavenProjectModel); MavenProjectModel mavenProject = (MavenProjectModel) project; Assert.assertEquals("testgroupid", mavenProject.getGroupId()); Assert.assertEquals("testartifactid", mavenProject.getArtifactId()); Assert.assertEquals("testname", mavenProject.getName()); Assert.assertEquals("1.0.0.testversion", mavenProject.getVersion()); Assert.assertEquals("testdescription", mavenProject.getDescription()); Assert.assertEquals(1, Iterables.size(mavenProject.getDependencies())); ProjectDependencyModel dependency = mavenProject.getDependencies().iterator().next(); Assert.assertEquals( "testdependency-groupid", ((MavenProjectModel) dependency.getProjectModel()).getGroupId()); Assert.assertEquals( "testdependency-artifactid", ((MavenProjectModel) dependency.getProjectModel()).getArtifactId()); Assert.assertEquals("1.4", dependency.getProjectModel().getVersion()); } }
@Test public void testNestedCondition() throws IOException { try (GraphContext context = factory.create()) { ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class); pm.setName("Main Project"); FileModel inputPath = context.getFramed().addVertex(null, FileModel.class); inputPath.setFilePath("src/test/resources/"); Path outputPath = Paths.get( FileUtils.getTempDirectory().toString(), "windup_" + UUID.randomUUID().toString()); FileUtils.deleteDirectory(outputPath.toFile()); Files.createDirectories(outputPath); inputPath.setProjectModel(pm); pm.setRootFileModel(inputPath); WindupConfiguration windupConfiguration = new WindupConfiguration() .setRuleProviderFilter( new NotPredicate( new RuleProviderPhasePredicate( MigrationRulesPhase.class, ReportGenerationPhase.class))) .setGraphContext(context); windupConfiguration.setInputPath(Paths.get(inputPath.getFilePath())); windupConfiguration.setOutputDirectory(outputPath); processor.execute(windupConfiguration); GraphService<ClassificationModel> classificationService = new GraphService<>(context, ClassificationModel.class); Assert.assertEquals(1, provider.getXmlFileMatches().size()); List<ClassificationModel> classifications = Iterators.asList(classificationService.findAll()); for (ClassificationModel model : classifications) { String classification = model.getClassification(); String classificationString = classification.toString(); Assert.assertEquals("Spring File", classificationString); } Assert.assertEquals(1, classifications.size()); Iterator<FileModel> iterator = classifications.get(0).getFileModels().iterator(); Assert.assertNotNull(iterator.next()); Assert.assertNotNull(iterator.next()); Assert.assertFalse(iterator.hasNext()); } }
@Before public void beforeTest() throws Exception { context = factory.create(); }