|
24 | 24 | import java.nio.charset.StandardCharsets; |
25 | 25 | import java.nio.file.Path; |
26 | 26 | import java.nio.file.Paths; |
| 27 | +import java.util.ArrayList; |
| 28 | +import java.util.LinkedList; |
| 29 | +import java.util.List; |
27 | 30 |
|
28 | 31 | import org.junit.Before; |
29 | 32 | import org.junit.Test; |
@@ -129,6 +132,16 @@ public void parse_error() { |
129 | 132 | ); |
130 | 133 | } |
131 | 134 |
|
| 135 | + @Test |
| 136 | + public void parse_openapi3_headers_ref() { |
| 137 | + inputFile("headers_ref.yaml"); |
| 138 | + activeRules = (new ActiveRulesBuilder()) |
| 139 | + .create(RuleKey.of(CheckList.REPOSITORY_KEY, ParsingErrorCheck.CHECK_KEY)) |
| 140 | + .activate() |
| 141 | + .build(); |
| 142 | + sensor().execute(context); |
| 143 | + } |
| 144 | + |
132 | 145 | @Test |
133 | 146 | public void parse_yaml_break_comment_ok() { |
134 | 147 | inputFile("parse-yaml.yaml"); |
@@ -165,6 +178,21 @@ public void parse_yaml_tabs_ok() { |
165 | 178 | assertThat(context.allAnalysisErrors()).hasSize(0); |
166 | 179 | } |
167 | 180 |
|
| 181 | + //@Test |
| 182 | + public void test_folder() { |
| 183 | + List<String> files = listFiles("files"); |
| 184 | + List<String> errorFiles = new LinkedList<>(); |
| 185 | + for (String file: files) { |
| 186 | + context = SensorContextTester.create(baseDir); |
| 187 | + inputFile(file); |
| 188 | + activeRules = (new ActiveRulesBuilder()).create(RuleKey.of(CheckList.REPOSITORY_KEY, ParsingErrorCheck.CHECK_KEY)) |
| 189 | + .activate().build(); |
| 190 | + sensor().execute(context); |
| 191 | + if (!context.allIssues().isEmpty() || !context.allAnalysisErrors().isEmpty()) errorFiles.add(file); |
| 192 | + } |
| 193 | + System.out.println(errorFiles); |
| 194 | + } |
| 195 | + |
168 | 196 | @Test |
169 | 197 | public void cancelled_analysis() { |
170 | 198 | InputFile inputFile = inputFile("file1.yaml"); |
@@ -193,4 +221,22 @@ private InputFile inputFile(String name) { |
193 | 221 | context.fileSystem().add(inputFile); |
194 | 222 | return inputFile; |
195 | 223 | } |
| 224 | + |
| 225 | + private List<String> listFiles(String folderName) { |
| 226 | + File folder = baseDir.resolve(folderName).toAbsolutePath().toFile(); |
| 227 | + return listFilesInFolder(folder, baseDir.toFile()); |
| 228 | + } |
| 229 | + private static List<String> listFilesInFolder(File folder, File baseFolder) { |
| 230 | + File[] files = folder.listFiles(); |
| 231 | + List<String> allPaths = new ArrayList<>(); |
| 232 | + for (File file : files) { |
| 233 | + if (file.isFile()) { |
| 234 | + String relativePath = baseFolder.toURI().relativize(file.toURI()).getPath(); |
| 235 | + allPaths.add(relativePath); |
| 236 | + } else if (file.isDirectory()) { |
| 237 | + allPaths.addAll(listFilesInFolder(file, baseFolder)); |
| 238 | + } |
| 239 | + } |
| 240 | + return allPaths; |
| 241 | + } |
196 | 242 | } |
0 commit comments