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:com.cemeterylistingswebtest.test.rest.CemeteryControllerTest.java
@Test(enabled = false) public void testreadClubById() { String cemeteryID = "2"; HttpEntity<?> requestEntity = getHttpEntity(); ResponseEntity<Cemetery> responseEntity = restTemplate.exchange(URL + "api/cemetery/id/" + cemeteryID, HttpMethod.GET, requestEntity, Cemetery.class); Cemetery cemetery = responseEntity.getBody(); Assert.assertNotNull(cemetery);//from ww w.j av a2 s . c o m }
From source file:com.pepaproch.gtswsdlclient.AddresCheckImplTest.java
/** * Test of checkAddres method, of class AddresCheckImpl. *//*from www.ja va2 s .c o m*/ @Test public void testCheckAddresAuthenticated() { System.out.println("checkAddres"); AddressQuery addrQuery = new AddressQuery(); RestTemplate restTemplate = getRestTemplate(); RestTemplate authRestTemplate = getRestTemplate(); AuthTokenProviderImpl authTokenProvider = new AuthTokenProviderImpl(BASE_URL, "test", "test", authRestTemplate, 1); AuthHeaderInterceptor securityTokenInterceptor = new AuthHeaderInterceptor(authTokenProvider); List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors(); if (interceptors == null) { interceptors = new ArrayList<>(); restTemplate.setInterceptors(interceptors); } interceptors.add(securityTokenInterceptor); RestContext restContext = Mockito.mock(RestContext.class); when(restContext.getRestTemplate()).thenReturn(restTemplate); when(restContext.getBASE_URL()).thenReturn(BASE_URL); //first request AddressResponse expResult = null; mockServer = MockRestServiceServer.createServer(restTemplate); this.mockServer.expect(requestTo(BASE_URL + AddresCheckImpl.ADDR_CHECK_PATH)) .andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(CHECK_ADDR_RESPONSE_BODY, MediaType.APPLICATION_JSON)); //auth token is not set so it will call remote for acces token mockServerAuthProvider = MockRestServiceServer.createServer(authRestTemplate); String authResponseBody = "{\"accessToken\" : \"testtoken\" }"; mockServerAuthProvider.expect(requestTo(BASE_URL + AUTH_PATH)).andExpect(method(HttpMethod.POST)) .andRespond(withSuccess(authResponseBody, MediaType.APPLICATION_JSON)); //token is set with no valid time so token should be renewed String authResponseBody1 = "{\"accessToken\" : \"testtoken-1\" }"; mockServerAuthProvider.expect(requestTo(BASE_URL + AUTH_PATH)).andExpect(method(HttpMethod.POST)) .andRespond(withSuccess(authResponseBody1, MediaType.APPLICATION_JSON)); //second call with no valid auth token this.mockServer.expect(requestTo(BASE_URL + AddresCheckImpl.ADDR_CHECK_PATH)) .andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(CHECK_ADDR_RESPONSE_BODY, MediaType.APPLICATION_JSON)); AddresCheckImpl instance = new AddresCheckImpl(restContext); AddressResponse result = instance.checkAddres(addrQuery); String authToken1 = authTokenProvider.getAuthorisationToken().toString(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } AddressResponse result1 = instance.checkAddres(addrQuery); String authToken2 = authTokenProvider.getAuthorisationToken().toString(); Integer expectedTotal = new Integer(3); assertEquals(result.getTotal(), expectedTotal); mockServer.verify(); mockServerAuthProvider.verify(); }
From source file:nl.flotsam.calendar.core.CalendarClient.java
public String getCalendarAsType(String key, String contentType) { String address = UriBuilder.fromUri(baseURI).path("calendars").build().toASCIIString() + "/{key}"; Map<String, Object> params = new HashMap<String, Object>(); params.put("key", key); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", contentType); HttpEntity<?> request = new HttpEntity(headers); HttpEntity<String> response = template.exchange(address, HttpMethod.GET, request, String.class, params); return response.getBody(); }
From source file:fi.helsinki.opintoni.server.OodiServer.java
public void expectStudentStudyRightsRequest(String studentNumber) { server.expect(requestTo(studyRightsUrl(studentNumber))).andExpect(method(HttpMethod.GET)).andRespond( withSuccess(SampleDataFiles.toText("oodi/studentstudyrights.json"), MediaType.APPLICATION_JSON)); }
From source file:io.pivotal.receptor.client.ReceptorClient.java
@Override public DesiredLRPResponse getDesiredLRP(String processGuid) { return restTemplate.exchange("{baseUrl}/desired_lrps/{processGuid}", HttpMethod.GET, null, DesiredLRPResponse.class, baseUrl, processGuid).getBody(); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetV2_OK() throws Exception { mockServer.expect(requestTo(baseURL + "/v2")).andExpect(method(HttpMethod.GET)) .andExpect(header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)) .andRespond(withSuccess(Utils.loadResource("json/getV2Response.json"), MediaType.APPLICATION_JSON)); Map<String, String> endpoints = ngsiClient.getV2().get(); assertEquals(4, endpoints.size());//ww w . j a va 2s . co m assertNotNull("/v2/entities", endpoints.get("entities_url")); }
From source file:it.reply.orchestrator.service.OneDataServiceTest.java
@Test public void testSuccessGetUserSpaceId() { UserSpaces userSpace = getUserSpaces(); HttpEntity<UserSpaces> entity = getEntity(onedataToken); ResponseEntity<UserSpaces> responseEntity = new ResponseEntity<UserSpaces>(userSpace, HttpStatus.OK); Mockito.when(restTemplate.exchange(defaultOneZoneEndpoint + "/" + oneZoneBaseRestPath + "user/spaces", HttpMethod.GET, entity, UserSpaces.class)).thenReturn(responseEntity); Assert.assertEquals(oneDataService.getUserSpacesId(defaultOneZoneEndpoint, onedataToken), userSpace); Assert.assertEquals(oneDataService.getUserSpacesId(onedataToken), userSpace); }
From source file:org.appverse.web.framework.backend.frontfacade.rest.MvcExceptionHandlerTests.java
@Test public void testNotFound() throws Exception { // Login first TestLoginInfo loginInfo = login();/*w w w .j av a2 s . com*/ HttpHeaders headers = new HttpHeaders(); headers.set("Cookie", loginInfo.getJsessionid()); HttpEntity<String> entity = new HttpEntity<String>(headers); // Calling protected resource - requires CSRF token UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + baseApiPath + "/badurl") .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken()); ResponseEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); }
From source file:com.capitalone.dashboard.collector.DefaultNexusIQClientTest.java
@Test public void getApplications404() throws Exception { settings.setSelectStricterLicense(true); String appJson = getJson("applications.json"); String instanceUrl = "http://nexusiq.com"; String appListUrl = "http://nexusiq.com/api/v2/applications"; doThrow(new RestClientException("404")).when(rest).exchange(eq(appListUrl), eq(HttpMethod.GET), Matchers.any(HttpEntity.class), eq(String.class)); List<NexusIQApplication> apps = defaultNexusIQClient.getApplications(instanceUrl); assertThat(apps.size(), is(0));/*from www .j av a 2 s .c o m*/ }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchPeople.java
/** * Method, where all people are read from server. * All heavy lifting is made here.//from w w w . j a va2 s . co m * * @param params omitted here * @return list of fetched people */ @Override protected List<Person> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_USER + Values.SERVICE_QUALIFIER_ALL; setState(RUNNING, R.string.working_ws_people); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<PersonList> response = restTemplate.exchange(url, HttpMethod.GET, entity, PersonList.class); PersonList body = response.getBody(); if (body != null) { return body.getPeople(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }