Search in sources :

Example 6 with User

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

the class SerializerEndpointTest method testSerializeCustom.

/**
	 * <p>Test for custom {@link AbstractSerializer}s.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testSerializeCustom() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/custom", redacted = "<redacted>";
    User user = new User(1, "Felix", "Walken", 28, false);
    User redactedUser = new User(1, redacted, redacted, 28, false);
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    serializerEndpoint.serializeCustom(user);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(new Gson().toJson(redactedUser))));
}
Also used : User(com.lonepulse.robozombie.model.User) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 7 with User

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

the class DeserializerEndpointTest method testParseCustom.

/**
	 * <p>Test for custom {@link AbstractDeserializer}s.
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testParseCustom() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/custom", redacted = "<redacted>";
    User user = new User(1, "Felix", "Walken", 28, false);
    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(user))));
    User deserializedUser = deserializerEndpoint.deserializeCustom();
    verify(getRequestedFor(urlEqualTo(subpath)));
    assertEquals(user.getId(), deserializedUser.getId());
    assertEquals(redacted, deserializedUser.getFirstName());
    assertEquals(redacted, deserializedUser.getLastName());
    assertEquals(user.getAge(), deserializedUser.getAge());
    assertEquals(user.isImmortal(), deserializedUser.isImmortal());
}
Also used : User(com.lonepulse.robozombie.model.User) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 8 with User

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

the class SerializerEndpointTest method testDetachSerializer.

/**
	 * <p>Test for detachment of the inherited serializer.</p>
	 *
	 * @since 1.3.0
	 */
@Test
public final void testDetachSerializer() throws ParseException, IOException {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/detach";
    User user = new User(1, "Roy", "Mustang", 30, false);
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    serializerEndpoint.detachSerializer(user);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(EntityUtils.toString(new SerializableEntity(user, true)))));
}
Also used : User(com.lonepulse.robozombie.model.User) SerializableEntity(org.apache.http.entity.SerializableEntity) Test(org.junit.Test)

Example 9 with User

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

the class SerializerEndpointTest method testPlain.

/**
	 * <p>Test for {@link Serializers#PLAIN}.</p>
	 *
	 * @since 1.3.0
	 */
@Test
public final void testPlain() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/plain";
    User user = new User(1, "Inori", "Yuzuhira", 16, false);
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    serializerEndpoint.plainString(user);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(user.toString())));
}
Also used : User(com.lonepulse.robozombie.model.User) Test(org.junit.Test)

Example 10 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)

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