-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for RepositoryTupleSwapperEngine.swapToRepositoryTuple…
…s() (#32460) * Refactor RepositoryTupleSwapperEngine * Add RepositoryTupleSwapperEngineTest * Add test cases for RepositoryTupleSwapperEngine.swapToRepositoryTuples()
- Loading branch information
Showing
8 changed files
with
306 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
.../src/test/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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.mode.tuple; | ||
|
||
import org.apache.shardingsphere.mode.tuple.fixture.leaf.LeafYamlRuleConfiguration; | ||
import org.apache.shardingsphere.mode.tuple.fixture.node.NodeYamlRuleConfiguration; | ||
import org.apache.shardingsphere.mode.tuple.fixture.node.NodeYamlRuleConfigurationEnum; | ||
import org.apache.shardingsphere.mode.tuple.fixture.none.NoneYamlRuleConfiguration; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class RepositoryTupleSwapperEngineTest { | ||
|
||
@Test | ||
void assertSwapToRepositoryTuplesWithoutRepositoryTupleEntityAnnotation() { | ||
assertTrue(new RepositoryTupleSwapperEngine().swapToRepositoryTuples(new NoneYamlRuleConfiguration()).isEmpty()); | ||
} | ||
|
||
@Test | ||
void assertSwapToRepositoryTuplesWithLeafYamlRuleConfiguration() { | ||
Collection<RepositoryTuple> actual = new RepositoryTupleSwapperEngine().swapToRepositoryTuples(new LeafYamlRuleConfiguration("foo")); | ||
assertThat(actual.size(), is(1)); | ||
RepositoryTuple actualTuple = actual.iterator().next(); | ||
assertThat(actualTuple.getKey(), is("leaf")); | ||
assertThat(actualTuple.getValue(), is("value: foo" + System.lineSeparator())); | ||
} | ||
|
||
@Test | ||
void assertSwapToRepositoryTuplesWithEmptyNodeYamlRuleConfiguration() { | ||
Collection<RepositoryTuple> actual = new RepositoryTupleSwapperEngine().swapToRepositoryTuples(new NodeYamlRuleConfiguration()); | ||
assertTrue(actual.isEmpty()); | ||
} | ||
|
||
@Test | ||
void assertSwapToRepositoryTuplesWithNodeYamlRuleConfiguration() { | ||
NodeYamlRuleConfiguration yamlRuleConfig = new NodeYamlRuleConfiguration(); | ||
yamlRuleConfig.setMapValue(Collections.singletonMap("k", new LeafYamlRuleConfiguration("v"))); | ||
yamlRuleConfig.setCollectionValue(Collections.singletonList(new LeafYamlRuleConfiguration("foo"))); | ||
yamlRuleConfig.setStringValue("str"); | ||
yamlRuleConfig.setBooleanValue(true); | ||
yamlRuleConfig.setIntegerValue(1); | ||
yamlRuleConfig.setLongValue(10L); | ||
yamlRuleConfig.setEnumValue(NodeYamlRuleConfigurationEnum.FOO); | ||
LeafYamlRuleConfiguration leaf = new LeafYamlRuleConfiguration(); | ||
leaf.setValue("leaf"); | ||
yamlRuleConfig.setLeaf(leaf); | ||
List<RepositoryTuple> actual = new ArrayList<>(new RepositoryTupleSwapperEngine().swapToRepositoryTuples(yamlRuleConfig)); | ||
assertThat(actual.size(), is(8)); | ||
assertThat(actual.get(0).getKey(), is("map_value/k")); | ||
assertThat(actual.get(0).getValue(), is("value: v" + System.lineSeparator())); | ||
assertThat(actual.get(1).getKey(), is("collection_value")); | ||
assertThat(actual.get(1).getValue(), is("- !!org.apache.shardingsphere.mode.tuple.fixture.leaf.LeafYamlRuleConfiguration" + System.lineSeparator() + " value: foo" + System.lineSeparator())); | ||
assertThat(actual.get(2).getKey(), is("string_value")); | ||
assertThat(actual.get(2).getValue(), is("str")); | ||
assertThat(actual.get(3).getKey(), is("boolean_value")); | ||
assertThat(actual.get(3).getValue(), is("true")); | ||
assertThat(actual.get(4).getKey(), is("integer_value")); | ||
assertThat(actual.get(4).getValue(), is("1")); | ||
assertThat(actual.get(5).getKey(), is("long_value")); | ||
assertThat(actual.get(5).getValue(), is("10")); | ||
assertThat(actual.get(6).getKey(), is("enum_value")); | ||
assertThat(actual.get(6).getValue(), is("FOO")); | ||
assertThat(actual.get(7).getKey(), is("leaf")); | ||
assertThat(actual.get(7).getValue(), is("value: leaf" + System.lineSeparator())); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...est/java/org/apache/shardingsphere/mode/tuple/fixture/leaf/LeafYamlRuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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.mode.tuple.fixture.leaf; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; | ||
import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration; | ||
import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity; | ||
|
||
@RepositoryTupleEntity(value = "leaf", leaf = true) | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public final class LeafYamlRuleConfiguration implements YamlRuleConfiguration { | ||
|
||
private String value; | ||
|
||
@Override | ||
public Class<? extends RuleConfiguration> getRuleConfigurationType() { | ||
return RuleConfiguration.class; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...est/java/org/apache/shardingsphere/mode/tuple/fixture/node/NodeYamlRuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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.mode.tuple.fixture.node; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; | ||
import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration; | ||
import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity; | ||
import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleField; | ||
import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleField.Type; | ||
import org.apache.shardingsphere.mode.tuple.fixture.leaf.LeafYamlRuleConfiguration; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
import java.util.Map; | ||
|
||
@RepositoryTupleEntity(value = "node") | ||
@Getter | ||
@Setter | ||
public final class NodeYamlRuleConfiguration implements YamlRuleConfiguration { | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private Map<String, LeafYamlRuleConfiguration> mapValue; | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private Collection<LeafYamlRuleConfiguration> collectionValue = new LinkedList<>(); | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private String stringValue = ""; | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private Boolean booleanValue; | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private Integer integerValue; | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private Long longValue; | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private NodeYamlRuleConfigurationEnum enumValue; | ||
|
||
@RepositoryTupleField(type = Type.OTHER) | ||
private LeafYamlRuleConfiguration leaf; | ||
|
||
@Override | ||
public Class<? extends RuleConfiguration> getRuleConfigurationType() { | ||
return RuleConfiguration.class; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...java/org/apache/shardingsphere/mode/tuple/fixture/node/NodeYamlRuleConfigurationEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.mode.tuple.fixture.node; | ||
|
||
public enum NodeYamlRuleConfigurationEnum { | ||
|
||
FOO | ||
} |
38 changes: 38 additions & 0 deletions
38
...t/java/org/apache/shardingsphere/mode/tuple/fixture/node/RuleNodePathProviderFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.mode.tuple.fixture.node; | ||
|
||
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; | ||
import org.apache.shardingsphere.mode.path.rule.RuleNodePath; | ||
import org.apache.shardingsphere.mode.spi.RuleNodePathProvider; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
public final class RuleNodePathProviderFixture implements RuleNodePathProvider { | ||
|
||
@Override | ||
public RuleNodePath getRuleNodePath() { | ||
return new RuleNodePath("node", Collections.singleton("map_value"), Arrays.asList("collection_value", "string_value", "boolean_value", "integer_value", "long_value", "enum_value", "leaf")); | ||
} | ||
|
||
@Override | ||
public Class<? extends RuleConfiguration> getType() { | ||
return RuleConfiguration.class; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...est/java/org/apache/shardingsphere/mode/tuple/fixture/none/NoneYamlRuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.mode.tuple.fixture.none; | ||
|
||
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; | ||
import org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration; | ||
|
||
public final class NoneYamlRuleConfiguration implements YamlRuleConfiguration { | ||
|
||
@Override | ||
public Class<? extends RuleConfiguration> getRuleConfigurationType() { | ||
return RuleConfiguration.class; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../test/resources/META-INF/services/org.apache.shardingsphere.mode.spi.RuleNodePathProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.shardingsphere.mode.tuple.fixture.node.RuleNodePathProviderFixture |