|
41 | 41 | import javax.ws.rs.core.Application;
|
42 | 42 | import javax.ws.rs.ext.RuntimeDelegate;
|
43 | 43 |
|
| 44 | +import org.eclipse.microprofile.config.Config; |
| 45 | +import org.eclipse.microprofile.config.spi.ConfigSource; |
44 | 46 | import org.glassfish.jersey.internal.ServiceFinder;
|
45 | 47 | import org.glassfish.jersey.internal.ServiceFinder.ServiceIteratorProvider;
|
46 | 48 | import org.glassfish.jersey.server.ApplicationHandler;
|
@@ -228,6 +230,75 @@ public final void shouldBuildCustomConfigurationFromPropertiesProvider() {
|
228 | 230 | assertThat(configuration.property(ServerProperties.AUTO_START), is(FALSE));
|
229 | 231 | }
|
230 | 232 |
|
| 233 | + @Test |
| 234 | + public final void shouldBuildCustomConfigurationFromMicroprofileConfig() { |
| 235 | + // given |
| 236 | + final JAXRS.Configuration.Builder configurationBuilder = new RuntimeDelegateImpl().createConfigurationBuilder(); |
| 237 | + final SSLContext mockSslContext = new SSLContext(null, null, null) { |
| 238 | + }; |
| 239 | + final Class<Server> mockServerClass = Server.class; |
| 240 | + final Config config = new Config() { |
| 241 | + @Override |
| 242 | + public final <T> T getValue(final String propertyName, final Class<T> propertyType) { |
| 243 | + return null; |
| 244 | + } |
| 245 | + |
| 246 | + @Override |
| 247 | + public final <T> Optional<T> getOptionalValue(final String propertyName, final Class<T> propertyType) { |
| 248 | + if (JAXRS.Configuration.PROTOCOL.equals(propertyName) && String.class.equals(propertyType)) { |
| 249 | + return Optional.of(propertyType.cast("HTTPS")); |
| 250 | + } |
| 251 | + if (JAXRS.Configuration.HOST.equals(propertyName) && String.class.equals(propertyType)) { |
| 252 | + return Optional.of(propertyType.cast("hostname")); |
| 253 | + } |
| 254 | + if (JAXRS.Configuration.PORT.equals(propertyName) && Integer.class.equals(propertyType)) { |
| 255 | + return Optional.of(propertyType.cast(8080)); |
| 256 | + } |
| 257 | + if (JAXRS.Configuration.ROOT_PATH.equals(propertyName) && String.class.equals(propertyType)) { |
| 258 | + return Optional.of(propertyType.cast("path")); |
| 259 | + } |
| 260 | + if (JAXRS.Configuration.SSL_CLIENT_AUTHENTICATION.equals(propertyName) |
| 261 | + && JAXRS.Configuration.SSLClientAuthentication.class.equals(propertyType)) { |
| 262 | + return Optional.of(propertyType.cast(JAXRS.Configuration.SSLClientAuthentication.OPTIONAL)); |
| 263 | + } |
| 264 | + if (JAXRS.Configuration.SSL_CONTEXT.equals(propertyName) && SSLContext.class.equals(propertyType)) { |
| 265 | + return Optional.of(propertyType.cast(mockSslContext)); |
| 266 | + } |
| 267 | + if (ServerProperties.HTTP_SERVER_CLASS.equals(propertyName) && Class.class.equals(propertyType)) { |
| 268 | + return Optional.of(propertyType.cast(mockServerClass)); |
| 269 | + } |
| 270 | + if (ServerProperties.AUTO_START.equals(propertyName) && Boolean.class.equals(propertyType)) { |
| 271 | + return Optional.of(propertyType.cast(FALSE)); |
| 272 | + } |
| 273 | + return Optional.empty(); |
| 274 | + } |
| 275 | + |
| 276 | + @Override |
| 277 | + public final Iterable<String> getPropertyNames() { |
| 278 | + return null; |
| 279 | + } |
| 280 | + |
| 281 | + @Override |
| 282 | + public final Iterable<ConfigSource> getConfigSources() { |
| 283 | + return null; |
| 284 | + } |
| 285 | + }; |
| 286 | + |
| 287 | + // when |
| 288 | + final JAXRS.Configuration configuration = configurationBuilder.from(config).build(); |
| 289 | + |
| 290 | + // then |
| 291 | + assertThat(configuration, is(notNullValue())); |
| 292 | + assertThat(configuration.protocol(), is("HTTPS")); |
| 293 | + assertThat(configuration.host(), is("hostname")); |
| 294 | + assertThat(configuration.port(), is(8080)); |
| 295 | + assertThat(configuration.rootPath(), is("path")); |
| 296 | + assertThat(configuration.sslClientAuthentication(), is(JAXRS.Configuration.SSLClientAuthentication.OPTIONAL)); |
| 297 | + assertThat(configuration.sslContext(), is(theInstance(mockSslContext))); |
| 298 | + assertThat(configuration.property(ServerProperties.HTTP_SERVER_CLASS), is(theInstance(mockServerClass))); |
| 299 | + assertThat(configuration.property(ServerProperties.AUTO_START), is(FALSE)); |
| 300 | + } |
| 301 | + |
231 | 302 | @Test
|
232 | 303 | public final void shouldBootstrapApplication() throws InterruptedException, ExecutionException, TimeoutException {
|
233 | 304 | // given
|
|
0 commit comments