|
| 1 | +package org.socialsignin.spring.data.dynamodb.repository.query.nested; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | +import org.junit.runner.RunWith; |
| 5 | +import org.socialsignin.spring.data.dynamodb.core.ConfigurationTI; |
| 6 | +import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.context.annotation.Configuration; |
| 9 | +import org.springframework.test.context.ContextConfiguration; |
| 10 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 11 | + |
| 12 | +import java.util.List; |
| 13 | + |
| 14 | +import static org.junit.Assert.assertEquals; |
| 15 | + |
| 16 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 17 | +@ContextConfiguration(classes = {ConfigurationTI.class, NestedPropertiesIT.TestAppConfig.class}) |
| 18 | +public class NestedPropertiesIT { |
| 19 | + |
| 20 | + @Configuration |
| 21 | + @EnableDynamoDBRepositories(basePackages = "org.socialsignin.spring.data.dynamodb.query.nested") |
| 22 | + public static class TestAppConfig { |
| 23 | + } |
| 24 | + |
| 25 | + @Autowired |
| 26 | + private PersonRepository personRepository; |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testNestedProperty() { |
| 30 | + |
| 31 | + Address usaAddress = new Address(); |
| 32 | + usaAddress.setCity("New York"); |
| 33 | + usaAddress.setCountry("USA"); |
| 34 | + |
| 35 | + Address deAddress = new Address(); |
| 36 | + deAddress.setCity("Frankfurt"); |
| 37 | + deAddress.setCity("Germany"); |
| 38 | + |
| 39 | + Person p1 = new Person(); |
| 40 | + p1.setName("personName"); |
| 41 | + p1.setPhone("phone"); |
| 42 | + p1.setArea("area"); |
| 43 | + p1.setAddress(usaAddress); |
| 44 | + |
| 45 | + Person p2 = new Person(); |
| 46 | + p2.setName("otherName"); |
| 47 | + p2.setPhone("42"); |
| 48 | + p2.setArea("otherArea"); |
| 49 | + p2.setAddress(deAddress); |
| 50 | + |
| 51 | +/// personRepository.save(p1); |
| 52 | + |
| 53 | + List<Person> actual = personRepository.findByAddressCountry("USA"); |
| 54 | + assertEquals(1, actual.size()); |
| 55 | + |
| 56 | + actual = personRepository.findByPhone("42"); |
| 57 | + assertEquals(1, actual.size()); |
| 58 | + } |
| 59 | +} |
0 commit comments