void canFindCommands()

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


    void canFindCommands() 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 Command
                .Builder(name1, user1, version1, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS)
                .withId(id1)
                .build(),
            null
        );
        Thread.sleep(1000);
        this.createConfigResource(
            new Command
                .Builder(name2, user2, version2, CommandStatus.DEPRECATED, EXECUTABLE_AND_ARGS)
                .withId(id2)
                .build(),
            null
        );
        Thread.sleep(1000);
        this.createConfigResource(
            new Command
                .Builder(name3, user3, version3, CommandStatus.INACTIVE, EXECUTABLE_AND_ARGS)
                .withId(id3)
                .build(),
            null
        );

        final RestDocumentationFilter findFilter = RestAssuredRestDocumentation.document(
            "{class-name}/{method-name}/{step}/",
            Snippets.COMMAND_SEARCH_QUERY_PARAMETERS, // Request query parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // Response headers
            Snippets.COMMAND_SEARCH_RESULT_FIELDS, // Result fields
            Snippets.SEARCH_LINKS // HAL Links
        );

        // Test finding all commands
        RestAssured
            .given(this.getRequestSpecification())
            .filter(findFilter)
            .when()
            .port(this.port)
            .get(COMMANDS_API)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(COMMANDS_LIST_PATH, Matchers.hasSize(3))
            .body(COMMANDS_ID_LIST_PATH, Matchers.containsInAnyOrder(id1, id2, id3))
            .body(
                COMMANDS_APPS_LINK_PATH,
                EntitiesLinksMatcher
                    .matchUrisAnyOrder(
                        COMMANDS_API,
                        APPLICATIONS_LINK_KEY,
                        null,
                        Lists.newArrayList(id1, id2, id3)
                    )
            )
            .body(
                COMMANDS_CLUSTERS_LINK_PATH,
                EntitiesLinksMatcher.
                    matchUrisAnyOrder(
                        COMMANDS_API,
                        CLUSTERS_LINK_KEY,
                        CLUSTERS_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(COMMANDS_API)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(COMMANDS_LIST_PATH, Matchers.hasSize(2));

        // Query by name
        RestAssured
            .given(this.getRequestSpecification())
            .filter(findFilter)
            .param("name", name2)
            .when()
            .port(this.port)
            .get(COMMANDS_API)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(COMMANDS_LIST_PATH, Matchers.hasSize(1))
            .body(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id2));

        // Query by user
        RestAssured
            .given(this.getRequestSpecification())
            .filter(findFilter)
            .param("user", user3)
            .when()
            .port(this.port)
            .get(COMMANDS_API)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(COMMANDS_LIST_PATH, Matchers.hasSize(1))
            .body(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id3));

        // Query by statuses
        RestAssured
            .given(this.getRequestSpecification())
            .filter(findFilter)
            .param("status", CommandStatus.ACTIVE.toString(), CommandStatus.INACTIVE.toString())
            .when()
            .port(this.port)
            .get(COMMANDS_API)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(COMMANDS_LIST_PATH, Matchers.hasSize(2))
            .body(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id3))
            .body(COMMANDS_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(COMMANDS_API)
            .then()
            .statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.containsString(MediaTypes.HAL_JSON_VALUE))
            .body(COMMANDS_LIST_PATH, Matchers.hasSize(1))
            .body(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id1));

        //TODO: Add tests for sort, orderBy etc

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