This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 0c097a24815 Add test cases on ShadowOperationType (#33529)
0c097a24815 is described below
commit 0c097a2481589cace6ac262e98ccee9a797476e1
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Nov 4 14:34:09 2024 +0800
Add test cases on ShadowOperationType (#33529)
---
.../shadow/spi/ShadowOperationType.java | 4 +--
.../shadow/spi/ShadowOperationTypeTest.java | 38 ++++++++++++++++++++++
.../AbstractColumnMatchedShadowAlgorithm.java | 2 +-
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git
a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowOperationType.java
b/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowOperationType.java
index 6550666191d..0420a39d7c9 100644
---
a/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowOperationType.java
+++
b/features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowOperationType.java
@@ -50,12 +50,12 @@ public enum ShadowOperationType {
HINT_MATCH;
/**
- * Contains operation type.
+ * Get shadow operation type value from text.
*
* @param operationType operation type
* @return shadow operation type
*/
- public static Optional<ShadowOperationType> contains(final String
operationType) {
+ public static Optional<ShadowOperationType> valueFrom(final String
operationType) {
if (INSERT.name().equalsIgnoreCase(operationType)) {
return Optional.of(INSERT);
}
diff --git
a/features/shadow/api/src/test/java/org/apache/shardingsphere/shadow/spi/ShadowOperationTypeTest.java
b/features/shadow/api/src/test/java/org/apache/shardingsphere/shadow/spi/ShadowOperationTypeTest.java
new file mode 100644
index 00000000000..34a617ff710
--- /dev/null
+++
b/features/shadow/api/src/test/java/org/apache/shardingsphere/shadow/spi/ShadowOperationTypeTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.shadow.spi;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class ShadowOperationTypeTest {
+
+ @Test
+ void assertValueFrom() {
+ assertThat(ShadowOperationType.valueFrom("INSERT"),
is(Optional.of(ShadowOperationType.INSERT)));
+ assertThat(ShadowOperationType.valueFrom("DELETE"),
is(Optional.of(ShadowOperationType.DELETE)));
+ assertThat(ShadowOperationType.valueFrom("UPDATE"),
is(Optional.of(ShadowOperationType.UPDATE)));
+ assertThat(ShadowOperationType.valueFrom("SELECT"),
is(Optional.of(ShadowOperationType.SELECT)));
+ assertFalse(ShadowOperationType.valueFrom("HINT_MATCH").isPresent());
+ }
+}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java
index d8a002a1913..8245d797051 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/AbstractColumnMatchedShadowAlgorithm.java
@@ -57,7 +57,7 @@ public abstract class AbstractColumnMatchedShadowAlgorithm
implements ColumnShad
private ShadowOperationType getShadowOperationType(final Properties props)
{
String operationType = props.getProperty(OPERATION_PROPS_KEY);
ShardingSpherePreconditions.checkNotNull(operationType, () -> new
AlgorithmInitializationException(this, "Column shadow algorithm operation
cannot be null"));
- Optional<ShadowOperationType> result =
ShadowOperationType.contains(operationType);
+ Optional<ShadowOperationType> result =
ShadowOperationType.valueFrom(operationType);
ShardingSpherePreconditions.checkState(result.isPresent(),
() -> new AlgorithmInitializationException(this, "Column
shadow algorithm operation must be one of [select, insert, update, delete]"));
return result.get();