Example usage for org.springframework.restdocs.payload JsonFieldType STRING

List of usage examples for org.springframework.restdocs.payload JsonFieldType STRING

Introduction

In this page you can find the example usage for org.springframework.restdocs.payload JsonFieldType STRING.

Prototype

JsonFieldType STRING

To view the source code for org.springframework.restdocs.payload JsonFieldType STRING.

Click Source Link

Document

A string.

Usage

From source file:org.springframework.restdocs.payload.JsonFieldTypeResolverTests.java

@Test
public void stringField() throws IOException {
    assertFieldType(JsonFieldType.STRING, "\"Foo\"");
}

From source file:com.example.restassured.Payload.java

public void explicitType() throws Exception {
    RestAssured.given(this.spec).accept("application/json")
            // tag::explicit-type[]
            .filter(document("user", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1>
                    .description("The user's email address"))))
            // end::explicit-type[]
            .when().get("/user/5").then().assertThat().statusCode(is(200));
}

From source file:com.example.mockmvc.Payload.java

public void explicitType() throws Exception {
    this.mockMvc.perform(get("/user/5").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            // tag::explicit-type[]
            .andDo(document("index", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1>
                    .description("The user's email address"))));
    // end::explicit-type[]
}

From source file:com.example.notes.ApiDocumentation.java

@Test
public void noteUpdateExample() throws Exception {
    Map<String, Object> note = new HashMap<String, Object>();
    note.put("title", "REST maturity model");
    note.put("body", "http://martinfowler.com/articles/richardsonMaturityModel.html");

    String noteLocation = this.mockMvc
            .perform(post("/notes").contentType(MediaTypes.HAL_JSON)
                    .content(this.objectMapper.writeValueAsString(note)))
            .andExpect(status().isCreated()).andReturn().getResponse().getHeader("Location");

    this.mockMvc.perform(get(noteLocation)).andExpect(status().isOk())
            .andExpect(jsonPath("title", is(note.get("title"))))
            .andExpect(jsonPath("body", is(note.get("body"))))
            .andExpect(jsonPath("_links.self.href", is(noteLocation)))
            .andExpect(jsonPath("_links.note-tags", is(notNullValue())));

    Map<String, String> tag = new HashMap<String, String>();
    tag.put("name", "REST");

    String tagLocation = this.mockMvc
            .perform(post("/tags").contentType(MediaTypes.HAL_JSON)
                    .content(this.objectMapper.writeValueAsString(tag)))
            .andExpect(status().isCreated()).andReturn().getResponse().getHeader("Location");

    Map<String, Object> noteUpdate = new HashMap<String, Object>();
    noteUpdate.put("tags", Arrays.asList(tagLocation));

    ConstrainedFields fields = new ConstrainedFields(NotePatchInput.class);

    this.mockMvc//  ww  w.  j  ava  2s. c o  m
            .perform(patch(noteLocation).contentType(MediaTypes.HAL_JSON)
                    .content(this.objectMapper.writeValueAsString(noteUpdate)))
            .andExpect(status().isNoContent())
            .andDo(this.documentationHandler.document(requestFields(
                    fields.withPath("title").description("The title of the note").type(JsonFieldType.STRING)
                            .optional(),
                    fields.withPath("body").description("The body of the note").type(JsonFieldType.STRING)
                            .optional(),
                    fields.withPath("tags").description("An array of tag resource URIs"))));
}