[TEST] Better fix for missing create spec

create is a shortcut to index with op_type=create that the clients support
This commit is contained in:
Luca Cavanna 2014-01-20 12:10:28 +01:00
parent 62b044697a
commit 8b2fe44fe3
2 changed files with 9 additions and 17 deletions

View File

@ -156,7 +156,11 @@ public class RestClient implements Closeable {
}
private HttpRequestBuilder callApiBuilder(String apiName, Map<String, String> params, String body) {
RestApi restApi = restApi(apiName);
//create doesn't exist in the spec but is supported in the clients (index with op_type=create)
boolean indexCreateApi = "create".equals(apiName);
String api = indexCreateApi ? "index" : apiName;
RestApi restApi = restApi(api);
HttpRequestBuilder httpRequestBuilder = httpRequestBuilder();
@ -186,6 +190,10 @@ public class RestClient implements Closeable {
}
}
if (indexCreateApi) {
httpRequestBuilder.addParam("op_type", "create");
}
//the http method is randomized (out of the available ones with the chosen api)
return httpRequestBuilder.method(RandomizedTest.randomFrom(restApi.getSupportedMethods(pathParts.keySet())))
.path(RandomizedTest.randomFrom(restApi.getFinalPaths(pathParts)));

View File

@ -38,22 +38,6 @@ public class RestSpec {
}
void addApi(RestApi restApi) {
if ("index".equals(restApi.getName())) {
RestApi create = new RestApi("create");
create.addPath("/{index}/{type}");
create.addPath("/{index}/{type}/{id}/_create");
create.setBodyRequired();
for (String method : restApi.getMethods()) {
create.addMethod(method);
}
for (String param : restApi.getParams()) {
create.addParam(param);
}
for (String pathPart : restApi.getPathParts()) {
create.addPathPart(pathPart);
}
restApiMap.put(create.getName(), create);
}
restApiMap.put(restApi.getName(), restApi);
}