|
| 1 | +/** |
| 2 | + * Copyright (C) 2010-2012 eBusiness Information, Excilys Group |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed To in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package org.androidannotations.test15.rest; |
| 17 | + |
| 18 | +import static org.mockito.Mockito.mock; |
| 19 | +import static org.mockito.Mockito.verify; |
| 20 | +import static org.mockito.Mockito.when; |
| 21 | + |
| 22 | +import org.androidannotations.test15.AndroidAnnotationsTestRunner; |
| 23 | +import org.junit.Test; |
| 24 | +import org.junit.runner.RunWith; |
| 25 | +import org.mockito.Mockito; |
| 26 | +import org.springframework.http.HttpEntity; |
| 27 | +import org.springframework.http.HttpHeaders; |
| 28 | +import org.springframework.http.HttpMethod; |
| 29 | +import org.springframework.http.ResponseEntity; |
| 30 | +import org.springframework.web.client.RestTemplate; |
| 31 | + |
| 32 | +@RunWith(AndroidAnnotationsTestRunner.class) |
| 33 | +public class HttpMethodServiceTest { |
| 34 | + |
| 35 | + @Test |
| 36 | + public void use_delete_http_method() { |
| 37 | + HttpMethodsService_ service = new HttpMethodsService_(); |
| 38 | + |
| 39 | + RestTemplate restTemplate = mock(RestTemplate.class); |
| 40 | + service.setRestTemplate(restTemplate); |
| 41 | + |
| 42 | + service.delete(); |
| 43 | + |
| 44 | + verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.DELETE), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void use_get_http_method() { |
| 49 | + HttpMethodsService_ service = new HttpMethodsService_(); |
| 50 | + |
| 51 | + RestTemplate restTemplate = mock(RestTemplate.class); |
| 52 | + service.setRestTemplate(restTemplate); |
| 53 | + |
| 54 | + service.get(); |
| 55 | + |
| 56 | + verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.GET), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + @SuppressWarnings("unchecked") |
| 61 | + public void use_head_http_method() { |
| 62 | + HttpMethodsService_ service = new HttpMethodsService_(); |
| 63 | + |
| 64 | + RestTemplate restTemplate = mock(RestTemplate.class); |
| 65 | + ResponseEntity<Object> response = mock(ResponseEntity.class); |
| 66 | + when(restTemplate.exchange("http://company.com/ajax/services/head/", HttpMethod.HEAD, null, null)).thenReturn(response); |
| 67 | + |
| 68 | + service.setRestTemplate(restTemplate); |
| 69 | + |
| 70 | + service.head(); |
| 71 | + |
| 72 | + verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.HEAD), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any()); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + @SuppressWarnings("unchecked") |
| 77 | + public void use_options_http_method() { |
| 78 | + HttpMethodsService_ service = new HttpMethodsService_(); |
| 79 | + |
| 80 | + RestTemplate restTemplate = mock(RestTemplate.class); |
| 81 | + ResponseEntity<Object> response = mock(ResponseEntity.class); |
| 82 | + when(restTemplate.exchange("http://company.com/ajax/services/options/", HttpMethod.OPTIONS, null, null)).thenReturn(response); |
| 83 | + HttpHeaders headers = mock(HttpHeaders.class); |
| 84 | + when(response.getHeaders()).thenReturn(headers); |
| 85 | + |
| 86 | + service.setRestTemplate(restTemplate); |
| 87 | + |
| 88 | + service.options(); |
| 89 | + |
| 90 | + verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.OPTIONS), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any()); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void use_post_http_method() { |
| 95 | + HttpMethodsService_ service = new HttpMethodsService_(); |
| 96 | + |
| 97 | + RestTemplate restTemplate = mock(RestTemplate.class); |
| 98 | + service.setRestTemplate(restTemplate); |
| 99 | + |
| 100 | + service.post(); |
| 101 | + |
| 102 | + verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.POST), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any()); |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + public void use_put_http_method() { |
| 107 | + HttpMethodsService_ service = new HttpMethodsService_(); |
| 108 | + |
| 109 | + RestTemplate restTemplate = mock(RestTemplate.class); |
| 110 | + service.setRestTemplate(restTemplate); |
| 111 | + |
| 112 | + service.put(); |
| 113 | + |
| 114 | + verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.PUT), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any()); |
| 115 | + } |
| 116 | + |
| 117 | +} |
0 commit comments