@Override public void destroy(ClientInstance<AbstractStub, ManagedChannel> clientInstance) { clientInstance.getClientSupplier() .map(Instance::getValue) .map(ManagedChannel.class::cast) .ifPresent(ManagedChannel::shutdownNow); }
@Override public void destroy(ClientInstance<WebTarget, Client> clientInstance) { clientInstance.getClientSupplier() .map(Instance::getValue) .map(Client.class::cast) .ifPresent(Client::close); }
/** * Execute the given function with the {@link #getClient()} value and * {@link #getClientSupplier()} value as its parameters. If client supplier is not present * {@code null} will passed in as client supplier value. * * @param <R> function return type * @param function the function * @return the result of executing the function */ default <R> R query(BiFunction<C, P, R> function) { return function.apply( getClient().getValue(), getClientSupplier().map(Instance::getValue).orElse(null) ); }
/** * Execute the given consumer function with the {@link #getClient()} value and * {@link #getClientSupplier()} value as its parameters. If client supplier is not present * {@code null} will passed in as client supplier value. * * @param consumer the consumer function */ default void command(BiConsumer<C, P> consumer) { consumer.accept( getClient().getValue(), getClientSupplier().map(Instance::getValue).orElse(null) ); } }
Optional<Instance<Object>> foundClientSupplier = clientInstance.getClientSupplier();
void createClient(TestContext testContext, TestConfigurer testConfigurer, ClientProvider clientProvider, Application application) { URI baseURI = testContext.getProperty(TestContextProperties.SERVER_BASE_URI); //configure and create the client Object clientConfig = clientProvider.configure(testContext, application, baseURI); clientConfig = testConfigurer.configure(testContext, clientConfig); ClientInstance<Object, Object> clientInstance = clientProvider.create(testContext, application, baseURI, clientConfig); testContext .addProperty(TestContextProperties.CLIENT_INSTANCE, clientInstance) .addProperty(clientInstance.getFqn(), clientInstance.getProperties()) .addProperty(TestContextProperties.CLIENT, clientInstance .getClient().getValue()); clientInstance.getClientSupplier() .map(Instance::getValue) .ifPresent(value -> { testContext.addProperty(TestContextProperties.CLIENT_SUPPLIER, value); }); }