|
17 | 17 |
|
18 | 18 | import static org.hamcrest.CoreMatchers.*;
|
19 | 19 | import static org.junit.Assert.*;
|
20 |
| -import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.*; |
21 |
| -import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.startsWith; |
| 20 | +import static org.springframework.data.domain.ExampleMatcher.*; |
| 21 | +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; |
| 22 | +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith; |
22 | 23 |
|
23 | 24 | import org.junit.Before;
|
24 | 25 | import org.junit.Test;
|
25 | 26 | import org.junit.runner.RunWith;
|
26 | 27 | import org.springframework.beans.factory.annotation.Autowired;
|
27 | 28 | import org.springframework.boot.test.SpringApplicationConfiguration;
|
28 | 29 | import org.springframework.data.domain.Example;
|
29 |
| -import org.springframework.data.domain.ExampleSpec; |
| 30 | +import org.springframework.data.domain.ExampleMatcher.StringMatcher; |
30 | 31 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
31 | 32 | import org.springframework.transaction.annotation.Transactional;
|
32 | 33 |
|
33 | 34 | /**
|
34 | 35 | * Integration test showing the usage of JPA Query-by-Example support through Spring Data repositories.
|
35 | 36 | *
|
36 | 37 | * @author Mark Paluch
|
| 38 | + * @author Oliver Gierke |
37 | 39 | */
|
| 40 | +@SuppressWarnings("unused") |
38 | 41 | @RunWith(SpringJUnit4ClassRunner.class)
|
39 | 42 | @Transactional
|
40 | 43 | @SpringApplicationConfiguration(classes = ApplicationConfiguration.class)
|
41 | 44 | public class UserRepositoryIntegrationTests {
|
42 | 45 |
|
43 |
| - @Autowired |
44 |
| - UserRepository repository; |
| 46 | + @Autowired UserRepository repository; |
45 | 47 |
|
46 |
| - User skyler, walter, flynn, marie, hank; |
| 48 | + User skyler, walter, flynn, marie, hank; |
47 | 49 |
|
48 |
| - @Before |
49 |
| - public void setUp() { |
| 50 | + @Before |
| 51 | + public void setUp() { |
50 | 52 |
|
51 |
| - repository.deleteAll(); |
| 53 | + repository.deleteAll(); |
52 | 54 |
|
53 |
| - this.skyler = repository.save(new User("Skyler", "White", 45)); |
54 |
| - this.walter = repository.save(new User("Walter", "White", 50)); |
55 |
| - this.flynn = repository.save(new User("Walter Jr. (Flynn)", "White", 17)); |
56 |
| - this.marie = repository.save(new User("Marie", "Schrader", 38)); |
57 |
| - this.hank = repository.save(new User("Hank", "Schrader", 43)); |
58 |
| - } |
| 55 | + this.skyler = repository.save(new User("Skyler", "White", 45)); |
| 56 | + this.walter = repository.save(new User("Walter", "White", 50)); |
| 57 | + this.flynn = repository.save(new User("Walter Jr. (Flynn)", "White", 17)); |
| 58 | + this.marie = repository.save(new User("Marie", "Schrader", 38)); |
| 59 | + this.hank = repository.save(new User("Hank", "Schrader", 43)); |
| 60 | + } |
59 | 61 |
|
60 |
| - /** |
61 |
| - * @see DATAJPA-218 |
62 |
| - */ |
63 |
| - @Test |
64 |
| - public void countBySimpleExample() { |
| 62 | + /** |
| 63 | + * @see #153 |
| 64 | + */ |
| 65 | + @Test |
| 66 | + public void countBySimpleExample() { |
65 | 67 |
|
66 |
| - Example<User> example = Example.of(new User(null, "White", null)); |
| 68 | + Example<User> example = Example.of(new User(null, "White", null)); |
67 | 69 |
|
68 |
| - assertThat(repository.count(example), is(3L)); |
69 |
| - } |
| 70 | + assertThat(repository.count(example), is(3L)); |
| 71 | + } |
70 | 72 |
|
71 |
| - /** |
72 |
| - * @see DATAJPA-218 |
73 |
| - */ |
74 |
| - @Test |
75 |
| - public void ignorePropertiesAndMatchByAge() { |
| 73 | + /** |
| 74 | + * @see #153 |
| 75 | + */ |
| 76 | + @Test |
| 77 | + public void ignorePropertiesAndMatchByAge() { |
76 | 78 |
|
77 |
| - ExampleSpec exampleSpec = ExampleSpec.untyped(). // |
78 |
| - withIgnorePaths("firstname", "lastname"); |
| 79 | + Example<User> example = Example.of(flynn, matching().// |
| 80 | + withIgnorePaths("firstname", "lastname")); |
79 | 81 |
|
80 |
| - assertThat(repository.findOne(Example.of(flynn, exampleSpec)), is(flynn)); |
81 |
| - } |
| 82 | + assertThat(repository.findOne(example), is(flynn)); |
| 83 | + } |
82 | 84 |
|
83 |
| - /** |
84 |
| - * @see DATAJPA-218 |
85 |
| - */ |
86 |
| - @Test |
87 |
| - public void substringMatching() { |
| 85 | + /** |
| 86 | + * @see #153 |
| 87 | + */ |
| 88 | + @Test |
| 89 | + public void substringMatching() { |
88 | 90 |
|
89 |
| - ExampleSpec exampleSpec = ExampleSpec.untyped().// |
90 |
| - withStringMatcherEnding(); |
| 91 | + Example<User> example = Example.of(new User("er", null, null), matching().// |
| 92 | + withStringMatcher(StringMatcher.ENDING)); |
91 | 93 |
|
92 |
| - assertThat(repository.findAll(Example.of(new User("er", null, null), exampleSpec)), hasItems(skyler, walter)); |
93 |
| - } |
| 94 | + assertThat(repository.findAll(example), hasItems(skyler, walter)); |
| 95 | + } |
94 | 96 |
|
95 |
| - /** |
96 |
| - * @see DATAJPA-218 |
97 |
| - */ |
98 |
| - @Test |
99 |
| - public void matchStartingStringsIgnoreCase() { |
| 97 | + /** |
| 98 | + * @see #153 |
| 99 | + */ |
| 100 | + @Test |
| 101 | + public void matchStartingStringsIgnoreCase() { |
100 | 102 |
|
101 |
| - ExampleSpec exampleSpec = ExampleSpec.untyped(). // |
102 |
| - withIgnorePaths("age").// |
103 |
| - withMatcher("firstname", startsWith()).// |
104 |
| - withMatcher("lastname", ignoreCase()); |
| 103 | + Example<User> example = Example.of(new User("Walter", "WHITE", null), |
| 104 | + matching().// |
| 105 | + withIgnorePaths("age").// |
| 106 | + withMatcher("firstname", startsWith()).// |
| 107 | + withMatcher("lastname", ignoreCase())); |
105 | 108 |
|
106 |
| - assertThat(repository.findAll(Example.of(new User("Walter", "WHITE", null), exampleSpec)), hasItems(flynn, walter)); |
107 |
| - } |
| 109 | + assertThat(repository.findAll(example), hasItems(flynn, walter)); |
| 110 | + } |
108 | 111 |
|
109 |
| - /** |
110 |
| - * @see DATAJPA-218 |
111 |
| - */ |
112 |
| - @Test |
113 |
| - public void configuringMatchersUsingLambdas() { |
| 112 | + /** |
| 113 | + * @see #153 |
| 114 | + */ |
| 115 | + @Test |
| 116 | + public void configuringMatchersUsingLambdas() { |
114 | 117 |
|
115 |
| - ExampleSpec exampleSpec = ExampleSpec.untyped().withIgnorePaths("age"). // |
116 |
| - withMatcher("firstname", matcher -> matcher.startsWith()). // |
117 |
| - withMatcher("lastname", matcher -> matcher.ignoreCase()); |
| 118 | + Example<User> example = Example.of(new User("Walter", "WHITE", null), |
| 119 | + matching().// |
| 120 | + withIgnorePaths("age").// |
| 121 | + withMatcher("firstname", matcher -> matcher.startsWith()).// |
| 122 | + withMatcher("lastname", matcher -> matcher.ignoreCase())); |
118 | 123 |
|
119 |
| - assertThat(repository.findAll(Example.of(new User("Walter", "WHITE", null), exampleSpec)), hasItems(flynn, walter)); |
120 |
| - } |
| 124 | + assertThat(repository.findAll(example), hasItems(flynn, walter)); |
| 125 | + } |
121 | 126 |
|
122 |
| - /** |
123 |
| - * @see DATAJPA-218 |
124 |
| - */ |
125 |
| - @Test |
126 |
| - public void valueTransformer() { |
| 127 | + /** |
| 128 | + * @see #153 |
| 129 | + */ |
| 130 | + @Test |
| 131 | + public void valueTransformer() { |
127 | 132 |
|
128 |
| - ExampleSpec exampleSpec = ExampleSpec.untyped(). // |
129 |
| - withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))); |
130 |
| - |
131 |
| - assertThat(repository.findAll(Example.of(new User(null, "White", 99), exampleSpec)), hasItems(walter)); |
132 |
| - } |
| 133 | + Example<User> example = Example.of(new User(null, "White", 99), matching(). // |
| 134 | + withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)))); |
133 | 135 |
|
| 136 | + assertThat(repository.findAll(example), hasItems(walter)); |
| 137 | + } |
134 | 138 | }
|
0 commit comments