1 /*
2 * Copyright 2010-2013 smartics, Kronseder & Reiner GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package de.smartics.testdoc.report.export.doc;
17
18 import java.util.Comparator;
19 import java.util.List;
20
21 import org.apache.commons.lang.NullArgumentException;
22
23 import de.smartics.testdoc.core.doc.ScenarioTestDoc;
24 import de.smartics.testdoc.core.doc.UnitTestDoc;
25 import de.smartics.testdoc.core.doc.UnitTestDocIndex;
26 import de.smartics.testdoc.report.junit.JUnitTestCaseManager;
27
28 /**
29 * Helper to access test documentation information and provides access to
30 * configuration information.
31 *
32 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
33 * @version $Revision:591 $
34 */
35 public class TestDocHelper
36 {
37 // ********************************* Fields *********************************
38
39 // --- constants ------------------------------------------------------------
40
41 // --- members --------------------------------------------------------------
42
43 /**
44 * The index of test documentation. May be <code>null</code>, if no index is
45 * requested.
46 */
47 private final UnitTestDocIndex index;
48
49 /**
50 * The configuration to control the generation of the report.
51 */
52 private final ReportConfig config;
53
54 // ****************************** Initializer *******************************
55
56 // ****************************** Constructors ******************************
57
58 /**
59 * Convenience constructor to create an instance with a filter that accepts
60 * all categories and shows defaults.
61 *
62 * @param index the index of test documentation.
63 */
64 public TestDocHelper(final UnitTestDocIndex index)
65 {
66 this(index, new ReportConfig());
67 }
68
69 /**
70 * Default constructor.
71 *
72 * @param index the index of test documentation.
73 * @param config the configuration to control the generation of the report.
74 * @throws NullArgumentException if <code>config</code> is <code>null</code>.
75 */
76 public TestDocHelper(final UnitTestDocIndex index, final ReportConfig config)
77 throws NullArgumentException
78 {
79 if (config == null)
80 {
81 throw new NullArgumentException("config");
82 }
83 this.index = index;
84 this.config = config;
85 }
86
87 // ****************************** Inner Classes *****************************
88
89 // ********************************* Methods ********************************
90
91 // --- init -----------------------------------------------------------------
92
93 // --- get&set --------------------------------------------------------------
94
95 /**
96 * Returns the index of test documentation. May be <code>null</code>, if no
97 * index is requested.
98 *
99 * @return the index of test documentation.
100 */
101 public UnitTestDocIndex getIndex()
102 {
103 return index;
104 }
105
106 /**
107 * Checks if test documentation information is provided.
108 *
109 * @return <code>true</code> if test documentation is provided,
110 * <code>false</code> otherwise.
111 */
112 public boolean isIndexProvided()
113 {
114 return index != null && !index.isEmpty();
115 }
116
117 /**
118 * Returns the configuration that tells which report information is to be
119 * displayed.
120 *
121 * @return the configuration that tells which report information is to be
122 * displayed.
123 */
124 public InformationFilter getInformationFilter()
125 {
126 return config.getInformationFilter();
127 }
128
129 /**
130 * Returns the manager to access JUnit report information. Is
131 * <code>null</code> if the information is not to be included.
132 *
133 * @return the manager to access JUnit report information.
134 */
135 public JUnitTestCaseManager getJunitManager()
136 {
137 return config.getJunitManager();
138 }
139
140 /**
141 * Returns the comparator to use to sort the rendering of unit test
142 * documentation.
143 *
144 * @return the comparator to use to sort the rendering of unit test
145 * documentation.
146 */
147 public Comparator<UnitTestDoc> getUnitTestDocComparator()
148 {
149 return config.getUnitTestDocComparator();
150 }
151
152 /**
153 * Checks whether or not to include JUnit report information.
154 *
155 * @return <code>true</code> if the information is requested to be included,
156 * <code>false</code> if it should be omitted.
157 */
158 public boolean isJUnitReportInformationRequested()
159 {
160 return config.getJunitManager() != null;
161 }
162
163 /**
164 * Returns the configuration of links to images used in reports.
165 *
166 * @return the configuration of links to images used in reports.
167 */
168 public ImageHelper getImageHelper()
169 {
170 return config.getImageHelper();
171 }
172
173 /**
174 * Returns the external reports to reference to.
175 *
176 * @return the external reports.
177 */
178 public ExternalReportReferences getReports()
179 {
180 return config.getReports();
181 }
182
183 /**
184 * Filters the given categories according the the given report configuration.
185 *
186 * @param categories the categories to be filtered.
187 * @return a copy of the given <code>categories</code> containing only those
188 * categories that are accepted.
189 */
190 public List<String> filter(final List<String> categories)
191 {
192 return config.getSelectionFilter().filterCategories(categories);
193 }
194
195 /**
196 * Filters scenarios by their categories according the the given report
197 * configuration.
198 *
199 * @param scenarios the scenarios to filter.
200 * @return the filtered scenarios.
201 */
202 public List<ScenarioTestDoc> filterScenarios(
203 final List<ScenarioTestDoc> scenarios)
204 {
205 return config.getSelectionFilter().filterScenarios(scenarios);
206 }
207
208 // --- business -------------------------------------------------------------
209
210 // --- object basics --------------------------------------------------------
211
212 }