void canUpdateCommand()

in genie-web/src/integTest/java/com/netflix/genie/web/apis/rest/v3/controllers/CommandRestControllerIntegrationTest.java [495:568]


    void canUpdateCommand() throws Exception {
        this.createConfigResource(
            new Command
                .Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS)
                .withId(ID)
                .build(),
            null
        );
        final String commandResource = COMMANDS_API + "/{id}";
        final Command createdCommand = GenieObjectMapper.getMapper()
            .readValue(
                RestAssured
                    .given(this.getRequestSpecification())
                    .when()
                    .port(this.port)
                    .get(commandResource, ID)
                    .then()
                    .statusCode(Matchers.is(HttpStatus.OK.value()))
                    .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
                    .extract()
                    .asByteArray(),
                new TypeReference<EntityModel<Command>>() {
                }
            ).getContent();
        Assertions.assertThat(createdCommand).isNotNull();
        Assertions.assertThat(createdCommand.getStatus()).isEqualByComparingTo(CommandStatus.ACTIVE);

        final Command.Builder updateCommand = new Command.Builder(
            createdCommand.getName(),
            createdCommand.getUser(),
            createdCommand.getVersion(),
            CommandStatus.INACTIVE,
            createdCommand.getExecutableAndArguments()
        )
            .withId(createdCommand.getId().orElseThrow(IllegalArgumentException::new))
            .withCreated(createdCommand.getCreated().orElseThrow(IllegalArgumentException::new))
            .withUpdated(createdCommand.getUpdated().orElseThrow(IllegalArgumentException::new))
            .withTags(createdCommand.getTags())
            .withConfigs(createdCommand.getConfigs())
            .withDependencies(createdCommand.getDependencies());

        createdCommand.getDescription().ifPresent(updateCommand::withDescription);
        createdCommand.getSetupFile().ifPresent(updateCommand::withSetupFile);

        final RestDocumentationFilter updateFilter = RestAssuredRestDocumentation.document(
            "{class-name}/{method-name}/{step}/",
            Snippets.CONTENT_TYPE_HEADER, // request header
            Snippets.ID_PATH_PARAM, // path parameters
            Snippets.getCommandRequestPayload() // payload fields
        );

        RestAssured
            .given(this.getRequestSpecification())
            .filter(updateFilter)
            .contentType(MediaType.APPLICATION_JSON_VALUE)
            .body(GenieObjectMapper.getMapper().writeValueAsBytes(updateCommand.build()))
            .when()
            .port(this.port)
            .put(commandResource, ID)
            .then()
            .statusCode(Matchers.is(HttpStatus.NO_CONTENT.value()));

        RestAssured
            .given(this.getRequestSpecification())
            .when()
            .port(this.port)
            .get(commandResource, ID)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(STATUS_PATH, Matchers.is(CommandStatus.INACTIVE.toString()));

        Assertions.assertThat(this.commandRepository.count()).isEqualTo(1L);
    }