Java Code Examples for software.amazon.awssdk.core.SdkBytes#fromString()

The following examples show how to use software.amazon.awssdk.core.SdkBytes#fromString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PresignedGetObjectRequestTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void equalsAndHashCode_differentProperty_signedPayload() {
    SdkBytes otherSignedPayload = SdkBytes.fromString("other-payload", StandardCharsets.UTF_8);

    PresignedGetObjectRequest request = generateMaximal();
    PresignedGetObjectRequest otherRequest = request.toBuilder().signedPayload(otherSignedPayload).build();

    assertThat(request).isNotEqualTo(otherRequest);
    assertThat(request.hashCode()).isNotEqualTo(otherRequest.hashCode());
}
 
Example 2
Source File: BeanTableSchemaTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void setBean_binarySet() {
    SdkBytes buffer1 = SdkBytes.fromString("one", StandardCharsets.UTF_8);
    SdkBytes buffer2 = SdkBytes.fromString("two", StandardCharsets.UTF_8);
    SdkBytes buffer3 = SdkBytes.fromString("three", StandardCharsets.UTF_8);

    BeanTableSchema<SetBean> beanTableSchema = BeanTableSchema.create(SetBean.class);
    SetBean setBean = new SetBean();
    setBean.setId("id-value");
    LinkedHashSet<SdkBytes> binarySet = new LinkedHashSet<>();
    binarySet.add(buffer1);
    binarySet.add(buffer2);
    binarySet.add(buffer3);
    setBean.setBinarySet(binarySet);

    Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(setBean, true);

    AttributeValue expectedAttributeValue = AttributeValue.builder()
                                                          .bs(buffer1, buffer2, buffer3)
                                                          .build();

    assertThat(itemMap.size(), is(2));
    assertThat(itemMap, hasEntry("id", stringValue("id-value")));
    assertThat(itemMap, hasEntry("binarySet", expectedAttributeValue));

    SetBean reverse = beanTableSchema.mapToItem(itemMap);
    assertThat(reverse, is(equalTo(setBean)));
}
 
Example 3
Source File: StaticTableSchemaTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void mapperCanHandleBinary() {
    SdkBytes sdkBytes = SdkBytes.fromString("test", UTF_8);
    verifyNullableAttribute(EnhancedType.of(SdkBytes.class),
                            a -> a.name("value")
                                  .getter(FakeMappedItem::getABinaryValue)
                                  .setter(FakeMappedItem::setABinaryValue),
                            FakeMappedItem.builder().aBinaryValue(sdkBytes).build(),
                            AttributeValue.builder().b(sdkBytes).build());
}
 
Example 4
Source File: KeyTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void binaryKeys_convertsToCorrectAttributeValue() {
    SdkBytes partition = SdkBytes.fromString("one", StandardCharsets.UTF_8);
    SdkBytes sort = SdkBytes.fromString("two", StandardCharsets.UTF_8);

    Key key = Key.builder().partitionValue(partition).sortValue(sort).build();

    assertThat(key.partitionKeyValue(), is(AttributeValue.builder().b(partition).build()));
    assertThat(key.sortKeyValue(), is(Optional.of(AttributeValue.builder().b(sort).build())));
}
 
Example 5
Source File: KinesisEncoder.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Override
public PutRecordsRequestEntry apply(final Message<String> message) {
    final String encodedMessage = textEncoder.apply(message);
    final SdkBytes sdkBytes = encodedMessage != null
            ? SdkBytes.fromString(encodedMessage, UTF_8)
            : SdkBytes.fromByteArray(new byte[]{});

    return PutRecordsRequestEntry.builder()
            .partitionKey(message.getKey().partitionKey())
            .data(sdkBytes)
            .build();
}
 
Example 6
Source File: SdkBytesDeserializer.java    From realworld-serverless-application with Apache License 2.0 4 votes vote down vote up
@Override
public SdkBytes deserialize(JsonParser jsonParser,
                            DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
  return SdkBytes.fromString(jsonParser.getValueAsString(), charset);
}