software.amazon.awssdk.services.dynamodb.model.AttributeValue Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.AttributeValue.
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: EnhancedClientUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
public static Key createKeyFromMap(Map<String, AttributeValue> itemMap, TableSchema<?> tableSchema, String indexName) { String partitionKeyName = tableSchema.tableMetadata().indexPartitionKey(indexName); Optional<String> sortKeyName = tableSchema.tableMetadata().indexSortKey(indexName); AttributeValue partitionKeyValue = itemMap.get(partitionKeyName); Optional<AttributeValue> sortKeyValue = sortKeyName.map(itemMap::get); return sortKeyValue.map( attributeValue -> Key.builder() .partitionValue(partitionKeyValue) .sortValue(attributeValue) .build()) .orElseGet( () -> Key.builder() .partitionValue(partitionKeyValue).build()); }
Example #2
Source File: DeleteItemOperation.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private DeleteItemRequest.Builder addExpressionsIfExist(DeleteItemRequest.Builder requestBuilder) { if (this.request.conditionExpression() != null) { requestBuilder = requestBuilder.conditionExpression(this.request.conditionExpression().expression()); Map<String, String> expressionNames = this.request.conditionExpression().expressionNames(); Map<String, AttributeValue> expressionValues = this.request.conditionExpression().expressionValues(); // Avoiding adding empty collections that the low level SDK will propagate to DynamoDb where it causes error. if (expressionNames != null && !expressionNames.isEmpty()) { requestBuilder = requestBuilder.expressionAttributeNames(expressionNames); } if (expressionValues != null && !expressionValues.isEmpty()) { requestBuilder = requestBuilder.expressionAttributeValues(expressionValues); } } return requestBuilder; }
Example #3
Source File: StaticTableSchemaTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void mapperCanHandleIntDoubleMap() { Map<Integer, Double> intDoubleMap = new ConcurrentHashMap<>(); intDoubleMap.put(1, 1.0); intDoubleMap.put(2, 3.0); Map<String, AttributeValue> attributeValueMap = new HashMap<>(); attributeValueMap.put("1", AttributeValue.builder().n("1.0").build()); attributeValueMap.put("2", AttributeValue.builder().n("3.0").build()); verifyNullableAttribute(EnhancedType.mapOf(Integer.class, Double.class), a -> a.name("value") .getter(FakeMappedItem::getAIntDoubleMap) .setter(FakeMappedItem::setAIntDoubleMap), FakeMappedItem.builder().aIntDoubleMap(intDoubleMap).build(), AttributeValue.builder().m(attributeValueMap).build()); }
Example #4
Source File: DynamoDbSignerTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test public void macListsUnsorted() throws GeneralSecurityException { Map<String, AttributeValue> itemAttributes = new HashMap<>(); Map<String, Set<EncryptionFlags>> attributeFlags = new HashMap<>(); itemAttributes.put("Key1", AttributeValue.builder().ss("Value3", "Value1", "Value2").build()); attributeFlags.put("Key1", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key2", AttributeValue.builder().ns("100", "300", "200").build()); attributeFlags.put("Key2", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key3", AttributeValue.builder().bs(SdkBytes.fromByteArray(new byte[] { 3, 2, 1}), SdkBytes.fromByteArray(new byte[] { 0, 1, 2, 3})).build()); attributeFlags.put("Key3", EnumSet.of(EncryptionFlags.SIGN, EncryptionFlags.ENCRYPT)); byte[] signature = signerRsa.calculateSignature(itemAttributes, attributeFlags, new byte[0], macKey); Map<String, AttributeValue> scrambledAttributes = new HashMap<>(); scrambledAttributes.put("Key1", AttributeValue.builder().ss("Value1", "Value2", "Value3").build()); scrambledAttributes.put("Key2", AttributeValue.builder().ns("100", "200", "300").build()); scrambledAttributes.put("Key3", AttributeValue.builder().bs(SdkBytes.fromByteArray(new byte[] { 0, 1, 2, 3}), SdkBytes.fromByteArray(new byte[] { 3, 2, 1})).build()); signerRsa.verifySignature(scrambledAttributes, attributeFlags, new byte[0], macKey, ByteBuffer.wrap(signature)); }
Example #5
Source File: DynamoDBLeaseSerializer.java From amazon-kinesis-client with Apache License 2.0 | 6 votes |
@Override public Lease fromDynamoRecord(final Map<String, AttributeValue> dynamoRecord) { Lease result = new Lease(); result.leaseKey(DynamoUtils.safeGetString(dynamoRecord, LEASE_KEY_KEY)); result.leaseOwner(DynamoUtils.safeGetString(dynamoRecord, LEASE_OWNER_KEY)); result.leaseCounter(DynamoUtils.safeGetLong(dynamoRecord, LEASE_COUNTER_KEY)); result.ownerSwitchesSinceCheckpoint(DynamoUtils.safeGetLong(dynamoRecord, OWNER_SWITCHES_KEY)); result.checkpoint( new ExtendedSequenceNumber( DynamoUtils.safeGetString(dynamoRecord, CHECKPOINT_SEQUENCE_NUMBER_KEY), DynamoUtils.safeGetLong(dynamoRecord, CHECKPOINT_SUBSEQUENCE_NUMBER_KEY)) ); result.parentShardIds(DynamoUtils.safeGetSS(dynamoRecord, PARENT_SHARD_ID_KEY)); if (!Strings.isNullOrEmpty(DynamoUtils.safeGetString(dynamoRecord, PENDING_CHECKPOINT_SEQUENCE_KEY))) { result.pendingCheckpoint( new ExtendedSequenceNumber( DynamoUtils.safeGetString(dynamoRecord, PENDING_CHECKPOINT_SEQUENCE_KEY), DynamoUtils.safeGetLong(dynamoRecord, PENDING_CHECKPOINT_SUBSEQUENCE_KEY)) ); } return result; }
Example #6
Source File: DelegatedEnvelopeEncryptionTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@BeforeMethod public void setUp() { prov = new WrappedMaterialsProvider(encryptionKey, encryptionKey, macKey, Collections.emptyMap()); encryptor = new DynamoDbEncryptor(prov, "encryptor-"); attribs = new HashMap<>(); attribs.put("intValue", AttributeValue.builder().n("123").build()); attribs.put("stringValue", AttributeValue.builder().s("Hello world!").build()); attribs.put("byteArrayValue", AttributeValue.builder().b(SdkBytes.fromByteArray(new byte[]{0, 1, 2, 3, 4, 5})).build()); attribs.put("stringSet",AttributeValue.builder().ss("Goodbye", "Cruel", "World", "?").build()); attribs.put("intSet", AttributeValue.builder().ns("1", "200", "10", "15", "0").build()); attribs.put("hashKey", AttributeValue.builder().n("5").build()); attribs.put("rangeKey", AttributeValue.builder().n("7").build()); attribs.put("version", AttributeValue.builder().n("0").build()); context = EncryptionContext.builder() .tableName("TableName") .hashKeyName("hashKey") .rangeKeyName("rangeKey") .build(); }
Example #7
Source File: DelegatedEncryptionTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@BeforeMethod public void setUp() { prov = new SymmetricStaticProvider(encryptionKey, macKey, Collections.emptyMap()); encryptor = new DynamoDbEncryptor(prov, "encryptor-"); attribs = new HashMap<>(); attribs.put("intValue", AttributeValue.builder().n("123").build()); attribs.put("stringValue", AttributeValue.builder().s("Hello world!").build()); attribs.put("byteArrayValue", AttributeValue.builder().b(SdkBytes.fromByteArray(new byte[] {0, 1, 2, 3, 4, 5})).build()); attribs.put("stringSet", AttributeValue.builder().ss("Goodbye", "Cruel", "World", "?").build()); attribs.put("intSet", AttributeValue.builder().ns("1", "200", "10", "15", "0").build()); attribs.put("hashKey", AttributeValue.builder().n("5").build()); attribs.put("rangeKey", AttributeValue.builder().n("7").build()); attribs.put("version", AttributeValue.builder().n("0").build()); context = EncryptionContext.builder() .tableName("TableName") .hashKeyName("hashKey") .rangeKeyName("rangeKey") .build(); }
Example #8
Source File: DynamoDBScanItems.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void scanItems( DynamoDbClient ddb,String tableName ) { try { ScanRequest scanRequest = ScanRequest.builder() .tableName(tableName) .build(); ScanResponse response = ddb.scan(scanRequest); for (Map<String, AttributeValue> item : response.items()) { Set<String> keys = item.keySet(); for (String key : keys) { System.out.println ("The key name is "+key +"\n" ); System.out.println("The value is "+item.get(key).s()); } } } catch (DynamoDbException e) { e.printStackTrace(); } // snippet-end:[dynamodb.java2.dynamoDB_scan.main] }
Example #9
Source File: QueryOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void generateRequest_filterExpression_withValues() { Map<String, AttributeValue> expressionValues = singletonMap(":test-key", stringValue("test-value")); Expression filterExpression = Expression.builder() .expression("test-expression") .expressionValues(expressionValues) .build(); QueryOperation<FakeItem> queryToTest = QueryOperation.create(QueryEnhancedRequest.builder() .queryConditional(keyEqualTo(k -> k.partitionValue(keyItem.getId()))) .filterExpression(filterExpression) .build()); QueryRequest queryRequest = queryToTest.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, null); assertThat(queryRequest.filterExpression(), is("test-expression")); assertThat(queryRequest.expressionAttributeValues(), hasEntry(":test-key", stringValue("test-value"))); }
Example #10
Source File: EmptyBinaryTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void getEmptyBytes() { Map<String, AttributeValue> itemMap = new HashMap<>(); itemMap.put("id", AttributeValue.builder().s("id123").build()); itemMap.put("b", EMPTY_BINARY); GetItemResponse response = GetItemResponse.builder() .item(itemMap) .build(); when(mockDynamoDbClient.getItem(any(GetItemRequest.class))).thenReturn(response); TestBean result = dynamoDbTable.getItem(r -> r.key(k -> k.partitionValue("id123"))); assertThat(result.getId()).isEqualTo("id123"); assertThat(result.getB()).isEqualTo(EMPTY_BYTES); }
Example #11
Source File: BeanTableSchemaTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void enumBean_listEnum() { BeanTableSchema<EnumBean> beanTableSchema = BeanTableSchema.create(EnumBean.class); EnumBean enumBean = new EnumBean(); enumBean.setId("id-value"); enumBean.setTestEnumList(Arrays.asList(EnumBean.TestEnum.ONE, EnumBean.TestEnum.TWO)); Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(enumBean, true); AttributeValue expectedAttributeValue = AttributeValue.builder() .l(stringValue("ONE"), stringValue("TWO")) .build(); assertThat(itemMap.size(), is(2)); assertThat(itemMap, hasEntry("id", stringValue("id-value"))); assertThat(itemMap, hasEntry("testEnumList", expectedAttributeValue)); EnumBean reverse = beanTableSchema.mapToItem(itemMap); assertThat(reverse, is(equalTo(enumBean))); }
Example #12
Source File: StaticTableSchemaTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void usesCustomAttributeConverterProvider() { String originalString = "test-string"; String expectedString = "test-string-custom"; when(provider1.converterFor(EnhancedType.of(String.class))).thenReturn(attributeConverter1); when(attributeConverter1.transformFrom(any())).thenReturn(AttributeValue.builder().s(expectedString).build()); StaticTableSchema<FakeMappedItem> tableSchema = StaticTableSchema.builder(FakeMappedItem.class) .newItemSupplier(FakeMappedItem::new) .addAttribute(String.class, a -> a.name("aString") .getter(FakeMappedItem::getAString) .setter(FakeMappedItem::setAString)) .attributeConverterProviders(provider1) .build(); Map<String, AttributeValue> resultMap = tableSchema.itemToMap(FakeMappedItem.builder().aString(originalString).build(), false); assertThat(resultMap.get("aString").s(), is(expectedString)); }
Example #13
Source File: BeanTableSchemaTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void documentBean_correctlyMapsAttributes() { BeanTableSchema<DocumentBean> beanTableSchema = BeanTableSchema.create(DocumentBean.class); AbstractBean abstractBean = new AbstractBean(); abstractBean.setAttribute2("two"); DocumentBean documentBean = new DocumentBean(); documentBean.setId("id-value"); documentBean.setAttribute1("one"); documentBean.setAbstractBean(abstractBean); AttributeValue expectedDocument = AttributeValue.builder() .m(singletonMap("attribute2", stringValue("two"))) .build(); Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(documentBean, true); assertThat(itemMap.size(), is(3)); assertThat(itemMap, hasEntry("id", stringValue("id-value"))); assertThat(itemMap, hasEntry("attribute1", stringValue("one"))); assertThat(itemMap, hasEntry("abstractBean", expectedDocument)); }
Example #14
Source File: DeleteItemOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void transformResponse_correctlyTransformsIntoAnItem() { FakeItem keyItem = createUniqueFakeItem(); DeleteItemOperation<FakeItem> deleteItemOperation = DeleteItemOperation.create(DeleteItemEnhancedRequest.builder().key(k -> k.partitionValue(keyItem.getId())).build()); Map<String, AttributeValue> responseMap = new HashMap<>(); responseMap.put("id", AttributeValue.builder().s(keyItem.getId()).build()); responseMap.put("subclass_attribute", AttributeValue.builder().s("test-value").build()); DeleteItemResponse response = DeleteItemResponse.builder() .attributes(responseMap) .build(); FakeItem result = deleteItemOperation.transformResponse(response, FakeItem.getTableSchema(), PRIMARY_CONTEXT, null); assertThat(result.getId(), is(keyItem.getId())); assertThat(result.getSubclassAttribute(), is("test-value")); }
Example #15
Source File: DirectKmsMaterialsProviderTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = DynamoDbEncryptionException.class) public void encryptionKeyIdMismatch() { DirectKmsMaterialsProvider directProvider = new DirectKmsMaterialsProvider(kms, keyId); String customKeyId = kms.createKey().keyMetadata().keyId(); Map<String, AttributeValue> attrVals = new HashMap<>(); attrVals.put("hk", AttributeValue.builder().n("10").build()); attrVals.put("rk", AttributeValue.builder().n("20").build()); attrVals.put("encryptionKeyId", AttributeValue.builder().s(customKeyId).build()); ctx = EncryptionContext.builder().hashKeyName("hk").rangeKeyName("rk") .tableName("KmsTableName").attributeValues(attrVals).build(); EncryptionMaterials eMat = directProvider.getEncryptionMaterials(ctx); EncryptionContext dCtx = ctx(eMat).toBuilder() .hashKeyName("hk") .rangeKeyName("rk") .tableName("KmsTableName") .attributeValues(attrVals) .build(); ExtendedKmsMaterialProvider extendedProvider = new ExtendedKmsMaterialProvider(kms, keyId, "encryptionKeyId"); extendedProvider.getDecryptionMaterials(dCtx); }
Example #16
Source File: BeanTableSchemaTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void parameterizedDocumentBean_correctlyMapsAttributes() { BeanTableSchema<ParameterizedDocumentBean> beanTableSchema = BeanTableSchema.create(ParameterizedDocumentBean.class); ParameterizedAbstractBean<String> abstractBean = new ParameterizedAbstractBean<>(); abstractBean.setAttribute2("two"); ParameterizedDocumentBean documentBean = new ParameterizedDocumentBean(); documentBean.setId("id-value"); documentBean.setAttribute1("one"); documentBean.setAbstractBean(abstractBean); AttributeValue expectedDocument = AttributeValue.builder() .m(singletonMap("attribute2", stringValue("two"))) .build(); Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(documentBean, true); assertThat(itemMap.size(), is(3)); assertThat(itemMap, hasEntry("id", stringValue("id-value"))); assertThat(itemMap, hasEntry("attribute1", stringValue("one"))); assertThat(itemMap, hasEntry("abstractBean", expectedDocument)); }
Example #17
Source File: BeanTableSchemaTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void listBean_stringListList() { BeanTableSchema<ListBean> beanTableSchema = BeanTableSchema.create(ListBean.class); ListBean listBean = new ListBean(); listBean.setId("id-value"); listBean.setStringListList(Arrays.asList(Arrays.asList("one", "two"), Arrays.asList("three", "four"))); Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(listBean, true); AttributeValue list1 = AttributeValue.builder().l(stringValue("one"), stringValue("two")).build(); AttributeValue list2 = AttributeValue.builder().l(stringValue("three"), stringValue("four")).build(); AttributeValue expectedAttributeValue = AttributeValue.builder() .l(list1, list2) .build(); assertThat(itemMap.size(), is(2)); assertThat(itemMap, hasEntry("id", stringValue("id-value"))); assertThat(itemMap, hasEntry("stringListList", expectedAttributeValue)); ListBean reverse = beanTableSchema.mapToItem(itemMap); assertThat(reverse, is(equalTo(listBean))); }
Example #18
Source File: DynamoDbSignerTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test public void sigEcdsaWithIgnoredChange() throws GeneralSecurityException { Map<String, AttributeValue> itemAttributes = new HashMap<>(); Map<String, Set<EncryptionFlags>> attributeFlags = new HashMap<>(); itemAttributes.put("Key1", AttributeValue.builder().s("Value1").build()); attributeFlags.put("Key1", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key2", AttributeValue.builder().n("100").build()); attributeFlags.put("Key2", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key3", AttributeValue.builder().b(SdkBytes.fromByteArray(new byte[] { 0, 1, 2, 3})).build()); attributeFlags.put("Key3", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key4", AttributeValue.builder().s("Ignored Value").build()); byte[] signature = signerEcdsa.calculateSignature(itemAttributes, attributeFlags, new byte[0], privKeyEcdsa); itemAttributes.put("Key4", AttributeValue.builder().s("New Ignored Value").build()); signerEcdsa.verifySignature(itemAttributes, attributeFlags, new byte[0], pubKeyEcdsa, ByteBuffer.wrap(signature)); }
Example #19
Source File: AttributeValueMarshallerTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test public void testComplexList() { final List<AttributeValue> list1 = Arrays.asList( AttributeValueBuilder.ofS("StringValue"), AttributeValueBuilder.ofN("1000"), AttributeValueBuilder.ofBool(Boolean.TRUE)); final List<AttributeValue> list22 = Arrays.asList( AttributeValueBuilder.ofS("AWS"), AttributeValueBuilder.ofN("-3700"), AttributeValueBuilder.ofBool(Boolean.FALSE)); final List<AttributeValue> list2 = Arrays.asList( AttributeValueBuilder.ofL(list22), AttributeValueBuilder.ofNull()); AttributeValue av = AttributeValueBuilder.ofL( AttributeValueBuilder.ofS("StringValue1"), AttributeValueBuilder.ofL(list1), AttributeValueBuilder.ofN("50"), AttributeValueBuilder.ofL(list2)); assertAttributesAreEqual(av, unmarshall(marshall(av))); }
Example #20
Source File: DynamoDBTest.java From dynein with Apache License 2.0 | 6 votes |
@Test public void testGetJob_Failure() throws Throwable { String token = getToken(4); JobTokenPayload tokenPayload = tokenManager.decodeToken(token); Map<String, AttributeValue> primaryKey = DynamoDBUtils.getPrimaryKeyFromToken(token, tokenPayload, maxShardId); GetItemRequest getItemRequest = GetItemRequest.builder() .key(primaryKey) .tableName(tableName) .attributesToGet(Collections.singletonList(DynamoDBUtils.Attribute.JOB_SPEC.columnName)) .build(); CompletableFuture<GetItemResponse> ret = new CompletableFuture<>(); Exception exception = new Exception(); ret.completeExceptionally(exception); when(ddbClient.getItem(getItemRequest)).thenReturn(ret); CompletableFuture<Schedule> response = scheduleManager.getJob(token); assertSame(getException(response), exception); verify(ddbClient, times(1)).getItem(getItemRequest); verifyNoMoreInteractions(ddbClient); }
Example #21
Source File: DelegatedEncryptionTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test public void fullEncryption() { Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(attribs), context, asList("hashKey", "rangeKey", "version")); assertThat(encryptedAttributes, AttrMatcher.invert(attribs)); Map<String, AttributeValue> decryptedAttributes = EncryptionTestHelper.decryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(encryptedAttributes), context, asList("hashKey", "rangeKey", "version")); assertThat(decryptedAttributes, AttrMatcher.match(attribs)); // Make sure keys and version are not encrypted assertAttrEquals(attribs.get("hashKey"), encryptedAttributes.get("hashKey")); assertAttrEquals(attribs.get("rangeKey"), encryptedAttributes.get("rangeKey")); assertAttrEquals(attribs.get("version"), encryptedAttributes.get("version")); // Make sure String has been encrypted (we'll assume the others are correct as well) assertTrue(encryptedAttributes.containsKey("stringValue")); assertNull(encryptedAttributes.get("stringValue").s()); assertNotNull(encryptedAttributes.get("stringValue").b()); }
Example #22
Source File: DynamoDbEncryptorTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test public void signedOnly() { Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, attribs.keySet()); assertThat(encryptedAttributes, AttrMatcher.invert(attribs)); Map<String, AttributeValue> decryptedAttributes = EncryptionTestHelper.decryptAllFieldsExcept(encryptor, encryptedAttributes, context, attribs.keySet()); assertThat(decryptedAttributes, AttrMatcher.match(attribs)); // Make sure keys and version are not encrypted assertAttrEquals(attribs.get("hashKey"), encryptedAttributes.get("hashKey")); assertAttrEquals(attribs.get("rangeKey"), encryptedAttributes.get("rangeKey")); assertAttrEquals(attribs.get("version"), encryptedAttributes.get("version")); // Make sure String has not been encrypted (we'll assume the others are correct as well) assertAttrEquals(attribs.get("stringValue"), encryptedAttributes.get("stringValue")); }
Example #23
Source File: BeanTableSchemaTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void emptyConverterProviderList_correct_whenAttributeConvertersAreSupplied() { BeanTableSchema<EmptyConverterProvidersValidBean> beanTableSchema = BeanTableSchema.create(EmptyConverterProvidersValidBean.class); EmptyConverterProvidersValidBean converterBean = new EmptyConverterProvidersValidBean(); converterBean.setId("id-value"); converterBean.setIntegerAttribute(123); Map<String, AttributeValue> itemMap = beanTableSchema.itemToMap(converterBean, false); assertThat(itemMap.size(), is(2)); assertThat(itemMap, hasEntry("id", stringValue("id-value-custom"))); assertThat(itemMap, hasEntry("integerAttribute", numberValue(133))); EmptyConverterProvidersValidBean reverse = beanTableSchema.mapToItem(itemMap); assertThat(reverse.getId(), is(equalTo("id-value-custom"))); assertThat(reverse.getIntegerAttribute(), is(equalTo(133))); }
Example #24
Source File: DynamoDBTest.java From dynein with Apache License 2.0 | 5 votes |
@Test public void testDeleteJob() throws Exception { String token = getToken(1); JobTokenPayload tokenPayload = tokenManager.decodeToken(token); Map<String, AttributeValue> primaryKey = DynamoDBUtils.getPrimaryKeyFromToken(token, tokenPayload, maxShardId); Map<String, String> attributeNames = new HashMap<>(); Map<String, AttributeValue> attributeValues = new HashMap<>(); attributeNames.put("#jobStatus", DynamoDBUtils.Attribute.JOB_STATUS.columnName); attributeValues.put( ":scheduled", AttributeValue.builder().s(Schedule.JobStatus.SCHEDULED.toString()).build()); DeleteItemRequest deleteItemRequest = DeleteItemRequest.builder() .tableName(tableName) .conditionExpression("#jobStatus = :scheduled") .key(primaryKey) .expressionAttributeNames(attributeNames) .expressionAttributeValues(attributeValues) .build(); when(ddbClient.deleteItem(deleteItemRequest)) .thenReturn(CompletableFuture.completedFuture(null)); CompletableFuture<Void> response = scheduleManager.deleteJob(token); response.get(1000, TimeUnit.MILLISECONDS); verify(ddbClient, times(1)).deleteItem(deleteItemRequest); verifyNoMoreInteractions(ddbClient); }
Example #25
Source File: Expression.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private Expression(String expression, Map<String, AttributeValue> expressionValues, Map<String, String> expressionNames) { this.expression = expression; this.expressionValues = expressionValues; this.expressionNames = expressionNames; }
Example #26
Source File: EmptyAttributeTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void syncClient_getItem_emptyString() { stubFor(any(urlEqualTo("/")) .willReturn(aResponse().withStatus(200).withBody("{\"Item\": {\"attribute\": {\"S\": \"\"}}}"))); GetItemResponse response = dynamoDbClient.getItem(r -> r.tableName("test")); assertThat(response.item()).containsKey("attribute"); AttributeValue attributeValue = response.item().get("attribute"); assertThat(attributeValue.s()).isEmpty(); }
Example #27
Source File: AttributeValueMarshallerTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test public void testNumberSOrdering() { AttributeValue av1 = AttributeValue.builder().ns(unmodifiableList(Arrays.asList("1337", "1", "5"))).build(); AttributeValue av2 = AttributeValue.builder().ns(unmodifiableList(Arrays.asList("1", "5", "1337"))).build(); assertAttributesAreEqual(av1, av2); ByteBuffer buff1 = marshall(av1); ByteBuffer buff2 = marshall(av2); assertEquals(buff1, buff2); }
Example #28
Source File: OptionalIntAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public OptionalInt transformTo(AttributeValue input) { if (input.n() != null) { return EnhancedAttributeValue.fromNumber(input.n()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); }
Example #29
Source File: DefaultDocumentTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void noExtension_mapsToItem() { FakeItem fakeItem = FakeItem.createUniqueFakeItem(); Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, true); Document defaultDocument = DefaultDocument.create(fakeItemMap); assertThat(defaultDocument.getItem(createMappedTable(null)), is(fakeItem)); }
Example #30
Source File: DynamodbAttributeValueTransformer.java From aws-lambda-java-libs with Apache License 2.0 | 5 votes |
static Map<String, AttributeValue> toAttributeValueMapV2( final Map<String, com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue> attributeValueMap ) { return attributeValueMap .entrySet() .stream() .collect(Collectors.toMap( Map.Entry::getKey, entry -> toAttributeValueV2(entry.getValue()) )); }