use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class CosmosMutationTest method makeConditionalQuery_MutationWithoutClusteringKeyGiven_ShouldReturnQuery.
@Test
public void makeConditionalQuery_MutationWithoutClusteringKeyGiven_ShouldReturnQuery() {
// Arrange
when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2)));
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Delete delete = new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
CosmosMutation cosmosMutation = new CosmosMutation(delete, metadata);
String concatenatedPartitionKey = cosmosMutation.getConcatenatedPartitionKey();
// Act
String actual = cosmosMutation.makeConditionalQuery();
// Assert
assertThat(actual).isEqualTo("select * from Record r where r.concatenatedPartitionKey = '" + concatenatedPartitionKey + "'");
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcServiceTest method whenDeleteOperationWithDeleteIfExistsConditionExecuted_shouldReturnTrueAndCallQueryBuilder.
@Test
public void whenDeleteOperationWithDeleteIfExistsConditionExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.where(any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeUpdate()).thenReturn(1);
// Act
Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.delete(delete, connection);
// Assert
assertThat(ret).isTrue();
verify(operationChecker).check(any(Delete.class));
verify(queryBuilder).deleteFrom(any(), any(), any());
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcServiceTest method whenDeleteOperationWithDeleteIfConditionExecuted_shouldReturnTrueAndCallQueryBuilder.
@Test
public void whenDeleteOperationWithDeleteIfConditionExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.where(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeUpdate()).thenReturn(1);
// Act
Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIf(new ConditionalExpression("v1", new TextValue("val2"), ConditionalExpression.Operator.EQ))).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.delete(delete, connection);
// Assert
assertThat(ret).isTrue();
verify(operationChecker).check(any(Delete.class));
verify(queryBuilder).deleteFrom(any(), any(), any());
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcServiceTest method whenDeleteOperationExecuted_shouldReturnTrueAndCallQueryBuilder.
@Test
public void whenDeleteOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.where(any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
// Act
Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.delete(delete, connection);
// Assert
assertThat(ret).isTrue();
verify(operationChecker).check(any(Delete.class));
verify(queryBuilder).deleteFrom(any(), any(), any());
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcServiceTest method whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder.
@Test
public void whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
// Arrange
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(queryBuilder.upsertInto(any(), any(), any())).thenReturn(upsertQueryBuilder);
when(upsertQueryBuilder.values(any(), any(), any())).thenReturn(upsertQueryBuilder);
when(upsertQueryBuilder.build()).thenReturn(upsertQuery);
when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.where(any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
// Act
Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.mutate(Arrays.asList(put, delete), connection);
// Assert
assertThat(ret).isTrue();
verify(operationChecker).check(anyList());
verify(operationChecker).check(any(Put.class));
verify(operationChecker).check(any(Delete.class));
verify(queryBuilder).upsertInto(any(), any(), any());
verify(queryBuilder).deleteFrom(any(), any(), any());
}
Aggregations