List of usage examples for org.springframework.http MediaType APPLICATION_JSON
MediaType APPLICATION_JSON
To view the source code for org.springframework.http MediaType APPLICATION_JSON.
Click Source Link
From source file:org.zalando.github.spring.StatusesTemplate.java
@Override public Status createStatus(String owner, String repository, String sha, StatusRequest body) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("owner", owner); uriVariables.put("repository", repository); uriVariables.put("sha", sha); URI uri = new UriTemplate(buildUriString("/repos/{owner}/{repository}/statuses/{sha}")) .expand(uriVariables);//ww w . ja v a 2s . c o m RequestEntity<StatusRequest> entity = RequestEntity.post(uri).contentType(MediaType.APPLICATION_JSON) .body(body); ResponseEntity<Status> responseEntity = getRestOperations().exchange(entity, Status.class); return responseEntity.getBody(); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.UserNotificationsResourceTest.java
private ResultActions insertNotifications() throws Exception { return mockMvc .perform(post("/api/private/v1/usernotifications").with(securityContext(studentSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .content(WebTestUtils.toJsonBytes(Arrays.asList("abc", "123", "cde", "456"))) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); }
From source file:io.github.howiefh.jeews.modules.sys.controller.LoginControllerTest.java
@Test public void testLogin() throws Exception { String user = "{\"username\":\"root\",\"password\":\"u12345\"}"; MvcResult result = mockMvc//from w w w .ja v a2s .c om .perform(post("/login").contentType(MediaType.APPLICATION_JSON).content(user) .accept(MediaTypes.HAL_JSON)) .andExpect(status().isOk()) // 200 .andExpect(jsonPath("$.access_token").exists()).andExpect(jsonPath("$.user.id").exists()) .andReturn(); String content = result.getResponse().getContentAsString(); JSONObject json = new JSONObject(content); String accessToken = json.get("access_token").toString(); mockMvc.perform( get("/users/1").header("Authorization", "Bearer " + accessToken).accept(MediaTypes.HAL_JSON)) .andExpect(status().isOk()) // 200 .andExpect(content().contentType(MediaTypes.HAL_JSON)) // ??contentType .andReturn(); mockMvc.perform(get("/users/1")).andExpect(status().isUnauthorized()) // 401 .andReturn(); String requestBody = "{\"username\":\"fh" + UUID.randomUUID() + "\",\"password\":\"123456\",\"email\":\"" + UUID.randomUUID() + "@qq.om\",\"mobile\":" + "\"" + new Random().nextInt() + "\",\"roles\":[1,2],\"organizations\":[1],\"locked\":true}"; mockMvc.perform(post("/users").header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaTypes.HAL_JSON)) // .andExpect(status().isCreated()) // 201 .andExpect(jsonPath("$.id").exists()) // Json path?JSON .andExpect(content().contentType(MediaTypes.HAL_JSON)).andReturn(); }
From source file:org.zalando.github.spring.OrganizationTemplateTest.java
@Test public void listAllOrganizations() throws Exception { mockServer.expect(requestTo("https://api.github.com/organizations?per_page=100")) .andExpect(method(HttpMethod.GET)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(new ClassPathResource("listOrgas.json", getClass()), MediaType.APPLICATION_JSON)); List<Organization> emailList = usersTemplate.listAllOranizations(); Assertions.assertThat(emailList).isNotNull(); Assertions.assertThat(emailList.size()).isEqualTo(1); }
From source file:com.marklogic.mgmt.admin.AdminManager.java
public void init(String licenseKey, String licensee) { final URI uri = adminConfig.buildUri("/admin/v1/init"); String json = null;//from w ww . j a v a 2 s . c o m if (licenseKey != null && licensee != null) { json = format("{\"license-key\":\"%s\", \"licensee\":\"%s\"}", licenseKey, licensee); } else { json = "{}"; } final String payload = json; logger.info("Initializing MarkLogic at: " + uri); invokeActionRequiringRestart(new ActionRequiringRestart() { @Override public boolean execute() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(payload, headers); try { ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class); logger.info("Initialization response: " + response); // According to http://docs.marklogic.com/REST/POST/admin/v1/init, a 202 is sent back in the event a // restart is needed. A 400 or 401 will be thrown as an error by RestTemplate. return HttpStatus.ACCEPTED.equals(response.getStatusCode()); } catch (HttpClientErrorException hcee) { String body = hcee.getResponseBodyAsString(); if (logger.isTraceEnabled()) { logger.trace("Response body: " + body); } if (body != null && body.contains("MANAGE-ALREADYINIT")) { logger.info("MarkLogic has already been initialized"); return false; } else { logger.error("Caught error, response body: " + body); throw hcee; } } } }); }
From source file:com.epam.ta.reportportal.ws.controller.impl.LogControllerTest.java
@SuppressWarnings("deprecation") @Test//from w w w . j a v a2 s .c o m public void createLogPositive() throws Exception { SaveLogRQ rq = new SaveLogRQ(); rq.setTestItemId("44524cc1553de753b3e5bb2f"); rq.setLogTime(new Date(2014, 5, 7)); this.mvcMock .perform(post(PROJECT_BASE_URL + "/log").principal(authentication()) .contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))) .andExpect(status().isCreated()); }
From source file:com.salatigacode.dao.ProductControllerTests.java
@Test public void testDelete() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<Object> entity = new HttpEntity<>(headers); ResponseEntity<String> responseEntity = restTemplate.exchange(BASE_URL + "abc123", HttpMethod.DELETE, entity, String.class); Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode().OK); }
From source file:com.hillert.botanic.controller.AuthenticationControllerTests.java
@Test public void testAuthenticateUnSuccessfully() throws Exception { mockMvc.perform(//from w ww. ja v a 2 s . c o m post("/authenticate").content("{ \"username\": \"wrong\", \"password\": \"password\" }".getBytes()) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isForbidden()) .andExpect(jsonPath("$.status", Matchers.is(HttpStatus.FORBIDDEN.value()))); }
From source file:org.kepennar.android.client.rest.HttpPostJsonXmlActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.http_post_json_xml_activity_layout); // Initiate the JSON POST request when the JSON button is clicked final Button buttonJson = (Button) findViewById(R.id.button_post_json); buttonJson.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new PostMessageTask().execute(MediaType.APPLICATION_JSON); }/*from ww w . j a va2 s . co m*/ }); // Initiate the XML POST request when the XML button is clicked final Button buttonXml = (Button) findViewById(R.id.button_post_xml); buttonXml.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new PostMessageTask().execute(MediaType.APPLICATION_XML); } }); }
From source file:com.t163.http.client.T163HttpClient.java
/** * postJson//from w w w. j ava 2 s. co m * @param url * @param request * @param responseType * @return */ public <T> T postJson(String url, Object request, Class<T> responseType) { return post(url, request, responseType, MediaType.APPLICATION_JSON); }