|
| 1 | +package org.socialsignin.spring.data.dynamodb.core; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertNotEquals; |
| 5 | +import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS; |
| 6 | + |
| 7 | +import java.time.LocalDateTime; |
| 8 | +import java.util.Random; |
| 9 | + |
| 10 | +import org.junit.Ignore; |
| 11 | +import org.junit.Test; |
| 12 | +import org.junit.runner.RunWith; |
| 13 | +import org.socialsignin.spring.data.dynamodb.domain.sample.Feed; |
| 14 | +import org.socialsignin.spring.data.dynamodb.domain.sample.FeedPagingRepository; |
| 15 | +import org.socialsignin.spring.data.dynamodb.domain.sample.FeedUserRepository; |
| 16 | +import org.socialsignin.spring.data.dynamodb.domain.sample.User; |
| 17 | +import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; |
| 18 | +import org.socialsignin.spring.data.dynamodb.utils.DynamoDBLocalResource; |
| 19 | +import org.socialsignin.spring.data.dynamodb.utils.DynamoDBResource; |
| 20 | +import org.socialsignin.spring.data.dynamodb.utils.TableCreationListener; |
| 21 | +import org.socialsignin.spring.data.dynamodb.utils.TableCreationListener.DynamoDBCreateTable; |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
| 23 | +import org.springframework.context.annotation.Configuration; |
| 24 | +import org.springframework.data.domain.Page; |
| 25 | +import org.springframework.data.domain.PageRequest; |
| 26 | +import org.springframework.data.domain.Sort; |
| 27 | +import org.springframework.data.domain.Sort.Direction; |
| 28 | +import org.springframework.test.context.ContextConfiguration; |
| 29 | +import org.springframework.test.context.TestExecutionListeners; |
| 30 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 31 | + |
| 32 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 33 | +@ContextConfiguration(classes = {SortPageableIT.TestAppConfig.class, DynamoDBLocalResource.class}) |
| 34 | +@TestExecutionListeners(listeners = TableCreationListener.class, mergeMode = MERGE_WITH_DEFAULTS) |
| 35 | +@DynamoDBCreateTable(entityClasses = {Feed.class}) |
| 36 | +public class SortPageableIT { |
| 37 | + private final Random r = new Random(); |
| 38 | + |
| 39 | + @Configuration |
| 40 | + @EnableDynamoDBRepositories(basePackages = "org.socialsignin.spring.data.dynamodb.domain.sample") |
| 41 | + public static class TestAppConfig { |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + @Autowired |
| 46 | + FeedPagingRepository feedPagingRepository; |
| 47 | + |
| 48 | + private Feed createFeed(String message) { |
| 49 | + Feed retValue = new Feed(); |
| 50 | + retValue.setUserIdx(r.nextInt()); |
| 51 | + retValue.setPaymentType(r.nextInt()); |
| 52 | + retValue.setMessage(message); |
| 53 | + retValue.setRegDate(LocalDateTime.now()); |
| 54 | + return retValue; |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void feed_test() { |
| 59 | + feedPagingRepository.save(createFeed("not yet me")); |
| 60 | + feedPagingRepository.save(createFeed("me")); |
| 61 | + feedPagingRepository.save(createFeed("not me")); |
| 62 | + feedPagingRepository.save(createFeed("me")); |
| 63 | + feedPagingRepository.save(createFeed("also not me")); |
| 64 | + |
| 65 | + PageRequest pageable = PageRequest.of(0, 10); |
| 66 | + |
| 67 | + Page<Feed> actuals = feedPagingRepository.findAllByMessageOrderByRegDateDesc("me", pageable); |
| 68 | + assertEquals(2, actuals.getTotalElements()); |
| 69 | + |
| 70 | + for (Feed actual : actuals) { |
| 71 | + assertNotEquals(0, actual.getPaymentType()); |
| 72 | + assertNotEquals(0, actual.getUserIdx()); |
| 73 | + } |
| 74 | + |
| 75 | + } |
| 76 | +} |
0 commit comments