Example usage for org.springframework.http MediaType APPLICATION_JSON_UTF8

List of usage examples for org.springframework.http MediaType APPLICATION_JSON_UTF8

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_JSON_UTF8.

Prototype

MediaType APPLICATION_JSON_UTF8

To view the source code for org.springframework.http MediaType APPLICATION_JSON_UTF8.

Click Source Link

Document

Public constant media type for application/json;charset=UTF-8 .

Usage

From source file:com.ge.predix.controller.test.ZoneControllerIT.java

public void testCreateAndGetAndDeleteZone() throws Exception {
    this.zone = this.jsonUtils.deserializeFromFile("controller-test/createZone.json", Zone.class);
    Assert.assertNotNull(this.zone, "createZone.json file not found or invalid");
    String zoneContent = this.objectWriter.writeValueAsString(this.zone);
    this.mockMvc// w w w  .  j a  va2 s .  co m
            .perform(put(V1_ZONE_URL, "zone-1").contentType(MediaType.APPLICATION_JSON).content(zoneContent))
            .andExpect(status().isCreated());

    this.mockMvc.perform(get(V1_ZONE_URL, "zone-1"))
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk())
            .andExpect(jsonPath("name", is("zone-1"))).andExpect(jsonPath("subdomain", is("subdomain-1")));

    this.mockMvc.perform(delete(V1_ZONE_URL, "zone-1")).andExpect(status().isNoContent());
}

From source file:com.hp.autonomy.frontend.find.core.savedsearches.query.AbstractSavedQueryIT.java

@Test
public void create() throws Exception {
    createSavedQuery(getBaseSavedQuery()).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$.id", not(nullValue()))).andExpect(jsonPath("$.title", equalTo(TITLE)))
            .andExpect(jsonPath("$.queryText", equalTo(QUERY_TEXT)))
            .andExpect(jsonPath("$.minScore", equalTo(MIN_SCORE)))
            .andExpect(jsonPath("$.conceptClusterPhrases", hasSize(2)))
            .andExpect(jsonPath("$.conceptClusterPhrases[*].phrase",
                    containsInAnyOrder(PRIMARY_PHRASE, OTHER_PHRASE)))
            .andExpect(jsonPath("$.conceptClusterPhrases[?(@.phrase=='" + PRIMARY_PHRASE + "')].primary",
                    contains(true)))//from  w w  w .j  a va2  s . c o  m
            .andExpect(jsonPath("$.conceptClusterPhrases[?(@.phrase== '" + PRIMARY_PHRASE + "')].clusterId",
                    contains(0)))
            .andExpect(jsonPath("$.conceptClusterPhrases[?(@.phrase== '" + OTHER_PHRASE + "')].primary",
                    contains(false)))
            .andExpect(jsonPath("$.conceptClusterPhrases[?(@.phrase=='" + OTHER_PHRASE + "')].clusterId",
                    contains(0)));
}

From source file:com.toptal.controller.SignupControllerTest.java

/**
 * One cannot register users with existing username.
 * @throws Exception If smth goes wrong.
 *///from   w w  w.ja v  a 2s  .co m
@Test
public final void cannotRegisterExistingUser() throws Exception {
    final String username = "existingUser";
    this.registerUser(username, "passw00rd1902", Role.ROLE_USER);
    final String user = this
            .json(User.builder().name(username).password("passw0rd1902").role(Role.ROLE_USER).build());
    final MvcResult result = this.getMvc()
            .perform(MockMvcRequestBuilders.post(SignupController.PATH)
                    .contentType(MediaType.APPLICATION_JSON_UTF8).content(user))
            .andDo(MockMvcResultHandlers.print()).andExpect(MockMvcResultMatchers.status().isBadRequest())
            .andReturn();
    Assert.assertEquals("User name 'existingUser' already exists", result.getResolvedException().getMessage());
}

From source file:com.toptal.controller.EntryControllerTest.java

/**
 * Any user can access list of his or her entries.
 * @throws Exception If smth goes wrong.
 *///from ww  w  .  ja v a2  s.  com
@Test
public final void userDoesAccessList() throws Exception {
    final String name = "nameA";
    final String password = "passwordA";
    this.users.save(User.builder().name(name).password(password).role(Role.ROLE_USER).build());
    this.getMvc()
            .perform(MockMvcRequestBuilders.get(EntryController.PATH)
                    .contentType(MediaType.APPLICATION_JSON_UTF8)
                    .headers(this.addAuth(new HttpHeaders(), name, password)))
            .andDo(MockMvcResultHandlers.print()).andExpect(MockMvcResultMatchers.status().isOk());
}

From source file:com.snv.calendar.CalendarControllerTest.java

@Test
public void should_return_todo_with_information_on_create() throws Exception {
    when(this.calendarService.create(Matchers.any(Calendar.class))).thenReturn(this.calendar);

    MvcResult result = mockMvc/*from   w w  w  . ja  v a  2 s. c o  m*/
            .perform(MockMvcRequestBuilders.post(CONTROLLER_URL)
                    .content(this.mapper.writeValueAsString(calendar))
                    .contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andReturn();

    verify(this.calendarService, times(1)).create(Matchers.any(Calendar.class));

    assertFalse(result.getResponse().getContentAsString().isEmpty());
    Calendar actual = objectMapper.readValue(result.getResponse().getContentAsString(), Calendar.class);
    assertNotNull("calendar created can not be null !", actual);
    assertEquals("calendar not same !", actual, this.calendar);
    assertEquals("calendar's text is not same", actual.getTitle(), this.calendar.getTitle());
    assertEquals("calendar's color is not same", actual.getColor(), this.calendar.getColor());
    assertEquals("calendar's Start Date is not same", actual.getStart(), this.calendar.getStart());
}

From source file:com.hp.autonomy.frontend.find.core.search.AbstractDocumentServiceIT.java

@Test
public void queryForPromotions() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = get(
            DocumentsController.SEARCH_PATH + '/' + DocumentsController.PROMOTIONS_PATH)
                    .param(DocumentsController.TEXT_PARAM, "*")
                    .param(DocumentsController.RESULTS_START_PARAM, "1")
                    .param(DocumentsController.MAX_RESULTS_PARAM, "50")
                    .param(DocumentsController.SUMMARY_PARAM, "context")
                    .param(DocumentsController.INDEXES_PARAM, mvcIntegrationTestUtils.getDatabases())
                    .with(authentication(userAuth()));

    mockMvc.perform(requestBuilder).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$.documents", empty()));
}

From source file:com.hp.autonomy.frontend.find.idol.comparison.ComparisonServiceIT.java

@Test
public void compareQueryStateTokens() throws Exception {
    final ComparisonRequest<String> comparisonRequest = new ComparisonRequest.Builder<String>()
            .setFirstQueryStateToken(twoDocStateToken).setSecondQueryStateToken(sixDocStateToken).build();

    final MockHttpServletRequestBuilder requestBuilder = post(
            ComparisonController.BASE_PATH + '/' + ComparisonController.COMPARE_PATH + '/')
                    .content(mapper.writeValueAsString(comparisonRequest))
                    .contentType(MediaType.APPLICATION_JSON).with(authentication(biAuth()));

    mockMvc.perform(requestBuilder).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$.documentsOnlyInFirstStateToken", isEmptyOrNullString()))
            .andExpect(jsonPath("$.documentsOnlyInSecondStateToken", not(isEmptyOrNullString())));
}

From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restSchemaDoesNotExistsTest() throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
    headers.add("graphql-schema", "no-such-schema");

    GraphQLServerRequest qlQuery = new GraphQLServerRequest("{viewer{ id }}");

    HttpEntity<GraphQLServerRequest> httpEntity = new HttpEntity<>(qlQuery, headers);
    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + "/graphql", HttpMethod.POST, httpEntity, GraphQLServerResult.class);

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertFalse(CollectionUtils.isEmpty(result.getErrors()));
    LOGGER.info(objectMapper.writeValueAsString(result));
}

From source file:com.hp.autonomy.frontend.find.core.parametricfields.AbstractParametricValuesServiceIT.java

@Test
public void getDateParametricValuesForField() throws Exception {
    final String url = ParametricValuesController.PARAMETRIC_VALUES_PATH
            + ParametricValuesController.BUCKET_PARAMETRIC_PATH + '/' + ParametricValuesService.AUTN_DATE_FIELD;

    final MockHttpServletRequestBuilder requestBuilder = get(url)
            .param(ParametricValuesController.DATABASES_PARAM, mvcIntegrationTestUtils.getDatabases())
            .param(ParametricValuesController.QUERY_TEXT_PARAM, "*")
            .param(ParametricValuesController.FIELD_TEXT_PARAM, "")
            .param(ParametricValuesController.TARGET_NUMBER_OF_BUCKETS_PARAM, "35")
            .param(ParametricValuesController.BUCKET_MIN_PARAM, "0")
            .param(ParametricValuesController.BUCKET_MAX_PARAM, String.valueOf(Integer.MAX_VALUE))
            .with(authentication(userAuth()));

    mockMvc.perform(requestBuilder).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$", not(empty())));
}

From source file:com.snv.bank.account.AccountControllerTest.java

@Test
public void should_return_BadRequest_when_call_with_empty_account_values() throws Exception {
    Account emptyAccount = new Account();

    emptyAccount.setBankAddress("");
    emptyAccount.setBankName("");
    emptyAccount.setBankWebSite("");

    mockMvc.perform(/*  w  ww.j  a v a 2 s.c o m*/
            MockMvcRequestBuilders.post(CONTROLLER_URL).content(this.mapper.writeValueAsString(emptyAccount))
                    .contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(MockMvcResultMatchers.status().is4xxClientError());
}