private void validateStaticIPReport(GraphContext context) { ReportService reportService = new ReportService(context); ReportModel reportModel = reportService.getUniqueByProperty( ReportModel.TEMPLATE_PATH, CreateStaticIPAddressReportRuleProvider.TEMPLATE_REPORT); TestStaticIPReportUtil util = new TestStaticIPReportUtil(); Path reportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); util.loadPage(reportPath); Assert.assertTrue( util.checkStaticIPInReport( "org.apache.wicket.protocol.http.mock.MockHttpServletRequest (67, 32)", "Line: 67, Position: 32", "127.0.0.1")); Assert.assertTrue( util.checkStaticIPInReport( "org.apache.wicket.protocol.http.mock.MockHttpServletRequest (723, 14)", "Line: 723, Position: 14", "127.0.0.1")); Assert.assertTrue( util.checkStaticIPInReport( "org.apache.wicket.protocol.http.mock.MockHttpServletRequest (727, 14)", "Line: 727, Position: 14", "127.0.0.1")); }
/** Validate that the report pages were generated correctly */ private void validateReports(GraphContext context) { ReportService reportService = new ReportService(context); ReportModel mainApplicationReportModel = getMainApplicationReport(context); Path mainAppReport = reportService.getReportDirectory().resolve(mainApplicationReportModel.getReportFilename()); ReportModel catchallApplicationReportModel = getMigrationIssuesReport(context); Path catchallAppReport = reportService .getReportDirectory() .resolve(catchallApplicationReportModel.getReportFilename()); TestJavaApplicationOverviewUtil javaApplicationOverviewUtil = new TestJavaApplicationOverviewUtil(); javaApplicationOverviewUtil.loadPage(mainAppReport); javaApplicationOverviewUtil.checkFilePathEffort("catchalltest", "FileWithoutCatchallHits", 13); javaApplicationOverviewUtil.checkFilePathEffort("catchalltest", "FileWithBoth", 27); javaApplicationOverviewUtil.checkFilePathEffort("catchalltest", "FileWithNoHintsRules", 63); TestMigrationIssuesReportUtil migrationIssuesReportUtil = new TestMigrationIssuesReportUtil(); migrationIssuesReportUtil.loadPage(catchallAppReport); Assert.assertTrue( migrationIssuesReportUtil.checkIssue( "java.util.* found ", 7, 7, "Requires architectural decision or change", 49)); }
private void validateEJBReport(GraphContext context) { ReportService reportService = new ReportService(context); ReportModel reportModel = reportService.getUniqueByProperty( ReportModel.TEMPLATE_PATH, CreateEJBReportRuleProvider.TEMPLATE_EJB_REPORT); TestEJBReportUtil util = new TestEJBReportUtil(); Path reportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); util.loadPage(reportPath); Assert.assertTrue( util.checkBeanInReport( EJBType.MDB, "MyNameForMessageDrivenBean", "org.windup.examples.ejb.messagedriven.MessageDrivenBean", "jms/MyQueue")); Assert.assertTrue( util.checkBeanInReport( EJBType.STATELESS, "MyNameForSimpleStatelessEJB", "", "org.windup.examples.ejb.simplestateless.SimpleStatelessEJB")); Assert.assertTrue( util.checkBeanInReport( EJBType.STATEFUL, "MyNameForSimpleStatefulEJB", "", "org.windup.examples.ejb.simplestateful.SimpleStatefulEJB")); }
private void validateSpringBeanReport(GraphContext context) { ReportService reportService = new ReportService(context); ReportModel reportModel = reportService.getUniqueByProperty( ReportModel.TEMPLATE_PATH, CreateSpringBeanReportRuleProvider.TEMPLATE_SPRING_REPORT); TestSpringBeanReportUtil util = new TestSpringBeanReportUtil(); Path reportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); util.loadPage(reportPath); Assert.assertTrue(util.checkSpringBeanInReport("mysamplebean", "org.example.MyExampleBean")); }
private void validateCompatibleReport(GraphContext context) { ReportService reportService = new ReportService(context); ReportModel reportModel = reportService.getUniqueByProperty( ReportModel.TEMPLATE_PATH, CreateCompatibleFileReportRuleProvider.TEMPLATE_APPLICATION_REPORT); TestCompatibleReportUtil util = new TestCompatibleReportUtil(); Path reportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); util.loadPage(reportPath); Assert.assertTrue( util.checkFileInReport("src/main/resources/springexample/spring-sample-file.xml", "")); Assert.assertTrue( util.checkFileInReport("org/windup/examples/ejb/entitybean/SecondEntity.java", "")); Assert.assertTrue( "An application has duplicate entries for a single file.", util.checkTableWithoutDuplicates()); }
/** Validate that the report pages were generated correctly */ private void validateReports(GraphContext context) { ReportService reportService = new ReportService(context); ReportModel reportModel = getMainApplicationReport(context); Path appReportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); TestJavaApplicationOverviewUtil util = new TestJavaApplicationOverviewUtil(); util.loadPage(appReportPath); util.checkFilePathAndTag("src_example", "src/main/resources/test.properties", "Properties"); util.checkFilePathAndTag("src_example", "src/main/resources/WEB-INF/web.xml", "Web XML 3.0"); util.checkFilePathAndTag( "src_example", "src/main/resources/WEB-INF/web.xml", "TestTag2"); // WINDUP-679 util.checkFilePathAndIssues( "src_example", "org.windup.examples.servlet.SampleServlet", "References annotation 'javax.servlet.annotation.WebServlet'"); util.checkFilePathAndIssues("src_example", "src/main/resources/WEB-INF/web.xml", "Container"); util.checkFilePathAndIssues( "src_example", "src/main/resources/WEB-INF/web.xml", "Title for Hint from XML"); util.checkFilePathAndIssues( "src_example", "src/main/resources/WEB-INF/web.xml", "title from user script"); util.checkFilePathAndIssues( "src_example", "org.windup.examples.servlet.SampleServlet", "javax.servlet.http.HttpServletRequest usage"); XsltTransformationService xsltService = new XsltTransformationService(context); Assert.assertTrue( Files.isRegularFile( xsltService.getTransformedXSLTPath().resolve("web-xml-converted-example.xml"))); Assert.assertTrue( Files.isRegularFile( xsltService .getTransformedXSLTPath() .resolve("web-xmluserscript-converted-example.xml"))); validateSpringBeanReport(context); validateEJBReport(context); validateJPAReport(context); validateMigrationIssuesReport(context); }
/** Validate that the report pages were generated correctly */ private void validateReports(GraphContext context) { ReportService reportService = new ReportService(context); ReportModel reportModel = reportService.getUniqueByProperty( ReportModel.TEMPLATE_PATH, CreateJavaApplicationOverviewReportRuleProvider.TEMPLATE_APPLICATION_REPORT); Path appReportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); TestJavaApplicationOverviewUtil util = new TestJavaApplicationOverviewUtil(); util.loadPage(appReportPath); util.checkFilePathAndTag( "Windup1x-javaee-example.war", "META-INF/maven/javaee/javaee/pom.properties", "Properties"); util.checkFilePathEffort( "Windup1x-javaee-example.war", "META-INF/maven/javaee/javaee/pom.properties", 0); util.checkFilePathEffort( "Windup1x-javaee-example.war/WEB-INF/lib/joda-time-2.0.jar", "org.joda.time.tz.DateTimeZoneBuilder", 32); validateStaticIPReport(context); }
private void validateJPAReport(GraphContext context) { TestJPAReportUtil util = new TestJPAReportUtil(); ReportService reportService = new ReportService(context); ReportModel reportModel = reportService.getUniqueByProperty( ReportModel.TEMPLATE_PATH, CreateJPAReportRuleProvider.TEMPLATE_JPA_REPORT); Path reportPath = Paths.get(reportService.getReportDirectory(), reportModel.getReportFilename()); util.loadPage(reportPath); Assert.assertTrue( util.checkEntityInReport( "SimpleEntity", "org.windup.examples.ejb.entitybean.SimpleEntity", "SimpleEntityTable")); Assert.assertTrue( util.checkEntityInReport( "SimpleEntityNoTableName", "org.windup.examples.ejb.entitybean.SimpleEntityNoTableName", "SimpleEntityNoTableName")); }
@Override public void perform( final GraphRewrite event, final EvaluationContext context, final ReportModel payload) { String templatePath = payload.getTemplatePath(); String outputFilename = payload.getReportFilename(); ExecutionStatistics.get() .begin("FreeMarkerIterationOperation.render(" + templatePath + ", " + outputFilename + ")"); try { ReportService reportService = new ReportService(event.getGraphContext()); Path outputDir = Paths.get(reportService.getReportDirectory()); if (!Files.isDirectory(outputDir)) { Files.createDirectories(outputDir); } Path outputPath = outputDir.resolve(outputFilename); LOG.info( "Reporting: Writing template \"" + templatePath + "\" to output file \"" + outputPath.toAbsolutePath().toString() + "\""); Configuration freemarkerConfig = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); DefaultObjectWrapperBuilder objectWrapperBuilder = new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); objectWrapperBuilder.setUseAdaptersForContainers(true); freemarkerConfig.setObjectWrapper(objectWrapperBuilder.build()); freemarkerConfig.setAPIBuiltinEnabled(true); freemarkerConfig.setTemplateLoader(new FurnaceFreeMarkerTemplateLoader()); freemarkerConfig.setTemplateUpdateDelayMilliseconds(3600); Template template = freemarkerConfig.getTemplate(templatePath); Variables variables = Variables.instance(event); // just the variables Map<String, Object> vars = FreeMarkerUtil.findFreeMarkerContextVariables( variables, variableNames.toArray(new String[variableNames.size()])); if (useDefaultPayloadVariableName) { vars.put(DEFAULT_ITERATION_PAYLOAD_NAME, payload); } // also, extension functions (these are kept separate from vars in order to prevent them // from being stored in the associated data with the reportmodel) final Map<String, Object> freeMarkerExtensions; freeMarkerExtensions = furnace .getLockManager() .performLocked( LockMode.WRITE, new Callable<Map<String, Object>>() { @Override public Map<String, Object> call() throws Exception { return FreeMarkerUtil.findFreeMarkerExtensions(furnace, event); } }); Map<String, Object> objects = new HashMap<>(vars); objects.putAll(freeMarkerExtensions); try (FileWriter fw = new FileWriter(outputPath.toFile())) { template.process(objects, fw); } FreeMarkerUtil.addAssociatedReportData(event.getGraphContext(), payload, vars); } catch (IOException | TemplateException e) { LOG.log( Level.WARNING, "Template \"" + templatePath + "\" Failed to write report at \"" + outputFilename + "\" due to: " + e.getMessage(), e); } finally { ExecutionStatistics.get() .end("FreeMarkerIterationOperation.render(" + templatePath + ", " + outputFilename + ")"); } }