|
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,16 +100,56 @@ 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"); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + 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 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + 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."); |
112 | 153 | } |
113 | 154 | } |
114 | 155 | } |
|
0 commit comments