/** * Test. * * @throws Exception e */ @Test public void testWriteRequests() throws Exception { // NOPMD final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.writeRequestAndGraphDetail("httpHitsRate"); assertNotEmptyAndClear(writer); // writeRequestAndGraphDetail avec drill-down collector.collectWithoutErrors(javaInformationsList); // si sqlCounter reste à displayed=false, // il ne sera pas utilisé dans writeRequestAndGraphDetail sqlCounter.setDisplayed(true); final String requestName = "test 1"; counter.bindContext(requestName, "complete test 1", null, -1); servicesCounter.clear(); servicesCounter.bindContext("myservices.service1", "service1", null, -1); sqlCounter.bindContext("sql1", "complete sql1", null, -1); sqlCounter.addRequest("sql1", 5, -1, false, -1); servicesCounter.addRequest("myservices.service1", 10, 10, false, -1); servicesCounter.bindContext("myservices.service2", "service2", null, -1); servicesCounter.addRequest("myservices.service2", 10, 10, false, -1); servicesCounter.addRequest("otherservices.service3", 10, 10, false, -1); servicesCounter.addRequest("otherservices", 10, 10, false, -1); jspCounter.addRequest("jsp1", 10, 10, false, -1); counter.addRequest(requestName, 0, 0, false, 1000); collector.collectWithoutErrors(javaInformationsList); final HtmlReport toutHtmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); for (final Counter collectorCounter : collector.getCounters()) { for (final CounterRequest request : collectorCounter.getRequests()) { toutHtmlReport.writeRequestAndGraphDetail(request.getId()); assertNotEmptyAndClear(writer); toutHtmlReport.writeRequestUsages(request.getId()); assertNotEmptyAndClear(writer); } } sqlCounter.setDisplayed(false); // writeCounterSummaryPerClass toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), null); String requestId = new CounterRequest("myservices", servicesCounter.getName()).getId(); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), requestId); requestId = new CounterRequest("otherservices", servicesCounter.getName()).getId(); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), requestId); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), "unknown"); }
/** Initialisation. */ @Before public void setUp() { Utils.initialize(); javaInformationsList = Collections.singletonList(new JavaInformations(null, true)); sqlCounter = new Counter("sql", "db.png"); sqlCounter.setDisplayed(false); servicesCounter = new Counter("services", "beans.png", sqlCounter); jspCounter = new Counter(Counter.JSP_COUNTER_NAME, null); // counterName doit être http, sql ou ejb pour que les libellés de graph soient trouvés dans les // traductions counter = new Counter("http", "dbweb.png", sqlCounter); errorCounter = new Counter(Counter.ERROR_COUNTER_NAME, null); final Counter jobCounter = JobGlobalListener.getJobCounter(); collector = new Collector( "test", Arrays.asList( counter, sqlCounter, servicesCounter, jspCounter, errorCounter, jobCounter)); writer = new StringWriter(); }