Skip to content

Commit 2e0ddfd

Browse files
committed
Caching is not based on locale
1 parent f86c325 commit 2e0ddfd

File tree

5 files changed

+271
-0
lines changed

5 files changed

+271
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.app170;
20+
21+
import javax.validation.Valid;
22+
import javax.validation.constraints.NotBlank;
23+
24+
import org.springframework.http.HttpEntity;
25+
import org.springframework.web.bind.annotation.GetMapping;
26+
import org.springframework.web.bind.annotation.RestController;
27+
28+
import io.swagger.v3.oas.annotations.tags.Tag;
29+
30+
@RestController
31+
@Tag(name = "greeting", description = "test")
32+
public class HelloLocaleController {
33+
34+
@GetMapping("/persons")
35+
public void persons(@Valid @NotBlank String name) {
36+
}
37+
38+
@GetMapping("/test")
39+
@Tag(name = "lang.change")
40+
public HttpEntity<String> demo2() {
41+
return null;
42+
}
43+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.app170;
20+
21+
import static org.hamcrest.Matchers.is;
22+
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
23+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
24+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
25+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
26+
27+
import java.util.Locale;
28+
29+
import org.junit.jupiter.api.Test;
30+
import org.springdoc.core.Constants;
31+
import org.springframework.boot.autoconfigure.SpringBootApplication;
32+
import org.springframework.context.annotation.Bean;
33+
import org.springframework.http.HttpHeaders;
34+
import org.springframework.test.context.TestPropertySource;
35+
import org.springframework.test.web.servlet.MvcResult;
36+
import org.springframework.web.servlet.LocaleResolver;
37+
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
38+
39+
import test.org.springdoc.api.AbstractSpringDocTest;
40+
41+
//@TestPropertySource(properties = Constants.SPRINGDOC_CACHE_DISABLED + "=true")
42+
public class SpringDocApp170Test extends AbstractSpringDocTest {
43+
44+
@SpringBootApplication
45+
static class SpringDocTestApp {}
46+
47+
@Bean
48+
public LocaleResolver localeResolver() {
49+
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
50+
localeResolver.setDefaultLocale(Locale.US);
51+
return localeResolver;
52+
}
53+
54+
@Test
55+
@Override
56+
public void testApp() throws Exception {
57+
Locale locale = new Locale("en","US");
58+
Locale.setDefault(locale);
59+
60+
className = getClass().getSimpleName();
61+
String testNumber = className.replaceAll("[^0-9]", "");
62+
MvcResult mockMvcResult =
63+
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL).locale(locale).header(HttpHeaders.ACCEPT_LANGUAGE, locale.toLanguageTag())).andExpect(status().isOk())
64+
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
65+
String result = mockMvcResult.getResponse().getContentAsString();
66+
String expected = getContent("results/app" + testNumber + "-1.json");
67+
assertEquals(expected, result, true);
68+
}
69+
70+
@Test
71+
public void testAppFr() throws Exception {
72+
Locale locale = new Locale("fr","FR");
73+
Locale.setDefault(locale);
74+
75+
className = getClass().getSimpleName();
76+
String testNumber = className.replaceAll("[^0-9]", "");
77+
MvcResult mockMvcResult =
78+
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL).locale(locale).header(HttpHeaders.ACCEPT_LANGUAGE, locale.toLanguageTag())).andExpect(status().isOk())
79+
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
80+
String result = mockMvcResult.getResponse().getContentAsString();
81+
String expected = getContent("results/app" + testNumber + "-2.json");
82+
assertEquals(expected, result, true);
83+
}
84+
85+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
greeting=Hello! Welcome to our website![FR]
2+
lang.change=Change the language[FR]
3+
lang.eng=English[FR]
4+
lang.fr=French[FR]
5+
mySample=toto[FR]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"tags": [
14+
{
15+
"name": "Change the language"
16+
},
17+
{
18+
"name": "Hello! Welcome to our website!",
19+
"description": "test"
20+
}
21+
],
22+
"paths": {
23+
"/test": {
24+
"get": {
25+
"tags": [
26+
"Change the language",
27+
"Hello! Welcome to our website!"
28+
],
29+
"operationId": "demo2",
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"/persons": {
45+
"get": {
46+
"tags": [
47+
"Hello! Welcome to our website!"
48+
],
49+
"operationId": "persons",
50+
"parameters": [
51+
{
52+
"name": "name",
53+
"in": "query",
54+
"required": true,
55+
"schema": {
56+
"type": "string"
57+
}
58+
}
59+
],
60+
"responses": {
61+
"200": {
62+
"description": "OK"
63+
}
64+
}
65+
}
66+
}
67+
},
68+
"components": {}
69+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"tags": [
14+
{
15+
"name": "Change the language[FR]"
16+
},
17+
{
18+
"name": "Hello! Welcome to our website![FR]",
19+
"description": "test"
20+
}
21+
],
22+
"paths": {
23+
"/test": {
24+
"get": {
25+
"tags": [
26+
"Change the language[FR]",
27+
"Hello! Welcome to our website![FR]"
28+
],
29+
"operationId": "demo2",
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"type": "string"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"/persons": {
45+
"get": {
46+
"tags": [
47+
"Hello! Welcome to our website![FR]"
48+
],
49+
"operationId": "persons",
50+
"parameters": [
51+
{
52+
"name": "name",
53+
"in": "query",
54+
"required": true,
55+
"schema": {
56+
"type": "string"
57+
}
58+
}
59+
],
60+
"responses": {
61+
"200": {
62+
"description": "OK"
63+
}
64+
}
65+
}
66+
}
67+
},
68+
"components": {}
69+
}

0 commit comments

Comments
 (0)