use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyException.
@Test
public void whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyException() {
// 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 PutIfNotExists();
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException();
}
use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithInvalidPutIfConditionWithIsNull_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithInvalidPutIfConditionWithIsNull_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 = ConditionBuilder.putIf(ConditionBuilder.buildConditionalExpression(IntColumn.of(COL1, 1), Operator.IS_NULL)).build();
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.BooleanValue in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithDeleteIfCondition_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 DeleteIf();
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.BooleanValue in project scalardb by scalar-labs.
the class PutTest method withValue_ProperValuesGiven_ShouldReturnWhatsSet.
@Test
public void withValue_ProperValuesGiven_ShouldReturnWhatsSet() {
// Arrange
Put put = preparePut();
// Act
put.withValue("val1", true).withValue("val2", 5678).withValue("val3", 1234L).withValue("val4", 4.56f).withValue("val5", 1.23).withValue("val6", "string_value").withValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)).withValue("val8", ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
// Assert
Map<String, Value<?>> values = put.getValues();
assertThat(values.size()).isEqualTo(8);
assertThat(values.get("val1")).isEqualTo(new BooleanValue("val1", true));
assertThat(values.get("val2")).isEqualTo(new IntValue("val2", 5678));
assertThat(values.get("val3")).isEqualTo(new BigIntValue("val3", 1234L));
assertThat(values.get("val4")).isEqualTo(new FloatValue("val4", 4.56f));
assertThat(values.get("val5")).isEqualTo(new DoubleValue("val5", 1.23));
assertThat(values.get("val6")).isEqualTo(new TextValue("val6", "string_value"));
assertThat(values.get("val7")).isEqualTo(new BlobValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(values.get("val8")).isEqualTo(new BlobValue("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
Map<String, Column<?>> columns = put.getColumns();
assertThat(columns.size()).isEqualTo(8);
assertThat(columns.get("val1")).isEqualTo(BooleanColumn.of("val1", true));
assertThat(columns.get("val2")).isEqualTo(IntColumn.of("val2", 5678));
assertThat(columns.get("val3")).isEqualTo(BigIntColumn.of("val3", 1234L));
assertThat(columns.get("val4")).isEqualTo(FloatColumn.of("val4", 4.56f));
assertThat(columns.get("val5")).isEqualTo(DoubleColumn.of("val5", 1.23));
assertThat(columns.get("val6")).isEqualTo(TextColumn.of("val6", "string_value"));
assertThat(columns.get("val7")).isEqualTo(BlobColumn.of("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(columns.get("val8")).isEqualTo(BlobColumn.of("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getContainedColumnNames()).isEqualTo(ImmutableSet.of("val1", "val2", "val3", "val4", "val5", "val6", "val7", "val8"));
assertThat(put.containsColumn("val1")).isTrue();
assertThat(put.isNullValue("val1")).isFalse();
assertThat(put.getBooleanValue("val1")).isTrue();
assertThat(put.getValueAsObject("val1")).isEqualTo(true);
assertThat(put.containsColumn("val2")).isTrue();
assertThat(put.isNullValue("val2")).isFalse();
assertThat(put.getIntValue("val2")).isEqualTo(5678);
assertThat(put.getValueAsObject("val2")).isEqualTo(5678);
assertThat(put.containsColumn("val3")).isTrue();
assertThat(put.isNullValue("val3")).isFalse();
assertThat(put.getBigIntValue("val3")).isEqualTo(1234L);
assertThat(put.getValueAsObject("val3")).isEqualTo(1234L);
assertThat(put.containsColumn("val4")).isTrue();
assertThat(put.isNullValue("val4")).isFalse();
assertThat(put.getFloatValue("val4")).isEqualTo(4.56f);
assertThat(put.getValueAsObject("val4")).isEqualTo(4.56f);
assertThat(put.containsColumn("val5")).isTrue();
assertThat(put.isNullValue("val5")).isFalse();
assertThat(put.getDoubleValue("val5")).isEqualTo(1.23);
assertThat(put.getValueAsObject("val5")).isEqualTo(1.23);
assertThat(put.containsColumn("val6")).isTrue();
assertThat(put.isNullValue("val6")).isFalse();
assertThat(put.getTextValue("val6")).isEqualTo("string_value");
assertThat(put.getValueAsObject("val6")).isEqualTo("string_value");
assertThat(put.containsColumn("val7")).isTrue();
assertThat(put.isNullValue("val7")).isFalse();
assertThat(put.getBlobValue("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsByteBuffer("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsBytes("val7")).isEqualTo("blob_value".getBytes(StandardCharsets.UTF_8));
assertThat(put.getValueAsObject("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.containsColumn("val8")).isTrue();
assertThat(put.isNullValue("val8")).isFalse();
assertThat(put.getBlobValue("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsByteBuffer("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsBytes("val8")).isEqualTo("blob_value2".getBytes(StandardCharsets.UTF_8));
assertThat(put.getValueAsObject("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
}
use of com.scalar.db.io.BooleanValue in project scalardb by scalar-labs.
the class ResultImplTest method getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet.
@Test
public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {
// Arrange
ResultImpl result = new ResultImpl(columns, TABLE_METADATA);
// Act
Map<String, Value<?>> actual = result.getValues();
// Assert
assertThat(actual.get(ANY_NAME_1)).isEqualTo(new TextValue(ANY_NAME_1, ANY_TEXT_1));
assertThat(actual.get(ANY_NAME_2)).isEqualTo(new TextValue(ANY_NAME_2, ANY_TEXT_2));
assertThat(actual.get(ANY_COLUMN_NAME_1)).isEqualTo(new BooleanValue(ANY_COLUMN_NAME_1, true));
assertThat(actual.get(ANY_COLUMN_NAME_7)).isEqualTo(new BlobValue(ANY_COLUMN_NAME_7, "bytes".getBytes(StandardCharsets.UTF_8)));
}
Aggregations