/** * Test. * * @throws Exception e */ @Test public void testWriteConnections() throws Exception { // NOPMD final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); // avant initH2 pour avoir une liste de connexions vide htmlReport.writeConnections(JdbcWrapper.getConnectionInformationsList(), false); assertNotEmptyAndClear(writer); // une connexion créée sur le thread courant final Connection connection = TestDatabaseInformations.initH2(); // une deuxième connexion créée sur un thread qui n'existera plus quand le rapport sera généré final ExecutorService executorService = Executors.newFixedThreadPool(1); final Callable<Connection> task = new Callable<Connection>() { @Override public Connection call() { return TestDatabaseInformations.initH2(); } }; final Future<Connection> future = executorService.submit(task); final Connection connection2 = future.get(); executorService.shutdown(); try { htmlReport.writeConnections(JdbcWrapper.getConnectionInformationsList(), false); assertNotEmptyAndClear(writer); htmlReport.writeConnections(JdbcWrapper.getConnectionInformationsList(), true); assertNotEmptyAndClear(writer); } finally { connection.close(); connection2.close(); } }
/** * Test. * * @throws Exception e */ @Test public void testOtherWrites() throws Exception { // NOPMD final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.writeAllCurrentRequestsAsPart(); assertNotEmptyAndClear(writer); htmlReport.writeAllThreadsAsPart(); assertNotEmptyAndClear(writer); htmlReport.writeSessionDetail("", null); assertNotEmptyAndClear(writer); htmlReport.writeSessions( Collections.<SessionInformations>emptyList(), "message", SESSIONS_PART); assertNotEmptyAndClear(writer); htmlReport.writeSessions(Collections.<SessionInformations>emptyList(), null, SESSIONS_PART); assertNotEmptyAndClear(writer); htmlReport.writeMBeans(MBeans.getAllMBeanNodes()); assertNotEmptyAndClear(writer); htmlReport.writeProcesses( ProcessInformations.buildProcessInformations( getClass().getResourceAsStream("/tasklist.txt"), true, false)); assertNotEmptyAndClear(writer); htmlReport.writeProcesses( ProcessInformations.buildProcessInformations( getClass().getResourceAsStream("/ps.txt"), false, false)); assertNotEmptyAndClear(writer); HtmlReport.writeAddAndRemoveApplicationLinks(null, writer); assertNotEmptyAndClear(writer); HtmlReport.writeAddAndRemoveApplicationLinks("test", writer); assertNotEmptyAndClear(writer); final Connection connection = TestDatabaseInformations.initH2(); try { htmlReport.writeDatabase(new DatabaseInformations(0)); // h2.memory assertNotEmptyAndClear(writer); htmlReport.writeDatabase(new DatabaseInformations(3)); // h2.settings avec nbColumns==2 assertNotEmptyAndClear(writer); JavaInformations.setWebXmlExistsAndPomXmlExists(true, true); htmlReport.toHtml(null, null); // pom.xml dans HtmlJavaInformationsReport.writeDependencies assertNotEmptyAndClear(writer); setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, Boolean.TRUE.toString()); htmlReport.toHtml(null, null); // writeSystemActionsLinks assertNotEmptyAndClear(writer); setProperty(Parameter.NO_DATABASE, Boolean.TRUE.toString()); htmlReport.toHtml(null, null); // writeSystemActionsLinks assertNotEmptyAndClear(writer); setProperty(Parameter.CUSTOM_REPORTS, "custom,dummy"); System.setProperty(Parameters.PARAMETER_SYSTEM_PREFIX + "custom", "custom.jsp"); htmlReport.toHtml(null, null); // writeMenu assertNotEmptyAndClear(writer); } finally { connection.close(); } }