Example usage for org.springframework.http MediaType APPLICATION_JSON

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

Introduction

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

Prototype

MediaType APPLICATION_JSON

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

Click Source Link

Document

Public constant media type for application/json .

Usage

From source file:com.mycompany.geocoordinate.config.AppConfiguration.java

@Bean
public ContentNegotiatingViewResolver contentViewResolver() {
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);

    MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
    defaultView.setExtractValueFromSingleKeyModel(true);

    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver()));
    contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
    return contentViewResolver;
}

From source file:fi.helsinki.opintoni.server.CoursePageServer.java

public void expectCourseImplementationRequest(String courseImplementationId, String responseFile) {
    server.expect(requestTo(courseImplementationUrl(courseImplementationId))).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(SampleDataFiles.toText("coursepage/" + responseFile),
                    MediaType.APPLICATION_JSON));
}

From source file:com.example.talk.TalkEndpoint.java

Mono<ServerResponse> all(final ServerRequest request) {
    return request.principal().cast(UsernamePasswordAuthenticationToken.class)
            .map(UsernamePasswordAuthenticationToken::getPrincipal).cast(UserAdapter.class)
            .map(UserAdapter::getUserId).map(talkRoomRepository::findTalkRoomByUserId)
            .flatMap(Flux::collectList)//from www . j  a  va2s  .c o  m
            .flatMap(list -> ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(Mono.just(list),
                    new ParameterizedTypeReference<List<TalkRoom>>() {
                    }))
            .switchIfEmpty(ServerResponse.notFound().build());
}

From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivateComponentVisibilityResourceTest.java

@Test
public void thatComponentVisibilityIsCreated() throws Exception {
    componentVisibilityRepository.deleteAll();

    UpdateComponentVisibilityRequest request = createRequest(PortfolioComponent.ATTAINMENTS,
            Visibility.PRIVATE);/*from w  ww  .  j  a v a2 s. co m*/

    mockMvc.perform(post("/api/private/v1/portfolio/2/componentvisibility")
            .with(securityContext(studentSecurityContext())).content(WebTestUtils.toJsonBytes(request))
            .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());

    ComponentVisibility permission = getByIdAndComponent(2L, PortfolioComponent.ATTAINMENTS).get();

    assertThat(permission.visibility).isEqualTo(Visibility.PRIVATE);
    assertThat(permission.component).isEqualTo(PortfolioComponent.ATTAINMENTS);
}

From source file:fi.helsinki.opintoni.web.rest.privateapi.UserSettingsResourcePermissionsTest.java

@Test
public void thatUserCanOnlyUpdateHerUserAvatar() throws Exception {
    UploadImageBase64Request uploadImageBase64Request = new UploadImageBase64Request();

    mockMvc.perform(put("/api/private/v1/usersettings/1/uploaduseravatar")
            .with(securityContext(studentSecurityContext())).characterEncoding("UTF-8")
            .contentType(MediaType.APPLICATION_JSON).content(WebTestUtils.toJsonBytes(uploadImageBase64Request))
            .accept(MediaType.APPLICATION_JSON)).andExpect(status().isForbidden());
}

From source file:fi.helsinki.opintoni.exception.GlobalExceptionHandlersTest.java

@Test
public void thatValidationErrorIsReturned() throws Exception {
    mockMvc.perform(get("/validationerror").with(securityContext(studentSecurityContext()))
            .accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnprocessableEntity());
}

From source file:monkeys.StepDefs.java

@When("^I do a get$")
public void I_do_a_get() throws Throwable {
    mvcResult = this.mockMvc.perform(get("/monkeys/{id}", this.id).contentType(MediaType.APPLICATION_JSON));
}

From source file:net.orpiske.tcs.service.rest.controller.DomainCreateIntegrationTest.java

/**
 * Tests the ability to add a new CSP to the system
 * @throws Exception/*from www . j  av a2s. com*/
 */
@Test
public void testCspTagCloudCreateNewCSP() throws Exception {
    when(tagCloudService.createDomain(any(RequestCreateDomainEvent.class))).thenReturn(cspCreateEvent());

    this.mockMvc
            .perform(post("/domain/{domain}", "terra.com.br")
                    .content("{ \"name\": \"Terra\", \"domain\": \"terra.com.br\" } ")
                    .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
            .andDo(print()).andExpect(status().isOk());
}

From source file:todos.MainControllerTest.java

@Test
public void testList() throws Exception {
    final Todo a = new Todo(1L, "a", false);
    final Todo b = new Todo(2L, "b", false);
    final Todo c = new Todo(3L, "c", false);
    when(repository.findAll()).thenReturn(Arrays.asList(a, b, c));

    mvc.perform(get("/todos").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(jsonPath("$", hasSize(3))).andExpect(jsonPath("$[0].id", is(1)))
            .andExpect(jsonPath("$[0].description", is("a"))).andExpect(jsonPath("$[0].complete", is(false)))
            .andExpect(jsonPath("$[1].id", is(2))).andExpect(jsonPath("$[1].description", is("b")))
            .andExpect(jsonPath("$[1].complete", is(false))).andExpect(jsonPath("$[2].id", is(3)))
            .andExpect(jsonPath("$[2].description", is("c"))).andExpect(jsonPath("$[2].complete", is(false)));

    verify(repository, times(1)).findAll();
    verifyNoMoreInteractions(repository);
}

From source file:org.cloudfoundry.identity.uaa.security.web.UaaRequestMatcherTests.java

@Test
public void pathMatcherMatchesExpectedPathsAndAcceptHeaderNull() throws Exception {
    // Accept only JSON
    UaaRequestMatcher matcher = new UaaRequestMatcher("/somePath");
    matcher.setAccept(Arrays.asList(MediaType.APPLICATION_JSON.toString()));
    assertTrue(matcher.matches(request("/somePath", null)));
}