in genie-web/src/integTest/java/com/netflix/genie/web/apis/rest/v3/controllers/CommandRestControllerIntegrationTest.java [1304:1416]
void canRemoveApplicationFromACommand() throws Exception {
this.createConfigResource(
new Command
.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS)
.withId(ID)
.build(),
null
);
final String commandApplicationsAPI = COMMANDS_API + "/{id}/applications";
final String placeholder = UUID.randomUUID().toString();
final String applicationId1 = UUID.randomUUID().toString();
final String applicationId2 = UUID.randomUUID().toString();
final String applicationId3 = UUID.randomUUID().toString();
this.createConfigResource(
new Application
.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE)
.withId(applicationId1)
.build(),
null
);
this.createConfigResource(
new Application
.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE)
.withId(applicationId2)
.build(),
null
);
this.createConfigResource(
new Application
.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE)
.withId(applicationId3)
.build(),
null
);
RestAssured
.given(this.getRequestSpecification())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(
GenieObjectMapper
.getMapper()
.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2, applicationId3))
)
.when()
.port(this.port)
.post(commandApplicationsAPI, ID)
.then()
.statusCode(Matchers.is(HttpStatus.NO_CONTENT.value()));
final RestDocumentationFilter deleteFilter = RestAssuredRestDocumentation.document(
"{class-name}/{method-name}/{step}/",
Snippets.ID_PATH_PARAM.and(
RequestDocumentation
.parameterWithName("applicationId")
.description("The id of the application to remove")
) // Path parameters
);
RestAssured
.given(this.getRequestSpecification())
.filter(deleteFilter)
.when()
.port(this.port)
.delete(commandApplicationsAPI + "/{applicationId}", ID, applicationId2)
.then()
.statusCode(Matchers.is(HttpStatus.NO_CONTENT.value()));
RestAssured
.given(this.getRequestSpecification())
.when()
.port(this.port)
.get(commandApplicationsAPI, ID)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body("$", Matchers.hasSize(2))
.body("[0].id", Matchers.is(applicationId1))
.body("[1].id", Matchers.is(applicationId3));
// Check reverse side of relationship
RestAssured
.given(this.getRequestSpecification())
.when()
.port(this.port)
.get(APPLICATIONS_API + "/{id}/commands", applicationId1)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body("$", Matchers.hasSize(1))
.body("[0].id", Matchers.is(ID));
RestAssured
.given(this.getRequestSpecification())
.when()
.port(this.port)
.get(APPLICATIONS_API + "/{id}/commands", applicationId2)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body("$", Matchers.empty());
RestAssured
.given(this.getRequestSpecification())
.when()
.port(this.port)
.get(APPLICATIONS_API + "/{id}/commands", applicationId3)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
.body("$", Matchers.hasSize(1))
.body("[0].id", Matchers.is(ID));
}