|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
5 | 5 |
|
6 | 6 | import java.math.BigDecimal;
|
| 7 | +import java.util.ArrayList; |
7 | 8 | import java.util.Arrays;
|
| 9 | +import java.util.Collections; |
| 10 | +import java.util.List; |
8 | 11 | import java.util.Map;
|
9 |
| -import java.util.Set; |
10 |
| -import java.util.TreeSet; |
11 | 12 |
|
12 | 13 | import org.eclipse.microprofile.config.Config;
|
13 | 14 | import org.eclipse.microprofile.openapi.annotations.media.Schema;
|
@@ -49,42 +50,52 @@ void testJacksonNamingOverridesConfig() throws Exception {
|
49 | 50 | }
|
50 | 51 |
|
51 | 52 | @Test
|
52 |
| - void testInvalidNamingStrategyClass() throws Exception { |
| 53 | + void testInvalidNamingStrategyClass() { |
53 | 54 | Config config = config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY,
|
54 | 55 | "com.fasterxml.jackson.databind.PropertyNamingStrategies$InvalidStrategy");
|
55 | 56 | assertThrows(OpenApiRuntimeException.class, () -> scan(config, NameStrategyKebab.class));
|
56 | 57 | }
|
57 | 58 |
|
58 | 59 | @Test
|
59 |
| - void testNoValidTranslationMethods() throws Exception { |
| 60 | + void testNoValidTranslationMethods() { |
60 | 61 | Config config = config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY,
|
61 | 62 | NoValidTranslationMethods.class.getName());
|
62 | 63 | assertThrows(OpenApiRuntimeException.class, () -> scan(config, NameStrategyKebab.class));
|
63 | 64 | }
|
64 | 65 |
|
65 | 66 | @Test
|
66 |
| - void testInvalidPropertyNameTranslationAttempt() throws Exception { |
| 67 | + void testInvalidPropertyNameTranslationAttempt() { |
67 | 68 | Config config = config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY,
|
68 | 69 | TranslationThrowsException.class.getName());
|
69 | 70 | assertThrows(OpenApiRuntimeException.class, () -> scan(config, NameStrategyBean3.class));
|
70 | 71 | }
|
71 | 72 |
|
72 | 73 | @ParameterizedTest(name = "testJsonbConstantStrategy-{0}")
|
73 | 74 | @CsvSource({
|
74 |
| - JsonbConstants.IDENTITY + ", simpleStringOne|anotherField|Y|z", |
75 |
| - JsonbConstants.LOWER_CASE_WITH_DASHES + ", simple-string-one|another-field|y|z", |
76 |
| - JsonbConstants.LOWER_CASE_WITH_UNDERSCORES + ", simple_string_one|another_field|y|z", |
77 |
| - JsonbConstants.UPPER_CAMEL_CASE + ", SimpleStringOne|AnotherField|Y|Z", |
78 |
| - JsonbConstants.UPPER_CAMEL_CASE_WITH_SPACES + ", Simple String One|Another Field|Y|Z", |
79 |
| - JsonbConstants.CASE_INSENSITIVE + ", simpleStringOne|anotherField|Y|z" |
| 75 | + JsonbConstants.IDENTITY + ", simpleStringOne|anotherField|Y|z|SOMEValue", |
| 76 | + JsonbConstants.LOWER_CASE_WITH_DASHES + ", simple-string-one|another-field|y|z|some-value", |
| 77 | + JsonbConstants.LOWER_CASE_WITH_UNDERSCORES + ", simple_string_one|another_field|y|z|some_value", |
| 78 | + JsonbConstants.UPPER_CAMEL_CASE + ", SimpleStringOne|AnotherField|Y|Z|SOMEValue", |
| 79 | + JsonbConstants.UPPER_CAMEL_CASE_WITH_SPACES + ", Simple String One|Another Field|Y|Z|SOME Value", |
| 80 | + JsonbConstants.CASE_INSENSITIVE + ", simpleStringOne|anotherField|Y|z|SOMEValue" |
80 | 81 | })
|
81 |
| - void testJsonbConstantStrategy(String strategy, String expectedNames) throws Exception { |
| 82 | + void testJsonbConstantStrategy(String strategy, String expectedNames) { |
82 | 83 | OpenAPI result = scan(config(SmallRyeOASConfig.SMALLRYE_PROPERTY_NAMING_STRATEGY, strategy), NameStrategyBean3.class);
|
83 |
| - Set<String> expectedNameSet = new TreeSet<>(Arrays.asList(expectedNames.split("\\|"))); |
| 84 | + List<String> expectedNameList = Arrays.asList(expectedNames.split("\\|")); |
| 85 | + Collections.sort(expectedNameList, String::compareToIgnoreCase); |
| 86 | + |
84 | 87 | Map<String, org.eclipse.microprofile.openapi.models.media.Schema> schemas = result.getComponents().getSchemas();
|
85 | 88 | org.eclipse.microprofile.openapi.models.media.Schema schema = schemas.get(NameStrategyBean3.class.getSimpleName());
|
86 |
| - assertEquals(expectedNameSet.size(), schema.getProperties().size()); |
87 |
| - assertEquals(expectedNameSet, schema.getProperties().keySet()); |
| 89 | + List<String> actualNameList = new ArrayList<>(schema.getProperties().keySet()); |
| 90 | + Collections.sort(actualNameList, String::compareToIgnoreCase); |
| 91 | + |
| 92 | + assertEquals(expectedNameList, actualNameList); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + void testMethodNamePreserved() throws Exception { |
| 97 | + OpenAPI result = scan(NameStrategyBean4.class); |
| 98 | + assertJsonEquals("components.schemas.method-name-preserved.json", result); |
88 | 99 | }
|
89 | 100 |
|
90 | 101 | @Schema
|
@@ -114,18 +125,60 @@ static class NameStrategyKebab {
|
114 | 125 | static class NameStrategyBean3 {
|
115 | 126 | String simpleStringOne;
|
116 | 127 | Integer anotherField;
|
117 |
| - BigDecimal Y; |
| 128 | + BigDecimal Y; // NOSONAR - naming intentional |
118 | 129 | double z;
|
| 130 | + String SOMEValue; // NOSONAR - naming intentional |
| 131 | + |
| 132 | + public String getSimpleStringOne() { |
| 133 | + return simpleStringOne; |
| 134 | + } |
| 135 | + |
| 136 | + public Integer getAnotherField() { |
| 137 | + return anotherField; |
| 138 | + } |
| 139 | + |
| 140 | + public BigDecimal getY() { |
| 141 | + return Y; |
| 142 | + } |
| 143 | + |
| 144 | + public double getZ() { |
| 145 | + return z; |
| 146 | + } |
| 147 | + |
| 148 | + public String getSOMEValue() { |
| 149 | + return SOMEValue; |
| 150 | + } |
119 | 151 | }
|
120 | 152 |
|
121 |
| - public static class NoValidTranslationMethods { |
122 |
| - public NoValidTranslationMethods() { |
| 153 | + @Schema |
| 154 | + static class NameStrategyBean4 { |
| 155 | + @Schema(name = "TESTValue", title = "Test Value") |
| 156 | + Integer TestValue; // NOSONAR - naming intentional |
| 157 | + |
| 158 | + @Schema(name = "eValue", title = "e-Value") |
| 159 | + String EValue; // NOSONAR - naming intentional |
| 160 | + |
| 161 | + @Schema(description = "Property for TestValue") |
| 162 | + public Integer getTESTValue() { |
| 163 | + return TestValue; |
| 164 | + } |
| 165 | + |
| 166 | + @Schema(description = "Property for e-Value") |
| 167 | + public String geteValue() { |
| 168 | + return EValue; |
123 | 169 | }
|
124 | 170 |
|
| 171 | + } |
| 172 | + |
| 173 | + public static class NoValidTranslationMethods { |
125 | 174 | public String translate() {
|
126 | 175 | return null;
|
127 | 176 | }
|
128 | 177 |
|
| 178 | + /** |
| 179 | + * @param v1 unused, demonstrated unsuitable translate method signature |
| 180 | + * @param v2 unused, demonstrated unsuitable translate method signature |
| 181 | + */ |
129 | 182 | public String translate(String v1, String v2) {
|
130 | 183 | return null;
|
131 | 184 | }
|
|
0 commit comments