Example usage for org.springframework.restdocs.mockmvc MockMvcRestDocumentation document

List of usage examples for org.springframework.restdocs.mockmvc MockMvcRestDocumentation document

Introduction

In this page you can find the example usage for org.springframework.restdocs.mockmvc MockMvcRestDocumentation document.

Prototype

public static RestDocumentationResultHandler document(String identifier,
        OperationRequestPreprocessor requestPreprocessor, OperationResponsePreprocessor responsePreprocessor,
        Snippet... snippets) 

Source Link

Document

Documents the API call with the given identifier using the given snippets in addition to any default snippets.

Usage

From source file:io.pivotal.strepsirrhini.chaosloris.docs.DocumentationUtilities.java

static RestDocumentationResultHandler document(Snippet... snippets) {
    return MockMvcRestDocumentation.document("{method-name}", preprocessRequest(prettyPrint()),
            preprocessResponse(prettyPrint()), snippets);
}

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

/**
 * Test to make sure that you can delete a cluster.
 *
 * @throws Exception on configuration error
 *//*from  w  w  w .j av  a2s  .  co m*/
@Test
public void canDeleteACluster() 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);
    this.createConfigResource(
            new Cluster.Builder(name2, user2, version2, ClusterStatus.OUT_OF_SERVICE).withId(id2).build(),
            null);
    this.createConfigResource(
            new Cluster.Builder(name3, user3, version3, ClusterStatus.TERMINATED).withId(id3).build(), null);
    Assert.assertThat(this.jpaClusterRepository.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(CLUSTERS_API + "/{id}", id2))
            .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler);

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

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

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 . ja v a2 s  . 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
 *///ww  w. j  a  va  2  s. co  m
@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

/**
 * Test to make sure that you can delete an application.
 *
 * @throws Exception on configuration error
 *///from   ww w.  ja va  2s .co 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));
}

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

/**
 * Test to make sure we can delete the dependencies for a cluster after it is created.
 *
 * @throws Exception on configuration problems
 *///from   ww w  .  j  a  v a2  s .  c  o  m
@Test
public void canDeleteDependenciesForCluster() 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}/dependencies", ID, deleteResultHandler);
}

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

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

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

/**
 * Test to make sure we can delete the configurations for an application after it is created.
 *
 * @throws Exception on configuration problems
 *///  ww  w  .  ja  v a 2s  .c  o m
@Test
public void canDeleteConfigsForApplication() 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 parameters
    );
    this.canDeleteElementsFromResource(APPLICATIONS_API + "/{id}/configs", ID, deleteResultHandler);
}

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

/**
 * Test to make sure we can delete the tags for a cluster after it is created.
 *
 * @throws Exception on configuration problems
 *//*  ww w  . j ava 2s  . c om*/
@Test
public void canDeleteTagsForCluster() 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);
    final String api = CLUSTERS_API + "/{id}/tags";
    this.canDeleteTagsForResource(api, ID, NAME, deleteResultHandler);
}

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

/**
 * Test to make sure we can delete the dependencies for an command after it is created.
 *
 * @throws Exception on configuration problems
 *///w ww  . j  a  v a2s.co  m
@Test
public void canDeleteDependenciesForCommand() 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 deleteResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
            Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // Path variables
    );
    this.canDeleteElementsFromResource(COMMANDS_API + "/{id}/dependencies", ID, deleteResultHandler);
}