Search in sources :

Example 11 with User

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

the class SerializerEndpointTest method testGsonUnavailable.

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

Example 12 with User

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

the class DeserializerEndpointTest method testGsonUnavailable.

/**
	 * <p>Test for integration with the Gson library when it's not detected on the classpath.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testGsonUnavailable() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/gsonunavailable";
    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withBody(new User(1, "Illyasviel", "Von Einzbern", 15, false).toString()).withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    deserializerEndpoint.gsonUnavailable();
    verify(getRequestedFor(urlEqualTo(subpath)));
}
Also used : User(com.lonepulse.robozombie.model.User) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Test(org.junit.Test)

Example 13 with User

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

the class DeserializerEndpointTest 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(get(urlEqualTo(subpath)).willReturn(aResponse().withBody(new User(1, "Kotomine", "Kirei", 34, false).toString()).withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    deserializerEndpoint.simpleXmlUnavailable();
    verify(getRequestedFor(urlEqualTo(subpath)));
}
Also used : User(com.lonepulse.robozombie.model.User) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Test(org.junit.Test)

Example 14 with User

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

the class AsyncEndpointTest method testAsyncErrorCallbackError.

/**
	 * <p>Tests an erroneous asynchronous request where the implementation of the 
	 * {@link AsyncHandler#onError(Exception)} callback throws an exception.</p>
	 *  
	 * @since 1.3.0
	 */
@Test
public final void testAsyncErrorCallbackError() throws InterruptedException {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/errorcallbackerror", body = "non-JSON-content";
    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(body)));
    final Lock lock = new ReentrantLock();
    final Condition condition = lock.newCondition();
    asyncEndpoint.asyncErrorCallbackError(new AsyncHandler<User>() {

        @Override
        public void onSuccess(HttpResponse httpResponse, User user) {
        }

        @Override
        public void onError(InvocationException error) {
            try {
                throw new IllegalStateException();
            } finally {
                lock.lock();
                condition.signal();
                lock.unlock();
            }
        }
    });
    lock.lock();
    condition.await();
    lock.unlock();
    verify(getRequestedFor(urlEqualTo(subpath)));
    //verify that the asynchronous request executor has survived the exception
    successScenario();
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) User(com.lonepulse.robozombie.model.User) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) HttpResponse(org.apache.http.HttpResponse) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) Test(org.junit.Test)

Example 15 with User

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

the class AsyncEndpointTest method testAsyncError.

/**
	 * <p>Tests asynchronous request execution with @{@link Async} and 
	 * {@link AsyncHandler#onError(Exception)}.</p>
	 *  
	 * @since 1.3.0
	 */
@Test
public final void testAsyncError() throws InterruptedException {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/asyncerror", body = "non-JSON-content";
    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(body)));
    final Object[] content = new Object[1];
    final Lock lock = new ReentrantLock();
    final Condition condition = lock.newCondition();
    asyncEndpoint.asyncError(new AsyncHandler<User>() {

        @Override
        public void onSuccess(HttpResponse httpResponse, User user) {
        }

        @Override
        public void onError(InvocationException error) {
            lock.lock();
            content[0] = error;
            condition.signal();
            lock.unlock();
        }
    });
    lock.lock();
    condition.await();
    lock.unlock();
    verify(getRequestedFor(urlEqualTo(subpath)));
    assertTrue(content[0] != null);
    assertTrue(content[0] instanceof InvocationException);
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) User(com.lonepulse.robozombie.model.User) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) HttpResponse(org.apache.http.HttpResponse) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) 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