List of usage examples for org.springframework.http MediaType TEXT_PLAIN
MediaType TEXT_PLAIN
To view the source code for org.springframework.http MediaType TEXT_PLAIN.
Click Source Link
From source file:org.zalando.logbook.servlet.TeeTest.java
@Test public void shouldSupportReader() throws Exception { mvc.perform(get("/api/reader").contentType(MediaType.TEXT_PLAIN).content("Hello, world!")) .andExpect(status().isOk()).andExpect(content().string("Hello, world!")); }
From source file:rugal.sample.springmvc.controller.StudentControllerIntegrationTest.java
@Test public void delete_204() throws Exception { LOG.debug("delete_204"); studentService.getDAO().save(bean);/* w w w. ja va 2s . com*/ this.mockMvc.perform(delete("/student/" + bean.getId()).header(SystemDefaultProperties.ID, "rugal") .header(SystemDefaultProperties.CREDENTIAL, "123").contentType(MediaType.TEXT_PLAIN) .accept(MediaType.TEXT_PLAIN)).andDo(print()).andExpect(status().isNoContent()); }
From source file:it.reply.orchestrator.controller.TemplateControllerTest.java
@Test public void getTemplate() throws Exception { Deployment deployment = ControllerTestUtils.createDeployment(); String template = new NoNullOrEmptyFile(new Utf8File(Paths.get(templatePath))).read(); deployment.setTemplate(template);/* w w w .j a v a2 s . c o m*/ Mockito.when(templateService.getTemplate(deployment.getId())).thenReturn(deployment.getTemplate()); MvcResult result = mockMvc .perform(get("/deployments/" + deployment.getId() + "/template") .header(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " <access token>")) .andExpect(status().isOk()) .andExpect(content().contentType(new MediaType(MediaType.TEXT_PLAIN.getType(), MediaType.TEXT_PLAIN.getSubtype(), Charset.forName("ISO-8859-1")))) .andDo(document("get-template")).andReturn(); String content = result.getResponse().getContentAsString(); assertEquals(content, template); }
From source file:mars.RobotControllerTests.java
@Test public void test360RightTurn() throws Exception { this.mockMvc.perform(post("/rest/mars/RRRR")).andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN)) .andExpect(content().string("(0, 0, N)\n")); }
From source file:rugal.sample.springmvc.controller.StudentControllerIntegrationTest.java
@Test public void delete_404() throws Exception { LOG.debug("delete_404"); this.mockMvc.perform(delete("/student/999").header(SystemDefaultProperties.ID, "rugal") .header(SystemDefaultProperties.CREDENTIAL, "123").contentType(MediaType.TEXT_PLAIN) .accept(MediaType.TEXT_PLAIN)).andDo(print()).andExpect(status().isNotFound()); }
From source file:org.zalando.logbook.servlet.MultiFilterTest.java
@Test public void shouldBufferResponseTwice() throws Exception { mvc.perform(get("/api/read-bytes").contentType(MediaType.TEXT_PLAIN).content("Hello, world!")).andReturn(); final TeeResponse firstResponse = getResponse(lastFilter); final TeeResponse secondResponse = getResponse(controller); assertThat(firstResponse.getOutput().toByteArray().length, is(greaterThan(0))); assertThat(secondResponse.getOutput().toByteArray().length, is(greaterThan(0))); }
From source file:org.wcy123.ProtobufMessageConverter.java
@Override protected Message readInternal(Class<? extends Message> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { MediaType contentType = inputMessage.getHeaders().getContentType(); contentType = (contentType != null ? contentType : PROTOBUF); Charset charset = getCharset(inputMessage.getHeaders()); InputStreamReader reader = new InputStreamReader(inputMessage.getBody(), charset); try {/*from ww w.ja v a2s.c om*/ Message.Builder builder = getMessageBuilder(clazz); if (MediaType.APPLICATION_JSON.isCompatibleWith(contentType)) { parser.merge(reader, builder); } else if (MediaType.TEXT_PLAIN.isCompatibleWith(contentType)) { TextFormat.merge(reader, this.extensionRegistry, builder); } else if (MediaType.APPLICATION_XML.isCompatibleWith(contentType)) { throw new UnsupportedOperationException("not supported yet"); } else { builder.mergeFrom(inputMessage.getBody(), this.extensionRegistry); } return builder.build(); } catch (Exception e) { throw new HttpMessageNotReadableException("Could not read Protobuf message: " + e.getMessage(), e); } }
From source file:org.zalando.logbook.servlet.MultiFilterSecurityTest.java
@Test public void shouldBufferAuthorizedRequestOnlyOnce() throws Exception { mvc.perform(get("/api/read-byte").contentType(MediaType.TEXT_PLAIN).content("Hello, world!")).andReturn(); final TeeRequest firstRequest = getRequest(securityFilter); final TeeRequest secondRequest = getRequest(controller); assertThat(firstRequest.getOutput().toByteArray().length, is(equalTo(0))); assertThat(secondRequest.getOutput().toByteArray().length, is(greaterThan(0))); }
From source file:mars.RobotControllerTests.java
@Test public void test360LeftTurn() throws Exception { this.mockMvc.perform(post("/rest/mars/LLLL")).andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_PLAIN)) .andExpect(content().string("(0, 0, N)\n")); }
From source file:csns.web.controller.RubricEvaluationController.java
@RequestMapping(value = "/rubric/evaluation/{role}/set", params = "comments") @ResponseBody/*from w ww .jav a 2s.co m*/ public ResponseEntity<String> set(@RequestParam Long id, @RequestParam String comments) { RubricEvaluation evaluation = rubricEvaluationDao.getRubricEvaluation(id); // Ignore the request if the rubric assignment is already past due. if (evaluation.getSubmission().getAssignment().isPastDue()) return new ResponseEntity<String>(HttpStatus.BAD_REQUEST); evaluation.setComments(comments); rubricEvaluationDao.saveRubricEvaluation(evaluation); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); return new ResponseEntity<String>(comments, headers, HttpStatus.OK); }