Search in sources :

Example 6 with BlobValue

use of com.scalar.db.io.BlobValue in project scalardb by scalar-labs.

the class ResultImplTest method getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet.

@Test
public void getValues_ProperValuesGivenInConstructor_ShouldReturnWhatsSet() {
    // Arrange
    ResultImpl result = new ResultImpl(values, 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)));
}
Also used : TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) IntValue(com.scalar.db.io.IntValue) DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) Value(com.scalar.db.io.Value) BigIntValue(com.scalar.db.io.BigIntValue) FloatValue(com.scalar.db.io.FloatValue) BlobValue(com.scalar.db.io.BlobValue) BooleanValue(com.scalar.db.io.BooleanValue) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 7 with BlobValue

use of com.scalar.db.io.BlobValue in project scalardb by scalar-labs.

the class ValueBinderTest method visit_AcceptCalledMultipleTimesWithNullValue_ShouldSkipNull.

@Test
public void visit_AcceptCalledMultipleTimesWithNullValue_ShouldSkipNull() {
    // Arrange
    IntValue value1 = new IntValue(ANY_NAME, ANY_INT);
    BlobValue value2 = new BlobValue(ANY_NAME, (byte[]) null);
    TextValue value3 = new TextValue(ANY_NAME, (String) null);
    IntValue value4 = new IntValue(ANY_NAME, ANY_INT);
    ValueBinder binder = new ValueBinder(bound);
    // Act
    value1.accept(binder);
    value2.accept(binder);
    value3.accept(binder);
    value4.accept(binder);
    // Assert
    verify(bound).setInt(0, ANY_INT);
    verify(bound, never()).setBytes(anyInt(), any(ByteBuffer.class));
    verify(bound, never()).setString(anyInt(), anyString());
    verify(bound).setInt(3, ANY_INT);
}
Also used : TextValue(com.scalar.db.io.TextValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) ByteBuffer(java.nio.ByteBuffer) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 8 with BlobValue

use of com.scalar.db.io.BlobValue in project scalardb by scalar-labs.

the class ValueBinderTest method visit_BlobValueAcceptCalled_ShouldCallSetString.

@Test
public void visit_BlobValueAcceptCalled_ShouldCallSetString() {
    // Arrange
    BlobValue value = new BlobValue(ANY_NAME, ANY_STRING.getBytes(StandardCharsets.UTF_8));
    ValueBinder binder = new ValueBinder(bound);
    // Act
    value.accept(binder);
    // Assert
    verify(bound).setBytes(0, (ByteBuffer) ByteBuffer.allocate(ANY_STRING.length()).put(ANY_STRING.getBytes(StandardCharsets.UTF_8)).flip());
}
Also used : BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 9 with BlobValue

use of com.scalar.db.io.BlobValue in project scalardb by scalar-labs.

the class ValueBinderTest method visit_BlobValueWithNullValueAcceptCalled_ShouldCallSetToNull.

@Test
public void visit_BlobValueWithNullValueAcceptCalled_ShouldCallSetToNull() {
    // Arrange
    BlobValue value = new BlobValue(ANY_NAME, (byte[]) null);
    ValueBinder binder = new ValueBinder(bound);
    // Act
    value.accept(binder);
    // Assert
    verify(bound).setToNull(0);
}
Also used : BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 10 with BlobValue

use of com.scalar.db.io.BlobValue in project scalardb by scalar-labs.

the class MapVisitorTest method visit_BlobValueWithNullValueAcceptCalled_ShouldGetMap.

@Test
public void visit_BlobValueWithNullValueAcceptCalled_ShouldGetMap() {
    // Act
    new BlobValue("any_blob", (byte[]) null).accept(visitor);
    // Assert
    assertThat(visitor.get().containsKey("any_blob")).isTrue();
    assertThat(visitor.get().get("any_blob")).isNull();
}
Also used : BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Aggregations

BlobValue (com.scalar.db.io.BlobValue)25 BigIntValue (com.scalar.db.io.BigIntValue)22 IntValue (com.scalar.db.io.IntValue)22 TextValue (com.scalar.db.io.TextValue)22 BooleanValue (com.scalar.db.io.BooleanValue)21 DoubleValue (com.scalar.db.io.DoubleValue)21 FloatValue (com.scalar.db.io.FloatValue)21 Test (org.junit.Test)14 Key (com.scalar.db.io.Key)12 Test (org.junit.jupiter.api.Test)10 Get (com.scalar.db.api.Get)6 Put (com.scalar.db.api.Put)6 Result (com.scalar.db.api.Result)6 Value (com.scalar.db.io.Value)6 BigIntColumn (com.scalar.db.io.BigIntColumn)2 BlobColumn (com.scalar.db.io.BlobColumn)2 BooleanColumn (com.scalar.db.io.BooleanColumn)2 Column (com.scalar.db.io.Column)2 DoubleColumn (com.scalar.db.io.DoubleColumn)2 FloatColumn (com.scalar.db.io.FloatColumn)2