Search in sources :

Example 1 with User

use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.

the class SerializerEndpointTest method testSimpleXmlUnavailable.

/**
	 * <p>Test for integration with the Simple-XML library when it's not detected on the classpath.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testSimpleXmlUnavailable() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/simplexmlunavailable";
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    serializerEndpoint.simpleXmlUnavailable(new User(1, "Emiya", "Kiritsugu", 31, false));
}
Also used : User(com.lonepulse.robozombie.model.User) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Test(org.junit.Test)

Example 2 with User

use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.

the class RequestParamEndpointTest method testFormParamsFail.

/**
	 * <p>Test for a {@link Request} having illegal {@link FormParam}s.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testFormParamsFail() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/formparamsfail";
    stubFor(post(urlMatching(subpath)).willReturn(aResponse().withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    requestEndpoint.formParamsFail(new User(1, "Ra's", "al Ghul", 47, false));
}
Also used : User(com.lonepulse.robozombie.model.User) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Test(org.junit.Test)

Example 3 with User

use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.

the class RequestParamEndpointTest method testFormParamsMultivaluedFail.

/**
	 * <p>Test for a {@link Request} having illegal multivalued query parameters.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testFormParamsMultivaluedFail() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/formparamsmultivaluedfail";
    Map<String, List<User>> params = new HashMap<String, List<User>>();
    List<User> subjects = new ArrayList<User>();
    subjects.add(new User(1, "(En) Sabah", "Nur", 5236, true));
    subjects.add(new User(2, "Stephen", "Strange", 41, false));
    params.put("subjects", subjects);
    stubFor(post(urlMatching(subpath)).willReturn(aResponse().withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    requestEndpoint.formParamsMultivaluedFail(params);
}
Also used : User(com.lonepulse.robozombie.model.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with User

use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.

the class RequestParamEndpointTest method testQueryParamsMultivaluedFail.

/**
	 * <p>Test for a {@link Request} having illegal multivalued query parameters.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testQueryParamsMultivaluedFail() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/queryparamsmultivaluedfail";
    Map<String, List<User>> params = new HashMap<String, List<User>>();
    List<User> subjects = new ArrayList<User>();
    subjects.add(new User(1, "(En) Sabah", "Nur", 5236, true));
    subjects.add(new User(2, "Stephen", "Strange", 41, false));
    params.put("subjects", subjects);
    stubFor(get(urlMatching(subpath)).willReturn(aResponse().withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    requestEndpoint.queryParamsMultivaluedFail(params);
}
Also used : User(com.lonepulse.robozombie.model.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 5 with User

use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.

the class RequestParamEndpointTest method testSerializableEntity.

/**
	 * <p>Test for a {@link Request} with a {@link Serializable} entity.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testSerializableEntity() throws ParseException, IOException {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/serializableentity";
    User entity = new User(1L, "Eren", "Yeager", 15, false);
    SerializableEntity se = new SerializableEntity(entity, true);
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    requestEndpoint.serializableEntity(entity);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(EntityUtils.toString(se))));
}
Also used : User(com.lonepulse.robozombie.model.User) SerializableEntity(org.apache.http.entity.SerializableEntity) Test(org.junit.Test)

Aggregations

User (com.lonepulse.robozombie.model.User)25 Test (org.junit.Test)25 InvocationException (com.lonepulse.robozombie.proxy.InvocationException)14 Gson (com.google.gson.Gson)8 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Condition (java.util.concurrent.locks.Condition)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 HttpResponse (org.apache.http.HttpResponse)2 SerializableEntity (org.apache.http.entity.SerializableEntity)2 Persister (org.simpleframework.xml.core.Persister)2 ExpectedException (org.junit.rules.ExpectedException)1 TestHttpResponse (org.robolectric.tester.org.apache.http.TestHttpResponse)1