use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingGetOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingGetOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = null;
List<String> projections = Arrays.asList(COL1, COL2, COL3);
Get get = new Get(partitionKey, clusteringKey).withProjections(projections).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(get)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingGetOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingGetOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(COL1, "1");
Key clusteringKey = null;
List<String> projections = Arrays.asList(COL1, COL2, COL3);
Get get = new Get(partitionKey, clusteringKey).withProjections(projections).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(get)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class CosmosOperationTest method getCosmosPartitionKey_MultipleKeysGiven_ShouldReturnPartitionKey.
@Test
public void getCosmosPartitionKey_MultipleKeysGiven_ShouldReturnPartitionKey() {
// Arrange
when(metadata.getPartitionKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3)));
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_INT_1);
Get get = new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
CosmosOperation cosmosOperation = new CosmosOperation(get, metadata);
// Act
PartitionKey actual = cosmosOperation.getCosmosPartitionKey();
// Assert
assertThat(actual).isEqualTo(new PartitionKey(ANY_TEXT_1 + ":" + ANY_TEXT_2 + ":" + ANY_INT_1));
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class CosmosOperationTest method getConcatenatedPartitionKey_MultipleKeysGiven_ShouldReturnConcatenatedPartitionKey.
@Test
public void getConcatenatedPartitionKey_MultipleKeysGiven_ShouldReturnConcatenatedPartitionKey() {
// Arrange
when(metadata.getPartitionKeyNames()).thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3)));
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_INT_1);
Get get = new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
CosmosOperation cosmosOperation = new CosmosOperation(get, metadata);
// Act
String actual = cosmosOperation.getConcatenatedPartitionKey();
// Assert
assertThat(actual).isEqualTo(ANY_TEXT_1 + ":" + ANY_TEXT_2 + ":" + ANY_INT_1);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class JdbcServiceTest method whenGetOperationExecuted_shouldCallQueryBuilder.
@Test
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION")
public void whenGetOperationExecuted_shouldCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.select(any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.from(any(), any(), any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.where(any(), any())).thenReturn(selectQueryBuilder);
when(selectQueryBuilder.build()).thenReturn(selectQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeQuery()).thenReturn(resultSet);
when(resultSet.next()).thenReturn(false);
// Act
Get get = new Get(new Key("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE);
jdbcService.get(get, connection);
// Assert
verify(operationChecker).check(any(Get.class));
verify(queryBuilder).select(any());
}
Aggregations