in genie-web/src/integTest/java/com/netflix/genie/web/apis/rest/v3/controllers/ClusterRestControllerIntegrationTest.java [199:316]
void canFindClusters() throws Exception {
final String id1 = UUID.randomUUID().toString();
final String id2 = UUID.randomUUID().toString();
final String id3 = UUID.randomUUID().toString();
final String name1 = UUID.randomUUID().toString();
final String name2 = UUID.randomUUID().toString();
final String name3 = UUID.randomUUID().toString();
final String user1 = UUID.randomUUID().toString();
final String user2 = UUID.randomUUID().toString();
final String user3 = UUID.randomUUID().toString();
final String version1 = UUID.randomUUID().toString();
final String version2 = UUID.randomUUID().toString();
final String version3 = UUID.randomUUID().toString();
this.createConfigResource(
new Cluster.Builder(name1, user1, version1, ClusterStatus.UP).withId(id1).build(),
null
);
Thread.sleep(1000);
this.createConfigResource(
new Cluster.Builder(name2, user2, version2, ClusterStatus.OUT_OF_SERVICE).withId(id2).build(),
null
);
Thread.sleep(1000);
this.createConfigResource(
new Cluster.Builder(name3, user3, version3, ClusterStatus.TERMINATED).withId(id3).build(),
null
);
final RestDocumentationFilter findFilter = RestAssuredRestDocumentation.document(
"{class-name}/{method-name}/{step}/",
Snippets.CLUSTER_SEARCH_QUERY_PARAMETERS, // Request query parameters
Snippets.HAL_CONTENT_TYPE_HEADER, // Response headers
Snippets.CLUSTER_SEARCH_RESULT_FIELDS, // Result fields
Snippets.SEARCH_LINKS // HAL Links
);
// Test finding all clusters
RestAssured
.given(this.getRequestSpecification())
.filter(findFilter)
.when()
.port(this.port)
.get(CLUSTERS_API)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body(CLUSTERS_LIST_PATH, Matchers.hasSize(3))
.body(CLUSTERS_ID_LIST_PATH, Matchers.containsInAnyOrder(id1, id2, id3))
.body(
CLUSTERS_COMMANDS_LINK_PATH,
EntitiesLinksMatcher.matchUrisAnyOrder(
CLUSTERS_API, COMMANDS_LINK_KEY, COMMANDS_OPTIONAL_HAL_LINK_PARAMETERS,
Lists.newArrayList(id1, id2, id3)
)
);
// Try to limit the number of results
RestAssured
.given(this.getRequestSpecification())
.filter(findFilter)
.param("size", 2)
.when()
.port(this.port)
.get(CLUSTERS_API)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body(CLUSTERS_LIST_PATH, Matchers.hasSize(2));
// Query by name
RestAssured
.given(this.getRequestSpecification())
.filter(findFilter)
.param("name", name2)
.when()
.port(this.port)
.get(CLUSTERS_API)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body(CLUSTERS_LIST_PATH, Matchers.hasSize(1))
.body(CLUSTERS_LIST_PATH + "[0].id", Matchers.is(id2));
// Query by statuses
RestAssured
.given(this.getRequestSpecification())
.filter(findFilter)
.param("status", ClusterStatus.UP.toString(), ClusterStatus.TERMINATED.toString())
.when()
.port(this.port)
.get(CLUSTERS_API)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body(CLUSTERS_LIST_PATH, Matchers.hasSize(2))
.body(CLUSTERS_LIST_PATH + "[0].id", Matchers.is(id3))
.body(CLUSTERS_LIST_PATH + "[1].id", Matchers.is(id1));
// Query by tags
RestAssured
.given(this.getRequestSpecification())
.filter(findFilter)
.param("tag", "genie.id:" + id1)
.when()
.port(this.port)
.get(CLUSTERS_API)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body(CLUSTERS_LIST_PATH, Matchers.hasSize(1))
.body(CLUSTERS_LIST_PATH + "[0].id", Matchers.is(id1));
//TODO: Add tests for searching by min and max update time as those are available parameters
//TODO: Add tests for sort, orderBy etc
Assertions.assertThat(this.clusterRepository.count()).isEqualTo(3L);
}