List of usage examples for org.springframework.http HttpMethod PUT
HttpMethod PUT
To view the source code for org.springframework.http HttpMethod PUT.
Click Source Link
From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImplTest.java
@Test public void testUpdatePageWithPaginationModeCategory() { final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); swaggerConfluenceConfig.setPaginationMode(PaginationMode.CATEGORY_PAGES); final String xhtml = IOUtils.readFull( AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream("/swagger-petstore-xhtml-example.html")); final ResponseEntity<String> postResponseEntity = new ResponseEntity<>(POST_RESPONSE, HttpStatus.OK); for (int i = 0; i < 5; i++) { when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity); when(responseEntity.getBody()).thenReturn(GET_RESPONSE_FOUND); when(restTemplate.exchange(any(URI.class), eq(HttpMethod.PUT), any(RequestEntity.class), eq(String.class))).thenReturn(postResponseEntity); }/*from w ww . j a v a 2s .c om*/ final ArgumentCaptor<HttpEntity> httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); verify(restTemplate, times(5)).exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class)); verify(restTemplate, times(5)).exchange(any(URI.class), eq(HttpMethod.PUT), httpEntityCaptor.capture(), eq(String.class)); final HttpEntity<String> capturedHttpEntity = httpEntityCaptor.getAllValues().get(3); final String expectedPostBody = IOUtils.readFull(AsciiDocToXHtmlServiceImplTest.class .getResourceAsStream("/swagger-confluence-update-json-body-definitions-example.json")); assertNotNull("Failed to Capture RequeestEntity for POST", capturedHttpEntity); // We'll do a full check on the last page versus a resource; not doing all of them as it // would be a pain to maintain, but this should give us a nod of confidence. assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); }
From source file:access.deploy.geoserver.PiazzaEnvironment.java
/** * Creates the Piazza workspace/*from ww w . j a v a 2 s. c om*/ */ private void createWorkspace() { // POST the Workspace authHeaders.setContentType(MediaType.APPLICATION_XML); String body = "<workspace><name>piazza</name></workspace>"; HttpEntity<String> request = new HttpEntity<>(body, authHeaders.get()); String uri = String.format("%s/rest/workspaces", accessUtilities.getGeoServerBaseUrl()); try { pzLogger.log(String.format("Creating Piazza Workspace to %s", uri), Severity.INFORMATIONAL, new AuditElement(ACCESS, "tryCreateGeoServerWorkspace", uri)); restTemplate.exchange(uri, HttpMethod.POST, request, String.class); try { // Hack/Workaround: With certain versions of GeoServer, The workspace is not entirely created with this // POST request. // In order to properly have layers in this workspace succeed, we must first modify the workspace. // Perform // a PUT request that does nothing - but internally in GeoServer this fixes some configuration bug where // the // workspace would otherwise not perform properly. String updateWorkspaceUri = String.format("%s/rest/workspaces/piazza.xml", accessUtilities.getGeoServerBaseUrl()); restTemplate.exchange(updateWorkspaceUri, HttpMethod.PUT, request, String.class); } catch (HttpClientErrorException | HttpServerErrorException exception) { String error = String.format( "Failed to execute a PUT request on the newly-created workspace: %s. This may indicate the workspace may not be fully configured for use.", exception.getResponseBodyAsString()); LOGGER.info(error, exception); pzLogger.log(error, Severity.WARNING); } } catch (HttpClientErrorException | HttpServerErrorException exception) { String error = String.format("HTTP Error occurred while trying to create Piazza Workspace: %s", exception.getResponseBodyAsString()); LOGGER.info(error, exception); pzLogger.log(error, Severity.ERROR); determineExit(); } catch (Exception exception) { String error = String.format("Unexpected Error occurred while trying to create Piazza Workspace: %s", exception.getMessage()); LOGGER.error(error, exception); pzLogger.log(error, Severity.ERROR); determineExit(); } }
From source file:de.hska.ld.core.AbstractIntegrationTest.java
protected HttpRequestWrapper put() { return new HttpRequestWrapper(HttpMethod.PUT); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.PublisherIntegrationTest.java
private void setCfApiExpectedCalls() { // checking if app exists cfServerMock.expect(requestTo(testCfApi + appExistsRequest)).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess("{\"total_results\": 0}", MediaType.APPLICATION_JSON)); // creating app record cfServerMock.expect(requestTo(testCfApi + APPS_ENDPOINT)).andRespond( withSuccess("{\"metadata\":{\"guid\":\"" + testAppGuid + "\",\"something\":\"something\"}}", MediaType.APPLICATION_JSON)); // getting available domains cfServerMock.expect(requestTo(testCfApi + SHARED_DOMAINS_ENDPOINT)) .andRespond(withSuccess("{\"resources\":[{\"metadata\":{\"guid\":\"" + testDomainGuid + "\"}}]}", MediaType.APPLICATION_JSON)); // getting route for app cfServerMock.expect(requestTo(testCfApi + getRouteRequest)).andRespond(withSuccess( "{\"total_results\":\"1\",\"resources\":[{\"metadata\":{\"guid\":\"" + testRouteGuid + "\"}}]}", MediaType.APPLICATION_JSON)); // binding route to app cfServerMock.expect(requestTo(testCfApi + bindRouteEndpoint)).andRespond( withSuccess("{\"metadata\":{\"guid\":\"" + testRouteGuid + "\"}}", MediaType.APPLICATION_JSON)); // uploading app bits cfServerMock.expect(requestTo(testCfApi + uploadAppBitsEndpoint)).andExpect(method(HttpMethod.PUT)) .andRespond(withSuccess());// ww w .j av a 2 s .c o m // getting service guid cfServerMock.expect(requestTo(testCfApi + getServiceGuidByNameEndpoint)) .andRespond(withSuccess("{\"resources\":[{\"metadata\":{\"guid\":\"" + testServiceGuid + "\"}}]}", MediaType.APPLICATION_JSON)); // getting service plan guid cfServerMock.expect(requestTo(testCfApi + servicePlanEndpoint)) .andRespond(withSuccess("{\"resources\":[{\"metadata\":{\"guid\":\"" + testPlanGuid + "\"}}]}", MediaType.APPLICATION_JSON)); // setting service plan visibility cfServerMock.expect(requestTo(testCfApi + servicePlanVisibilityEndpoint)).andRespond(withSuccess()); }
From source file:org.cloudfoundry.identity.uaa.integration.ScimUserEndpointsIntegrationTests.java
@Test public void updateUserWithNewAuthoritiesSucceeds() throws Exception { ResponseEntity<ScimUser> response = createUser(JOE, "Joe", "User", "joe@blah.com"); ScimUser joe = response.getBody();//from w w w .j a v a2 s.c o m assertEquals(JOE, joe.getUserName()); joe.setUserType("admin"); HttpHeaders headers = new HttpHeaders(); headers.add("If-Match", "\"" + joe.getVersion() + "\""); response = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}", HttpMethod.PUT, new HttpEntity<ScimUser>(joe, headers), ScimUser.class, joe.getId()); ScimUser joe1 = response.getBody(); assertEquals(JOE, joe1.getUserName()); assertEquals(joe.getId(), joe1.getId()); assertNull(joe1.getUserType()); // check that authorities was not updated }
From source file:com.orange.ngsi.client.NgsiRestClientTest.java
@Test public void testUpdateContextAttribute_JSON() throws Exception { String responseBody = json(jsonConverter, new StatusCode(CodeEnum.CODE_200)); mockServer.expect(requestTo(baseUrl + "/ngsi10/contextEntities/123/attributes/temp")) .andExpect(method(HttpMethod.PUT)).andExpect(jsonPath("$.name").value("temp")) .andExpect(jsonPath("$.type").value("float")).andExpect(jsonPath("$.value").value("15.5")) .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON)); StatusCode response = ngsiRestClient.updateContextAttribute(baseUrl, null, "123", "temp", Util.createUpdateContextAttributeTemperature()).get(); this.mockServer.verify(); assertEquals(CodeEnum.CODE_200.getLabel(), response.getCode()); }
From source file:org.zalando.boot.etcd.EtcdClientTest.java
@Test public void compareAndSwapWithPrevIndex() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevIndex=2")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")).andRespond( MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.compareAndSwap("sample", "Hello world", 2); Assert.assertNotNull("response", response); server.verify();/*from w w w .j a v a2 s .com*/ }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testReplaceEntity_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/entities/room1?type=Room")).andExpect(method(HttpMethod.PUT)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(jsonPath("$.temperature.value").value(35.6)).andRespond(withNoContent()); ngsiClient.replaceEntity("room1", "Room", Collections.singletonMap("temperature", new Attribute(35.6))) .get();//w ww. j av a2 s .c o m }
From source file:ru.anr.base.facade.web.api.RestClient.java
/** * PUT method.//from w ww. j a v a 2s. c om * * @param path * Relative or absolute path * @param body * Request body (as expected by * {@link #setContentType(MediaType)}), default "application/json * @return Response with a body and state */ public ResponseEntity<String> put(String path, String body) { return exchange(path, HttpMethod.PUT, body, String.class); }
From source file:com.cloud.baremetal.networkservice.Force10BaremetalSwitchBackend.java
@Override public void removePortFromVlan(BaremetalVlanStruct struct) { String link = buildLink(struct.getSwitchIp(), String.format("/api/running/ftos/interface/vlan/%s", struct.getVlan())); HttpHeaders headers = createBasicAuthenticationHeader(struct); HttpEntity<String> request = new HttpEntity<>(headers); logger.debug(String.format("http get: %s, body: %s", link, request)); ResponseEntity rsp = rest.exchange(link, HttpMethod.GET, request, String.class); if (rsp.getStatusCode() == HttpStatus.NOT_FOUND) { logger.debug(String.format( "vlan[%s] has been deleted on force10[ip:%s], no need to remove the port[%s] anymore", struct.getVlan(), struct.getSwitchIp(), struct.getPort())); } else if (rsp.getStatusCode() == HttpStatus.OK) { PortInfo port = new PortInfo(struct); XmlObject xml = XmlObjectParser.parseFromString((String) rsp.getBody()); List<XmlObject> ports = xml.getAsList("untagged.tengigabitethernet"); ports.addAll(xml.<XmlObject>getAsList("untagged.gigabitethernet")); ports.addAll(xml.<XmlObject>getAsList("untagged.fortyGigE")); List<XmlObject> newPorts = new ArrayList<>(); boolean needRemove = false; for (XmlObject pxml : ports) { XmlObject name = pxml.get("name"); if (port.port.equals(name.getText())) { needRemove = true;/*from ww w .j a va2 s . c o m*/ continue; } newPorts.add(pxml); } if (!needRemove) { return; } xml.setText(null); xml.removeElement("mtu"); XmlObject tagged = xml.get("untagged"); tagged.removeAllChildren(); for (XmlObject p : newPorts) { tagged.putElement(p.getTag(), p); } request = new HttpEntity<>(xml.dump(), headers); logger.debug(String.format("http get: %s, body: %s", link, request)); rsp = rest.exchange(link, HttpMethod.PUT, request, String.class); if (!successHttpStatusCode.contains(rsp.getStatusCode())) { throw new CloudRuntimeException(String.format( "failed to program vlan[%s] for port[%s] on force10[ip:%s]. http status:%s, body dump:%s", struct.getVlan(), struct.getPort(), struct.getSwitchIp(), rsp.getStatusCode(), rsp.getBody())); } else { logger.debug(String.format("removed port[%s] from vlan[%s] on force10[ip:%s]", struct.getPort(), struct.getVlan(), struct.getSwitchIp())); } } else { throw new CloudRuntimeException( String.format("force10[ip:%s] returns unexpected error[%s] when http getting %s, body dump:%s", struct.getSwitchIp(), rsp.getStatusCode(), link, rsp.getBody())); } }