Skip to content

Commit 420ad3f

Browse files
committed
Test to proof that resources with syntax error will be ignored and all other get parsed (#568)
1 parent 472a970 commit 420ad3f

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
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+
* https://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 org.springframework.sbm.project.parser;
17+
18+
import org.junit.jupiter.api.DisplayName;
19+
import org.junit.jupiter.api.Test;
20+
import org.openrewrite.SourceFile;
21+
import org.openrewrite.yaml.tree.Yaml;
22+
import org.springframework.sbm.engine.context.ProjectContext;
23+
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
24+
import org.springframework.sbm.project.resource.TestProjectContext;
25+
26+
import java.util.List;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* @author Fabian Krüger
32+
*/
33+
public class ForgivingParsingOfTestResourcesTest {
34+
35+
@Test
36+
@DisplayName("Proof that resource with syntax error is excluded from AST but other resources aren't")
37+
void test_renameMe() {
38+
ProjectContext context = TestProjectContext
39+
.buildProjectContext()
40+
.addProjectResource("src/test/resources/one.yaml", "valid: true")
41+
.addProjectResource("src/test/resources/error.yaml",
42+
"""
43+
min-risk-score:
44+
100 # illegal line break
45+
attenuation-duration: !include attenuation-duration_ok.yaml
46+
risk-score-classes: !include risk-score-class_ok.yaml # illegal indentation
47+
exposure-config: !include exposure-config_ok.yaml
48+
""")
49+
.addProjectResource("src/test/resources/three.yaml", "is.valid: true")
50+
.build();
51+
52+
List<RewriteSourceFileHolder<? extends SourceFile>> parsedResources = context.getProjectResources().list();
53+
assertThat(parsedResources).hasSize(3);
54+
assertThat(parsedResources.get(0).getSourcePath().toString()).isEqualTo("pom.xml");
55+
assertThat(parsedResources.get(1).getSourcePath().toString()).isEqualTo("src/test/resources/one.yaml");
56+
// src/test/resources/error.yaml is ignored
57+
assertThat(parsedResources.get(2).getSourcePath().toString()).isEqualTo("src/test/resources/three.yaml");
58+
}
59+
}

0 commit comments

Comments
 (0)