use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method prepare_DeleteOperationWithIfGiven_ShouldPrepareProperQuery.
@Test
public void prepare_DeleteOperationWithIfGiven_ShouldPrepareProperQuery() {
// Arrange
String expected = Joiner.on(" ").skipNulls().join(new String[] { "DELETE", "FROM", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME, "WHERE", ANY_NAME_1 + "=?", "AND", ANY_NAME_2 + "=?", "IF", ANY_NAME_3 + "=?", "AND", ANY_NAME_4 + "=?;" });
configureBehavior(expected);
del = prepareDeleteWithClusteringKey();
del.withCondition(new DeleteIf(new ConditionalExpression(ANY_NAME_3, new IntValue(ANY_INT_1), Operator.EQ), new ConditionalExpression(ANY_NAME_4, new TextValue(ANY_TEXT_3), Operator.EQ)));
// Act
handler.prepare(del);
// Assert
verify(session).prepare(expected);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method bind_DeleteOperationWithIfGiven_ShouldBindProperly.
@Test
public void bind_DeleteOperationWithIfGiven_ShouldBindProperly() {
// Arrange
configureBehavior(null);
del = prepareDeleteWithClusteringKey();
del.withCondition(new DeleteIf(new ConditionalExpression(ANY_NAME_3, new IntValue(ANY_INT_1), Operator.EQ), new ConditionalExpression(ANY_NAME_4, new TextValue(ANY_TEXT_3), Operator.EQ)));
// Act
handler.bind(prepared, del);
// Assert
verify(bound).setString(0, ANY_TEXT_1);
verify(bound).setString(1, ANY_TEXT_2);
verify(bound).setInt(2, ANY_INT_1);
verify(bound).setString(3, ANY_TEXT_3);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPutIfCondition_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithInvalidPutIfCondition_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
MutationCondition condition = new PutIf(new ConditionalExpression(COL1, new TextValue("1"), ConditionalExpression.Operator.EQ));
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
List<Value<?>> values = Arrays.asList(new TextValue(COL1, "1"), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
MutationCondition condition = new PutIfNotExists();
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class JdbcServiceTest method whenPutOperationWithPutIfConditionFails_shouldReturnFalseAndCallQueryBuilder.
@Test
public void whenPutOperationWithPutIfConditionFails_shouldReturnFalseAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.update(any(), any(), any())).thenReturn(updateQueryBuilder);
when(updateQueryBuilder.set(any())).thenReturn(updateQueryBuilder);
when(updateQueryBuilder.where(any(), any(), any())).thenReturn(updateQueryBuilder);
when(updateQueryBuilder.build()).thenReturn(updateQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeUpdate()).thenReturn(0);
// Act
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIf(new ConditionalExpression("v1", new TextValue("val2"), ConditionalExpression.Operator.EQ))).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.put(put, connection);
// Assert
assertThat(ret).isFalse();
verify(operationChecker).check(any(Put.class));
verify(queryBuilder).update(any(), any(), any());
}
Aggregations