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:org.owasp.webgoat.plugin.StoredXssCommentsTest.java

@Test
public void failure() throws Exception {
    ResultActions results = mockMvc.perform(MockMvcRequestBuilders.post("/CrossSiteScripting/stored-xss")
            .content("{\"text\":\"someTextHere<script>alert('Xss')</script>MoreTextHere\"}")
            .contentType(MediaType.APPLICATION_JSON));

    results.andExpect(status().isOk());/*from w  ww . j  a v a2 s . c  o  m*/
    results.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(false)));
}

From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java

public static ExtDirectPollResponse performPollRequest(MockMvc mockMvc, String bean, String method,
        String event, Map<String, String> params, HttpHeaders headers, List<Cookie> cookies,
        boolean withSession) throws Exception {
    MockHttpServletRequestBuilder request = post("/poll/" + bean + "/" + method + "/" + event)
            .accept(MediaType.ALL).contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8");

    if (cookies != null) {
        request.cookie(cookies.toArray(new Cookie[cookies.size()]));
    }/*w  w  w .  j av  a  2s  .co m*/

    if (withSession) {
        request.session(new MockHttpSession());
    }

    if (params != null) {
        for (String paramName : params.keySet()) {
            request.param(paramName, params.get(paramName));
        }
    }

    if (headers != null) {
        request.headers(headers);
    }

    MvcResult result = mockMvc.perform(request).andExpect(status().isOk())
            .andExpect(content().contentType("application/json;charset=UTF-8"))
            .andExpect(content().encoding("UTF-8")).andReturn();

    return readDirectPollResponse(result.getResponse().getContentAsByteArray());
}

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

@Test
public void thatDegreesAreDeleted() throws Exception {
    mockMvc.perform(post("/api/private/v1/portfolio/2/degree").with(securityContext(studentSecurityContext()))
            .content(WebTestUtils.toJsonBytes(newArrayList())).contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk()).andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(0)));
}

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

public void expectTeacherEventsRequest(String teacherNumber) {
    server.expect(requestTo(teacherEventsUrl(teacherNumber))).andExpect(method(HttpMethod.GET)).andRespond(
            withSuccess(SampleDataFiles.toText("oodi/teacherevents.json"), MediaType.APPLICATION_JSON));
}

From source file:org.codeqinvest.web.sonar.SonarControllerTest.java

@Test
public void shouldReturnFalseWhenGivenSonarIsNotReachable() throws Exception {
    when(sonarConnectionCheckerService.isReachable(any(SonarConnectionSettings.class))).thenReturn(false);
    mockMvc.perform(put("/sonar/reachable").contentType(MediaType.APPLICATION_JSON)
            .content("{\"url\": \"http://localhost\"}")).andExpect(status().isOk())
            .andExpect(jsonPath("$.ok").value(false));
}

From source file:controllers.EventTypeControllerTest.java

/**
 * Test of getEventTypesByTransport method, of class EventTypeController.
 *//* w  w w .j  a va 2  s  .c o m*/
@Test
public void testGetEventTypesByTransport() throws DataAccessException, RecordNotFoundException, Exception {
    EventType eventType1 = new EventType("Jam", Arrays.asList(Transportation.CAR));
    EventType eventType2 = new EventType("RoadWork", Arrays.asList(Transportation.CAR));
    when(databaseMock.getEventtypes(Transportation.CAR))
            .thenReturn(Arrays.asList(new Pair(1, eventType1), new Pair(1, eventType2)));
    mockMVC.perform(get("/eventtype/").param("transportationType", "car").characterEncoding("UTF-8"))
            .andExpect(status().isOk())

            .andExpect(content().contentType(new MediaType(MediaType.APPLICATION_JSON.getType(),
                    MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"))))
            .andExpect(jsonPath("$", hasSize(2))).andExpect(jsonPath("$[0].type", is("Jam")))
            .andExpect(jsonPath("$[1].type", is("RoadWork")));
}

From source file:sample.HandsOnSecurityApplicationTests.java

@Before
public void setup() {
    mockMvc = MockMvcBuilders.webAppContextSetup(wac)
            .defaultRequest(get("/").header("X-FORWARDED-FOR", "184.154.83.119").header("User-Agent", "JUnit")
                    .accept(MediaType.APPLICATION_JSON))
            .alwaysDo(print())//  ww w  . j a  v a2 s.  c  om
            .addFilters(springSessionRepositoryFilter, sessionDetailsFilter, requestContextFilter)
            .apply(springSecurity()).build();
}

From source file:net.kaczmarzyk.EqualE2eTest.java

@Test
public void findsByExactStringValue() throws Exception {
    mockMvc.perform(get("/customers").param("firstName", "Homer").accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk()).andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$[0].firstName").value("Homer")).andExpect(jsonPath("$[1]").doesNotExist());
}

From source file:de.tobiasbruns.fs20.sender.SenderControllerTest.java

@Test
public void sendSwitchRequest() throws Exception {
    String request = TestUtils.loadTextFile("requests/SwitchCommandRequest.json");

    mockMvc.perform(post("/").contentType(MediaType.APPLICATION_JSON).content(request))
            .andExpect(status().isNoContent());

    verify(service).executeRequest(requestCaptor.capture());
    assertThat(requestCaptor.getValue()).isInstanceOf(CommandRequest.class);

    CommandRequest comReq = (CommandRequest) requestCaptor.getValue();
    assertThat(comReq.getCommand()).isEqualTo((short) 18);
}

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

@Test
public void thatTeacherNewsAreReturned() throws Exception {
    flammaServer.expectTeacherNews();//from w ww .j  a  va2 s . c om

    mockMvc.perform(get("/api/private/v1/news/teacher").with(securityContext(teacherSecurityContext()))
            .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON).locale(new Locale("fi"))
            .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(content().contentType(WebConstants.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(2)))
            .andExpect(jsonPath("$[0].title").value("Reflekta palkittiin parhaana opiskelijakilpailussa"))
            .andExpect(jsonPath("$[0].url").value("https://flamma.helsinki.fi/portal/home/sisalto1"))
            .andExpect(jsonPath("$[0].content").value("Content"))
            .andExpect(jsonPath("$[1].title").value("Tukea yliopisto-opettajille"))
            .andExpect(jsonPath("$[1].url").value("https://flamma.helsinki.fi/portal/home/sisalto2"))
            .andExpect(jsonPath("$[1].content").value("Content"));
}