From 5097571e53b16bd1efac5e54b2b9f4372ecc8049 Mon Sep 17 00:00:00 2001 From: Pavan Baloju Date: Sun, 15 Oct 2023 18:51:52 +0530 Subject: [PATCH] Add unit test for YamlTableDataConsistencyCheckResultSwapper (#28735) --- ...DataConsistencyCheckResultSwapperTest.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/result/yaml/YamlTableDataConsistencyCheckResultSwapperTest.java diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/result/yaml/YamlTableDataConsistencyCheckResultSwapperTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/result/yaml/YamlTableDataConsistencyCheckResultSwapperTest.java new file mode 100644 index 0000000000000..72a2d5c9cfa5b --- /dev/null +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/result/yaml/YamlTableDataConsistencyCheckResultSwapperTest.java @@ -0,0 +1,112 @@ +/* + * 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.data.pipeline.core.consistencycheck.result.yaml; + +import org.apache.shardingsphere.data.pipeline.core.consistencycheck.result.TableDataConsistencyCheckIgnoredType; +import org.apache.shardingsphere.data.pipeline.core.consistencycheck.result.TableDataConsistencyCheckResult; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class YamlTableDataConsistencyCheckResultSwapperTest { + + private YamlTableDataConsistencyCheckResultSwapper yamlTableDataConsistencyCheckResultSwapper; + + @BeforeEach + void setUp() { + yamlTableDataConsistencyCheckResultSwapper = new YamlTableDataConsistencyCheckResultSwapper(); + } + + @Test + void assertSwapToYamlConfigurationWithTableDataConsistencyCheckIgnoredType() { + TableDataConsistencyCheckResult data = new TableDataConsistencyCheckResult(TableDataConsistencyCheckIgnoredType.NO_UNIQUE_KEY); + YamlTableDataConsistencyCheckResult result = yamlTableDataConsistencyCheckResultSwapper.swapToYamlConfiguration(data); + assertThat(result.getIgnoredType(), is("NO_UNIQUE_KEY")); + assertFalse(result.isMatched()); + } + + @Test + void assertSwapToYamlConfigurationWithTableDataConsistencyCheckResultMatched() { + TableDataConsistencyCheckResult data = new TableDataConsistencyCheckResult(true); + YamlTableDataConsistencyCheckResult result = yamlTableDataConsistencyCheckResultSwapper.swapToYamlConfiguration(data); + assertNull(result.getIgnoredType()); + assertTrue(result.isMatched()); + } + + @Test + void assertSwapToObjectWithYamlTableDataConsistencyCheckResultIgnoredType() { + YamlTableDataConsistencyCheckResult yamlConfig = new YamlTableDataConsistencyCheckResult(); + yamlConfig.setIgnoredType("NO_UNIQUE_KEY"); + TableDataConsistencyCheckResult result = yamlTableDataConsistencyCheckResultSwapper.swapToObject(yamlConfig); + assertThat(result.getIgnoredType(), is(TableDataConsistencyCheckIgnoredType.NO_UNIQUE_KEY)); + assertFalse(result.isMatched()); + } + + @Test + void assertSwapToObjectWithYamlTableDataConsistencyCheckResultMatched() { + YamlTableDataConsistencyCheckResult yamlConfig = new YamlTableDataConsistencyCheckResult(true); + TableDataConsistencyCheckResult result = yamlTableDataConsistencyCheckResultSwapper.swapToObject(yamlConfig); + assertNull(result.getIgnoredType()); + assertTrue(result.isMatched()); + } + + @Test + void assertSwapToObjectWithNullYamlTableDataConsistencyCheckResult() { + assertNull(yamlTableDataConsistencyCheckResultSwapper.swapToObject((YamlTableDataConsistencyCheckResult) null)); + } + + @Test + void assertSwapToObjectWithNullYamlTableDataConsistencyCheckResultIgnoredType() { + YamlTableDataConsistencyCheckResult yamlConfig = new YamlTableDataConsistencyCheckResult(); + yamlConfig.setIgnoredType(null); + TableDataConsistencyCheckResult result = yamlTableDataConsistencyCheckResultSwapper.swapToObject(yamlConfig); + assertNull(result.getIgnoredType()); + assertFalse(result.isMatched()); + } + + @Test + void assertSwapToObjectWithEmptyYamlTableDataConsistencyCheckResultMatched() { + YamlTableDataConsistencyCheckResult yamlConfig = new YamlTableDataConsistencyCheckResult(); + yamlConfig.setIgnoredType(""); + TableDataConsistencyCheckResult result = yamlTableDataConsistencyCheckResultSwapper.swapToObject(yamlConfig); + assertNull(result.getIgnoredType()); + assertFalse(result.isMatched()); + } + + @Test + void assertSwapToObjectWithString() { + TableDataConsistencyCheckResult result = yamlTableDataConsistencyCheckResultSwapper.swapToObject("ignoredType: NO_UNIQUE_KEY"); + assertThat(result.getIgnoredType(), is(TableDataConsistencyCheckIgnoredType.NO_UNIQUE_KEY)); + assertFalse(result.isMatched()); + } + + @Test + void assertSwapToObjectWithEmptyString() { + assertNull(yamlTableDataConsistencyCheckResultSwapper.swapToObject("")); + } + + @Test + void assertSwapToObjectWithBlankString() { + assertNull(yamlTableDataConsistencyCheckResultSwapper.swapToObject(" ")); + } +}