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

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

Introduction

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

Prototype

public static OperationRequestPreprocessor preprocessRequest(OperationPreprocessor... preprocessors) 

Source Link

Document

Returns an OperationRequestPreprocessor that will preprocess the request by applying the given preprocessors to it.

Usage

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

/**
 * Test to make sure that an application can be patched.
 *
 * @throws Exception on configuration errors
 */// www.  jav  a2s  . c o  m
@Test
public void canPatchApplication() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));
    final String id = this.createConfigResource(
            new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null);
    final String applicationResource = APPLICATIONS_API + "/{id}";
    this.mvc.perform(MockMvcRequestBuilders.get(applicationResource, id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath(USER_PATH, Matchers.is(USER)));

    final String newUser = UUID.randomUUID().toString();
    final String patchString = "[{ \"op\": \"replace\", \"path\": \"/user\", \"value\": \"" + newUser + "\" }]";
    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(applicationResource, id)
            .contentType(MediaType.APPLICATION_JSON).content(this.objectMapper.writeValueAsBytes(patch)))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(patchResultHandler);

    this.mvc.perform(MockMvcRequestBuilders.get(applicationResource, id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(USER_PATH, Matchers.is(newUser)));
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(1L));
}

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

/**
 * Test to make sure we can update the configurations for a cluster after it is created.
 *
 * @throws Exception on configuration problems
 *///from  ww w.ja  va 2s .c  om
@Test
public void canUpdateConfigsForCluster() 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 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
            PayloadDocumentation.requestFields(Snippets.CONFIG_FIELDS) // Request fields
    );
    this.canUpdateElementsForResource(CLUSTERS_API + "/{id}/configs", ID, updateResultHandler);
}

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

/**
 * Test to make sure we can delete the configurations for a cluster after it is created.
 *
 * @throws Exception on configuration problems
 *//*from   ww w.  j a  va  2s .c o  m*/
@Test
public void canDeleteConfigsForCluster() 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 RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM);
    this.canDeleteElementsFromResource(CLUSTERS_API + "/{id}/configs", ID, deleteResultHandler);
}

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

/**
 * Test to make sure that you can delete a command.
 *
 * @throws Exception on configuration error
 *///from  w  ww .jav  a 2  s. com
@Test
public void canDeleteACommand() 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);
    this.createConfigResource(
            new Command.Builder(name2, user2, version2, CommandStatus.ACTIVE, executable2, CHECK_DELAY)
                    .withId(id2).build(),
            null);
    this.createConfigResource(
            new Command.Builder(name3, user3, version3, CommandStatus.ACTIVE, executable3, CHECK_DELAY)
                    .withId(id3).build(),
            null);
    Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(3L));

    final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // path parameters
    );

    this.mvc.perform(RestDocumentationRequestBuilders.delete(COMMANDS_API + "/{id}", id2))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler);

    this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API + "/{id}", id2))
            .andExpect(MockMvcResultMatchers.status().isNotFound());

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

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

/**
 * Make sure can successfully delete all applications.
 *
 * @throws Exception on a configuration error
 *//* w  ww .ja v  a2  s.  co  m*/
@Test
public void canDeleteAllApplications() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));
    this.createConfigResource(new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).build(),
            null);
    this.createConfigResource(
            new Application.Builder(NAME, USER, VERSION, ApplicationStatus.DEPRECATED).build(), null);
    this.createConfigResource(new Application.Builder(NAME, USER, VERSION, ApplicationStatus.INACTIVE).build(),
            null);
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(3L));

    final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()));

    this.mvc.perform(MockMvcRequestBuilders.delete(APPLICATIONS_API))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler);

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

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

/**
 * Test to make sure we can add dependencies to the cluster after it is created.
 *
 * @throws Exception on configuration problems
 *///  www  . j ava2 s .  c o m
@Test
public void canAddDependenciesToCluster() 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 RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params
            Snippets.CONTENT_TYPE_HEADER, // request header
            PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // response fields
    );
    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params
            Snippets.JSON_CONTENT_TYPE_HEADER, // response headers
            PayloadDocumentation.responseFields(Snippets.DEPENDENCIES_FIELDS) // response fields
    );
    this.canAddElementsToResource(CLUSTERS_API + "/{id}/dependencies", ID, addResultHandler, getResultHandler);
}

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

private void checkJobRequest(final int documentationId, final String id, final String commandArgs,
        final String setupFile, final String clusterTag, final String commandTag, final String depFile1)
        throws Exception {
    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/" + documentationId + "/getJobRequest/",
            Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // Path parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // Response Headers
            Snippets.getJobRequestResponsePayload(), // Response fields
            Snippets.JOB_REQUEST_LINKS // Links
    );/*from   w  w  w  . ja  v  a2 s. co m*/
    this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/request", id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .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(JOB_NAME)))
            .andExpect(MockMvcResultMatchers.jsonPath(VERSION_PATH, Matchers.is(JOB_VERSION)))
            .andExpect(MockMvcResultMatchers.jsonPath(USER_PATH, Matchers.is(JOB_USER)))
            .andExpect(MockMvcResultMatchers.jsonPath(DESCRIPTION_PATH, Matchers.is(JOB_DESCRIPTION)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMAND_ARGS_PATH, Matchers.is(commandArgs)))
            .andExpect(MockMvcResultMatchers.jsonPath(SETUP_FILE_PATH, Matchers.is(setupFile)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTER_CRITERIAS_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTER_CRITERIAS_PATH + "[0].tags", Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(CLUSTER_CRITERIAS_PATH + "[0].tags[0]",
                    Matchers.is(clusterTag)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMAND_CRITERIA_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(COMMAND_CRITERIA_PATH + "[0]", Matchers.is(commandTag)))
            .andExpect(MockMvcResultMatchers.jsonPath(GROUP_PATH, Matchers.nullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(DISABLE_LOG_ARCHIVAL_PATH, Matchers.is(true)))
            .andExpect(MockMvcResultMatchers.jsonPath(DEPENDENCIES_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(DEPENDENCIES_PATH + "[0]", Matchers.is(depFile1)))
            .andExpect(MockMvcResultMatchers.jsonPath(EMAIL_PATH, Matchers.nullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(CPU_PATH, Matchers.nullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(MEMORY_PATH, Matchers.nullValue()))
            .andExpect(MockMvcResultMatchers.jsonPath(APPLICATIONS_PATH, Matchers.empty()))
            .andDo(getResultHandler);
}

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

/**
 * Test to make sure we can add configurations to the command after it is created.
 *
 * @throws Exception on configuration problems
 *//*from  w ww.j a v a  2 s  .  c o m*/
@Test
public void canAddConfigsToCommand() throws Exception {
    Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L));
    this.createConfigResource(
            new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE, CHECK_DELAY).withId(ID)
                    .build(),
            null);

    final RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params
            Snippets.CONTENT_TYPE_HEADER, // request header
            PayloadDocumentation.requestFields(Snippets.CONFIG_FIELDS) // response fields
    );
    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params
            Snippets.JSON_CONTENT_TYPE_HEADER, // response headers
            PayloadDocumentation.responseFields(Snippets.CONFIG_FIELDS) // response fields
    );
    this.canAddElementsToResource(COMMANDS_API + "/{id}/configs", ID, addResultHandler, getResultHandler);
}

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

/**
 * Test to make sure we can update the dependencies for a cluster after it is created.
 *
 * @throws Exception on configuration problems
 *///from w  w  w .j  ava  2 s . c  o  m
@Test
public void canUpdateDependenciesForCluster() 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 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
            PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // Request fields
    );
    this.canUpdateElementsForResource(CLUSTERS_API + "/{id}/configs", ID, updateResultHandler);
}

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

/**
 * Test to make sure that you can delete an application.
 *
 * @throws Exception on configuration error
 *///w w  w.ja v  a 2s . c  o m
@Test
public void canDeleteAnApplication() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.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 Application.Builder(name1, user1, version1, ApplicationStatus.ACTIVE).withId(id1).build(),
            null);
    this.createConfigResource(
            new Application.Builder(name2, user2, version2, ApplicationStatus.DEPRECATED).withId(id2).build(),
            null);
    this.createConfigResource(
            new Application.Builder(name3, user3, version3, ApplicationStatus.INACTIVE).withId(id3).build(),
            null);
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(3L));

    final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // path parameters
    );

    this.mvc.perform(RestDocumentationRequestBuilders.delete(APPLICATIONS_API + "/{id}", id2))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler);

    this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API + "/{id}", id2))
            .andExpect(MockMvcResultMatchers.status().isNotFound());

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