Example usage for org.springframework.restdocs.operation.preprocess Preprocessors prettyPrint

List of usage examples for org.springframework.restdocs.operation.preprocess Preprocessors prettyPrint

Introduction

In this page you can find the example usage for org.springframework.restdocs.operation.preprocess Preprocessors prettyPrint.

Prototype

public static OperationPreprocessor prettyPrint() 

Source Link

Document

Returns an OperationPreprocessor that will pretty print the content of the request or response.

Usage

From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java

/**
 * Test creating an application without an ID.
 *
 * @throws Exception on configuration issue
 *///from  w w  w  .  ja va2s  .  c o  m
@Test
public void canCreateApplicationWithoutId() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));

    final RestDocumentationResultHandler creationResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request headers
            Snippets.getApplicationRequestPayload(), // Request fields
            Snippets.LOCATION_HEADER // Response headers
    );

    final String id = this
            .createConfigResource(
                    new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withType(TYPE)
                            .withDependencies(
                                    Sets.newHashSet("s3://mybucket/spark/" + VERSION + "/spark.tar.gz"))
                            .withSetupFile("s3://mybucket/spark/" + VERSION + "/setup-spark.sh")
                            .withConfigs(Sets.newHashSet("s3://mybucket/spark/" + VERSION + "/spark-env.sh"))
                            .withDescription("Spark for Genie")
                            .withTags(Sets.newHashSet("type:" + TYPE, "ver:" + VERSION)).build(),
                    creationResultHandler);

    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // response headers
            Snippets.getApplicationResponsePayload(), // response payload
            Snippets.APPLICATION_LINKS // response links
    );

    this.mvc.perform(RestDocumentationRequestBuilders.get(APPLICATIONS_API + "/{id}", id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(ID_PATH, Matchers.is(id)))
            .andExpect(MockMvcResultMatchers.jsonPath(UPDATED_PATH, Matchers.notNullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(CREATED_PATH, Matchers.notNullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(NAME_PATH, Matchers.is(NAME)))
            .andExpect(MockMvcResultMatchers.jsonPath(VERSION_PATH, Matchers.is(VERSION)))
            .andExpect(MockMvcResultMatchers.jsonPath(USER_PATH, Matchers.is(USER)))
            .andExpect(MockMvcResultMatchers.jsonPath(DESCRIPTION_PATH, Matchers.is("Spark for Genie")))
            .andExpect(MockMvcResultMatchers.jsonPath(SETUP_FILE_PATH,
                    Matchers.is("s3://mybucket/spark/" + VERSION + "/setup-spark.sh")))
            .andExpect(MockMvcResultMatchers.jsonPath(CONFIGS_PATH,
                    Matchers.hasItem("s3://mybucket/spark/" + VERSION + "/spark-env.sh")))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasSize(4)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("genie.id:" + id)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("genie.name:" + NAME)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("ver:" + VERSION)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("type:" + TYPE)))
            .andExpect(MockMvcResultMatchers.jsonPath(STATUS_PATH,
                    Matchers.is(ApplicationStatus.ACTIVE.toString())))
            .andExpect(MockMvcResultMatchers.jsonPath(DEPENDENCIES_PATH,
                    Matchers.hasItem("s3://mybucket/spark/" + VERSION + "/spark.tar.gz")))
            .andExpect(MockMvcResultMatchers.jsonPath(TYPE_PATH, Matchers.is(TYPE)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH + ".*", Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(SELF_LINK_KEY)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(COMMANDS_LINK_KEY)))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATION_COMMANDS_LINK_PATH, EntityLinkMatcher
                    .matchUri(APPLICATIONS_API, COMMANDS_LINK_KEY, COMMANDS_OPTIONAL_HAL_LINK_PARAMETERS, id)))
            .andDo(getResultHandler);

    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(1L));
}

From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java

/**
 * Test creating a cluster without an ID.
 *
 * @throws Exception on configuration issue
 *///from  w  ww  . ja  v  a 2  s . c o  m
@Test
public void canCreateClusterWithoutId() throws Exception {
    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L));

    final RestDocumentationResultHandler creationResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request headers
            Snippets.getClusterRequestPayload(), // Request fields
            Snippets.LOCATION_HEADER // Response headers
    );

    final String id = this.createConfigResource(
            new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).build(), creationResultHandler);

    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // response headers
            Snippets.getClusterResponsePayload(), // response payload
            Snippets.CLUSTER_LINKS // response links
    );

    this.mvc.perform(RestDocumentationRequestBuilders.get(CLUSTERS_API + "/{id}", id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(ID_PATH, Matchers.is(id)))
            .andExpect(MockMvcResultMatchers.jsonPath(CREATED_PATH, Matchers.notNullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(UPDATED_PATH, Matchers.notNullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(NAME_PATH, Matchers.is(NAME)))
            .andExpect(MockMvcResultMatchers.jsonPath(USER_PATH, Matchers.is(USER)))
            .andExpect(MockMvcResultMatchers.jsonPath(VERSION_PATH, Matchers.is(VERSION)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("genie.id:" + id)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("genie.name:" + NAME)))
            .andExpect(MockMvcResultMatchers.jsonPath(SETUP_FILE_PATH, Matchers.nullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(STATUS_PATH, Matchers.is(ClusterStatus.UP.toString())))
            .andExpect(MockMvcResultMatchers.jsonPath(CONFIGS_PATH, Matchers.hasSize(0)))
            .andExpect(MockMvcResultMatchers.jsonPath(DEPENDENCIES_PATH, Matchers.hasSize(0)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH + ".*", Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(SELF_LINK_KEY)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(COMMANDS_LINK_KEY)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTER_COMMANDS_LINK_PATH, EntityLinkMatcher
                    .matchUri(CLUSTERS_API, COMMANDS_LINK_KEY, COMMANDS_OPTIONAL_HAL_LINK_PARAMETERS, id)))
            .andDo(getResultHandler);

    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(1L));
}

From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java

/**
 * Test creating a command without an ID.
 *
 * @throws Exception on configuration issue
 *///  w w w. ja  va 2s . c  o m
@Test
public void canCreateCommandWithoutId() throws Exception {
    Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L));

    final RestDocumentationResultHandler creationResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request headers
            Snippets.getCommandRequestPayload(), // Request fields
            Snippets.LOCATION_HEADER // Response headers
    );

    final String id = this.createConfigResource(
            new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE, CHECK_DELAY)
                    .withDescription(DESCRIPTION).withMemory(MEMORY).withConfigs(CONFIGS)
                    .withDependencies(DEPENDENCIES).withTags(TAGS).build(),
            creationResultHandler);

    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // response headers
            Snippets.getCommandResponsePayload(), // response payload
            Snippets.COMMAND_LINKS // response links
    );

    this.mvc.perform(RestDocumentationRequestBuilders.get(COMMANDS_API + "/{id}", id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(ID_PATH, Matchers.is(id)))
            .andExpect(MockMvcResultMatchers.jsonPath(CREATED_PATH, Matchers.notNullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(UPDATED_PATH, Matchers.notNullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(NAME_PATH, Matchers.is(NAME)))
            .andExpect(MockMvcResultMatchers.jsonPath(USER_PATH, Matchers.is(USER)))
            .andExpect(MockMvcResultMatchers.jsonPath(VERSION_PATH, Matchers.is(VERSION)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(STATUS_PATH, Matchers.is(CommandStatus.ACTIVE.toString())))
            .andExpect(MockMvcResultMatchers.jsonPath(EXECUTABLE_PATH, Matchers.is(EXECUTABLE)))
            .andExpect(MockMvcResultMatchers.jsonPath(CHECK_DELAY_PATH, Matchers.is((int) CHECK_DELAY)))
            .andExpect(MockMvcResultMatchers.jsonPath(DESCRIPTION_PATH, Matchers.is(DESCRIPTION)))
            .andExpect(MockMvcResultMatchers.jsonPath(MEMORY_PATH, Matchers.is(MEMORY)))
            .andExpect(MockMvcResultMatchers.jsonPath(CONFIGS_PATH, Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath(CONFIGS_PATH, Matchers.hasItems(CONFIG_1, CONFIG_2)))
            .andExpect(MockMvcResultMatchers.jsonPath(DEPENDENCIES_PATH, Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath(DEPENDENCIES_PATH, Matchers.hasItems(DEP_1, DEP_2)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasSize(4)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("genie.id:" + id)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItem("genie.name:" + NAME)))
            .andExpect(MockMvcResultMatchers.jsonPath(TAGS_PATH, Matchers.hasItems(TAG_1, TAG_2)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH + ".*", Matchers.hasSize(3)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(SELF_LINK_KEY)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(CLUSTERS_LINK_KEY)))
            .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(APPLICATIONS_LINK_KEY)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMAND_CLUSTERS_LINK_PATH,
                    EntityLinkMatcher.matchUri(COMMANDS_API, CLUSTERS_LINK_KEY,
                            CLUSTERS_OPTIONAL_HAL_LINK_PARAMETERS, id)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMAND_APPS_LINK_PATH,
                    EntityLinkMatcher.matchUri(COMMANDS_API, APPLICATIONS_LINK_KEY, null, id)))
            .andDo(getResultHandler);

    Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(1L));
}

From source file:com.netflix.genie.web.controllers.RestControllerIntegrationTestBase.java

/**
 * Clean out the db before every test./*from  w ww .  jav a2s  .  c o m*/
 *
 * @throws Exception on error
 */
public void setup() throws Exception {
    this.jobRepository.deleteAll();
    this.clusterRepository.deleteAll();
    this.commandRepository.deleteAll();
    this.applicationRepository.deleteAll();
    this.fileRepository.deleteAll();
    this.tagRepository.deleteAll();

    this.requestSpecification = new RequestSpecBuilder()
            .addFilter(RestAssuredRestDocumentation.documentationConfiguration(this.restDocumentation)
                    .snippets().withAdditionalDefaults(new WireMockSnippet()).and().operationPreprocessors()
                    .withRequestDefaults(Preprocessors.prettyPrint(),
                            Preprocessors.modifyUris().scheme(URI_SCHEME).host(URI_HOST).removePort())
                    .withResponseDefaults(Preprocessors.prettyPrint(),
                            Preprocessors.modifyUris().host(URI_HOST).scheme(URI_SCHEME).removePort()))
            .build();
}

From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java

/**
 * Test to make sure that you can search for clusters by various parameters.
 *
 * @throws Exception on configuration error
 *///from   w ww  . j  a  v  a  2  s .c  o  m
@Test
public void canFindClusters() throws Exception {
    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L));
    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 RestDocumentationResultHandler findResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()),
            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
    this.mvc.perform(MockMvcRequestBuilders.get(CLUSTERS_API)).andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH, Matchers.hasSize(3)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_ID_LIST_PATH,
                    Matchers.containsInAnyOrder(id1, id2, id3)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_COMMANDS_LINK_PATH,
                    EntitiesLinksMatcher.matchUrisAnyOrder(CLUSTERS_API, COMMANDS_LINK_KEY,
                            COMMANDS_OPTIONAL_HAL_LINK_PARAMETERS, Lists.newArrayList(id1, id2, id3))))
            .andDo(findResultHandler);

    // Try to limit the number of results
    this.mvc.perform(MockMvcRequestBuilders.get(CLUSTERS_API).param("size", "2"))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH, Matchers.hasSize(2)))
            .andDo(findResultHandler);

    // Query by name
    this.mvc.perform(MockMvcRequestBuilders.get(CLUSTERS_API).param("name", name2))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH + "[0].id", Matchers.is(id2)))
            .andDo(findResultHandler);

    // Query by statuses
    this.mvc.perform(MockMvcRequestBuilders.get(CLUSTERS_API).param("status", ClusterStatus.UP.toString(),
            ClusterStatus.TERMINATED.toString())).andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH, Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH + "[0].id", Matchers.is(id3)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH + "[1].id", Matchers.is(id1)))
            .andDo(findResultHandler);

    // Query by tags
    this.mvc.perform(MockMvcRequestBuilders.get(CLUSTERS_API).param("tag", "genie.id:" + id1))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH + "[0].id", Matchers.is(id1)))
            .andDo(findResultHandler);

    //TODO: Add tests for searching by min and max update time as those are available parameters
    //TODO: Add tests for sort, orderBy etc

    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(3L));
}

From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java

/**
 * Test to make sure that you can search for commands by various parameters.
 *
 * @throws Exception on configuration error
 *///from  ww w .j av a 2  s. c om
@Test
public void canFindCommands() throws Exception {
    Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L));
    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();
    final String executable1 = UUID.randomUUID().toString();
    final String executable2 = UUID.randomUUID().toString();
    final String executable3 = UUID.randomUUID().toString();

    this.createConfigResource(
            new Command.Builder(name1, user1, version1, CommandStatus.ACTIVE, executable1, CHECK_DELAY)
                    .withId(id1).build(),
            null);
    Thread.sleep(1000);
    this.createConfigResource(
            new Command.Builder(name2, user2, version2, CommandStatus.DEPRECATED, executable2, CHECK_DELAY)
                    .withId(id2).build(),
            null);
    Thread.sleep(1000);
    this.createConfigResource(
            new Command.Builder(name3, user3, version3, CommandStatus.INACTIVE, executable3, CHECK_DELAY)
                    .withId(id3).build(),
            null);

    final RestDocumentationResultHandler findResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()),
            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
    this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API)).andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH, Matchers.hasSize(3)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_ID_LIST_PATH,
                    Matchers.containsInAnyOrder(id1, id2, id3)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_APPS_LINK_PATH,
                    EntitiesLinksMatcher.matchUrisAnyOrder(COMMANDS_API, APPLICATIONS_LINK_KEY, null,
                            Lists.newArrayList(id1, id2, id3))))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_CLUSTERS_LINK_PATH,
                    EntitiesLinksMatcher.matchUrisAnyOrder(COMMANDS_API, CLUSTERS_LINK_KEY,
                            CLUSTERS_OPTIONAL_HAL_LINK_PARAMETERS, Lists.newArrayList(id1, id2, id3))))
            .andDo(findResultHandler);

    // Try to limit the number of results
    this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API).param("size", "2"))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH, Matchers.hasSize(2)))
            .andDo(findResultHandler);

    // Query by name
    this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API).param("name", name2))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id2)))
            .andDo(findResultHandler);

    // Query by user
    this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API).param("user", user3))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id3)))
            .andDo(findResultHandler);

    // Query by statuses
    this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API).param("status", CommandStatus.ACTIVE.toString(),
            CommandStatus.INACTIVE.toString())).andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH, Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id3)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH + "[1].id", Matchers.is(id1)))
            .andDo(findResultHandler);

    // Query by tags
    this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API).param("tag", "genie.id:" + id1))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMANDS_LIST_PATH + "[0].id", Matchers.is(id1)))
            .andDo(findResultHandler);

    //TODO: Add tests for sort, orderBy etc

    Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(3L));
}

From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java

/**
 * Test to make sure that a cluster can be updated.
 *
 * @throws Exception on configuration errors
 *//*from  w  ww  .j  av a 2 s .c  o  m*/
@Test
public void canUpdateCluster() throws Exception {
    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L));
    this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(),
            null);
    final String clusterResource = CLUSTERS_API + "/{id}";
    final Cluster createdCluster = this.objectMapper
            .readValue(this.mvc.perform(MockMvcRequestBuilders.get(clusterResource, ID)).andReturn()
                    .getResponse().getContentAsByteArray(), ClusterResource.class)
            .getContent();
    Assert.assertThat(createdCluster.getStatus(), Matchers.is(ClusterStatus.UP));

    final Cluster.Builder updateCluster = new Cluster.Builder(createdCluster.getName(),
            createdCluster.getUser(), createdCluster.getVersion(), ClusterStatus.OUT_OF_SERVICE)
                    .withId(createdCluster.getId().orElseThrow(IllegalArgumentException::new))
                    .withCreated(createdCluster.getCreated().orElseThrow(IllegalArgumentException::new))
                    .withUpdated(createdCluster.getUpdated().orElseThrow(IllegalArgumentException::new))
                    .withTags(createdCluster.getTags()).withConfigs(createdCluster.getConfigs())
                    .withDependencies(createdCluster.getDependencies());

    createdCluster.getDescription().ifPresent(updateCluster::withDescription);
    createdCluster.getSetupFile().ifPresent(updateCluster::withSetupFile);

    final RestDocumentationResultHandler updateResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // request header
            Snippets.ID_PATH_PARAM, // path parameters
            Snippets.getClusterRequestPayload() // payload fields
    );

    this.mvc.perform(
            RestDocumentationRequestBuilders.put(clusterResource, ID).contentType(MediaType.APPLICATION_JSON)
                    .content(this.objectMapper.writeValueAsBytes(updateCluster.build())))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(updateResultHandler);

    this.mvc.perform(MockMvcRequestBuilders.get(clusterResource, ID))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(STATUS_PATH,
                    Matchers.is(ClusterStatus.OUT_OF_SERVICE.toString())));
    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(1L));
}

From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java

/**
 * Test to make sure that you can search for applications by various parameters.
 *
 * @throws Exception on configuration error
 *///from  w  w  w .j  av  a2 s .  c o  m
@Test
public void canFindApplications() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));
    final Application spark151 = new Application.Builder("spark", "genieUser1", "1.5.1",
            ApplicationStatus.ACTIVE)
                    .withDependencies(Sets.newHashSet("s3://mybucket/spark/spark-1.5.1.tar.gz"))
                    .withSetupFile("s3://mybucket/spark/setup-spark.sh")
                    .withConfigs(Sets.newHashSet("s3://mybucket/spark/spark-env.sh"))
                    .withDescription("Spark 1.5.1 for Genie")
                    .withTags(Sets.newHashSet("type:spark", "ver:1.5.1")).withType("spark").build();

    final Application spark150 = new Application.Builder("spark", "genieUser2", "1.5.0",
            ApplicationStatus.ACTIVE)
                    .withDependencies(Sets.newHashSet("s3://mybucket/spark/spark-1.5.0.tar.gz"))
                    .withSetupFile("s3://mybucket/spark/setup-spark.sh")
                    .withConfigs(Sets.newHashSet("s3://mybucket/spark/spark-env.sh"))
                    .withDescription("Spark 1.5.0 for Genie")
                    .withTags(Sets.newHashSet("type:spark", "ver:1.5.0")).withType("spark").build();

    final Application spark141 = new Application.Builder("spark", "genieUser3", "1.4.1",
            ApplicationStatus.INACTIVE)
                    .withDependencies(Sets.newHashSet("s3://mybucket/spark/spark-1.4.1.tar.gz"))
                    .withSetupFile("s3://mybucket/spark/setup-spark.sh")
                    .withConfigs(Sets.newHashSet("s3://mybucket/spark/spark-env.sh"))
                    .withDescription("Spark 1.4.1 for Genie")
                    .withTags(Sets.newHashSet("type:spark", "ver:1.4.1")).withType("spark").build();

    final Application spark140 = new Application.Builder("spark", "genieUser4", "1.4.0",
            ApplicationStatus.DEPRECATED)
                    .withDependencies(Sets.newHashSet("s3://mybucket/spark/spark-1.4.0.tar.gz"))
                    .withSetupFile("s3://mybucket/spark/setup-spark.sh")
                    .withConfigs(Sets.newHashSet("s3://mybucket/spark/spark-env.sh"))
                    .withDescription("Spark 1.4.0 for Genie")
                    .withTags(Sets.newHashSet("type:spark", "ver:1.4.0")).withType("spark").build();

    final Application spark131 = new Application.Builder("spark", "genieUser5", "1.3.1",
            ApplicationStatus.DEPRECATED)
                    .withDependencies(Sets.newHashSet("s3://mybucket/spark/spark-1.3.1.tar.gz"))
                    .withSetupFile("s3://mybucket/spark/setup-spark.sh")
                    .withConfigs(Sets.newHashSet("s3://mybucket/spark/spark-env.sh"))
                    .withDescription("Spark 1.3.1 for Genie")
                    .withTags(Sets.newHashSet("type:spark", "ver:1.3.1")).withType("spark").build();

    final Application pig = new Application.Builder("spark", "genieUser6", "0.4.0", ApplicationStatus.ACTIVE)
            .withDependencies(Sets.newHashSet("s3://mybucket/pig/pig-0.15.0.tar.gz"))
            .withSetupFile("s3://mybucket/pig/setup-pig.sh")
            .withConfigs(Sets.newHashSet("s3://mybucket/pig/pig.properties"))
            .withDescription("Pig 0.15.0 for Genie").withTags(Sets.newHashSet("type:pig", "ver:0.15.0"))
            .withType("pig").build();

    final Application hive = new Application.Builder("hive", "genieUser7", "1.0.0", ApplicationStatus.ACTIVE)
            .withDependencies(Sets.newHashSet("s3://mybucket/hive/hive-1.0.0.tar.gz"))
            .withSetupFile("s3://mybucket/hive/setup-hive.sh")
            .withConfigs(Sets.newHashSet("s3://mybucket/hive/hive-env.sh",
                    "s3://mybucket/hive/hive-log4j.properties"))
            .withDescription("Hive 1.0.0 for Genie").withTags(Sets.newHashSet("type:hive", "ver:1.0.0"))
            .withType("hive").build();

    final String spark151Id = this.createConfigResource(spark151, null);
    final String spark150Id = this.createConfigResource(spark150, null);
    final String spark141Id = this.createConfigResource(spark141, null);
    final String spark140Id = this.createConfigResource(spark140, null);
    final String spark131Id = this.createConfigResource(spark131, null);
    final String pigId = this.createConfigResource(pig, null);
    final String hiveId = this.createConfigResource(hive, null);

    final List<String> appIds = Lists.newArrayList(spark151Id, spark150Id, spark141Id, spark140Id, spark131Id,
            pigId, hiveId);

    final RestDocumentationResultHandler documentationResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()),
            Snippets.APPLICATION_SEARCH_QUERY_PARAMETERS, // Request query parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // Response headers
            Snippets.APPLICATION_SEARCH_RESULT_FIELDS, // Result fields
            Snippets.SEARCH_LINKS // HAL Links
    );

    // Test finding all applications
    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH, Matchers.hasSize(7)))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_ID_LIST_PATH, Matchers.hasSize(7)))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_ID_LIST_PATH,
                    Matchers.containsInAnyOrder(spark151Id, spark150Id, spark141Id, spark140Id, spark131Id,
                            pigId, hiveId)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_COMMANDS_LINK_PATH,
                            EntitiesLinksMatcher.matchUrisAnyOrder(APPLICATIONS_API, COMMANDS_LINK_KEY,
                                    COMMANDS_OPTIONAL_HAL_LINK_PARAMETERS, appIds)))
            .andDo(documentationResultHandler);

    // Limit the size
    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API).param("size", "2"))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH, Matchers.hasSize(2)))
            .andDo(documentationResultHandler);

    // Query by name
    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API).param("name", "hive"))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[0].id", Matchers.is(hiveId)))
            .andDo(documentationResultHandler);

    // Query by user
    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API).param("user", "genieUser3"))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[0].id", Matchers.is(spark141Id)))
            .andDo(documentationResultHandler);

    // Query by statuses
    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API).param("status",
            ApplicationStatus.ACTIVE.toString(), ApplicationStatus.DEPRECATED.toString()))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH, Matchers.hasSize(6)))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[0].id", Matchers.is(hiveId)))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[1].id", Matchers.is(pigId)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[2].id", Matchers.is(spark131Id)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[3].id", Matchers.is(spark140Id)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[4].id", Matchers.is(spark150Id)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[5].id", Matchers.is(spark151Id)))
            .andDo(documentationResultHandler);

    // Query by tags
    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API).param("tag", "genie.id:" + spark131Id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[0].id", Matchers.is(spark131Id)))
            .andDo(documentationResultHandler);

    // Query by type
    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API).param("type", "spark"))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH, Matchers.hasSize(5)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[0].id", Matchers.is(spark131Id)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[1].id", Matchers.is(spark140Id)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[2].id", Matchers.is(spark141Id)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[3].id", Matchers.is(spark150Id)))
            .andExpect(
                    MockMvcResultMatchers.jsonPath(APPLICATIONS_LIST_PATH + "[4].id", Matchers.is(spark151Id)))
            .andDo(documentationResultHandler);

    //TODO: Add tests for sort, orderBy etc

    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(7L));
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java

private String submitJob(final int documentationId, final JobRequest jobRequest,
        final List<MockMultipartFile> attachments) throws Exception {
    final MvcResult result;

    if (attachments != null) {
        final RestDocumentationResultHandler createResultHandler = MockMvcRestDocumentation.document(
                "{class-name}/" + documentationId + "/submitJobWithAttachments/",
                Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
                Preprocessors.preprocessResponse(Preprocessors.prettyPrint()),
                HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE)
                        .description(MediaType.MULTIPART_FORM_DATA_VALUE)), // Request headers
                RequestDocumentation.requestParts(
                        RequestDocumentation.partWithName("request").description(
                                "The job request JSON. Content type must be application/json for part"),
                        RequestDocumentation.partWithName("attachment").description(
                                "An attachment file. There can be multiple. Type should be octet-stream")), // Request parts
                Snippets.LOCATION_HEADER // Response Headers
        );/*from   w ww . j av a2 s  .c om*/

        final MockMultipartFile json = new MockMultipartFile("request", "", MediaType.APPLICATION_JSON_VALUE,
                this.objectMapper.writeValueAsBytes(jobRequest));

        final MockMultipartHttpServletRequestBuilder builder = RestDocumentationRequestBuilders
                .fileUpload(JOBS_API).file(json);

        for (final MockMultipartFile attachment : attachments) {
            builder.file(attachment);
        }

        builder.contentType(MediaType.MULTIPART_FORM_DATA);
        result = this.mvc.perform(builder).andExpect(MockMvcResultMatchers.status().isAccepted())
                .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue()))
                .andDo(createResultHandler).andReturn();
    } else {
        // Use regular POST
        final RestDocumentationResultHandler createResultHandler = MockMvcRestDocumentation.document(
                "{class-name}/" + documentationId + "/submitJobWithoutAttachments/",
                Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
                Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request headers
                Snippets.getJobRequestRequestPayload(), // Request Fields
                Snippets.LOCATION_HEADER // Response Headers
        );

        result = this.mvc
                .perform(MockMvcRequestBuilders.post(JOBS_API).contentType(MediaType.APPLICATION_JSON)
                        .content(this.objectMapper.writeValueAsBytes(jobRequest)))
                .andExpect(MockMvcResultMatchers.status().isAccepted())
                .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue()))
                .andDo(createResultHandler).andReturn();
    }

    return this.getIdFromLocation(result.getResponse().getHeader(HttpHeaders.LOCATION));
}

From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java

/**
 * Test to make sure that a cluster can be patched.
 *
 * @throws Exception on configuration errors
 *//*from   w  w w.j  a v  a 2 s  . c  om*/
@Test
public void canPatchCluster() throws Exception {
    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L));
    final String id = this.createConfigResource(
            new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null);
    final String clusterResource = CLUSTERS_API + "/{id}";
    this.mvc.perform(MockMvcRequestBuilders.get(clusterResource, id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath(NAME_PATH, Matchers.is(NAME)));

    final String newName = UUID.randomUUID().toString();
    final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + newName + "\" }]";
    final JsonPatch patch = JsonPatch.fromJson(this.objectMapper.readTree(patchString));

    final RestDocumentationResultHandler patchResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // request headers
            Snippets.ID_PATH_PARAM, // path params
            Snippets.PATCH_FIELDS // request payload
    );

    this.mvc.perform(RestDocumentationRequestBuilders.patch(clusterResource, id)
            .contentType(MediaType.APPLICATION_JSON).content(this.objectMapper.writeValueAsBytes(patch)))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(patchResultHandler);

    this.mvc.perform(MockMvcRequestBuilders.get(clusterResource, id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(NAME_PATH, Matchers.is(newName)));
    Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(1L));
}