Skip to content

Commit e02115f

Browse files
committed
Add failing test with multiple locales and customizer accessing getServers()
1 parent 542f12f commit e02115f

File tree

4 files changed

+225
-0
lines changed

4 files changed

+225
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://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+
19+
package test.org.springdoc.api.app189;
20+
21+
import io.swagger.v3.oas.annotations.Operation;
22+
import io.swagger.v3.oas.annotations.Parameter;
23+
import io.swagger.v3.oas.annotations.media.Content;
24+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
25+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
26+
import org.springframework.http.MediaType;
27+
import org.springframework.http.codec.multipart.FilePart;
28+
import org.springframework.web.bind.annotation.PostMapping;
29+
import org.springframework.web.bind.annotation.RequestPart;
30+
import org.springframework.web.bind.annotation.RestController;
31+
import reactor.core.publisher.Mono;
32+
33+
34+
@RestController
35+
public class HelloController {
36+
37+
38+
@Operation(summary = "Parse Resume")
39+
@PostMapping(value = "/parse-resume", produces = { MediaType.APPLICATION_JSON_VALUE }, consumes = {
40+
MediaType.MULTIPART_FORM_DATA_VALUE })
41+
@ApiResponses({ @ApiResponse(responseCode = "400", description = "Invalid input") })
42+
public Mono<String> parse(
43+
@RequestPart(name = "resumeFile") @Parameter(description = "Resume file to be parsed", content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE)) FilePart resumeFile) {
44+
return null;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://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+
19+
package test.org.springdoc.api.app189;
20+
21+
import org.json.JSONException;
22+
import org.junit.jupiter.api.Test;
23+
import org.springdoc.core.Constants;
24+
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
25+
import org.springframework.test.web.reactive.server.EntityExchangeResult;
26+
import test.org.springdoc.api.AbstractCommonTest;
27+
28+
import java.time.Duration;
29+
30+
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
31+
32+
@WebFluxTest
33+
public class SpringDocApp189Test extends AbstractCommonTest {
34+
35+
@Test
36+
public void testWithDifferentLocales() throws Exception {
37+
runTestWithLocale("en-GB");
38+
runTestWithLocale("de-DE");
39+
}
40+
41+
private void runTestWithLocale(String locale) throws JSONException {
42+
EntityExchangeResult<byte[]> getResult = webTestClient.mutate().responseTimeout(Duration.ofMinutes(1000)).build()
43+
.get().uri(Constants.DEFAULT_API_DOCS_URL)
44+
.header("Accept-Language", locale)
45+
.exchange()
46+
.expectStatus().isOk().expectBody().returnResult();
47+
48+
String result = new String(getResult.getResponseBody());
49+
String className = getClass().getSimpleName();
50+
String testNumber = className.replaceAll("[^0-9]", "");
51+
String expected = getContent("results/app" + testNumber + ".json");
52+
assertEquals(expected, result, true);
53+
}
54+
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://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+
19+
package test.org.springdoc.api.app189;
20+
21+
import io.swagger.v3.oas.models.Components;
22+
import io.swagger.v3.oas.models.OpenAPI;
23+
import io.swagger.v3.oas.models.info.Info;
24+
import io.swagger.v3.oas.models.info.License;
25+
import io.swagger.v3.oas.models.security.SecurityScheme;
26+
import org.springdoc.core.customizers.OpenApiCustomiser;
27+
import org.springframework.boot.SpringApplication;
28+
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
import org.springframework.context.annotation.Bean;
30+
import org.springframework.context.annotation.ComponentScan;
31+
32+
@SpringBootApplication
33+
@ComponentScan(basePackages = { "org.springdoc", "test.org.springdoc.api.app189" })
34+
public class SpringDocTestApp {
35+
public static void main(String[] args) {
36+
SpringApplication.run(SpringDocTestApp.class, args);
37+
}
38+
39+
@Bean
40+
public OpenAPI customOpenAPI() {
41+
return new OpenAPI()
42+
.components(new Components().addSecuritySchemes("basicScheme",
43+
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
44+
.info(new Info().title("Tweet API").version("v0")
45+
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
46+
}
47+
48+
@Bean
49+
OpenApiCustomiser serverUrlCustomizer() {
50+
return openApi ->
51+
openApi.getServers().forEach(server -> {
52+
server.setDescription("customized description");
53+
server.setUrl("https://customized.url");
54+
System.out.println(server);
55+
});
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "Tweet API",
5+
"license": {
6+
"name": "Apache 2.0",
7+
"url": "http://springdoc.org"
8+
},
9+
"version": "v0"
10+
},
11+
"servers": [
12+
{
13+
"url": "https://customized.url",
14+
"description": "customized description"
15+
}
16+
],
17+
"paths": {
18+
"/parse-resume": {
19+
"post": {
20+
"tags": [
21+
"hello-controller"
22+
],
23+
"summary": "Parse Resume",
24+
"operationId": "parse",
25+
"requestBody": {
26+
"content": {
27+
"multipart/form-data": {
28+
"schema": {
29+
"required": [
30+
"resumeFile"
31+
],
32+
"type": "object",
33+
"properties": {
34+
"resumeFile": {
35+
"type": "string",
36+
"description": "Resume file to be parsed",
37+
"format": "binary"
38+
}
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"responses": {
45+
"400": {
46+
"description": "Invalid input",
47+
"content": {
48+
"application/json": {
49+
"schema": {
50+
"type": "string"
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
},
59+
"components": {
60+
"securitySchemes": {
61+
"basicScheme": {
62+
"type": "http",
63+
"scheme": "basic"
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)