View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */
19  package org.apache.rat.testhelpers.data;
20  
21  import java.nio.file.Path;
22  import java.nio.file.Paths;
23  import org.apache.rat.ReportConfiguration;
24  import org.apache.rat.Reporter;
25  import org.apache.rat.document.DocumentName;
26  import org.apache.rat.report.claim.ClaimStatistic;
27  import org.w3c.dom.Document;
28  
29  /**
30   * The validator for test data.
31   */
32  public final class ValidatorData {
33      /** The report output */
34      private final Reporter.Output output;
35      /** the base directory where the test setup was created */
36      private final Path baseDir;
37  
38      /**
39       * Constructor.
40       * @param output The report output.
41       * @param baseDir the directory where the test setup was created.
42       */
43      public ValidatorData(final Reporter.Output output, final String baseDir) {
44          this.output = output;
45          this.baseDir = Paths.get(baseDir);
46      }
47  
48      /**
49       * Gets the directory where the test setup was created as a DocumentName.
50       * @return the DocumentName for the baseDir directory.
51       */
52      public DocumentName getBaseName() {
53          return DocumentName.builder(baseDir.toFile()).build();
54      }
55  
56      /**
57       * Creates a DocumentName for a file name.  The root of the document Name will be the baseDir.
58       * @param fileName the file name to create a document name for.
59       * @return the Document name for the file.
60       */
61      public DocumentName mkDocName(String fileName) {
62          return DocumentName.builder().setBaseName(baseDir.toFile()).setName(fileName).build();
63      }
64  
65      /**
66       * Gets the reporter output object.
67       * @return the reporter output object.
68       */
69      public Reporter.Output getOutput() {
70          return output;
71      }
72  
73      /**
74       * Gets the document that was generated during execution.
75       * @return the document that was generated during execution.
76       */
77      public Document getDocument() {
78          return output.getDocument();
79      }
80  
81      /**
82       * Gets the claim statistics from the run
83       * @return the ClaimStatistic from the run.
84       */
85      public ClaimStatistic getStatistic() {
86          return output.getStatistic();
87      }
88  
89      /**
90       * Gets the configuration from the run.
91       * @return the configuration from the run.
92       */
93      public ReportConfiguration getConfiguration() {
94          return output.getConfiguration();
95      }
96  
97      /**
98       * Gets the path to the base directory.
99       * @return the path to the base directory.
100      */
101     public Path getBaseDir() {
102         return baseDir;
103     }
104 
105 }