@SuppressWarnings("deprecation") @After public void tearDown() throws Exception { if (server != null && server.isStarted()) { server.stop(); } }
@Rank(Integer.MAX_VALUE) @Singleton @Override public Client provide() { if (!httpServer.isStarted()) { throw new TestException("test server not started"); } Object testInstance = testContext.getTestInstance(); Class<? extends Object> testClass = testInstance.getClass(); Optional<ClientConfig> optional = of(testClass.getDeclaredMethods()) .filter(p -> p.getDeclaredAnnotation(Config.class) != null) .filter(p -> p.getParameterCount() == 0) .filter(p -> p.getReturnType().isAssignableFrom(ClientConfig.class)) .findFirst() .map(p -> reflectionUtil.invokeMethod(testInstance, p)) .map(ClientConfig.class::cast); ClientConfig clientConfig = optional.orElseGet(ClientConfig::new); JerseyTest jerseyTest = testContext.getTestInstance().getClass().getAnnotation(JerseyTest.class); if (jerseyTest.logTraffic() && !clientConfig.isRegistered(LoggingFilter.class)) { clientConfig.register(new LoggingFilter(log, jerseyTest.dumpEntity())); } return ClientBuilder.newClient(clientConfig); }