@@ -113,6 +113,102 @@ void severalRepositoriesIdenticalGroups() throws IOException {
113
113
}
114
114
}
115
115
116
+
117
+ /*
118
+ * A rewrite of severalRepositoriesIdenticalGroups() using "containsOnlyKeys" to show actual vs. expected when assert fails.
119
+ */
120
+ @ Test
121
+ void severalRepositoriesIdenticalGroups_rewritten () throws IOException {
122
+ try (InputStream foo = getInputStreamFor ("foo" )) {
123
+ try (InputStream foo2 = getInputStreamFor ("foo2" )) {
124
+ ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder .create (foo , foo2 )
125
+ .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
136
+ assertThat (repo .getAllGroups ()).containsOnlyKeys ("spring.foo" );
137
+
138
+ 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" );
161
+ }
162
+ }
163
+ }
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
+ */
172
+ @ Test
173
+ void severalRepositoriesIdenticalGroups3 () throws IOException {
174
+ try (InputStream foo = getInputStreamFor ("foo" )) {
175
+ try (InputStream foo3 = getInputStreamFor ("foo3" )) {
176
+ ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder .create (foo , foo3 )
177
+ .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
+ 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" );
207
+ }
208
+ }
209
+ }
210
+
211
+
116
212
@ Test
117
213
void emptyGroups () throws IOException {
118
214
try (InputStream in = getInputStreamFor ("empty-groups" )) {
0 commit comments