Skip to content

Commit ace219f

Browse files
authored
[HotFix][Core][API] Fix OptionValidation error code (#3439)
* [BugFix][Api][Option] Fix OptionValidation error code * [BugFix][Api][Option] Update assert * [BugFix][Api][Option] Fix code * [BugFix][Api][Option] Fix code format * [BugFix][Api][Option] Fix code format
1 parent 7bf00fb commit ace219f

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

seatunnel-api/src/main/java/org/apache/seatunnel/api/configuration/util/OptionValidationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public OptionValidationException(String message) {
3434
}
3535

3636
public OptionValidationException(String formatMessage, Object... args) {
37-
super(String.format(formatMessage, args));
37+
super(SeaTunnelAPIErrorCode.OPTION_VALIDATION_FAILED, String.format(formatMessage, args));
3838
}
3939
}

seatunnel-api/src/test/java/org/apache/seatunnel/api/configuration/util/ConfigValidatorTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public void testAbsolutelyRequiredOption() {
7878

7979
// absent
8080
config.put(TEST_PORTS.key(), "[9090]");
81-
assertEquals("There are unconfigured options, the options('password', 'username') are required.",
81+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('password', 'username') are required.",
8282
assertThrows(OptionValidationException.class, executable).getMessage());
8383

8484
config.put(KEY_USERNAME.key(), "asuka");
85-
assertEquals("There are unconfigured options, the options('password') are required.",
85+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('password') are required.",
8686
assertThrows(OptionValidationException.class, executable).getMessage());
8787

8888
// all present
@@ -102,7 +102,7 @@ public void testBundledRequiredOptions() {
102102

103103
// case2: some present
104104
config.put(KEY_USERNAME.key(), "asuka");
105-
assertEquals("These options('password', 'username') are bundled, must be present or absent together." +
105+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options('password', 'username') are bundled, must be present or absent together." +
106106
" The options present are: 'username'. The options absent are 'password'.",
107107
assertThrows(OptionValidationException.class, executable).getMessage());
108108

@@ -120,7 +120,7 @@ public void testSimpleExclusiveRequiredOptions() {
120120
Executable executable = () -> validate(config, rule);
121121

122122
// all absent
123-
assertEquals("There are unconfigured options, these options(['option.topic-pattern'], ['option.topic']) are mutually exclusive," +
123+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, these options(['option.topic-pattern'], ['option.topic']) are mutually exclusive," +
124124
" allowing only one set(\"[] for a set\") of options to be configured.",
125125
assertThrows(OptionValidationException.class, executable).getMessage());
126126

@@ -130,7 +130,7 @@ public void testSimpleExclusiveRequiredOptions() {
130130

131131
// present > 1
132132
config.put(TEST_TOPIC.key(), "[\"saitou\"]");
133-
assertEquals("These options(['option.topic-pattern'], ['option.topic']) are mutually exclusive, " +
133+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options(['option.topic-pattern'], ['option.topic']) are mutually exclusive, " +
134134
"allowing only one set(\"[] for a set\") of options to be configured.",
135135
assertThrows(OptionValidationException.class, executable).getMessage());
136136
}
@@ -147,13 +147,13 @@ public void testComplexExclusiveRequiredOptions() {
147147
Executable executable = () -> validate(config, rule);
148148

149149
// all absent
150-
assertEquals("There are unconfigured options, these options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
150+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, these options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
151151
" allowing only one set(\"[] for a set\") of options to be configured.",
152152
assertThrows(OptionValidationException.class, executable).getMessage());
153153

154154
// bundled option some present
155155
config.put(KEY_USERNAME.key(), "asuka");
156-
assertEquals("These options('password', 'username') are bundled, must be present or absent together." +
156+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options('password', 'username') are bundled, must be present or absent together." +
157157
" The options present are: 'username'. The options absent are 'password'.",
158158
assertThrows(OptionValidationException.class, executable).getMessage());
159159

@@ -163,13 +163,13 @@ public void testComplexExclusiveRequiredOptions() {
163163

164164
// tow set options present
165165
config.put(KEY_BEARER_TOKEN.key(), "ashulin");
166-
assertEquals("These options(['password', 'username'], ['bearer-token']) are mutually exclusive," +
166+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options(['password', 'username'], ['bearer-token']) are mutually exclusive," +
167167
" allowing only one set(\"[] for a set\") of options to be configured.",
168168
assertThrows(OptionValidationException.class, executable).getMessage());
169169

170170
// three set options present
171171
config.put(KEY_KERBEROS_TICKET.key(), "zongwen");
172-
assertEquals("These options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
172+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - These options(['kerberos-ticket'], ['password', 'username'], ['bearer-token']) are mutually exclusive," +
173173
" allowing only one set(\"[] for a set\") of options to be configured.",
174174
assertThrows(OptionValidationException.class, executable).getMessage());
175175
}
@@ -187,7 +187,7 @@ public void testSimpleConditionalRequiredOptionsWithDefaultValue() {
187187

188188
// Expression match, and required options absent
189189
config.put(TEST_MODE.key(), "timestamp");
190-
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
190+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
191191
" because ['option.mode' == TIMESTAMP] is true.",
192192
assertThrows(OptionValidationException.class, executable).getMessage());
193193

@@ -213,7 +213,7 @@ public void testSimpleConditionalRequiredOptionsWithoutDefaultValue() {
213213

214214
// Expression match, and required options absent
215215
config.put(KEY_USERNAME.key(), "ashulin");
216-
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
216+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
217217
" because ['username' == ashulin] is true.",
218218
assertThrows(OptionValidationException.class, executable).getMessage());
219219

@@ -242,7 +242,7 @@ public void testComplexConditionalRequiredOptions() {
242242

243243
// 'username' == ashulin, and required options absent
244244
config.put(KEY_USERNAME.key(), "ashulin");
245-
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
245+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
246246
" because ['username' == ashulin || ('username' == asuka && 'password' == saito)] is true.",
247247
assertThrows(OptionValidationException.class, executable).getMessage());
248248

@@ -260,7 +260,7 @@ public void testComplexConditionalRequiredOptions() {
260260

261261
// 'username' == asuka && 'password' == saito, and required options absent
262262
config.remove(TEST_TIMESTAMP.key());
263-
assertEquals("There are unconfigured options, the options('option.timestamp') are required" +
263+
assertEquals("ErrorCode:[API-02], ErrorDescription:[Option item validate failed] - There are unconfigured options, the options('option.timestamp') are required" +
264264
" because ['username' == ashulin || ('username' == asuka && 'password' == saito)] is true.",
265265
assertThrows(OptionValidationException.class, executable).getMessage());
266266
}

seatunnel-connectors-v2/connector-http/connector-http-myhours/src/main/java/org/apache/seatunnel/connectors/seatunnel/myhours/source/config/MyHoursSourceParameter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.seatunnel.common.utils.JsonUtils;
2121
import org.apache.seatunnel.connectors.seatunnel.http.config.HttpParameter;
22+
import org.apache.seatunnel.connectors.seatunnel.http.config.HttpRequestMethod;
2223

2324
import org.apache.seatunnel.shade.com.typesafe.config.Config;
2425

@@ -38,7 +39,7 @@ public void buildWithLoginConfig(Config pluginConfig) {
3839
// set url
3940
this.setUrl(MyHoursSourceConfig.AUTHORIZATION_URL);
4041
// set method
41-
this.setMethod(MyHoursSourceConfig.POST);
42+
this.setMethod(HttpRequestMethod.valueOf(MyHoursSourceConfig.POST));
4243
// set body
4344
Map<String, String> bodyParams = new HashMap<>();
4445
String email = pluginConfig.getString(MyHoursSourceConfig.EMAIL.key());

0 commit comments

Comments
 (0)