void canGetCommandsForApplication()

in genie-web/src/integTest/java/com/netflix/genie/web/apis/rest/v3/controllers/ApplicationRestControllerIntegrationTest.java [832:941]


    void canGetCommandsForApplication() throws Exception {
        this.createConfigResource(
            new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(),
            null
        );
        final String placeholder = UUID.randomUUID().toString();
        final String command1Id = UUID.randomUUID().toString();
        final String command2Id = UUID.randomUUID().toString();
        final String command3Id = UUID.randomUUID().toString();
        this.createConfigResource(
            new Command
                .Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS, 1000L)
                .withId(command1Id)
                .build(),
            null
        );
        this.createConfigResource(
            new Command
                .Builder(placeholder, placeholder, placeholder, CommandStatus.INACTIVE, EXECUTABLE_AND_ARGS, 1100L)
                .withId(command2Id)
                .build(),
            null
        );
        this.createConfigResource(
            new Command
                .Builder(placeholder, placeholder, placeholder, CommandStatus.DEPRECATED, EXECUTABLE_AND_ARGS, 1200L)
                .withId(command3Id)
                .build(),
            null
        );

        final Set<String> appIds = Sets.newHashSet(ID);
        RestAssured
            .given(this.getRequestSpecification())
            .contentType(MediaType.APPLICATION_JSON_VALUE)
            .body(GenieObjectMapper.getMapper().writeValueAsBytes(appIds))
            .when()
            .port(this.port)
            .post(COMMANDS_API + "/{id}/applications", command1Id)
            .then()
            .statusCode(Matchers.is(HttpStatus.NO_CONTENT.value()));
        RestAssured
            .given(this.getRequestSpecification())
            .contentType(MediaType.APPLICATION_JSON_VALUE)
            .body(GenieObjectMapper.getMapper().writeValueAsBytes(appIds))
            .when()
            .port(this.port)
            .post(COMMANDS_API + "/{id}/applications", command3Id)
            .then()
            .statusCode(Matchers.is(HttpStatus.NO_CONTENT.value()));

        final String applicationCommandsAPI = APPLICATIONS_API + "/{id}/commands";

        Arrays.asList(
            GenieObjectMapper.getMapper().readValue(
                RestAssured
                    .given(this.getRequestSpecification())
                    .when()
                    .port(this.port)
                    .get(applicationCommandsAPI, ID)
                    .then()
                    .statusCode(Matchers.is(HttpStatus.OK.value()))
                    .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
                    .extract()
                    .asByteArray(),
                Command[].class
            )
        ).forEach(
            command -> {
                if (!command.getId().orElseThrow(IllegalArgumentException::new).equals(command1Id)
                    && !command.getId().orElseThrow(IllegalArgumentException::new).equals(command3Id)) {
                    Assertions.fail("Unexpected command");
                }
            }
        );

        // Filter by status
        final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
            "{class-name}/{method-name}/{step}/",
            Snippets.ID_PATH_PARAM, // Path parameters
            RequestDocumentation.requestParameters(
                RequestDocumentation
                    .parameterWithName("status")
                    .description("The status of commands to search for")
                    .attributes(
                        Attributes.key(Snippets.CONSTRAINTS).value(CommandStatus.values())
                    )
                    .optional()
            ), // Query Parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // Response Headers
            PayloadDocumentation.responseFields(
                PayloadDocumentation
                    .subsectionWithPath("[]")
                    .description("The list of commands found")
                    .attributes(Snippets.EMPTY_CONSTRAINTS)
            )
        );
        RestAssured
            .given(this.getRequestSpecification())
            .param("status", CommandStatus.ACTIVE.toString(), CommandStatus.INACTIVE.toString())
            .filter(getFilter)
            .when()
            .port(this.port)
            .get(applicationCommandsAPI, ID)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body("$", Matchers.hasSize(1))
            .body("[0].id", Matchers.is(command1Id));
    }