Skip to content

Commit b151240

Browse files
Fix code formatting style in YamlValidationTest for issue #2628
1 parent 3adc5fd commit b151240

1 file changed

Lines changed: 28 additions & 31 deletions

File tree

test-harness/src/test/java/io/jenkins/plugins/casc/YamlValidationTest.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.containsString;
5-
import static org.hamcrest.Matchers.equalTo;
65
import static org.hamcrest.Matchers.is;
7-
import static org.junit.jupiter.api.Assertions.assertEquals;
86

97
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
108
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
@@ -32,76 +30,74 @@ public class YamlValidationTest {
3230
void validYaml(JenkinsConfiguredWithCodeRule j) throws Exception {
3331
// Disable CSRF protection to simplify testing
3432
j.jenkins.setCrumbIssuer(null);
35-
36-
WebResponse response = performYamlValidation(j,
37-
"jenkins:\n systemMessage: \"Hello from test\"");
38-
33+
34+
WebResponse response = performYamlValidation(j, "jenkins:\n systemMessage: \"Hello from test\"");
35+
3936
assertThat(response.getStatusCode(), is(200));
4037
assertThat(response.getContentType(), is("application/json"));
41-
38+
4239
JSONArray jsonResponse = JSONArray.fromObject(response.getContentAsString());
4340
assertThat(jsonResponse.size(), is(0));
4441
}
45-
42+
4643
/**
4744
* Tests that YAML with incorrect indentation returns proper JSON response.
4845
*/
4946
@Test
5047
@Issue("2628")
5148
void invalidIndentation(JenkinsConfiguredWithCodeRule j) throws Exception {
5249
j.jenkins.setCrumbIssuer(null);
53-
54-
WebResponse response = performYamlValidation(j,
55-
"jenkins:\nsystemMessage: \"Bad indentation\"");
56-
50+
51+
WebResponse response = performYamlValidation(j, "jenkins:\nsystemMessage: \"Bad indentation\"");
52+
5753
assertThat(response.getContentType(), is("application/json"));
58-
54+
5955
// Verify the response contains valid JSON regardless of status code
6056
String responseString = response.getContentAsString();
6157
JSONArray jsonResponse = JSONArray.fromObject(responseString);
62-
58+
6359
// The response should be a non-empty JSON array
6460
assertThat("Should return error details", jsonResponse.size() > 0, is(true));
6561
}
66-
62+
6763
/**
6864
* Tests that YAML with invalid structure returns proper JSON response.
6965
*/
7066
@Test
7167
@Issue("2628")
7268
void invalidStructure(JenkinsConfiguredWithCodeRule j) throws Exception {
7369
j.jenkins.setCrumbIssuer(null);
74-
75-
WebResponse response = performYamlValidation(j,
76-
"jenkins:\n numExecutors: {");
77-
70+
71+
WebResponse response = performYamlValidation(j, "jenkins:\n numExecutors: {");
72+
7873
assertThat(response.getContentType(), is("application/json"));
79-
74+
8075
// Verify the response contains valid JSON regardless of status code
8176
String responseString = response.getContentAsString();
8277
JSONArray jsonResponse = JSONArray.fromObject(responseString);
83-
78+
8479
// The response should be a non-empty JSON array
8580
assertThat("Should return error details", jsonResponse.size() > 0, is(true));
8681
}
87-
82+
8883
/**
8984
* Tests that YAML with unknown property returns proper JSON response.
9085
*/
9186
@Test
9287
@Issue("2628")
9388
void unknownProperty(JenkinsConfiguredWithCodeRule j) throws Exception {
9489
j.jenkins.setCrumbIssuer(null);
95-
96-
WebResponse response = performYamlValidation(j,
90+
91+
WebResponse response = performYamlValidation(
92+
j,
9793
"jenkins:\n nonExistentProperty: \"This property doesn't exist\"\n systemMessage: \"Valid property\"");
98-
94+
9995
assertThat(response.getContentType(), is("application/json"));
100-
96+
10197
// Verify the response contains valid JSON regardless of status code
10298
String responseString = response.getContentAsString();
10399
JSONArray jsonResponse = JSONArray.fromObject(responseString);
104-
100+
105101
// The response should be a non-empty JSON array with details about the unknown property
106102
assertThat("Should return error details", jsonResponse.size() > 0, is(true));
107103
assertThat(responseString, containsString("nonExistentProperty"));
@@ -111,15 +107,16 @@ void unknownProperty(JenkinsConfiguredWithCodeRule j) throws Exception {
111107
* Helper method to perform YAML validation.
112108
*/
113109
private WebResponse performYamlValidation(JenkinsConfiguredWithCodeRule j, String yamlContent) throws Exception {
114-
URL apiURL = new URL(MessageFormat.format("{0}configuration-as-code/check", j.getURL().toString()));
110+
URL apiURL = new URL(MessageFormat.format(
111+
"{0}configuration-as-code/check", j.getURL().toString()));
115112
WebRequest request = new WebRequest(apiURL, HttpMethod.POST);
116113
request.setCharset(StandardCharsets.UTF_8);
117114
request.setRequestBody(yamlContent);
118-
115+
119116
WebClient client = j.createWebClient();
120117
// Don't throw exceptions for error status codes
121118
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
122-
119+
123120
return client.getPage(request).getWebResponse();
124121
}
125-
}
122+
}

0 commit comments

Comments
 (0)