List of usage examples for org.springframework.http HttpMethod GET
HttpMethod GET
To view the source code for org.springframework.http HttpMethod GET.
Click Source Link
From source file:edu.infsci2560.AboutIT.java
@Test public void testAboutPage() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = this.restTemplate.exchange("/about.html", HttpMethod.GET, new HttpEntity<>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); }
From source file:net.paslavsky.springrest.SpringAnnotationPreprocessorTest.java
private Object[] rowData(Class<?> clientClass, String methodName) { MetadataBuilder builder = new MetadataBuilder(); if ("test1".equals(methodName)) { builder.setAdditionalPath("/test1").setHttpMethod(HttpMethod.PUT).setRequestParameter(0); } else if ("test7".equals(methodName)) { builder.setAdditionalPath("/test7/{path}").setHttpMethod(HttpMethod.GET).addUriVarParameter("path", 0) .addQueryParameter("size", 1).setMethodReturnType(Map.class).setResponseClass(Map.class); } else if ("test2".equals(methodName)) { builder.setAdditionalPath("/test2").setHttpMethod(HttpMethod.GET).addRequestHeaderParameter("OAuth", 0) .setMethodReturnType(ResponseEntity.class).setResponseClass(Map.class); } else if ("test3".equals(methodName)) { builder.setAdditionalPath("/test3").setHttpMethod(HttpMethod.GET) .setMethodReturnType(ResponseEntity.class).setResponseClass(Map.class); } else if ("test4".equals(methodName)) { builder.setAdditionalPath("/test4").setHttpMethod(HttpMethod.GET) .setMethodReturnType(ResponseEntity.class).setResponseClass(byte[].class); } else if ("test5".equals(methodName)) { builder.setAdditionalPath("/test5").setHttpMethod(HttpMethod.GET) .setMethodReturnType(ResponseEntity.class).setResponseClass(byte[].class); } else if ("test6".equals(methodName)) { builder.setAdditionalPath("/test6").setHttpMethod(HttpMethod.GET).setMethodReturnType(Object.class) .setResponseClass(byte[].class); } else if ("test8".equals(methodName)) { builder.setCommonPath("/common").setAdditionalPath("/test8").setHttpMethod(HttpMethod.PUT); } else if ("test9".equals(methodName)) { builder.setCommonPath("/common").setAdditionalPath("/test9").setHttpMethod(HttpMethod.GET) .setMethodReturnType(String.class).setResponseClass(String.class); } else if ("test10".equals(methodName)) { builder.setCommonPath("/common").setHttpMethod(HttpMethod.GET).setMethodReturnType(String.class) .setResponseClass(String.class); } else if ("test11".equals(methodName)) { builder.setCommonPath("/common").setHttpMethod(HttpMethod.GET).setMethodReturnType(String.class) .setResponseClass(String.class); }/*from w w w. ja va2 s . c o m*/ return new Object[] { clientClass, getMethod(clientClass, methodName), builder.build() }; }
From source file:com.example.user.UserEndpoint.java
@GetMapping List<UserJson> getUsers() { final ResponseEntity<PagedResources<Resource<UserEntity>>> entity = restTemplate.exchange(USER_END_POINT, HttpMethod.GET, null, new ParameterizedTypeReference<PagedResources<Resource<UserEntity>>>() { });// w w w .j a v a 2 s . co m return entity.getBody().getContent().stream() .map(r -> new UserEntity.Resource(r.getContent().getName(), r.getLink("self").getHref())) .map(UserEntity.Resource::toJson).collect(toList()); }
From source file:edu.infsci2560.LoginIT.java
@Test public void testLoginPage() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, new HttpEntity<>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("_csrf"); }
From source file:com.bodybuilding.argos.discovery.ClusterListDiscoveryTest.java
@Test public void testGetClusters() { String mockBody = "" + "[\n" + "{\n" + "\"name\": \"test1\",\n" + "\"link\": \"http://meh.com\",\n" + "\"turbineStream\": \"http://meh.com/turbine/turbine.stream?cluster=test1\"\n" + "},\n" + "{\n" + "\"name\": \"test2\",\n" + "\"link\": \"http://meh2.com\",\n" + "\"turbineStream\": \"http://meh2.com:8080/turbine/turbine.stream?cluster=test2\"\n" + "}" + "]"; RestTemplate restTemplate = new RestTemplate(); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); mockServer.expect(requestTo("http://127.0.0.1")).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(mockBody, MediaType.APPLICATION_JSON)); ClusterListDiscovery discovery = new ClusterListDiscovery(Sets.newHashSet("http://127.0.0.1"), restTemplate);//from w w w. j a va 2s . com Collection<Cluster> clusters = discovery.getCurrentClusters(); mockServer.verify(); assertNotNull(clusters); assertEquals(2, clusters.size()); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.http.FilesDownloaderTest.java
@Before public void setUp() throws IOException { this.testPath = Files.createTempFile("some", "file"); when(restTemplateMock.exchange(testCredentials.getHost() + testResource, HttpMethod.GET, HttpCommunication.basicAuthRequest(testCredentials.getBasicAuthToken()), byte[].class)) .thenReturn(responseMock); }
From source file:org.zalando.boot.etcd.EtcdClientTest.java
@Test public void get() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_get.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.get("sample"); Assert.assertNotNull("response", response); server.verify();/*w ww . j a v a 2 s . co m*/ }
From source file:org.trustedanalytics.h2oscoringengine.publisher.http.FilesDownloader.java
public Path download(String resourcePath, Path destinationFilePath) throws IOException { basicAuthRestTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter()); String resourceUrl = serverUrl + resourcePath; LOGGER.info("Downloading " + resourceUrl); try {//www .jav a 2 s . c o m ResponseEntity<byte[]> response = basicAuthRestTemplate.exchange(resourceUrl, HttpMethod.GET, HttpCommunication.basicAuthRequest(basicAuthToken), byte[].class); return Files.write(destinationFilePath, response.getBody()); } catch (HttpClientErrorException e) { String errorMessage = prepareErrorMessage(e.getStatusCode(), resourceUrl); LOGGER.error(errorMessage); throw new IOException(errorMessage, e); } }
From source file:com.bradley.musicapp.test.restapi.PersonRestControllerTest.java
public void testRead() { HttpEntity<?> requestEntity = getHttpEntity(); ResponseEntity<Person[]> responseEntity = restTemplate.exchange("URL", HttpMethod.GET, requestEntity, Person[].class); Person[] people = responseEntity.getBody(); for (Person person : people) { }//from w w w .jav a 2 s. c o m }
From source file:com.borabora.ui.secure.SampleSecureApplicationTests.java
@Test public void testHome() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity.getBody().contains("<title>Login")); }