entity = template.exchange(url, HttpMethod.HEAD, null, byte[].class);
+ return ConditionEvaluationResult
+ .enabled("Successfully connected to Elasticsearch server: " + entity.getStatusCode());
+ } catch (RuntimeException e) {
+ return ConditionEvaluationResult.disabled("Elasticsearch unavailable at " + url + "; " + e.getMessage());
+ }
+ }
+}
diff --git a/elasticsearch/reactive/src/test/java/example/springdata/elasticsearch/util/AssumeConnection.java b/elasticsearch/util/src/main/java/example/springdata/elasticsearch/util/EnabledOnElasticsearch.java
similarity index 53%
rename from elasticsearch/reactive/src/test/java/example/springdata/elasticsearch/util/AssumeConnection.java
rename to elasticsearch/util/src/main/java/example/springdata/elasticsearch/util/EnabledOnElasticsearch.java
index 6842b554..0d157735 100644
--- a/elasticsearch/reactive/src/test/java/example/springdata/elasticsearch/util/AssumeConnection.java
+++ b/elasticsearch/util/src/main/java/example/springdata/elasticsearch/util/EnabledOnElasticsearch.java
@@ -5,7 +5,7 @@
* 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
+ * http://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,
@@ -23,11 +23,26 @@ import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
/**
+ * {@code @EnableOnElasticsearch} is used to signal that the annotated test class or test method is only
+ * enabled if Elasticsearch is available at {@link #url()}.
+ *
+ * When applied at the class level, all test methods within that class will be enabled if Elasticsearch is available.
+ *
+ * If a test method is disabled via this annotation, that does not prevent the test class from being instantiated.
+ * Rather, it prevents the execution of the test method and method-level lifecycle callbacks such as {@code @BeforeEach}
+ * methods, {@code @AfterEach} methods, and corresponding extension APIs.
+ *
* @author Prakhar Gupta
+ * @author Mark Paluch
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
-@ExtendWith(ElasticsearchAvailable.class)
-public @interface AssumeConnection {
+@ExtendWith(ElasticsearchAvailableCondition.class)
+public @interface EnabledOnElasticsearch {
+
+ /**
+ * URL pointing at the Elasticsearch instance to check.
+ */
String url() default "http://localhost:9200";
+
}