@Test public void testRunWindupTiny() throws Exception { try (GraphContext context = createGraphContext()) { super.runTest( context, "../test-files/jee-example-app-1.0.0.ear", false, Arrays.asList("com.acme")); Path graphDirectory = context.getGraphDirectory(); Path reportsDirectory = graphDirectory.resolve("reports"); Path indexPath = graphDirectory.resolve(Paths.get("index.html")); Path appReportPath = resolveChildPath( reportsDirectory, "ApplicationDetails_JEE_Example_App__org_windup_example_jee_example_app_1_0_0_\\.html"); Path appNonClassifiedReportPath = resolveChildPath( reportsDirectory, "compatiblefiles_JEE_Example_App__org_windup_example_jee_example_app_1_0_0_\\.html"); Path productCatalogBeanPath = resolveChildPath(reportsDirectory, "ProductCatalogBean_java\\.html"); Assert.assertTrue(indexPath.toFile().exists()); Assert.assertTrue(appReportPath.toFile().exists()); Assert.assertTrue(appNonClassifiedReportPath.toFile().exists()); Assert.assertTrue(productCatalogBeanPath.toFile().exists()); String appReportContent = new String(Files.readAllBytes(appReportPath)); Assert.assertTrue(appReportContent.contains("Used only to support migration activities.")); allDecompiledFilesAreLinked(context); } }
@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()); } }
private Path executeWindupAgainstAppUntilRule( final String inputDir, final GraphContext grCtx, final Class<MavenizeRuleProvider> ruleToRunUpTo) throws IOException, IllegalAccessException, InstantiationException { Assume.assumeTrue("Exists: " + inputDir, new File(inputDir).exists()); final Path outputPath = Paths.get(FileUtils.getTempDirectory().toString(), "Windup-Mavenization-output"); FileUtils.deleteDirectory(outputPath.toFile()); Files.createDirectories(outputPath); grCtx.getGraph().getBaseGraph().commit(); // Configure Windup core final WindupConfiguration processorConfig = new WindupConfiguration(); processorConfig.setRuleProviderFilter(new RuleProviderWithDependenciesPredicate(ruleToRunUpTo)); processorConfig.setGraphContext(grCtx); processorConfig.addInputPath(Paths.get(inputDir)); processorConfig.setOutputDirectory(outputPath); processorConfig.setOptionValue(ScanPackagesOption.NAME, Collections.singletonList("")); processorConfig.setOptionValue(SourceModeOption.NAME, false); processorConfig.setOptionValue(MavenizeOption.NAME, true); processor.execute(processorConfig); return outputPath; }
@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()); } }
/** Add report data as associations to this report instance */ @SuppressWarnings("unchecked") public static void addAssociatedReportData( GraphContext context, ReportModel reportModel, Map<String, Object> reportData) { Map<String, WindupVertexFrame> relatedResources = new HashMap<>(); for (Map.Entry<String, Object> varEntry : reportData.entrySet()) { Object value = varEntry.getValue(); if (value instanceof WindupVertexFrame) { relatedResources.put(varEntry.getKey(), (WindupVertexFrame) varEntry.getValue()); } else if (value instanceof Iterable) { WindupVertexListModel list = context.getFramed().addVertex(null, WindupVertexListModel.class); for (WindupVertexFrame frame : (Iterable<? extends WindupVertexFrame>) value) { list.addItem(frame); } relatedResources.put(varEntry.getKey(), list); } else { throw new WindupException( "Unrecognized variable type: " + value.getClass().getCanonicalName() + " encountered!"); } } }
@Test public void testQuerying() throws Exception { FileModel f1 = context.getFramed().addVertex(null, FileModel.class); f1.setFilePath("/f1"); FileModel f2 = context.getFramed().addVertex(null, FileModel.class); f2.setFilePath("/f2"); FileModel f3 = context.getFramed().addVertex(null, FileModel.class); f3.setFilePath("/f3"); FileModel f4 = context.getFramed().addVertex(null, FileModel.class); f4.setFilePath("/f4"); FileModel f5 = context.getFramed().addVertex(null, FileModel.class); f5.setFilePath("/f5"); FileModel f6 = context.getFramed().addVertex(null, FileModel.class); f6.setFilePath("/f6"); FileModel f7 = context.getFramed().addVertex(null, FileModel.class); f7.setFilePath("/f7"); BlackListModel b1 = context.getFramed().addVertex(null, BlackListModel.class); BlackListModel b1b = context.getFramed().addVertex(null, BlackListModel.class); b1.setFileModel(f1); b1b.setFileModel(f1); BlackListModel b2 = context.getFramed().addVertex(null, BlackListModel.class); b2.setFileModel(f2); ClassificationModel c1 = context.getFramed().addVertex(null, ClassificationModel.class); ClassificationModel c1b = context.getFramed().addVertex(null, ClassificationModel.class); c1.setFileModel(f1); c1b.setFileModel(f1); ClassificationModel c2 = context.getFramed().addVertex(null, ClassificationModel.class); c2.setFileModel(f3); List<Vertex> vertexList = new ArrayList<>(); for (Vertex v : context .getFramed() .query() .has(WindupVertexFrame.TYPE_FIELD, Text.CONTAINS, "FileResource") .vertices()) { vertexList.add(v); } GremlinPipeline<Vertex, Vertex> pipeline = new GremlinPipeline<>( context .getFramed() .query() .has(WindupVertexFrame.TYPE_FIELD, Text.CONTAINS, "FileResource") .vertices()); GraphRewrite event = new GraphRewrite(context); // manually execute this criterion (this just adds things to the pipeline) new FindClassifiedFilesGremlinCriterion().query(event, pipeline); List<FileModel> fileModels = new ArrayList<>(); for (Vertex v : pipeline) { // Explicit cast here insures that the frame returned was actually a FileModel. If it is not, // a // ClassCastException will // occur and the test will fail. // // If we called frame(v, FileModel.class) directly, frames would happily force it to be a // FileModel // even if the underlying query were returning invalid results. FileModel fm = (FileModel) context.getFramed().frame(v, WindupVertexFrame.class); fileModels.add(fm); } boolean foundF1 = false; boolean foundF2 = false; boolean foundF3 = false; Assert.assertEquals(3, fileModels.size()); for (FileModel fm : fileModels) { if (fm.getFilePath().equals(f1.getFilePath())) { foundF1 = true; } else if (fm.getFilePath().equals(f2.getFilePath())) { foundF2 = true; } else if (fm.getFilePath().equals(f3.getFilePath())) { foundF3 = true; } } Assert.assertTrue(foundF1); Assert.assertTrue(foundF2); Assert.assertTrue(foundF3); }
@After public void afterTest() throws Exception { context.close(); context.clear(); }
@Test public void testFindingNonClassifiedFiles() throws Exception { FileModel f1 = context.getFramed().addVertex(null, FileModel.class); f1.setFilePath("/f1"); FileModel f2 = context.getFramed().addVertex(null, FileModel.class); f2.setFilePath("/f2"); FileModel f3 = context.getFramed().addVertex(null, FileModel.class); f3.setFilePath("/f3"); FileModel f4 = context.getFramed().addVertex(null, FileModel.class); f4.setFilePath("/f4"); FileModel f5 = context.getFramed().addVertex(null, FileModel.class); f5.setFilePath("/f5"); FileModel f6 = context.getFramed().addVertex(null, FileModel.class); f6.setFilePath("/f6"); FileModel f7 = context.getFramed().addVertex(null, FileModel.class); f7.setFilePath("/f7"); InlineHintModel b1 = context.getFramed().addVertex(null, InlineHintModel.class); InlineHintModel b1b = context.getFramed().addVertex(null, InlineHintModel.class); b1.setFile(f1); b1b.setFile(f1); InlineHintModel b2 = context.getFramed().addVertex(null, InlineHintModel.class); b2.setFile(f2); ClassificationModel c1 = context.getFramed().addVertex(null, ClassificationModel.class); ClassificationModel c1b = context.getFramed().addVertex(null, ClassificationModel.class); c1.addFileModel(f1); c1b.addFileModel(f1); ClassificationModel c2 = context.getFramed().addVertex(null, ClassificationModel.class); c2.addFileModel(f3); List<Vertex> vertexList = new ArrayList<>(); for (Vertex v : context.getQuery().type(FileModel.class).vertices()) { vertexList.add(v); } // manually execute this criterion (this just adds things to the pipeline) Iterable<Vertex> allFMVertices = context.getQuery().type(FileModel.class).vertices(); Iterable<Vertex> fileModelIterable = new FindFilesNotClassifiedOrHintedGremlinCriterion().query(context, allFMVertices); List<FileModel> fileModels = new ArrayList<>(); for (Vertex v : fileModelIterable) { // Explicit cast here insures that the frame returned was actually a FileModel. If it is not, // a // ClassCastException will // occur and the test will fail. // // If we called frame(v, FileModel.class) directly, frames would happily force it to be a // FileModel // even if the underlying query were returning invalid results. FileModel fm = (FileModel) context.getFramed().frame(v, WindupVertexFrame.class); fileModels.add(fm); } boolean foundF4 = false; boolean foundF5 = false; boolean foundF6 = false; boolean foundF7 = false; Assert.assertEquals(4, fileModels.size()); for (FileModel fm : fileModels) { if (fm.getFilePath().equals(f4.getFilePath())) { foundF4 = true; } else if (fm.getFilePath().equals(f5.getFilePath())) { foundF5 = true; } else if (fm.getFilePath().equals(f6.getFilePath())) { foundF6 = true; } else if (fm.getFilePath().equals(f7.getFilePath())) { foundF7 = true; } } Assert.assertTrue(foundF4); Assert.assertTrue(foundF5); Assert.assertTrue(foundF6); Assert.assertTrue(foundF7); }