This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new 9d3a2e957 Rename PropertiesPreconditions (#2324)
9d3a2e957 is described below
commit 9d3a2e95726d7c01492c9414e2deff3857bdda09
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Oct 28 20:05:12 2023 +0800
Rename PropertiesPreconditions (#2324)
* Rename PropertiesPreconditions
* Rename PropertiesPreconditions
* Fix test cases
* Fix test cases
---
...DingtalkJobErrorHandlerPropertiesValidator.java | 8 +--
...talkJobErrorHandlerPropertiesValidatorTest.java | 2 +-
.../EmailJobErrorHandlerPropertiesValidator.java | 16 +++---
...mailJobErrorHandlerPropertiesValidatorTest.java | 2 +-
.../WechatJobErrorHandlerPropertiesValidator.java | 8 +--
...chatJobErrorHandlerPropertiesValidatorTest.java | 2 +-
.../infra/exception/PropertiesPreconditions.java | 61 ++++++++++++++++++++++
.../infra/validate/JobPropertiesValidateRule.java | 60 ---------------------
.../PropertiesPreconditionsTest.java} | 18 +++----
9 files changed, 89 insertions(+), 88 deletions(-)
diff --git
a/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidator.java
b/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidator.java
index a652779f0..de97f1bb8 100644
---
a/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidator.java
+++
b/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidator.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.error.handler.dingtalk;
import
org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerPropertiesValidator;
-import
org.apache.shardingsphere.elasticjob.infra.validate.JobPropertiesValidateRule;
+import
org.apache.shardingsphere.elasticjob.infra.exception.PropertiesPreconditions;
import java.util.Properties;
@@ -29,9 +29,9 @@ public final class DingtalkJobErrorHandlerPropertiesValidator
implements JobErro
@Override
public void validate(final Properties props) {
- JobPropertiesValidateRule.validateIsRequired(props,
DingtalkPropertiesConstants.WEBHOOK);
- JobPropertiesValidateRule.validateIsPositiveInteger(props,
DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECONDS);
- JobPropertiesValidateRule.validateIsPositiveInteger(props,
DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECONDS);
+ PropertiesPreconditions.checkRequired(props,
DingtalkPropertiesConstants.WEBHOOK);
+ PropertiesPreconditions.checkPositiveInteger(props,
DingtalkPropertiesConstants.CONNECT_TIMEOUT_MILLISECONDS);
+ PropertiesPreconditions.checkPositiveInteger(props,
DingtalkPropertiesConstants.READ_TIMEOUT_MILLISECONDS);
}
@Override
diff --git
a/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidatorTest.java
b/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidatorTest.java
index 4ee20ef25..55ddddf94 100644
---
a/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidatorTest.java
+++
b/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandlerPropertiesValidatorTest.java
@@ -47,7 +47,7 @@ class DingtalkJobErrorHandlerPropertiesValidatorTest {
void assertValidateWithWebhookIsNull() {
try {
TypedSPILoader.getService(JobErrorHandlerPropertiesValidator.class,
"DINGTALK").validate(new Properties());
- } catch (final NullPointerException ex) {
+ } catch (final IllegalArgumentException ex) {
assertThat(ex.getMessage(), is(String.format("The property `%s` is
required.", DingtalkPropertiesConstants.WEBHOOK)));
}
}
diff --git
a/ecosystem/error-handler/type/email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidator.java
b/ecosystem/error-handler/type/email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidator.java
index 3b0fa050a..a48e20c50 100644
---
a/ecosystem/error-handler/type/email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidator.java
+++
b/ecosystem/error-handler/type/email/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidator.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.error.handler.email;
import
org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerPropertiesValidator;
-import
org.apache.shardingsphere.elasticjob.infra.validate.JobPropertiesValidateRule;
+import
org.apache.shardingsphere.elasticjob.infra.exception.PropertiesPreconditions;
import java.util.Properties;
@@ -29,13 +29,13 @@ public final class EmailJobErrorHandlerPropertiesValidator
implements JobErrorHa
@Override
public void validate(final Properties props) {
- JobPropertiesValidateRule.validateIsRequired(props,
EmailPropertiesConstants.HOST);
- JobPropertiesValidateRule.validateIsRequired(props,
EmailPropertiesConstants.PORT);
- JobPropertiesValidateRule.validateIsPositiveInteger(props,
EmailPropertiesConstants.PORT);
- JobPropertiesValidateRule.validateIsRequired(props,
EmailPropertiesConstants.USERNAME);
- JobPropertiesValidateRule.validateIsRequired(props,
EmailPropertiesConstants.PASSWORD);
- JobPropertiesValidateRule.validateIsRequired(props,
EmailPropertiesConstants.FROM);
- JobPropertiesValidateRule.validateIsRequired(props,
EmailPropertiesConstants.TO);
+ PropertiesPreconditions.checkRequired(props,
EmailPropertiesConstants.HOST);
+ PropertiesPreconditions.checkRequired(props,
EmailPropertiesConstants.PORT);
+ PropertiesPreconditions.checkPositiveInteger(props,
EmailPropertiesConstants.PORT);
+ PropertiesPreconditions.checkRequired(props,
EmailPropertiesConstants.USERNAME);
+ PropertiesPreconditions.checkRequired(props,
EmailPropertiesConstants.PASSWORD);
+ PropertiesPreconditions.checkRequired(props,
EmailPropertiesConstants.FROM);
+ PropertiesPreconditions.checkRequired(props,
EmailPropertiesConstants.TO);
}
@Override
diff --git
a/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
b/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
index b4d614b9d..34e7dd76a 100644
---
a/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
+++
b/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerPropertiesValidatorTest.java
@@ -51,7 +51,7 @@ class EmailJobErrorHandlerPropertiesValidatorTest {
void assertValidateWithHostIsNull() {
try {
TypedSPILoader.getService(JobErrorHandlerPropertiesValidator.class,
"EMAIL").validate(new Properties());
- } catch (final NullPointerException ex) {
+ } catch (final IllegalArgumentException ex) {
assertThat(ex.getMessage(), is(String.format("The property `%s` is
required.", EmailPropertiesConstants.HOST)));
}
}
diff --git
a/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidator.java
b/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidator.java
index b0b07ff54..c2a6947c6 100644
---
a/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidator.java
+++
b/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidator.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.error.handler.wechat;
import
org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandlerPropertiesValidator;
-import
org.apache.shardingsphere.elasticjob.infra.validate.JobPropertiesValidateRule;
+import
org.apache.shardingsphere.elasticjob.infra.exception.PropertiesPreconditions;
import java.util.Properties;
@@ -29,9 +29,9 @@ public final class WechatJobErrorHandlerPropertiesValidator
implements JobErrorH
@Override
public void validate(final Properties props) {
- JobPropertiesValidateRule.validateIsRequired(props,
WechatPropertiesConstants.WEBHOOK);
- JobPropertiesValidateRule.validateIsPositiveInteger(props,
WechatPropertiesConstants.CONNECT_TIMEOUT_MILLISECONDS);
- JobPropertiesValidateRule.validateIsPositiveInteger(props,
WechatPropertiesConstants.READ_TIMEOUT_MILLISECONDS);
+ PropertiesPreconditions.checkRequired(props,
WechatPropertiesConstants.WEBHOOK);
+ PropertiesPreconditions.checkPositiveInteger(props,
WechatPropertiesConstants.CONNECT_TIMEOUT_MILLISECONDS);
+ PropertiesPreconditions.checkPositiveInteger(props,
WechatPropertiesConstants.READ_TIMEOUT_MILLISECONDS);
}
@Override
diff --git
a/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidatorTest.java
b/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidatorTest.java
index 05882b65d..254e2a012 100644
---
a/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidatorTest.java
+++
b/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandlerPropertiesValidatorTest.java
@@ -47,7 +47,7 @@ class WechatJobErrorHandlerPropertiesValidatorTest {
void assertValidateWithWebhookIsNull() {
try {
TypedSPILoader.getService(JobErrorHandlerPropertiesValidator.class,
"WECHAT").validate(new Properties());
- } catch (final NullPointerException ex) {
+ } catch (final IllegalArgumentException ex) {
assertThat(ex.getMessage(), is(String.format("The property `%s` is
required.", WechatPropertiesConstants.WEBHOOK)));
}
}
diff --git
a/infra/src/main/java/org/apache/shardingsphere/elasticjob/infra/exception/PropertiesPreconditions.java
b/infra/src/main/java/org/apache/shardingsphere/elasticjob/infra/exception/PropertiesPreconditions.java
new file mode 100644
index 000000000..60aaecde6
--- /dev/null
+++
b/infra/src/main/java/org/apache/shardingsphere/elasticjob/infra/exception/PropertiesPreconditions.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.infra.exception;
+
+import com.google.common.base.Preconditions;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.Properties;
+
+/**
+ * Properties preconditions.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PropertiesPreconditions {
+
+ /**
+ * Check property value is required.
+ *
+ * @param props properties to be checked
+ * @param key property key to be checked
+ */
+ public static void checkRequired(final Properties props, final String key)
{
+ Preconditions.checkArgument(props.containsKey(key), "The property `%s`
is required.", key);
+ }
+
+ /**
+ * Check property value is positive integer.
+ *
+ * @param props properties to be checked
+ * @param key property key to be checked
+ */
+ public static void checkPositiveInteger(final Properties props, final
String key) {
+ String propertyValue = props.getProperty(key);
+ if (null == propertyValue) {
+ return;
+ }
+ int integerValue;
+ try {
+ integerValue = Integer.parseInt(propertyValue);
+ } catch (final NumberFormatException ignored) {
+ throw new IllegalArgumentException(String.format("The property
`%s` should be integer.", key));
+ }
+ Preconditions.checkArgument(integerValue > 0, "The property `%s`
should be positive.", key);
+ }
+}
diff --git
a/infra/src/main/java/org/apache/shardingsphere/elasticjob/infra/validate/JobPropertiesValidateRule.java
b/infra/src/main/java/org/apache/shardingsphere/elasticjob/infra/validate/JobPropertiesValidateRule.java
deleted file mode 100644
index a13d04ad0..000000000
---
a/infra/src/main/java/org/apache/shardingsphere/elasticjob/infra/validate/JobPropertiesValidateRule.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.elasticjob.infra.validate;
-
-import com.google.common.base.Preconditions;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Properties;
-
-/**
- * Job properties validate rule.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class JobPropertiesValidateRule {
-
- /**
- * Validate property value is required.
- *
- * @param props properties to be validated
- * @param key property key to be validated
- */
- public static void validateIsRequired(final Properties props, final String
key) {
- Preconditions.checkNotNull(props.getProperty(key), "The property `%s`
is required.", key);
- }
-
- /**
- * Validate property value is positive integer.
- *
- * @param props properties to be validated
- * @param key property key to be validated
- */
- public static void validateIsPositiveInteger(final Properties props, final
String key) {
- String propertyValue = props.getProperty(key);
- if (null != propertyValue) {
- int integerValue;
- try {
- integerValue = Integer.parseInt(propertyValue);
- } catch (final NumberFormatException ignored) {
- throw new IllegalArgumentException(String.format("The property
`%s` should be integer.", key));
- }
- Preconditions.checkArgument(integerValue > 0, "The property `%s`
should be positive.", key);
- }
- }
-}
diff --git
a/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/validate/JobPropertiesValidateRuleTest.java
b/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/exception/PropertiesPreconditionsTest.java
similarity index 78%
rename from
infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/validate/JobPropertiesValidateRuleTest.java
rename to
infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/exception/PropertiesPreconditionsTest.java
index aed6124fe..7500c99b9 100644
---
a/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/validate/JobPropertiesValidateRuleTest.java
+++
b/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/exception/PropertiesPreconditionsTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.infra.validate;
+package org.apache.shardingsphere.elasticjob.infra.exception;
import org.junit.jupiter.api.Test;
@@ -24,13 +24,13 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class JobPropertiesValidateRuleTest {
+class PropertiesPreconditionsTest {
@Test
void assertValidateIsRequiredWithValidateError() {
try {
- JobPropertiesValidateRule.validateIsRequired(new Properties(),
"key");
- } catch (NullPointerException ex) {
+ PropertiesPreconditions.checkRequired(new Properties(), "key");
+ } catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), is(String.format("The property `%s` is
required.", "key")));
}
}
@@ -39,19 +39,19 @@ class JobPropertiesValidateRuleTest {
void assertValidateIsRequiredWithNormal() {
Properties props = new Properties();
props.setProperty("key", "value");
- JobPropertiesValidateRule.validateIsRequired(props, "key");
+ PropertiesPreconditions.checkRequired(props, "key");
}
@Test
void assertValidateIsPositiveIntegerWithValueNoExist() {
- JobPropertiesValidateRule.validateIsPositiveInteger(new Properties(),
"key");
+ PropertiesPreconditions.checkPositiveInteger(new Properties(), "key");
}
@Test
void assertValidateIsPositiveIntegerWithNormal() {
Properties props = new Properties();
props.setProperty("key", "1");
- JobPropertiesValidateRule.validateIsPositiveInteger(props, "key");
+ PropertiesPreconditions.checkPositiveInteger(props, "key");
}
@Test
@@ -59,7 +59,7 @@ class JobPropertiesValidateRuleTest {
Properties props = new Properties();
props.setProperty("key", "wrong_value");
try {
- JobPropertiesValidateRule.validateIsPositiveInteger(props, "key");
+ PropertiesPreconditions.checkPositiveInteger(props, "key");
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), is(String.format("The property `%s`
should be integer.", "key")));
}
@@ -70,7 +70,7 @@ class JobPropertiesValidateRuleTest {
Properties props = new Properties();
props.setProperty("key", "-1");
try {
- JobPropertiesValidateRule.validateIsPositiveInteger(props, "key");
+ PropertiesPreconditions.checkPositiveInteger(props, "key");
} catch (IllegalArgumentException ex) {
assertThat(ex.getMessage(), is(String.format("The property `%s`
should be positive.", "key")));
}