package cz.xtf.client;

import cz.xtf.core.config.WaitingConfig;
import cz.xtf.core.waiting.SimpleWaiter;
import cz.xtf.core.waiting.Waiter;

import java.io.IOException;
import java.util.function.BooleanSupplier;

public class HttpWaiters {
	private final Http client;

	HttpWaiters(Http httpClient) {
		this.client = httpClient;
	}

	public Waiter ok() {
		return code(200);
	}

	public Waiter code(int code) {
		BooleanSupplier bs = () -> {
			try {
				return client.execute().code() == code;
			} catch (IOException e) {
				return false;
			}
		};
		return new SimpleWaiter(bs, "Waiting for " + client.getUrl().toExternalForm() + " to return " + code).timeout(WaitingConfig.timeout());
	}
}

@@ -17,16 +17,120 @@
 lient;%0A%0A
+import java.io.IOException;%0Aimport java.util.function.BooleanSupplier;%0Aimport java.util.stream.Stream;%0A%0A
 import c
@@ -162,16 +162,16 @@
 Config;%0A
-
 import c
@@ -243,80 +243,8 @@
 r;%0A%0A
-import java.io.IOException;%0Aimport java.util.function.BooleanSupplier;%0A%0A
 publ
@@ -578,16 +578,16 @@
 %09%7D%0A%09%09%7D;%0A
-
 %09%09return
@@ -718,11 +718,455 @@
 t());%0A%09%7D
+%0A%0A%09public Waiter responseContains(final String... strings) %7B%0A%09%09BooleanSupplier bs = () -%3E %7B%0A%09%09%09try %7B%0A%09%09%09%09final String response = client.execute().response();%0A%09%09%09%09return Stream.of(strings).allMatch(response::contains);%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D;%0A%09%09return new SimpleWaiter(bs, %22Waiting for %22 + client.getUrl().toExternalForm() + %22 to contain (%22 + String.join(%22,%22, strings) + %22)%22).timeout(WaitingConfig.timeout());%0A%09%7D
 %0A%7D%0A

Add waiter for response containing string