use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.
the class DeserializerEndpointTest method testDeserializeJsonToGenericType.
/**
* <p>Test for {@link Deserializers#JSON} with a generic type.</p>
*
* @since 1.3.3
*/
@Test
public final void testDeserializeJsonToGenericType() {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/jsonarray";
User user1 = new User(0, "Tenzen0", "Yakushiji0", 300, true);
User user2 = new User(1, "Tenzen1", "Yakushiji1", 300, true);
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(Arrays.asList(user1, user2)))));
List<User> deserializedUsers = deserializerEndpoint.deserializeJsonToGenericType();
verify(getRequestedFor(urlEqualTo(subpath)));
for (int i = 0; i < deserializedUsers.size(); i++) {
User user = deserializedUsers.get(i);
assertEquals(i, user.getId());
assertEquals("Tenzen" + String.valueOf(i), user.getFirstName());
assertEquals("Yakushiji" + String.valueOf(i), user.getLastName());
assertEquals(300, user.getAge());
assertEquals(true, user.isImmortal());
}
}
use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.
the class DeserializerEndpointTest method testDetachDeserializer.
/**
* <p>Test for detachment of the inherited deserializer.</p>
*
* @since 1.3.0
*/
@Test
public final void testDetachDeserializer() {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
User user = new User(1, "Riza", "Hawkeye", 29, false);
String subpath = "/detach", body = new Gson().toJson(user);
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withBody(body)));
String responseContent = "";
try {
responseContent = deserializerEndpoint.detachDeserializer();
} catch (Exception e) {
fail("JSON deserialization was attempted.");
}
verify(getRequestedFor(urlEqualTo(subpath)));
assertEquals(body, responseContent);
}
use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.
the class DeserializerEndpointTest method testParseJson.
/**
* <p>Test for {@link Deserializers#JSON}.
*
* @since 1.3.0
*/
@Test
public final void testParseJson() {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/json";
User user = new User(1, "Tenzen", "Yakushiji", 300, true);
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(user))));
User deserializedUser = deserializerEndpoint.deserializeJson();
verify(getRequestedFor(urlEqualTo(subpath)));
assertEquals(user.getId(), deserializedUser.getId());
assertEquals(user.getFirstName(), deserializedUser.getFirstName());
assertEquals(user.getLastName(), deserializedUser.getLastName());
assertEquals(user.getAge(), deserializedUser.getAge());
assertEquals(user.isImmortal(), deserializedUser.isImmortal());
}
use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.
the class DeserializerEndpointTest method testParseXml.
/**
* <p>Test for {@link Deserializers#XML}.
*
* @throws Exception
* if the test terminated with an error
*
* @since 1.3.0
*/
@Test
public final void testParseXml() throws Exception {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/xml";
User user = new User(1, "Shiro", "Wretched-Egg", 17, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new Persister().write(user, baos);
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(baos.toString())));
User deserializedUser = deserializerEndpoint.deserializeXml();
verify(getRequestedFor(urlEqualTo(subpath)));
assertEquals(user.getId(), deserializedUser.getId());
assertEquals(user.getFirstName(), deserializedUser.getFirstName());
assertEquals(user.getLastName(), deserializedUser.getLastName());
assertEquals(user.getAge(), deserializedUser.getAge());
assertEquals(user.isImmortal(), deserializedUser.isImmortal());
}
use of com.lonepulse.robozombie.model.User in project RoboZombie by sahan.
the class RequestParamEndpointTest method testQueryParamsFail.
/**
* <p>Test for a {@link Request} having illegal {@link QueryParam}s.</p>
*
* @since 1.3.0
*/
@Test
public final void testQueryParamsFail() {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/queryparamsfail";
stubFor(get(urlMatching(subpath)).willReturn(aResponse().withStatus(200)));
expectedException.expect(Is.isA(InvocationException.class));
requestEndpoint.queryParamsFail(new User(1, "Ra's", "al Ghul", 47, false));
}
Aggregations