com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException Java Examples
The following examples show how to use
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException.
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: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Use APPEND_SET to put a new item in the table. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testAppendSetWithKeyAndNonKeyAttributesSpecifiedRecordNotInTable() throws Exception { TestItem testItem = new TestItem(); testItem.setHashKey(UUID.randomUUID().toString()); testItem.setRangeKey(System.currentTimeMillis()); testItem.setNonKeyAttribute("new item"); testItem.setStringSetAttribute(generateRandomStringSet(3)); dynamoMapper.save(testItem, appendSetConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertEquals(testItem.getNonKeyAttribute(), returnedObject.getNonKeyAttribute()); assertEquals(testItem.getStringSetAttribute(), returnedObject.getStringSetAttribute()); }
Example #2
Source File: MetaStoreTests.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test public void twoDifferentMaterials() { assertEquals(-1, store.getMaxVersion(MATERIAL_NAME)); final EncryptionMaterialsProvider prov1 = store.newProvider(MATERIAL_NAME); assertEquals(0, store.getMaxVersion(MATERIAL_NAME)); final EncryptionMaterialsProvider prov2 = store.newProvider(MATERIAL_NAME); assertEquals(1, store.getMaxVersion(MATERIAL_NAME)); final EncryptionMaterials eMat = prov1.getEncryptionMaterials(ctx); assertEquals(0, store.getVersionFromMaterialDescription(eMat.getMaterialDescription())); final SecretKey encryptionKey = eMat.getEncryptionKey(); assertNotNull(encryptionKey); try { prov2.getDecryptionMaterials(ctx(eMat)); fail("Missing expected exception"); } catch (final DynamoDBMappingException ex) { // Expected Exception } final EncryptionMaterials eMat2 = prov2.getEncryptionMaterials(ctx); assertEquals(1, store.getVersionFromMaterialDescription(eMat2.getMaterialDescription())); }
Example #3
Source File: DirectKmsMaterialProviderTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void encryptionKeyIdMismatch() throws GeneralSecurityException { DirectKmsMaterialProvider directProvider = new DirectKmsMaterialProvider(kms, keyId); String customKeyId = kms.createKey().getKeyMetadata().getKeyId(); Map<String, AttributeValue> attrVals = new HashMap<>(); attrVals.put("hk", new AttributeValue().withN("10")); attrVals.put("rk", new AttributeValue().withN("20")); attrVals.put("encryptionKeyId", new AttributeValue().withS(customKeyId)); ctx = new EncryptionContext.Builder().withHashKeyName("hk").withRangeKeyName("rk") .withTableName("KmsTableName").withAttributeValues(attrVals).build(); EncryptionMaterials eMat = directProvider.getEncryptionMaterials(ctx); EncryptionContext dCtx = new EncryptionContext.Builder(ctx(eMat)).withHashKeyName("hk") .withRangeKeyName("rk").withTableName("KmsTableName").withAttributeValues(attrVals) .build(); ExtendedKmsMaterialProvider extendedProvider = new ExtendedKmsMaterialProvider(kms, keyId, "encryptionKeyId"); extendedProvider.getDecryptionMaterials(dCtx); }
Example #4
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Tests that a key-only object could be saved with * UPDATE configuration, even when the key has already existed in the table. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testDefaultWithOnlyKeyAttributesSpecifiedRecordInTable() throws Exception { /* First put a new item (with non-key attribute)*/ TestItem testItem = putRandomUniqueItem("foo", null); /* Put an key-only object with the same key */ testItem.setNonKeyAttribute(null); dynamoMapper.save(testItem, defaultConfig); /* The non-key attribute should be nulled out. */ TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertNull(returnedObject.getNonKeyAttribute()); }
Example #5
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Tests an edge case that we have fixed according a forum bug report. If * the object is only specified with key attributes, and such key is not * present in the table, we should add this object by a key-only put * request even if it is using UPDATE configuration. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testDefaultWithOnlyKeyAttributesSpecifiedRecordNotInTable() throws Exception { TestItem testItem = new TestItem(); testItem.setHashKey(UUID.randomUUID().toString()); testItem.setRangeKey(System.currentTimeMillis()); dynamoMapper.save(testItem, defaultConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertNull(returnedObject.getNonKeyAttribute()); }
Example #6
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Use UPDATE to put a new item in the table. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testDefaultWithKeyAndNonKeyAttributesSpecifiedRecordNotInTable() throws Exception { TestItem testItem = new TestItem(); testItem.setHashKey(UUID.randomUUID().toString()); testItem.setRangeKey(System.currentTimeMillis()); testItem.setNonKeyAttribute("new item"); dynamoMapper.save(testItem, defaultConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertEquals(testItem.getNonKeyAttribute(), returnedObject.getNonKeyAttribute()); }
Example #7
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * When using UPDATE_SKIP_NULL_ATTRIBUTES, key-only update on existing item * should not affect the item at all, since all the null-valued non-key * attributes are ignored. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testUpdateSkipNullWithOnlyKeyAttributesSpecifiedRecordInTable() throws Exception { /* First put a new item (with non-key attribute)*/ TestItem testItem = putRandomUniqueItem("foo", null); /* Put an key-only object with the same key */ testItem.setNonKeyAttribute(null); dynamoMapper.save(testItem, updateSkipNullConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); /* The non-key attribute should not be removed */ assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertEquals("foo", returnedObject.getNonKeyAttribute()); }
Example #8
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * The behavior should be the same as UPDATE. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testUpdateSkipNullWithOnlyKeyAttributesSpecifiedRecordNotInTable() throws Exception { TestItem testItem = new TestItem(); testItem.setHashKey(UUID.randomUUID().toString()); testItem.setRangeKey(System.currentTimeMillis()); dynamoMapper.save(testItem, updateSkipNullConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertNull(returnedObject.getNonKeyAttribute()); }
Example #9
Source File: KeyStoreMaterialsProvider.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Override public DecryptionMaterials getDecryptionMaterials(EncryptionContext context) { CurrentMaterials materials = currMaterials.get(); if (context.getMaterialDescription().entrySet().containsAll(description.entrySet())) { if (materials.encryptionEntry instanceof SecretKeyEntry) { return materials.symRawMaterials; } else { try { return makeAsymMaterials(materials, context.getMaterialDescription()); } catch (GeneralSecurityException ex) { throw new DynamoDBMappingException("Unable to decrypt envelope key", ex); } } } else { return null; } }
Example #10
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Use UPDATE_SKIP_NULL_ATTRIBUTES to put a new item in the table. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testUpdateSkipNullWithKeyAndNonKeyAttributesSpecifiedRecordNotInTable() throws Exception { TestItem testItem = new TestItem(); testItem.setHashKey(UUID.randomUUID().toString()); testItem.setRangeKey(System.currentTimeMillis()); testItem.setNonKeyAttribute("new item"); dynamoMapper.save(testItem, updateSkipNullConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertEquals(testItem.getNonKeyAttribute(), returnedObject.getNonKeyAttribute()); }
Example #11
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * The behavior should be the same as UPDATE_SKIP_NULL_ATTRIBUTES. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testAppendSetWithOnlyKeyAttributesSpecifiedRecordInTable() throws Exception { /* First put a new item (with non-key attributes)*/ Set<String> randomSet = generateRandomStringSet(3); TestItem testItem = putRandomUniqueItem("foo", randomSet); /* Put an key-only object with the same key */ testItem.setNonKeyAttribute(null); testItem.setStringSetAttribute(null); dynamoMapper.save(testItem, appendSetConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); /* The non-key attribute should not be removed */ assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertEquals("foo", returnedObject.getNonKeyAttribute()); assertTrue(assertSetEquals(randomSet, returnedObject.getStringSetAttribute())); }
Example #12
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * The behavior should be the same as UPDATE and UPDATE_SKIP_NULL_ATTRIBUTES. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testAppendSetWithOnlyKeyAttributesSpecifiedRecordNotInTable() throws Exception { TestItem testItem = new TestItem(); testItem.setHashKey(UUID.randomUUID().toString()); testItem.setRangeKey(System.currentTimeMillis()); dynamoMapper.save(testItem, appendSetConfig); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertNull(returnedObject.getNonKeyAttribute()); assertNull(returnedObject.getStringSetAttribute()); }
Example #13
Source File: EnvironmentVariableTableNameResolver.java From Building-Serverless-Architectures with MIT License | 5 votes |
@Override public String getTableName(Class<?> clazz, DynamoDBMapperConfig config) { String environmentVariableName = "DynamoDb" + clazz.getSimpleName() + "Table"; String tableName = System.getenv(environmentVariableName); if (tableName == null) { throw new DynamoDBMappingException("DynamoDB table name for " + clazz + " cannot be determined. " + environmentVariableName + " environment variable should be set."); } return tableName; }
Example #14
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testPrivateSetterLoad() throws Exception { DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); PrivateSetter object = new PrivateSetter(); object.setStringProperty("value"); util.save(object); util.load(PrivateSetter.class, object.getKey()); }
Example #15
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testOverloadedSetter() { OverloadedSetter obj = new OverloadedSetter(); obj.setKey("" + startKey++); obj.setAttribute("abc", "123"); DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); mapper.save(obj); mapper.load(OverloadedSetter.class, obj.getKey()); }
Example #16
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testWrongTypeForSetter() { WrongTypeForSetter obj = new WrongTypeForSetter(); obj.setKey("" + startKey++); obj.setAttribute(123); DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); mapper.save(obj); mapper.load(WrongTypeForSetter.class, obj.getKey()); }
Example #17
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testWrongDataType() { Map<String, AttributeValue> attr = new HashMap<String, AttributeValue>(); attr.put("integerProperty", new AttributeValue().withS("abc")); attr.put(KEY_NAME, new AttributeValue().withS("" + startKey++)); dynamo.putItem(new PutItemRequest().withTableName(TABLE_NAME).withItem(attr)); DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); util.load(NumericFields.class, attr.get(KEY_NAME).getS()); }
Example #18
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testPrivateKeySetterLoad() throws Exception { Map<String, AttributeValue> attr = new HashMap<String, AttributeValue>(); attr.put(KEY_NAME, new AttributeValue().withS("abc")); dynamo.putItem(new PutItemRequest().withTableName(TABLE_NAME).withItem(attr)); DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); util.load(PrivateKeySetter.class, "abc"); }
Example #19
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testWrongDataType2() { Map<String, AttributeValue> attr = new HashMap<String, AttributeValue>(); attr.put("integerProperty", new AttributeValue().withNS("1", "2", "3")); attr.put(KEY_NAME, new AttributeValue().withS("" + startKey++)); dynamo.putItem(new PutItemRequest().withTableName(TABLE_NAME).withItem(attr)); DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); util.load(NumericFields.class, attr.get(KEY_NAME).getS()); }
Example #20
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testUnsupportedHashKeyType() { ComplexType complexType = new ComplexType("" + startKey++, new ComplexType("" + startKey++, null)); ComplexHashKeyType obj = new ComplexHashKeyType(); obj.setKey(complexType); obj.setAttribute("abc"); DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); util.save(obj); }
Example #21
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testFractionalVersionAttribute() { FractionalVersionAttribute obj = new FractionalVersionAttribute(); obj.setKey("" + startKey++); obj.setVersion(0d); DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); mapper.save(obj); }
Example #22
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testAutoGeneratedIntegerHashKey() { AutoGeneratedIntegerKey obj = new AutoGeneratedIntegerKey(); obj.setValue("fdgfdsgf"); DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); mapper.save(obj); }
Example #23
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testAutoGeneratedIntegerRangeKey() { AutoGeneratedIntegerRangeKey obj = new AutoGeneratedIntegerRangeKey(); obj.setKey("Bldadsfa"); obj.setValue("fdgfdsgf"); DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); mapper.save(obj); }
Example #24
Source File: MapperSaveConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
/** * Update an existing item in the table. */ @Test(expectedExceptions = DynamoDBMappingException.class) public void testDefaultWithKeyAndNonKeyAttributesSpecifiedRecordInTable() throws Exception { /* First put a new item (without non-key attribute)*/ TestItem testItem = putRandomUniqueItem(null, null); String hashKeyValue = testItem.getHashKey(); Long rangeKeyValue = testItem.getRangeKey(); TestItem returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(hashKeyValue, returnedObject.getHashKey()); assertEquals(rangeKeyValue, returnedObject.getRangeKey()); assertNull(returnedObject.getNonKeyAttribute()); /* Put an updated object with the same key and an additional non-key attribute. */ testItem.setHashKey(hashKeyValue); testItem.setRangeKey(rangeKeyValue); testItem.setNonKeyAttribute("update"); dynamoMapper.save(testItem, defaultConfig); returnedObject = (TestItem) dynamoMapper.load(testItem); assertNotNull(returnedObject); assertEquals(testItem.getHashKey(), returnedObject.getHashKey()); assertEquals(testItem.getRangeKey(), returnedObject.getRangeKey()); assertEquals(testItem.getNonKeyAttribute(), returnedObject.getNonKeyAttribute()); }
Example #25
Source File: EnvironmentVariableTableNameResolver.java From Building-Serverless-Architectures with MIT License | 5 votes |
@Override public String getTableName(Class<?> clazz, DynamoDBMapperConfig config) { String environmentVariableName = "DynamoDb" + clazz.getSimpleName() + "Table"; String tableName = System.getenv(environmentVariableName); if (tableName == null) { throw new DynamoDBMappingException("DynamoDB table name for " + clazz + " cannot be determined. " + environmentVariableName + " environment variable should be set."); } return tableName; }
Example #26
Source File: EnvironmentVariableTableNameResolver.java From Building-Serverless-Architectures with MIT License | 5 votes |
@Override public String getTableName(Class<?> clazz, DynamoDBMapperConfig config) { String environmentVariableName = "DynamoDb" + clazz.getSimpleName() + "Table"; String tableName = System.getenv(environmentVariableName); if (tableName == null) { throw new DynamoDBMappingException("DynamoDB table name for " + clazz + " cannot be determined. " + environmentVariableName + " environment variable should be set."); } return tableName; }
Example #27
Source File: EnvironmentVariableTableNameResolver.java From Building-Serverless-Architectures with MIT License | 5 votes |
@Override public String getTableName(Class<?> clazz, DynamoDBMapperConfig config) { String environmentVariableName = "DynamoDb" + clazz.getSimpleName() + "Table"; String tableName = System.getenv(environmentVariableName); if (tableName == null) { throw new DynamoDBMappingException("DynamoDB table name for " + clazz + " cannot be determined. " + environmentVariableName + " environment variable should be set."); } return tableName; }
Example #28
Source File: ExceptionHandlingITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DynamoDBMappingException.class) public void testNoDefaultConstructor() { DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); NoDefaultConstructor obj = new NoDefaultConstructor("" + startKey++, "abc"); util.save(obj); util.load(NoDefaultConstructor.class, obj.getKey()); }
Example #29
Source File: EnvironmentVariableTableNameResolver.java From Building-Serverless-Architectures with MIT License | 5 votes |
@Override public String getTableName(Class<?> clazz, DynamoDBMapperConfig config) { String environmentVariableName = "DynamoDb" + clazz.getSimpleName() + "Table"; String tableName = System.getenv(environmentVariableName); if (tableName == null) { throw new DynamoDBMappingException("DynamoDB table name for " + clazz + " cannot be determined. " + environmentVariableName + " environment variable should be set."); } return tableName; }
Example #30
Source File: DirectKmsMaterialProviderTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Override protected void validateEncryptionKeyId(String encryptionKeyId, EncryptionContext context) throws DynamoDBMappingException { if (!context.getAttributeValues().containsKey(encryptionKeyIdAttributeName)) { throw new DynamoDBMappingException("encryption key attribute is not provided"); } String customEncryptionKeyId = context.getAttributeValues().get(encryptionKeyIdAttributeName).getS(); if (!customEncryptionKeyId.equals(encryptionKeyId)) { throw new DynamoDBMappingException("encryption key ids do not match."); } }