com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshaller Java Examples
The following examples show how to use
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshaller.
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: AbstractDynamoDBQueryCriteria.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected <V> Object getPropertyAttributeValue(String propertyName, Object value) { DynamoDBMarshaller<V> marshaller = (DynamoDBMarshaller<V>) entityInformation.getMarshallerForProperty(propertyName); if (marshaller != null) { return marshaller.marshall((V) value); } else { return value; } }
Example #2
Source File: AbstractDynamoDBQueryCriteria.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
private List<String> getDateListAsStringList(List<Date> dateList) { DynamoDBMarshaller<Date> marshaller = new DefaultDynamoDBDateMarshaller(); List<String> list = new ArrayList<String>(); for (Date date : dateList) { if (date != null) { list.add(marshaller.marshall(date)); } else { list.add(null); } } return list; }
Example #3
Source File: DynamoDBIdIsHashKeyEntityInformationImplUnitTest.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@Test public void testGetMarshallerForProperty_DelegatesToEntityMetadata_IrrespectiveOfEntityInformationSetup() { DynamoDBMarshaller<?> marshaller1 = dynamoDBPlaylistEntityInformation.getMarshallerForProperty("marshalledProperty"); Assert.assertEquals(mockPropertyMarshaller, marshaller1); DynamoDBMarshaller<?> marshaller2 = dynamoDBUserEntityInformation.getMarshallerForProperty("marshalledProperty"); Assert.assertEquals(mockPropertyMarshaller, marshaller2); }
Example #4
Source File: DynamoDBIdIsHashAndRangeKeyEntityInformationImplUnitTest.java From spring-data-dynamodb with Apache License 2.0 | 5 votes |
@Test public void testGetMarshallerForProperty_DelegatesToEntityMetadata_IrrespectiveOfEntityInformationSetup() { DynamoDBMarshaller<?> marshaller1 = dynamoDBPlaylistEntityInformation.getMarshallerForProperty("marshalledProperty"); Assert.assertEquals(mockPropertyMarshaller, marshaller1); }
Example #5
Source File: DynamoDBIdIsHashKeyEntityInformationImpl.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
@Override public DynamoDBMarshaller<?> getMarshallerForProperty(String propertyName) { return metadata.getMarshallerForProperty(propertyName); }
Example #6
Source File: DynamoDBIdIsHashAndRangeKeyEntityInformationImpl.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
@Override public DynamoDBMarshaller<?> getMarshallerForProperty(String propertyName) { return metadata.getMarshallerForProperty(propertyName); }
Example #7
Source File: PartTreeDynamoDBQueryUnitTest.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testExecute_WhenFinderMethodIsFindingEntityList_WithSingleDateParameter_WithCustomMarshaller_WhenNotFindingByHashKey() throws ParseException { String joinYearString = "2013"; DateFormat dateFormat = new SimpleDateFormat("yyyy"); Date joinYear = dateFormat.parse(joinYearString); setupCommonMocksForThisRepositoryMethod(mockUserEntityMetadata, mockDynamoDBUserQueryMethod, User.class, "findByJoinYear", 1, "id", null); Mockito.when(mockDynamoDBUserQueryMethod.isCollectionQuery()).thenReturn(true); DynamoDBMarshaller marshaller = new DynamoDBYearMarshaller(); Mockito.when(mockUserEntityMetadata.getMarshallerForProperty("joinYear")).thenReturn(marshaller); // Mock out specific DynamoDBOperations behavior expected by this method ArgumentCaptor<DynamoDBScanExpression> scanCaptor = ArgumentCaptor.forClass(DynamoDBScanExpression.class); ArgumentCaptor<Class> classCaptor = ArgumentCaptor.forClass(Class.class); Mockito.when(mockUserScanResults.get(0)).thenReturn(mockUser); Mockito.when(mockUserScanResults.size()).thenReturn(1); Mockito.when(mockDynamoDBOperations.scan(classCaptor.capture(), scanCaptor.capture())).thenReturn( mockUserScanResults); // Execute the query Object[] parameters = new Object[] { joinYear }; Object o = partTreeDynamoDBQuery.execute(parameters); // Assert that we obtain the expected list of results assertEquals(o, mockUserScanResults); // Assert that the list of results contains the correct elements assertEquals(1, mockUserScanResults.size()); assertEquals(mockUser, mockUserScanResults.get(0)); // Assert that we scanned DynamoDB for the correct class assertEquals(classCaptor.getValue(), User.class); // Assert that we have only one filter condition, for the name of the // property Map<String, Condition> filterConditions = scanCaptor.getValue().getScanFilter(); assertEquals(1, filterConditions.size()); Condition filterCondition = filterConditions.get("joinYear"); assertNotNull(filterCondition); assertEquals(ComparisonOperator.EQ.name(), filterCondition.getComparisonOperator()); // Assert we only have one attribute value for this filter condition assertEquals(1, filterCondition.getAttributeValueList().size()); // Assert that there the attribute value type for this attribute value // is String, // and its value is the parameter expected assertEquals(joinYearString, filterCondition.getAttributeValueList().get(0).getS()); // Assert that all other attribute value types other than String type // are null assertNull(filterCondition.getAttributeValueList().get(0).getSS()); assertNull(filterCondition.getAttributeValueList().get(0).getN()); assertNull(filterCondition.getAttributeValueList().get(0).getNS()); assertNull(filterCondition.getAttributeValueList().get(0).getB()); assertNull(filterCondition.getAttributeValueList().get(0).getBS()); // Verify that the expected DynamoDBOperations method was called Mockito.verify(mockDynamoDBOperations).scan(classCaptor.getValue(), scanCaptor.getValue()); }
Example #8
Source File: PartTreeDynamoDBQueryUnitTest.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testExecute_WhenFinderMethodIsFindingEntityList_WithSingleDateParameter_WithCustomMarshaller_WhenFindingByGlobalSecondaryHashIndexHashKey() throws ParseException { String joinYearString = "2013"; DateFormat dateFormat = new SimpleDateFormat("yyyy"); Date joinYear = dateFormat.parse(joinYearString); setupCommonMocksForThisRepositoryMethod(mockUserEntityMetadata, mockDynamoDBUserQueryMethod, User.class, "findByJoinYear", 1, "id", null); Mockito.when(mockDynamoDBUserQueryMethod.isCollectionQuery()).thenReturn(true); DynamoDBMarshaller marshaller = new DynamoDBYearMarshaller(); Mockito.when(mockUserEntityMetadata.isGlobalIndexHashKeyProperty("joinYear")).thenReturn(true); Mockito.when(mockUserEntityMetadata.getMarshallerForProperty("joinYear")).thenReturn(marshaller); Map<String, String[]> indexRangeKeySecondaryIndexNames = new HashMap<String,String[]>(); indexRangeKeySecondaryIndexNames.put("joinYear", new String[] {"JoinYear-index"}); Mockito.when(mockUserEntityMetadata.getGlobalSecondaryIndexNamesByPropertyName()).thenReturn(indexRangeKeySecondaryIndexNames); Mockito.when(mockUserEntityMetadata.getDynamoDBTableName()).thenReturn("user"); // Mock out specific QueryRequestMapper behavior expected by this method ArgumentCaptor<QueryRequest> queryCaptor = ArgumentCaptor.forClass(QueryRequest.class); ArgumentCaptor<Class> classCaptor = ArgumentCaptor.forClass(Class.class); Mockito.when(mockUserQueryResults.get(0)).thenReturn(mockUser); Mockito.when(mockUserQueryResults.size()).thenReturn(1); Mockito.when(mockDynamoDBOperations.query(classCaptor.capture(), queryCaptor.capture())) .thenReturn(mockUserQueryResults); Mockito.when(mockDynamoDBOperations.getOverriddenTableName("user")).thenReturn("user"); // Execute the query Object[] parameters = new Object[] { joinYear}; Object o = partTreeDynamoDBQuery.execute(parameters); // Assert that we obtain the expected results assertEquals(mockUserQueryResults, o); assertEquals(1, mockUserQueryResults.size()); assertEquals(mockUser, mockUserQueryResults.get(0)); // Assert that we scanned DynamoDB for the correct class assertEquals(classCaptor.getValue(), User.class); String indexName = queryCaptor.getValue().getIndexName(); assertNotNull(indexName); assertEquals("JoinYear-index",indexName); assertEquals("user",queryCaptor.getValue().getTableName()); // Assert that we have only one range condition for the global secondary index hash key assertEquals(1,queryCaptor.getValue().getKeyConditions().size()); Condition condition = queryCaptor.getValue().getKeyConditions().get("joinYear"); assertEquals(ComparisonOperator.EQ.name(),condition.getComparisonOperator()); assertEquals(1,condition.getAttributeValueList().size()); assertEquals(joinYearString,condition.getAttributeValueList().get(0).getS()); // Assert that all other attribute value types other than String type // are null assertNull(condition.getAttributeValueList().get(0).getSS()); assertNull(condition.getAttributeValueList().get(0).getN()); assertNull(condition.getAttributeValueList().get(0).getNS()); assertNull(condition.getAttributeValueList().get(0).getB()); assertNull(condition.getAttributeValueList().get(0).getBS()); // Verify that the expected DynamoDBOperations method was called Mockito.verify(mockDynamoDBOperations).query(classCaptor.getValue(), queryCaptor.getValue()); }
Example #9
Source File: PartTreeDynamoDBQueryUnitTest.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testExecute_WhenFinderMethodIsFindingEntityList_WithDateParameterAndStringParameter_WithCustomMarshaller_WhenFindingByGlobalSecondaryHashAndRangeIndexHashAndRangeKey() throws ParseException { String joinYearString = "2013"; DateFormat dateFormat = new SimpleDateFormat("yyyy"); Date joinYear = dateFormat.parse(joinYearString); setupCommonMocksForThisRepositoryMethod(mockUserEntityMetadata, mockDynamoDBUserQueryMethod, User.class, "findByJoinYearAndPostCode", 2, "id", null); Mockito.when(mockDynamoDBUserQueryMethod.isCollectionQuery()).thenReturn(true); DynamoDBMarshaller marshaller = new DynamoDBYearMarshaller(); Mockito.when(mockUserEntityMetadata.isGlobalIndexHashKeyProperty("joinYear")).thenReturn(true); Mockito.when(mockUserEntityMetadata.isGlobalIndexRangeKeyProperty("postCode")).thenReturn(true); Mockito.when(mockUserEntityMetadata.getMarshallerForProperty("joinYear")).thenReturn(marshaller); Map<String, String[]> indexRangeKeySecondaryIndexNames = new HashMap<String,String[]>(); indexRangeKeySecondaryIndexNames.put("joinYear", new String[] {"JoinYear-index"}); indexRangeKeySecondaryIndexNames.put("postCode", new String[] {"JoinYear-index"}); Mockito.when(mockUserEntityMetadata.getGlobalSecondaryIndexNamesByPropertyName()).thenReturn(indexRangeKeySecondaryIndexNames); // Mock out specific QueryRequestMapper behavior expected by this method ArgumentCaptor<QueryRequest> queryCaptor = ArgumentCaptor.forClass(QueryRequest.class); ArgumentCaptor<Class> classCaptor = ArgumentCaptor.forClass(Class.class); Mockito.when(mockUserQueryResults.get(0)).thenReturn(mockUser); Mockito.when(mockUserQueryResults.size()).thenReturn(1); Mockito.when(mockDynamoDBOperations.query(classCaptor.capture(), queryCaptor.capture())) .thenReturn(mockUserQueryResults); Mockito.when(mockUserEntityMetadata.getDynamoDBTableName()).thenReturn("user"); Mockito.when(mockDynamoDBOperations.getOverriddenTableName("user")).thenReturn("user"); // Execute the query Object[] parameters = new Object[] { joinYear,"nw1"}; Object o = partTreeDynamoDBQuery.execute(parameters); // Assert that we obtain the expected results assertEquals(mockUserQueryResults, o); assertEquals(1, mockUserQueryResults.size()); assertEquals(mockUser, mockUserQueryResults.get(0)); // Assert that we scanned DynamoDB for the correct class assertEquals(classCaptor.getValue(), User.class); String indexName = queryCaptor.getValue().getIndexName(); assertNotNull(indexName); assertEquals("JoinYear-index",indexName); // Assert that we have only two range conditions for the global secondary index hash key and range key assertEquals(2,queryCaptor.getValue().getKeyConditions().size()); Condition yearCondition = queryCaptor.getValue().getKeyConditions().get("joinYear"); assertEquals(ComparisonOperator.EQ.name(),yearCondition.getComparisonOperator()); assertEquals(1,yearCondition.getAttributeValueList().size()); assertEquals(joinYearString,yearCondition.getAttributeValueList().get(0).getS()); Condition postCodeCondition = queryCaptor.getValue().getKeyConditions().get("postCode"); assertEquals(ComparisonOperator.EQ.name(),postCodeCondition.getComparisonOperator()); assertEquals(1,postCodeCondition.getAttributeValueList().size()); assertEquals("nw1",postCodeCondition.getAttributeValueList().get(0).getS()); assertEquals("user",queryCaptor.getValue().getTableName()); // Assert that all other attribute value types other than String type // are null assertNull(yearCondition.getAttributeValueList().get(0).getSS()); assertNull(yearCondition.getAttributeValueList().get(0).getN()); assertNull(yearCondition.getAttributeValueList().get(0).getNS()); assertNull(yearCondition.getAttributeValueList().get(0).getB()); assertNull(yearCondition.getAttributeValueList().get(0).getBS()); assertNull(postCodeCondition.getAttributeValueList().get(0).getSS()); assertNull(postCodeCondition.getAttributeValueList().get(0).getN()); assertNull(postCodeCondition.getAttributeValueList().get(0).getNS()); assertNull(postCodeCondition.getAttributeValueList().get(0).getB()); assertNull(postCodeCondition.getAttributeValueList().get(0).getBS()); // Verify that the expected DynamoDBOperations method was called Mockito.verify(mockDynamoDBOperations).query(classCaptor.getValue(),queryCaptor.getValue()); }
Example #10
Source File: PartTreeDynamoDBQueryUnitTest.java From spring-data-dynamodb with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testExecute_WhenFinderMethodIsFindingEntityList_WithSingleStringParameter_WithCustomMarshaller_WhenNotFindingByHashKey() throws ParseException { String postcode = "N1"; setupCommonMocksForThisRepositoryMethod(mockUserEntityMetadata, mockDynamoDBUserQueryMethod, User.class, "findByPostCode", 1, "id", null); Mockito.when(mockDynamoDBUserQueryMethod.isCollectionQuery()).thenReturn(true); DynamoDBMarshaller marshaller = new CaseChangingMarshaller(); Mockito.when(mockUserEntityMetadata.getMarshallerForProperty("postCode")).thenReturn(marshaller); // Mock out specific DynamoDBOperations behavior expected by this method ArgumentCaptor<DynamoDBScanExpression> scanCaptor = ArgumentCaptor.forClass(DynamoDBScanExpression.class); ArgumentCaptor<Class> classCaptor = ArgumentCaptor.forClass(Class.class); Mockito.when(mockUserScanResults.get(0)).thenReturn(mockUser); Mockito.when(mockUserScanResults.size()).thenReturn(1); Mockito.when(mockDynamoDBOperations.scan(classCaptor.capture(), scanCaptor.capture())).thenReturn( mockUserScanResults); // Execute the query Object[] parameters = new Object[] { postcode }; Object o = partTreeDynamoDBQuery.execute(parameters); // Assert that we obtain the expected list of results assertEquals(o, mockUserScanResults); // Assert that the list of results contains the correct elements assertEquals(1, mockUserScanResults.size()); assertEquals(mockUser, mockUserScanResults.get(0)); // Assert that we scanned DynamoDB for the correct class assertEquals(classCaptor.getValue(), User.class); // Assert that we have only one filter condition, for the name of the // property Map<String, Condition> filterConditions = scanCaptor.getValue().getScanFilter(); assertEquals(1, filterConditions.size()); Condition filterCondition = filterConditions.get("postCode"); assertNotNull(filterCondition); assertEquals(ComparisonOperator.EQ.name(), filterCondition.getComparisonOperator()); // Assert we only have one attribute value for this filter condition assertEquals(1, filterCondition.getAttributeValueList().size()); // Assert that there the attribute value type for this attribute value // is String, // and its value is the parameter expected assertEquals("n1", filterCondition.getAttributeValueList().get(0).getS()); // Assert that all other attribute value types other than String type // are null assertNull(filterCondition.getAttributeValueList().get(0).getSS()); assertNull(filterCondition.getAttributeValueList().get(0).getN()); assertNull(filterCondition.getAttributeValueList().get(0).getNS()); assertNull(filterCondition.getAttributeValueList().get(0).getB()); assertNull(filterCondition.getAttributeValueList().get(0).getBS()); // Verify that the expected DynamoDBOperations method was called Mockito.verify(mockDynamoDBOperations).scan(classCaptor.getValue(), scanCaptor.getValue()); }
Example #11
Source File: DynamoDBHashKeyExtractingEntityMetadata.java From spring-data-dynamodb with Apache License 2.0 | votes |
public DynamoDBMarshaller<?> getMarshallerForProperty(String propertyName);