terrymanu commented on a change in pull request #3205: bugfix for #3144
URL:
https://github.com/apache/incubator-shardingsphere/pull/3205#discussion_r333917645
##########
File path:
sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/router/sharding/validator/impl/ShardingUpdateStatementValidatorTest.java
##########
@@ -30,32 +42,66 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.util.Collections;
-
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public final class ShardingUpdateStatementValidatorTest {
-
+
@Mock
private ShardingRule shardingRule;
-
+
@Test
public void assertValidateUpdateWithoutShardingKey() {
when(shardingRule.isShardingColumn("id", "user")).thenReturn(false);
- new ShardingUpdateStatementValidator().validate(shardingRule,
createUpdateStatement());
+ new ShardingUpdateStatementValidator().validate(shardingRule,
createUpdateStatement(), Collections.emptyList());
}
-
+
@Test(expected = ShardingException.class)
public void assertValidateUpdateWithShardingKey() {
when(shardingRule.isShardingColumn("id", "user")).thenReturn(true);
- new ShardingUpdateStatementValidator().validate(shardingRule,
createUpdateStatement());
+ new ShardingUpdateStatementValidator().validate(shardingRule,
createUpdateStatement(), Collections.emptyList());
+ }
+
+ @Test
+ public void assertValidateUpdateWithoutShardingKeyAndParameters() {
+ when(shardingRule.isShardingColumn("id", "user")).thenReturn(false);
+ List parameters = Arrays.asList(1, 1);
+ new ShardingUpdateStatementValidator().validate(shardingRule,
createUpdateStatement(), parameters);
}
-
+
+ @Test
+ public void
assertValidateUpdateWithShardingKeyAndShardingParameterEquals() {
+ when(shardingRule.isShardingColumn("id", "user")).thenReturn(true);
+ List parameters = Arrays.asList(1, 1);
+ new ShardingUpdateStatementValidator().validate(shardingRule,
createUpdateStatementAndParameters(1), parameters);
+ }
+
+ @Test(expected = ShardingException.class)
+ public void
assertValidateUpdateWithShardingKeyAndShardingParameterNotEquals() {
+ when(shardingRule.isShardingColumn("id", "user")).thenReturn(true);
+ List parameters = Arrays.asList(1, 1);
+ new ShardingUpdateStatementValidator().validate(shardingRule,
createUpdateStatementAndParameters(2), parameters);
+ }
+
private UpdateStatement createUpdateStatement() {
UpdateStatement result = new UpdateStatement();
result.getAllSQLSegments().add(new TableSegment(0, 0, "user"));
result.setSetAssignment(new SetAssignmentsSegment(0, 0,
Collections.singletonList(new AssignmentSegment(0, 0, new ColumnSegment(0, 0,
"id"), new LiteralExpressionSegment(0, 0, "")))));
return result;
}
+
+ private UpdateStatement createUpdateStatementAndParameters(final Object
shardingColumnPatamater) {
+ UpdateStatement result = new UpdateStatement();
+ result.getAllSQLSegments().add(new TableSegment(0, 0, "user"));
+ // set shardingColumnPatamater
Review comment:
Can you remove all inline comments?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services