1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /* $Id$ */
19 
20 package org.apache.fop.layoutengine;
21 
22 import java.io.File;
23 
24 /**
25  * A class that contains the information needed to run a suite of layout engine and FO tree
26  * tests.
27  */
28 public final class TestFilesConfiguration {
29 
30     private final File testDirectory;
31     private final String singleTest;
32     private final String testStartsWith;
33     private final String testFileSuffix;
34     private final String testSet;
35     private final String disabledTests;
36     private final boolean privateTests;
37 
TestFilesConfiguration(Builder builder)38     private TestFilesConfiguration(Builder builder) {
39         this.testDirectory = new File(builder.testDirectory);
40         this.singleTest = builder.singleTest;
41         this.testStartsWith = builder.testStartsWith;
42         this.testFileSuffix = builder.testFileSuffix;
43         this.testSet = builder.testSet;
44         this.privateTests = builder.privateTests;
45         this.disabledTests = builder.disabledTests;
46     }
47 
48     /**
49      * Returns the directory of the tests.
50      * @return the test directory
51      */
getTestDirectory()52     public File getTestDirectory() {
53         return testDirectory;
54     }
55 
56     /**
57      * Returns the name of the single test file to run.
58      * @return the single test file name
59      */
getSingleTest()60     public String getSingleTest() {
61         return singleTest;
62     }
63 
64     /**
65      * Returns the string that must prefix the test file names.
66      * @return the prefixing string
67      */
getStartsWith()68     public String getStartsWith() {
69         return testStartsWith;
70     }
71 
72     /**
73      * Returns the file suffix (i.e. ".xml" for XML files and ".fo" for FOs).
74      * @return the file suffix
75      */
getFileSuffix()76     public String getFileSuffix() {
77         return testFileSuffix;
78     }
79 
80     /**
81      * Returns the directory set of tests to be run.
82      * @return the directory tests
83      */
getTestSet()84     public String getTestSet() {
85         return testSet;
86     }
87 
88     /**
89      * Returns the name of the XML file containing the disabled tests.
90      * @return a file name, may be null
91      */
getDisabledTests()92     public String getDisabledTests() {
93         return disabledTests;
94     }
95 
96     /**
97      * Whether any private tests should be invoked.
98      * @return true if private tests should be tested
99      */
hasPrivateTests()100     public boolean hasPrivateTests() {
101         return privateTests;
102     }
103 
104     /**
105      * A builder class that configures the data for running a suite of tests designed for the
106      * layout engine and FOTree.
107      */
108     public static class Builder {
109 
110         private String testDirectory;
111         private String singleTest;
112         private String testStartsWith;
113         private String testFileSuffix;
114         private String testSet;
115         private String disabledTests;
116         private boolean privateTests;
117 
118         /**
119          * Configures the test directory.
120          * @param dir the test directory
121          * @return {@code this}
122          */
testDir(String dir)123         public Builder testDir(String dir) {
124             testDirectory = dir;
125             return this;
126         }
127 
128         /**
129          * Configures the name of the single test to run.
130          * @param singleProperty name of the property that determines the single test case
131          * @return {@code this}
132          */
singleProperty(String singleProperty)133         public Builder singleProperty(String singleProperty) {
134             singleTest = getSystemProperty(singleProperty);
135             return this;
136         }
137 
138         /**
139          * Configures the prefix that all test cases must match.
140          * @param startsWithProperty name of the property that determines the common prefix
141          * @return {@code this}
142          */
startsWithProperty(String startsWithProperty)143         public Builder startsWithProperty(String startsWithProperty) {
144             testStartsWith = getSystemProperty(startsWithProperty);
145             return this;
146         }
147 
148         /**
149          * Configures the test file name suffix.
150          * @param suffix the suffixing string
151          * @return {@code this}
152          */
suffix(String suffix)153         public Builder suffix(String suffix) {
154             testFileSuffix = suffix;
155             return this;
156         }
157 
158         /**
159          * Configures the name of the directory containing the set of tests.
160          * @param testSet the directory of tests. If null, defaults to "standard-testcases"
161          * @return {@code this}
162          */
testSet(String testSet)163         public Builder testSet(String testSet) {
164             this.testSet = testSet != null ? testSet : "standard-testcases";
165             return this;
166         }
167 
168         /**
169          * Configures whether any tests are disabled.
170          * @param disabledProperty name of the property that determines the file of
171          * disabled test cases
172          * @param defaultValue if the property was not defined, uses this file name
173          * instead
174          * @return {@code this}
175          */
disabledProperty(String disabledProperty, String defaultValue)176         public Builder disabledProperty(String disabledProperty, String defaultValue) {
177             String property = getSystemProperty(disabledProperty);
178             disabledTests = property != null ? property : defaultValue;
179             return this;
180         }
181 
182         /**
183          * Configures whether private tests must be run or not.
184          * @param privateTestsProperty name of the property containing the boolean switch
185          * @return {@code this}
186          */
privateTestsProperty(String privateTestsProperty)187         public Builder privateTestsProperty(String privateTestsProperty) {
188             String property = getSystemProperty(privateTestsProperty);
189             this.privateTests = property != null && property.equalsIgnoreCase("true");
190             return this;
191         }
192 
getSystemProperty(String property)193         private String getSystemProperty(String property) {
194             return System.getProperty(property);
195         }
196 
197         /**
198          * Creates the configuration instance.
199          * @return a configuration instance configured by this builder
200          */
build()201         public TestFilesConfiguration build() {
202             return new TestFilesConfiguration(this);
203         }
204     }
205 }
206