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.CommandRestControllerIntegrationTests.java

/**
 * Test to make sure we can update the tags for a command after it is created.
 *
 * @throws Exception on configuration problems
 *///  w w  w  . jav a2s. c o  m
@Test
public void canUpdateTagsForCommand() 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 String api = COMMANDS_API + "/{id}/tags";

    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.TAGS_FIELDS) // Request fields
    );
    this.canUpdateTagsForResource(api, ID, NAME, updateResultHandler);
}

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

/**
 * Test to make sure we can delete the dependencies for an application after it is created.
 *
 * @throws Exception on configuration problems
 *///from  w w  w. j a va  2 s. co  m
@Test
public void canDeleteDependenciesForApplication() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));
    this.createConfigResource(
            new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).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 // Path variables
    );
    this.canDeleteElementsFromResource(APPLICATIONS_API + "/{id}/dependencies", ID, deleteResultHandler);
}

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

private void checkJobApplications(final int documentationId, final String id) throws Exception {
    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/" + documentationId + "/getJobApplications/",
            Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // Path parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // Response Headers
            PayloadDocumentation.responseFields(PayloadDocumentation.fieldWithPath("[]")
                    .description("The applications for the job").attributes(Snippets.EMPTY_CONSTRAINTS)) // Response fields
    );//from w w  w. j av  a2  s  .c o  m
    this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/applications", id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(APP1_ID)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(APP2_ID))).andDo(getResultHandler);
}

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

/**
 * Test to make sure we can add tags to the application after it is created.
 *
 * @throws Exception on configuration problems
 *///ww w .  j  a  va 2  s  .  com
@Test
public void canAddTagsToApplication() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));
    this.createConfigResource(
            new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null);
    final String api = APPLICATIONS_API + "/{id}/tags";

    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.TAGS_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 parameters
            Snippets.JSON_CONTENT_TYPE_HEADER, // response headers
            PayloadDocumentation.responseFields(Snippets.TAGS_FIELDS) // response fields
    );
    this.canAddTagsToResource(api, ID, NAME, addResultHandler, getResultHandler);
}

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

/**
 * Test to make sure we can delete the tags for a command after it is created.
 *
 * @throws Exception on configuration problems
 */// ww w.ja  v  a 2 s  .  com
@Test
public void canDeleteTagsForCommand() 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 String api = COMMANDS_API + "/{id}/tags";

    final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM);
    this.canDeleteTagsForResource(api, ID, NAME, deleteResultHandler);
}

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

private void checkFindJobs(final int documentationId, final String id, final String user) throws Exception {
    final RestDocumentationResultHandler findResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/" + documentationId + "/findJobs/",
            Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.JOB_SEARCH_QUERY_PARAMETERS, // Request query parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // Response headers
            Snippets.JOB_SEARCH_RESULT_FIELDS, // Result fields
            Snippets.SEARCH_LINKS // HAL Links
    );//from  ww  w .ja va 2  s .co  m
    this.mvc.perform(MockMvcRequestBuilders.get(JOBS_API).param("user", user))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath(JOBS_LIST_PATH, Matchers.hasSize(1)))
            .andExpect(MockMvcResultMatchers.jsonPath(JOBS_LIST_PATH + "[0].id", Matchers.is(id)))
            .andDo(findResultHandler);
}

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

/**
 * Test to make sure we can delete a tag for a command after it is created.
 *
 * @throws Exception on configuration problems
 *///from   ww w . j a v a  2 s.co  m
@Test
public void canDeleteTagForCommand() 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 String api = COMMANDS_API + "/{id}/tags";

    final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM
                    .and(RequestDocumentation.parameterWithName("tag").description("The tag to remove")));
    this.canDeleteTagForResource(api, ID, NAME, deleteResultHandler);
}

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

/**
 * Test to make sure we can update the tags for an application after it is created.
 *
 * @throws Exception on configuration problems
 *///from  w ww . java2s.  c  o  m
@Test
public void canUpdateTagsForApplication() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));
    this.createConfigResource(
            new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null);
    final String api = APPLICATIONS_API + "/{id}/tags";

    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.TAGS_FIELDS) // Request fields
    );
    this.canUpdateTagsForResource(api, ID, NAME, updateResultHandler);
}

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

/**
 * Test to make sure we can delete the tags for an application after it is created.
 *
 * @throws Exception on configuration problems
 *//*from w ww  .j  a v a 2  s  . c  om*/
@Test
public void canDeleteTagsForApplication() throws Exception {
    Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L));
    this.createConfigResource(
            new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null);
    final String api = APPLICATIONS_API + "/{id}/tags";

    final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM);
    this.canDeleteTagsForResource(api, ID, NAME, deleteResultHandler);
}

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

/**
 * Make sure can add the applications for a command.
 *
 * @throws Exception on configuration error
 *///from www. ja  va 2 s .c o m
@Test
public void canAddApplicationsForACommand() throws Exception {
    this.createConfigResource(
            new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE, CHECK_DELAY).withId(ID)
                    .build(),
            null);
    final String commandApplicationsAPI = COMMANDS_API + "/{id}/applications";
    this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty()));

    final String placeholder = UUID.randomUUID().toString();
    final String applicationId1 = UUID.randomUUID().toString();
    final String applicationId2 = UUID.randomUUID().toString();
    this.createConfigResource(
            new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE)
                    .withId(applicationId1).build(),
            null);
    this.createConfigResource(
            new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE)
                    .withId(applicationId2).build(),
            null);

    final RestDocumentationResultHandler addResultHandler = 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 parameters
            PayloadDocumentation.requestFields(PayloadDocumentation.fieldWithPath("[]")
                    .description("Array of application ids to add to existing set of applications")
                    .attributes(Snippets.EMPTY_CONSTRAINTS)) // Request payload
    );

    this.mvc.perform(RestDocumentationRequestBuilders.post(commandApplicationsAPI, ID)
            .contentType(MediaType.APPLICATION_JSON)
            .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2))))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(addResultHandler);

    this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId1)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId2)));

    //Shouldn't add anything
    this.mvc.perform(
            MockMvcRequestBuilders.post(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON)
                    .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList())))
            .andExpect(MockMvcResultMatchers.status().isPreconditionFailed());

    final String applicationId3 = UUID.randomUUID().toString();
    this.createConfigResource(
            new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE)
                    .withId(applicationId3).build(),
            null);
    this.mvc.perform(
            MockMvcRequestBuilders.post(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON)
                    .content(objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId3))))
            .andExpect(MockMvcResultMatchers.status().isNoContent());

    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
            PayloadDocumentation.responseFields(PayloadDocumentation.fieldWithPath("[]")
                    .description("The set of applications this command depends on")
                    .attributes(Snippets.EMPTY_CONSTRAINTS)));

    this.mvc.perform(RestDocumentationRequestBuilders.get(commandApplicationsAPI, ID))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON))
            .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(3)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId1)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId2)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[2].id", Matchers.is(applicationId3)))
            .andDo(getResultHandler);
}