Skip to content

Commit

Permalink
Allow resolving the server URL via a property
Browse files Browse the repository at this point in the history
Fixes #527
  • Loading branch information
alvarosanchez committed Feb 27, 2024
1 parent 0fa6264 commit e98a7e6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CompositeResolverLoader implements ResolverLoader {

private final List<TestResourcesResolver> resolvers;

public CompositeResolverLoader(List<TestResourcesResolver> resolverBeans) {
public CompositeResolverLoader(List<InjectableTestResourcesResolver> resolverBeans) {
var loader = TestResourcesResolverLoader.getInstance();
this.resolvers = new ArrayList<>(resolverBeans.size() + loader.getResolvers().size());
this.resolvers.addAll(resolverBeans);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.testresources.server;

import io.micronaut.testresources.core.TestResourcesResolver;

/**
* Marker interface for a {@link TestResourcesResolver} implementations that can be injected.
*
* @author Álvaro Sánchez-Mariscal
* @since 2.4.0
*/
public interface InjectableTestResourcesResolver extends TestResourcesResolver {

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
@Internal
@Singleton
public class InternalTestResourcesServiceResolver implements TestResourcesResolver {
public class InternalTestResourcesServiceResolver implements InjectableTestResourcesResolver {

public static final String SERVER_URI = "micronaut.test.resources.server.uri";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestResourcesControllerTest extends Specification {

def "verifies that server can instantiate container"() {
expect:
client.resolvableProperties ==~ ['kafka.bootstrap.servers', 'failing.message', 'failing.container']
client.resolvableProperties ==~ ['kafka.bootstrap.servers', 'failing.message', 'failing.container', 'micronaut.test.resources.server.uri']
client.listContainers().empty

when:
Expand All @@ -40,7 +40,7 @@ class TestResourcesControllerTest extends Specification {

def "can resolve a valid property after an error in a regular test resource"() {
expect:
client.resolvableProperties ==~ ['kafka.bootstrap.servers', 'failing.message', 'failing.container']
client.resolvableProperties ==~ ['kafka.bootstrap.servers', 'failing.message', 'failing.container', 'micronaut.test.resources.server.uri']
client.listContainers().empty

when: "resolution of a property fails"
Expand All @@ -66,7 +66,7 @@ class TestResourcesControllerTest extends Specification {

def "can resolve a valid property after an error in a container test resource"() {
expect:
client.resolvableProperties ==~ ['kafka.bootstrap.servers', 'failing.message', 'failing.container']
client.resolvableProperties ==~ ['kafka.bootstrap.servers', 'failing.message', 'failing.container', 'micronaut.test.resources.server.uri']
client.listContainers().empty

when: "resolution of a property which starts a container"
Expand Down Expand Up @@ -96,7 +96,7 @@ class TestResourcesControllerTest extends Specification {

then:
url.isPresent()
url.get() == "http://localhost:8080"
url.get().startsWith("http://localhost:")
}

@Client("/")
Expand Down

0 comments on commit e98a7e6

Please sign in to comment.