001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.plugins.core.testdetailsviewer.client;
021
022 import com.google.gwt.i18n.client.Dictionary;
023 import com.google.gwt.user.client.ui.FlowPanel;
024 import com.google.gwt.user.client.ui.HorizontalPanel;
025 import com.google.gwt.user.client.ui.Widget;
026 import org.sonar.gwt.Metrics;
027 import org.sonar.gwt.ui.Page;
028 import org.sonar.gwt.ui.ViewerHeader;
029 import org.sonar.wsclient.services.Measure;
030 import org.sonar.wsclient.services.Resource;
031
032 public class TestsViewer extends Page {
033
034 public static final String GWT_ID = "org.sonar.plugins.core.testdetailsviewer.TestsViewer";
035
036 @Override
037 protected Widget doOnResourceLoad(Resource resource) {
038 FlowPanel flowPanel = new FlowPanel();
039 flowPanel.add(new UnitTestsHeader(resource));
040 flowPanel.add(new TestsPanel(resource));
041 return flowPanel;
042 }
043
044 private static class UnitTestsHeader extends ViewerHeader {
045 public UnitTestsHeader(Resource resource) {
046
047 super(resource, new String[]{
048 Metrics.TEST_ERRORS,
049 Metrics.TEST_FAILURES,
050 Metrics.TEST_SUCCESS_DENSITY,
051 Metrics.TESTS,
052 Metrics.SKIPPED_TESTS,
053 Metrics.TEST_EXECUTION_TIME}
054 );
055 }
056
057 @Override
058 protected void display(FlowPanel header, Resource resource) {
059 Dictionary l10n = Dictionary.getDictionary("l10n");
060 HorizontalPanel panel = new HorizontalPanel();
061 header.add(panel);
062
063 Measure measure = resource.getMeasure(Metrics.TEST_SUCCESS_DENSITY);
064 if (measure == null) {
065 addBigCell(panel, "100%"); // best value
066 } else {
067 addBigCell(panel, measure.getFormattedValue());
068 }
069
070 String skippedHtml = "";
071 Measure skipped = resource.getMeasure(Metrics.SKIPPED_TESTS);
072 if (skipped != null && skipped.getValue() > 0.0) {
073 skippedHtml += " (+" + skipped.getFormattedValue() + " " + l10n.get("unittest.skipped") + ")";
074 }
075 addCell(panel,
076 l10n.get("unittest.tests") + ": ",
077 resource.getMeasureFormattedValue(Metrics.TESTS, "-") + skippedHtml);
078
079 addCell(panel,
080 l10n.get("unittest.failures") + ": ",
081 resource.getMeasureFormattedValue(Metrics.TEST_FAILURES, "0") + "/" + resource.getMeasureFormattedValue(Metrics.TEST_ERRORS, "0"));
082
083 addCell(panel,
084 l10n.get("unittest.duration") + ": ",
085 resource.getMeasureFormattedValue(Metrics.TEST_EXECUTION_TIME, "-"));
086 }
087 }
088
089 }