|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -64,93 +64,77 @@ void hintsOnMaps() throws IOException {
|
64 | 64 |
|
65 | 65 | @Test
|
66 | 66 | void severalRepositoriesNoConflict() throws IOException {
|
67 |
| - try (InputStream foo = getInputStreamFor("foo")) { |
68 |
| - try (InputStream bar = getInputStreamFor("bar")) { |
69 |
| - ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, bar) |
70 |
| - .build(); |
71 |
| - validateFoo(repo); |
72 |
| - validateBar(repo); |
73 |
| - assertThat(repo.getAllGroups()).hasSize(2); |
74 |
| - contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter", |
75 |
| - "spring.bar.name", "spring.bar.description", "spring.bar.counter"); |
76 |
| - assertThat(repo.getAllProperties()).hasSize(6); |
77 |
| - } |
| 67 | + try (InputStream foo = getInputStreamFor("foo"); InputStream bar = getInputStreamFor("bar")) { |
| 68 | + ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, bar).build(); |
| 69 | + validateFoo(repo); |
| 70 | + validateBar(repo); |
| 71 | + assertThat(repo.getAllGroups()).hasSize(2); |
| 72 | + contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter", |
| 73 | + "spring.bar.name", "spring.bar.description", "spring.bar.counter"); |
| 74 | + assertThat(repo.getAllProperties()).hasSize(6); |
78 | 75 | }
|
79 | 76 | }
|
80 | 77 |
|
81 | 78 | @Test
|
82 | 79 | void repositoryWithRoot() throws IOException {
|
83 |
| - try (InputStream foo = getInputStreamFor("foo")) { |
84 |
| - try (InputStream root = getInputStreamFor("root")) { |
85 |
| - ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, root) |
86 |
| - .build(); |
87 |
| - validateFoo(repo); |
88 |
| - assertThat(repo.getAllGroups()).hasSize(2); |
| 80 | + try (InputStream foo = getInputStreamFor("foo"); InputStream root = getInputStreamFor("root")) { |
| 81 | + ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, root).build(); |
| 82 | + validateFoo(repo); |
| 83 | + assertThat(repo.getAllGroups()).hasSize(2); |
89 | 84 |
|
90 |
| - contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter", |
91 |
| - "spring.root.name", "spring.root2.name"); |
92 |
| - assertThat(repo.getAllProperties()).hasSize(5); |
93 |
| - } |
| 85 | + contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter", |
| 86 | + "spring.root.name", "spring.root2.name"); |
| 87 | + assertThat(repo.getAllProperties()).hasSize(5); |
94 | 88 | }
|
95 | 89 | }
|
96 | 90 |
|
97 | 91 | @Test
|
98 | 92 | void severalRepositoriesIdenticalGroups() throws IOException {
|
99 |
| - try (InputStream foo = getInputStreamFor("foo")) { |
100 |
| - try (InputStream foo2 = getInputStreamFor("foo2")) { |
101 |
| - ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo2) |
102 |
| - .build(); |
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"); |
107 |
| - ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
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"); |
117 |
| - } |
| 93 | + try (InputStream foo = getInputStreamFor("foo"); InputStream foo2 = getInputStreamFor("foo2")) { |
| 94 | + ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo2).build(); |
| 95 | + Iterable<String> allKeys = Arrays.asList("spring.foo.name", "spring.foo.description", "spring.foo.counter", |
| 96 | + "spring.foo.enabled", "spring.foo.type"); |
| 97 | + assertThat(repo.getAllProperties()).containsOnlyKeys(allKeys); |
| 98 | + assertThat(repo.getAllGroups()).containsOnlyKeys("spring.foo"); |
| 99 | + ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
| 100 | + assertThat(group.getProperties()).containsOnlyKeys(allKeys); |
| 101 | + assertThat(group.getSources()).containsOnlyKeys("org.acme.Foo", "org.acme.Foo2", |
| 102 | + "org.springframework.boot.FooProperties"); |
| 103 | + assertThat(group.getSources().get("org.acme.Foo").getProperties()).containsOnlyKeys("spring.foo.name", |
| 104 | + "spring.foo.description"); |
| 105 | + assertThat(group.getSources().get("org.acme.Foo2").getProperties()).containsOnlyKeys("spring.foo.enabled", |
| 106 | + "spring.foo.type"); |
| 107 | + assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties()) |
| 108 | + .containsOnlyKeys("spring.foo.name", "spring.foo.counter"); |
118 | 109 | }
|
119 | 110 | }
|
120 | 111 |
|
121 | 112 | @Test
|
122 | 113 | void severalRepositoriesIdenticalGroupsWithSameType() throws IOException {
|
123 |
| - try (InputStream foo = getInputStreamFor("foo")) { |
124 |
| - try (InputStream foo3 = getInputStreamFor("foo3")) { |
125 |
| - ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo3) |
126 |
| - .build(); |
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); |
130 |
| - assertThat(repo.getAllGroups()).containsOnlyKeys("spring.foo"); |
131 |
| - ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
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"); |
139 |
| - } |
| 114 | + try (InputStream foo = getInputStreamFor("foo"); InputStream foo3 = getInputStreamFor("foo3")) { |
| 115 | + ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo3).build(); |
| 116 | + Iterable<String> allKeys = Arrays.asList("spring.foo.name", "spring.foo.description", "spring.foo.counter", |
| 117 | + "spring.foo.enabled", "spring.foo.type"); |
| 118 | + assertThat(repo.getAllProperties()).containsOnlyKeys(allKeys); |
| 119 | + assertThat(repo.getAllGroups()).containsOnlyKeys("spring.foo"); |
| 120 | + ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
| 121 | + assertThat(group.getProperties()).containsOnlyKeys(allKeys); |
| 122 | + assertThat(group.getSources()).containsOnlyKeys("org.acme.Foo", "org.springframework.boot.FooProperties"); |
| 123 | + assertThat(group.getSources().get("org.acme.Foo").getProperties()).containsOnlyKeys("spring.foo.name", |
| 124 | + "spring.foo.description", "spring.foo.enabled", "spring.foo.type"); |
| 125 | + assertThat(group.getSources().get("org.springframework.boot.FooProperties").getProperties()) |
| 126 | + .containsOnlyKeys("spring.foo.name", "spring.foo.counter"); |
140 | 127 | }
|
141 | 128 | }
|
142 | 129 |
|
143 | 130 | @Test
|
144 | 131 | void severalRepositoriesIdenticalGroupsWithSameTypeDoesNotOverrideSource() throws IOException {
|
145 |
| - try (InputStream foo = getInputStreamFor("foo")) { |
146 |
| - try (InputStream foo3 = getInputStreamFor("foo3")) { |
147 |
| - ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo3) |
148 |
| - .build(); |
149 |
| - ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
150 |
| - ConfigurationMetadataSource fooSource = group.getSources().get("org.acme.Foo"); |
151 |
| - assertThat(fooSource.getSourceMethod()).isEqualTo("foo()"); |
152 |
| - assertThat(fooSource.getDescription()).isEqualTo("This is Foo."); |
153 |
| - } |
| 132 | + try (InputStream foo = getInputStreamFor("foo"); InputStream foo3 = getInputStreamFor("foo3")) { |
| 133 | + ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo3).build(); |
| 134 | + ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); |
| 135 | + ConfigurationMetadataSource fooSource = group.getSources().get("org.acme.Foo"); |
| 136 | + assertThat(fooSource.getSourceMethod()).isEqualTo("foo()"); |
| 137 | + assertThat(fooSource.getDescription()).isEqualTo("This is Foo."); |
154 | 138 | }
|
155 | 139 | }
|
156 | 140 |
|
@@ -185,22 +169,19 @@ void multiGroups() throws IOException {
|
185 | 169 |
|
186 | 170 | @Test
|
187 | 171 | void builderInstancesAreIsolated() throws IOException {
|
188 |
| - try (InputStream foo = getInputStreamFor("foo")) { |
189 |
| - try (InputStream bar = getInputStreamFor("bar")) { |
190 |
| - ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder |
191 |
| - .create(); |
192 |
| - ConfigurationMetadataRepository firstRepo = builder.withJsonResource(foo).build(); |
193 |
| - validateFoo(firstRepo); |
194 |
| - ConfigurationMetadataRepository secondRepo = builder.withJsonResource(bar).build(); |
195 |
| - validateFoo(secondRepo); |
196 |
| - validateBar(secondRepo); |
197 |
| - // first repo not impacted by second build |
198 |
| - assertThat(secondRepo).isNotEqualTo(firstRepo); |
199 |
| - assertThat(firstRepo.getAllGroups()).hasSize(1); |
200 |
| - assertThat(firstRepo.getAllProperties()).hasSize(3); |
201 |
| - assertThat(secondRepo.getAllGroups()).hasSize(2); |
202 |
| - assertThat(secondRepo.getAllProperties()).hasSize(6); |
203 |
| - } |
| 172 | + try (InputStream foo = getInputStreamFor("foo"); InputStream bar = getInputStreamFor("bar")) { |
| 173 | + ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create(); |
| 174 | + ConfigurationMetadataRepository firstRepo = builder.withJsonResource(foo).build(); |
| 175 | + validateFoo(firstRepo); |
| 176 | + ConfigurationMetadataRepository secondRepo = builder.withJsonResource(bar).build(); |
| 177 | + validateFoo(secondRepo); |
| 178 | + validateBar(secondRepo); |
| 179 | + // first repo not impacted by second build |
| 180 | + assertThat(secondRepo).isNotEqualTo(firstRepo); |
| 181 | + assertThat(firstRepo.getAllGroups()).hasSize(1); |
| 182 | + assertThat(firstRepo.getAllProperties()).hasSize(3); |
| 183 | + assertThat(secondRepo.getAllGroups()).hasSize(2); |
| 184 | + assertThat(secondRepo.getAllProperties()).hasSize(6); |
204 | 185 | }
|
205 | 186 | }
|
206 | 187 |
|
|
0 commit comments