Search in sources :

Example 1 with TestHttpClient

use of com.github.mjeanroy.junit.servers.annotations.TestHttpClient in project junit-servers by mjeanroy.

the class HttpClientParameterResolverFunction method resolve.

@Override
public Object resolve(ParameterContext parameterContext, EmbeddedServerRunner serverAdapter) {
    log.debug("Resolving HTTP Client for parameter: {}", parameterContext);
    final Optional<TestHttpClient> maybeAnnotation = parameterContext.findAnnotation(TestHttpClient.class);
    final HttpClientConfiguration configuration;
    final HttpClientStrategy strategy;
    if (maybeAnnotation.isPresent()) {
        TestHttpClient annotation = maybeAnnotation.get();
        strategy = getStrategy(annotation);
        configuration = getConfiguration(annotation);
    } else {
        strategy = defaultStrategy();
        configuration = defaultConfiguration();
    }
    return serverAdapter.getClient(strategy, configuration);
}
Also used : HttpClientStrategy(com.github.mjeanroy.junit.servers.client.HttpClientStrategy) HttpClientConfiguration(com.github.mjeanroy.junit.servers.client.HttpClientConfiguration) TestHttpClient(com.github.mjeanroy.junit.servers.annotations.TestHttpClient)

Example 2 with TestHttpClient

use of com.github.mjeanroy.junit.servers.annotations.TestHttpClient in project junit-servers by mjeanroy.

the class HttpClientAnnotationHandler method before.

@Override
public void before(Object target, Field field) {
    log.debug("Inject HTTP client to {} # {}", target, field);
    TestHttpClient httpClient = Annotations.findAnnotation(field, TestHttpClient.class);
    if (httpClient != null) {
        HttpClientStrategy strategy = httpClient.strategy();
        setter(target, field, strategy.build(server));
    }
}
Also used : HttpClientStrategy(com.github.mjeanroy.junit.servers.client.HttpClientStrategy) TestHttpClient(com.github.mjeanroy.junit.servers.annotations.TestHttpClient)

Aggregations

TestHttpClient (com.github.mjeanroy.junit.servers.annotations.TestHttpClient)2 HttpClientStrategy (com.github.mjeanroy.junit.servers.client.HttpClientStrategy)2 HttpClientConfiguration (com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)1