|
19 | 19 |
|
20 | 20 | import static org.assertj.core.api.Assertions.assertThat; |
21 | 21 |
|
| 22 | +import org.junit.jupiter.api.Nested; |
22 | 23 | import org.junit.jupiter.api.Test; |
23 | 24 | import org.osgi.service.cm.Configuration; |
24 | 25 | import org.osgi.service.cm.ConfigurationAdmin; |
@@ -151,4 +152,101 @@ public void testMethodConfigurationFactoryCreate() throws Exception { |
151 | 152 |
|
152 | 153 | } |
153 | 154 |
|
| 155 | + @Nested |
| 156 | + class LocationTests { |
| 157 | + |
| 158 | + private static final String TEST = "test"; |
| 159 | + |
| 160 | + @Test |
| 161 | + @WithConfiguration(pid = PARAM_PID, properties = { |
| 162 | + @Property(key = "bar", value = "foo") |
| 163 | + }) |
| 164 | + public void testMethodLevelNoLocation(@InjectService |
| 165 | + ConfigurationAdmin ca) throws Exception { |
| 166 | + |
| 167 | + Configuration cs = ConfigUtil.getConfigsByServicePid(ca, PARAM_PID); |
| 168 | + assertThat(cs).isNotNull(); |
| 169 | + assertThat(cs.getBundleLocation()).isNull(); |
| 170 | + } |
| 171 | + |
| 172 | + @Test |
| 173 | + public void testInjectedNoLocation( |
| 174 | + @InjectConfiguration(withConfig = @WithConfiguration(pid = PARAM_PID, properties = { |
| 175 | + @Property(key = "bar", value = "foo") |
| 176 | + })) |
| 177 | + Configuration cs) throws Exception { |
| 178 | + |
| 179 | + assertThat(cs).isNotNull(); |
| 180 | + assertThat(cs.getBundleLocation()).isNull(); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + @WithConfiguration(pid = PARAM_PID, location = "?", properties = { |
| 185 | + @Property(key = "bar", value = "foo") |
| 186 | + }) |
| 187 | + public void testMethodLevelWithLocation(@InjectService |
| 188 | + ConfigurationAdmin ca) throws Exception { |
| 189 | + |
| 190 | + Configuration cs = ConfigUtil.getConfigsByServicePid(ca, PARAM_PID); |
| 191 | + assertThat(cs).isNotNull(); |
| 192 | + assertThat(cs.getBundleLocation()).isEqualTo("?"); |
| 193 | + } |
| 194 | + |
| 195 | + @Test |
| 196 | + public void testInjectedWithLocation( |
| 197 | + @InjectConfiguration(withConfig = @WithConfiguration(pid = PARAM_PID, location = "?", properties = { |
| 198 | + @Property(key = "bar", value = "foo") |
| 199 | + })) |
| 200 | + Configuration cs) throws Exception { |
| 201 | + |
| 202 | + assertThat(cs).isNotNull(); |
| 203 | + assertThat(cs.getBundleLocation()).isEqualTo("?"); |
| 204 | + } |
| 205 | + |
| 206 | + @Test |
| 207 | + @WithFactoryConfiguration(factoryPid = PARAM_PID, name = TEST, properties = { |
| 208 | + @Property(key = "bar", value = "foo") |
| 209 | + }) |
| 210 | + public void testMethodLevelFactoryNoLocation(@InjectService |
| 211 | + ConfigurationAdmin ca) throws Exception { |
| 212 | + |
| 213 | + Configuration cs = ConfigUtil.getConfigsByServicePid(ca, PARAM_PID + "~" + TEST); |
| 214 | + assertThat(cs).isNotNull(); |
| 215 | + assertThat(cs.getBundleLocation()).isNull(); |
| 216 | + } |
| 217 | + |
| 218 | + @Test |
| 219 | + public void testInjectedFactoryNoLocation( |
| 220 | + @InjectConfiguration(withFactoryConfig = @WithFactoryConfiguration(factoryPid = PARAM_PID, name = TEST, properties = { |
| 221 | + @Property(key = "bar", value = "foo") |
| 222 | + })) |
| 223 | + Configuration cs) throws Exception { |
| 224 | + |
| 225 | + assertThat(cs).isNotNull(); |
| 226 | + assertThat(cs.getBundleLocation()).isNull(); |
| 227 | + } |
| 228 | + |
| 229 | + @Test |
| 230 | + @WithFactoryConfiguration(factoryPid = PARAM_PID, name=TEST, location = "?", properties = { |
| 231 | + @Property(key = "bar", value = "foo") |
| 232 | + }) |
| 233 | + public void testMethodLevelFactoryWithLocation(@InjectService |
| 234 | + ConfigurationAdmin ca) throws Exception { |
| 235 | + |
| 236 | + Configuration cs = ConfigUtil.getConfigsByServicePid(ca, PARAM_PID + "~" + TEST); |
| 237 | + assertThat(cs).isNotNull(); |
| 238 | + assertThat(cs.getBundleLocation()).isEqualTo("?"); |
| 239 | + } |
| 240 | + |
| 241 | + @Test |
| 242 | + public void testInjectedFactoryWithLocation( |
| 243 | + @InjectConfiguration(withFactoryConfig = @WithFactoryConfiguration(factoryPid = PARAM_PID, name = TEST, location = "?", properties = { |
| 244 | + @Property(key = "bar", value = "foo") |
| 245 | + })) |
| 246 | + Configuration cs) throws Exception { |
| 247 | + |
| 248 | + assertThat(cs).isNotNull(); |
| 249 | + assertThat(cs.getBundleLocation()).isEqualTo("?"); |
| 250 | + } |
| 251 | + } |
154 | 252 | } |
0 commit comments