public abstract class IndexAction<K extends ActionRequest> implements ClusterAction<List<K>> {
+ public static final String MISSING_INDEX_EXCEPTION = "Cannot execute request on null index";
+
protected final String indexType;
private final boolean requiresRefresh;
private Index index;
@Override
public final List<K> call() throws Exception {
if (index == null) {
- throw new IllegalStateException("Cannot execute request on null index");
+ throw new IllegalStateException(MISSING_INDEX_EXCEPTION);
}
return doCall(index);
}
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
String key = "test_key";
DeleteKey<String> deleteAction = new DeleteKey<String>(TEST_INDEX.getIndexType(), key);
- List<DeleteRequest> requests = deleteAction.doCall(index);
+ try {
+ deleteAction.call();
+ fail();
+ } catch (Exception e) {
+ assertThat(e.getMessage()).isEqualTo(IndexAction.MISSING_INDEX_EXCEPTION);
+ }
+
+ // Insert Index for action
+ deleteAction.setIndex(index);
+
+ List<DeleteRequest> requests = deleteAction.call();
assertThat(requests).hasSize(1);
DeleteRequest request = requests.get(0);