List of usage examples for org.springframework.http MediaType parseMediaType
public static MediaType parseMediaType(String mediaType)
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void resetPasswordNotExistingUser() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); String userId = "222"; this.mockHttpSession = loginAsAdmin(); // Check 404 is returned this.mockMvc/* www . j a v a 2s . c o m*/ .perform(post("/api/users/" + userId + "/actions/forget-password") .contentType(MediaType.APPLICATION_JSON).param("password", "newpassword") .param("password2", "newpassword").session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(jsonPath("$.description", is("User not found"))).andExpect(status().is(404)); }
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void resetPasswordSameUser() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); final User user = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(user);/* ww w .j a v a 2 s . c om*/ Assert.assertTrue(user.getProfile().equals(Profile.Editor)); this.mockHttpSession = loginAs(user); this.mockMvc.perform(post("/api/users/" + user.getId() + "/actions/forget-password") .contentType(MediaType.APPLICATION_JSON).param("password", "newpassword") .param("password2", "newpassword").session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))).andExpect(status().is(204)); }
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void updateUser() throws Exception { User userToUpdate = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(userToUpdate);// w w w. j a va 2 s . c om UserDto user = new UserDto(); user.setUsername(userToUpdate.getUsername()); user.setName(userToUpdate.getName() + "-updated"); user.setProfile(userToUpdate.getProfile().toString()); user.setGroupsEditor(Collections.singletonList("2")); user.setEmail(new ArrayList(userToUpdate.getEmailAddresses())); user.setEnabled(true); Gson gson = new Gson(); String json = gson.toJson(user); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform( put("/api/users/" + userToUpdate.getId()).content(json).contentType(MediaType.APPLICATION_JSON) .session(this.mockHttpSession).accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(204)); }
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void updateUserDuplicatedUsername() throws Exception { User userToUpdate = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(userToUpdate);//from w w w . j a v a 2 s .com User userToReuseUsername = _userRepo.findOneByUsername("testuser-reviewer"); Assert.assertNotNull(userToReuseUsername); UserDto user = new UserDto(); // Try to set the username of other existing user user.setUsername(userToReuseUsername.getUsername()); user.setName(userToUpdate.getName()); user.setProfile(userToUpdate.getProfile().toString()); user.setGroupsEditor(Collections.singletonList("2")); user.setEmail(new ArrayList(userToUpdate.getEmailAddresses())); user.setEnabled(true); Gson gson = new Gson(); String json = gson.toJson(user); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); // Check 400 is returned and a message indicating that username is duplicated this.mockMvc .perform(put("/api/users/" + userToUpdate.getId()).content(json) .contentType(MediaType.APPLICATION_JSON).session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(jsonPath("$.description", is("Another user with username " + "'testuser-editor' ignore case already exists"))) .andExpect(status().is(400)); }
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void updateUserDuplicatedUsernameIgnoreCase() throws Exception { User userToUpdate = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(userToUpdate);//from www . j av a 2 s . c om User userToReuseUsername = _userRepo.findOneByUsername("testuser-reviewer"); Assert.assertNotNull(userToReuseUsername); UserDto user = new UserDto(); // Try to set the username of other existing user with other letter case user.setUsername(StringUtils.swapCase(userToReuseUsername.getUsername())); user.setName(userToUpdate.getName()); user.setProfile(userToUpdate.getProfile().toString()); user.setGroupsEditor(Collections.singletonList("2")); user.setEmail(new ArrayList(userToUpdate.getEmailAddresses())); user.setEnabled(true); Gson gson = new Gson(); String json = gson.toJson(user); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); // Check 400 is returned and a message indicating that username is duplicated this.mockMvc .perform(put("/api/users/" + userToUpdate.getId()).content(json) .contentType(MediaType.APPLICATION_JSON).session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(jsonPath("$.description", is("Another user with username 'testuser-editor' ignore case already exists"))) .andExpect(status().is(400)); }
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void updateUserDuplicatedUsernameChangeNameCase() throws Exception { User userToUpdate = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(userToUpdate);/* w w w . j av a 2s . c o m*/ User userToReuseUsername = _userRepo.findOneByUsername("testuser-EDITOR"); Assert.assertNotNull(userToReuseUsername); UserDto user = new UserDto(); // Try to set the username of other existing user with other letter case user.setUsername("TESTUSER-editor"); user.setName(userToUpdate.getName()); user.setProfile(userToUpdate.getProfile().toString()); user.setGroupsEditor(Collections.singletonList("2")); user.setEmail(new ArrayList(userToUpdate.getEmailAddresses())); user.setEnabled(true); Gson gson = new Gson(); String json = gson.toJson(user); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); // Check 400 is returned and a message indicating that username is duplicated this.mockMvc.perform( put("/api/users/" + userToUpdate.getId()).content(json).contentType(MediaType.APPLICATION_JSON) .session(this.mockHttpSession).accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(204)); }
From source file:org.fao.geonet.api.users.UsersApiTest.java
@Test public void updateUserAlreadyExistingUsernameCase() throws Exception { User userToUpdate = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(userToUpdate);// ww w . ja v a 2 s . c o m User userToReuseUsername = _userRepo.findOneByUsername("testuser-EDITOR"); Assert.assertNotNull(userToReuseUsername); UserDto user = new UserDto(); // Try to set the username of other existing user with other letter case user.setUsername(userToReuseUsername.getUsername()); user.setName(userToUpdate.getName()); user.setProfile(userToUpdate.getProfile().toString()); user.setGroupsEditor(Collections.singletonList("2")); user.setEmail(new ArrayList(userToUpdate.getEmailAddresses())); user.setEnabled(true); Gson gson = new Gson(); String json = gson.toJson(user); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); // Check 400 is returned and a message indicating that username is duplicated this.mockMvc .perform(put("/api/users/" + userToUpdate.getId()).content(json) .contentType(MediaType.APPLICATION_JSON).session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(400)).andExpect(jsonPath("$.description", is("Another user with username 'testuser-editor' ignore case already exists"))); }
From source file:org.hoteia.qalingo.web.mvc.controller.customer.CustomerDocumentController.java
@RequestMapping(value = "/documents/**", method = RequestMethod.GET) public ResponseEntity<byte[]> customerDetails(final HttpServletRequest request, final Model model) throws Exception { final RequestData requestData = requestUtil.getRequestData(request); final String requestURL = request.getRequestURL().toString(); final Customer customer = requestData.getCustomer(); if (customer != null) { final List<OrderPurchase> orders = orderPurchaseService .findOrdersByCustomerId(customer.getId().toString()); for (Iterator<OrderPurchase> iterator = orders.iterator(); iterator.hasNext();) { OrderPurchase order = (OrderPurchase) iterator.next(); if (requestURL.contains(order.getPrefixHashFolder())) { String filename = null; String filePath = null; if (requestURL.contains(OrderDocumentType.ORDER_CONFIRMATION.getPropertyKey())) { filename = documentService.buildOrderConfirmationFileName(order); filePath = documentService.getOrderConfirmationFilePath(order); } else if (requestURL.contains(OrderDocumentType.SHIPPING_CONFIRMATION.getPropertyKey())) { filename = documentService.buildShippingConfirmationFileName(order); filePath = documentService.getShippingConfirmationFilePath(order); } else if (requestURL.contains(OrderDocumentType.INVOICE.getPropertyKey())) { filename = documentService.buildInvoiceFileName(order); filePath = documentService.getInvoiceFilePath(order); }//from w w w . j a v a 2 s. c o m if (StringUtils.isNotEmpty(filename) && StringUtils.isNotEmpty(filePath)) { Path path = Paths.get(filePath); byte[] contents = Files.readAllBytes(path); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("application/pdf")); headers.setContentDispositionFormData(filename, filename); headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(contents, headers, HttpStatus.OK); return response; } } } logger.warn("This request can't be display, customer " + customer.getEmail() + " is logged, but the Hash doesn't matched:" + requestURL); } else { logger.warn("This request can't be display, customer is not logged:" + requestURL); } return null; }
From source file:org.kuali.student.cm.course.service.impl.AbstractExportCourseHelperImpl.java
/** * Generates a response for the report./*w ww .j a va2 s . c om*/ * @return */ public ResponseEntity<byte[]> getResponseEntity() { byte[] bytes = getBytes(); HttpHeaders headers = new HttpHeaders(); /* * Setup the header for the response. */ if (isSaveDocument()) { // Try to persuade the agent to save the document (in accordance with http://tools.ietf.org/html/rfc2616#section-19.5.1) headers.setContentType(MediaType.parseMediaType("application/octet-stream")); String contentDisposition = String.format("attachment; filename=%s", getFileName()); headers.set("Content-Disposition", contentDisposition); } else { headers.setContentType(MediaType.parseMediaType(getExportFileType().getMimeType())); headers.setContentDispositionFormData(getFileName(), getFileName()); } headers.setCacheControl(CurriculumManagementConstants.Export.DOCUMENT_DOWNLOAD_CACHE_CONTROL); return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK); }
From source file:org.openrepose.filters.ratelimiting.RateLimitingHandler.java
private static Optional<MediaType> parseMediaType(String type) { Optional<MediaType> parsedType = Optional.empty(); try {//from w w w . j av a 2s .co m parsedType = Optional.of(MediaType.parseMediaType(type)); } catch (IllegalArgumentException iae) { LOG.warn("Media type could not be parsed: {}", type, iae); } return parsedType; }