|
18 | 18 |
|
19 | 19 | import java.io.IOException; |
20 | 20 | import java.io.InputStream; |
| 21 | +import java.util.Arrays; |
21 | 22 | import java.util.Map; |
22 | 23 |
|
23 | 24 | import org.junit.jupiter.api.Test; |
@@ -99,116 +100,60 @@ void severalRepositoriesIdenticalGroups() throws IOException { |
99 | 100 | try (InputStream foo2 = getInputStreamFor("foo2")) { |
100 | 101 | ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo2) |
101 | 102 | .build(); |
102 | | - assertThat(repo.getAllGroups()).hasSize(1); |
| 103 | + Iterable<String> allKeys = Arrays.asList("spring.foo.name", "spring.foo.description", |
| 104 | + "spring.foo.counter", "spring.foo.enabled", "spring.foo.type"); |
| 105 | + assertThat(repo.getAllProperties()).containsOnlyKeys(allKeys); |
| 106 | + assertThat(repo.getAllGroups()).containsOnlyKeys("spring.foo"); |
103 | 107 | ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
104 | | - contains(group.getSources(), "org.acme.Foo", "org.acme.Foo2", "org.springframework.boot.FooProperties"); |
105 | | - assertThat(group.getSources()).hasSize(3); |
106 | | - contains(group.getProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter", |
107 | | - "spring.foo.enabled", "spring.foo.type"); |
108 | | - assertThat(group.getProperties()).hasSize(5); |
109 | | - contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter", |
110 | | - "spring.foo.enabled", "spring.foo.type"); |
111 | | - assertThat(repo.getAllProperties()).hasSize(5); |
| 108 | + assertThat(group.getProperties()).containsOnlyKeys(allKeys); |
| 109 | + assertThat(group.getSources()).containsOnlyKeys("org.acme.Foo", "org.acme.Foo2", |
| 110 | + "org.springframework.boot.FooProperties"); |
| 111 | + assertThat(group.getSources().get("org.acme.Foo").getProperties()).containsOnlyKeys("spring.foo.name", |
| 112 | + "spring.foo.description"); |
| 113 | + assertThat(group.getSources().get("org.acme.Foo2").getProperties()) |
| 114 | + .containsOnlyKeys("spring.foo.enabled", "spring.foo.type"); |
| 115 | + assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties()) |
| 116 | + .containsOnlyKeys("spring.foo.name", "spring.foo.counter"); |
112 | 117 | } |
113 | 118 | } |
114 | 119 | } |
115 | 120 |
|
116 | | - |
117 | | - /* |
118 | | - * A rewrite of severalRepositoriesIdenticalGroups() using "containsOnlyKeys" to show actual vs. expected when assert fails. |
119 | | - */ |
120 | 121 | @Test |
121 | | - void severalRepositoriesIdenticalGroups_rewritten() throws IOException { |
| 122 | + void severalRepositoriesIdenticalGroupsWithSameType() throws IOException { |
122 | 123 | try (InputStream foo = getInputStreamFor("foo")) { |
123 | | - try (InputStream foo2 = getInputStreamFor("foo2")) { |
124 | | - ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo2) |
| 124 | + try (InputStream foo3 = getInputStreamFor("foo3")) { |
| 125 | + ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo3) |
125 | 126 | .build(); |
126 | | - |
127 | | - // assert all properties are found |
128 | | - assertThat(repo.getAllProperties()).containsOnlyKeys( |
129 | | - "spring.foo.name", |
130 | | - "spring.foo.description", |
131 | | - "spring.foo.counter", |
132 | | - "spring.foo.enabled", |
133 | | - "spring.foo.type"); |
134 | | - |
135 | | - // we have a single group containing all properties |
| 127 | + Iterable<String> allKeys = Arrays.asList("spring.foo.name", "spring.foo.description", |
| 128 | + "spring.foo.counter", "spring.foo.enabled", "spring.foo.type"); |
| 129 | + assertThat(repo.getAllProperties()).containsOnlyKeys(allKeys); |
136 | 130 | assertThat(repo.getAllGroups()).containsOnlyKeys("spring.foo"); |
137 | | - |
138 | 131 | ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
139 | | - assertThat(group.getProperties()).containsOnlyKeys( |
140 | | - "spring.foo.name", |
141 | | - "spring.foo.description", |
142 | | - "spring.foo.counter", |
143 | | - "spring.foo.enabled", |
144 | | - "spring.foo.type"); |
145 | | - |
146 | | - // the group contains 3 different sources |
147 | | - assertThat(group.getSources()).containsOnlyKeys( |
148 | | - "org.acme.Foo", "org.acme.Foo2", "org.springframework.boot.FooProperties"); |
149 | | - |
150 | | - assertThat(group.getSources().get("org.acme.Foo").getProperties()).containsOnlyKeys( |
151 | | - "spring.foo.name", |
152 | | - "spring.foo.description"); |
153 | | - |
154 | | - assertThat(group.getSources().get("org.acme.Foo2").getProperties()).containsOnlyKeys( |
155 | | - "spring.foo.enabled", |
156 | | - "spring.foo.type"); |
157 | | - |
158 | | - assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties()).containsOnlyKeys( |
159 | | - "spring.foo.name", |
160 | | - "spring.foo.counter"); |
| 132 | + assertThat(group.getProperties()).containsOnlyKeys(allKeys); |
| 133 | + assertThat(group.getSources()).containsOnlyKeys("org.acme.Foo", |
| 134 | + "org.springframework.boot.FooProperties"); |
| 135 | + assertThat(group.getSources().get("org.acme.Foo").getProperties()).containsOnlyKeys("spring.foo.name", |
| 136 | + "spring.foo.description", "spring.foo.enabled", "spring.foo.type"); |
| 137 | + assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties()) |
| 138 | + .containsOnlyKeys("spring.foo.name", "spring.foo.counter"); |
161 | 139 | } |
162 | 140 | } |
163 | 141 | } |
164 | | - |
165 | | - /* |
166 | | - * "foo3" contains the same properties as "foo2" except they refer to a group that already exists in |
167 | | - * "foo1" (same NAME, same TYPE). |
168 | | - * |
169 | | - * This test shows that the union of properties collected from the sources is less than what the group actually |
170 | | - * contains (some properties are missing). |
171 | | - */ |
| 142 | + |
172 | 143 | @Test |
173 | | - void severalRepositoriesIdenticalGroups3() throws IOException { |
| 144 | + void severalRepositoriesIdenticalGroupsWithSameTypeDoesNotOverrideSource() throws IOException { |
174 | 145 | try (InputStream foo = getInputStreamFor("foo")) { |
175 | 146 | try (InputStream foo3 = getInputStreamFor("foo3")) { |
176 | 147 | ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo3) |
177 | 148 | .build(); |
178 | | - |
179 | | - assertThat(repo.getAllProperties()).containsOnlyKeys( |
180 | | - "spring.foo.name", |
181 | | - "spring.foo.description", |
182 | | - "spring.foo.counter", |
183 | | - "spring.foo.enabled", |
184 | | - "spring.foo.type"); |
185 | | - |
186 | | - assertThat(repo.getAllGroups()).containsOnlyKeys("spring.foo"); |
187 | | - |
188 | 149 | ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
189 | | - assertThat(group.getProperties()).containsOnlyKeys( |
190 | | - "spring.foo.name", |
191 | | - "spring.foo.description", |
192 | | - "spring.foo.counter", |
193 | | - "spring.foo.enabled", |
194 | | - "spring.foo.type"); |
195 | | - |
196 | | - |
197 | | - assertThat(group.getSources()).containsOnlyKeys("org.acme.Foo", "org.springframework.boot.FooProperties"); |
198 | | - assertThat(group.getSources().get("org.acme.Foo").getProperties()).containsOnlyKeys( |
199 | | - "spring.foo.name", |
200 | | - "spring.foo.description", |
201 | | - "spring.foo.enabled", // <-- missing although present in repo.getAllProperties() |
202 | | - "spring.foo.type"); // <-- missing although present in repo.getAllProperties() |
203 | | - |
204 | | - assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties()).containsOnlyKeys( |
205 | | - "spring.foo.name", |
206 | | - "spring.foo.counter"); |
| 150 | + ConfigurationMetadataSource fooSource = group.getSources().get("org.acme.Foo"); |
| 151 | + assertThat(fooSource.getSourceMethod()).isEqualTo("foo()"); |
| 152 | + assertThat(fooSource.getDescription()).isEqualTo("This is Foo."); |
207 | 153 | } |
208 | 154 | } |
209 | 155 | } |
210 | | - |
211 | | - |
| 156 | + |
212 | 157 | @Test |
213 | 158 | void emptyGroups() throws IOException { |
214 | 159 | try (InputStream in = getInputStreamFor("empty-groups")) { |
|
0 commit comments