Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* Copyright (C) 2010-2012 eBusiness Information, Excilys Group
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test15.rest;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.androidannotations.test15.AndroidAnnotationsTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

@RunWith(AndroidAnnotationsTestRunner.class)
public class HttpMethodServiceTest {

@Test
public void use_delete_http_method() {
HttpMethodsService_ service = new HttpMethodsService_();

RestTemplate restTemplate = mock(RestTemplate.class);
service.setRestTemplate(restTemplate);

service.delete();

verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.DELETE), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any());
}

@Test
public void use_get_http_method() {
HttpMethodsService_ service = new HttpMethodsService_();

RestTemplate restTemplate = mock(RestTemplate.class);
service.setRestTemplate(restTemplate);

service.get();

verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.GET), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any());
}

@Test
@SuppressWarnings("unchecked")
public void use_head_http_method() {
HttpMethodsService_ service = new HttpMethodsService_();

RestTemplate restTemplate = mock(RestTemplate.class);
ResponseEntity<Object> response = mock(ResponseEntity.class);
when(restTemplate.exchange("http://company.com/ajax/services/head/", HttpMethod.HEAD, null, null)).thenReturn(response);

service.setRestTemplate(restTemplate);

service.head();

verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.HEAD), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any());
}

@Test
@SuppressWarnings("unchecked")
public void use_options_http_method() {
HttpMethodsService_ service = new HttpMethodsService_();

RestTemplate restTemplate = mock(RestTemplate.class);
ResponseEntity<Object> response = mock(ResponseEntity.class);
when(restTemplate.exchange("http://company.com/ajax/services/options/", HttpMethod.OPTIONS, null, null)).thenReturn(response);
HttpHeaders headers = mock(HttpHeaders.class);
when(response.getHeaders()).thenReturn(headers);

service.setRestTemplate(restTemplate);

service.options();

verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.OPTIONS), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any());
}

@Test
public void use_post_http_method() {
HttpMethodsService_ service = new HttpMethodsService_();

RestTemplate restTemplate = mock(RestTemplate.class);
service.setRestTemplate(restTemplate);

service.post();

verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.POST), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any());
}

@Test
public void use_put_http_method() {
HttpMethodsService_ service = new HttpMethodsService_();

RestTemplate restTemplate = mock(RestTemplate.class);
service.setRestTemplate(restTemplate);

service.put();

verify(restTemplate).exchange(Mockito.anyString(), Mockito.<HttpMethod> eq(HttpMethod.PUT), Mockito.<HttpEntity<?>> any(), Mockito.<Class<Object>> any());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,24 @@ public void getEventsGenericsMap() {
assertEquals(event2, eventsMap.get("event2"));
}

@Test
public void urlWithAParameterDeclaredTwiceTest() {
addPendingResponse("[[{'id':1,'name':'event1'},{'id':2,'name':'event2'}],[{'id':1,'name':'event1'},{'id':2,'name':'event2'}]]");
Event[][] results = myService.urlWithAParameterDeclaredTwice(1985);

Event event1 = new Event(1, "event1");
Event event2 = new Event(2, "event2");
Event[][] events = new Event[][] {{event1, event2}, {event1, event2}};

for (int i = 0 ; i < events.length ; i++) {

assertEquals(results[i].length, events[i].length);

for (int j = 0 ; j < events[i].length ; j++) {
assertEquals(events[i][j].getName(), results[i][j].getName());
assertEquals(events[i][j].getId(), results[i][j].getId());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (C) 2010-2012 eBusiness Information, Excilys Group
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.test15.rest;

import java.util.Set;

import org.androidannotations.annotations.rest.Delete;
import org.androidannotations.annotations.rest.Get;
import org.androidannotations.annotations.rest.Head;
import org.androidannotations.annotations.rest.Options;
import org.androidannotations.annotations.rest.Post;
import org.androidannotations.annotations.rest.Put;
import org.androidannotations.annotations.rest.Rest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

// if defined, the rootUrl will be added as a prefix to every request
@Rest(rootUrl = "http://company.com/ajax/services", converters = { MappingJacksonHttpMessageConverter.class }, interceptors = { RequestInterceptor.class })
public interface HttpMethodsService {

@Delete("/delete/")
void delete();

@Get("/get/")
void get();

@Head("/head/")
HttpHeaders head();

@Options("/options/")
Set<HttpMethod> options();

@Post("/post/")
void post();

@Put("/put/")
void put();

void setRestTemplate(RestTemplate restTemplate);

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.