Search in sources :

Example 21 with User

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

the class RequestParamEndpointTest method testQueryParamsBatchElementFail.

/**
	 * <p>Test for a {@link Request} having illegal batch {@link QueryParams} elements.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testQueryParamsBatchElementFail() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/queryparamsbatchelementfail";
    Map<String, User> params = new HashMap<String, User>();
    params.put("subject", new User(1, "Kurt", "Wagner", 32, false));
    stubFor(get(urlMatching(subpath)).willReturn(aResponse().withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    requestEndpoint.queryParamsBatchElementFail(params);
}
Also used : User(com.lonepulse.robozombie.model.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Test(org.junit.Test)

Example 22 with User

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

the class RequestParamEndpointTest method testFormParamsBatchElementFail.

/**
	 * <p>Test for a {@link Request} having illegal batch {@link FormParams} elements.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testFormParamsBatchElementFail() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/formparamsbatchelementfail";
    Map<String, User> params = new HashMap<String, User>();
    params.put("subject", new User(1, "Kurt", "Wagner", 32, false));
    stubFor(post(urlMatching(subpath)).willReturn(aResponse().withStatus(200)));
    expectedException.expect(Is.isA(InvocationException.class));
    requestEndpoint.formParamsBatchElementFail(params);
}
Also used : User(com.lonepulse.robozombie.model.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Test(org.junit.Test)

Example 23 with User

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

the class ResponseEndpointTest method testNoDeserializer.

/**
	 * <p>Test for a request which expects the raw {@link HttpEntity}.</p>
	 *
	 * @since 1.3.0
	 */
@Test
public final void testNoDeserializer() {
    String subpath = "/nodeserializer";
    String url = "http://0.0.0.0:8080" + subpath;
    String body = new Gson().toJson(new User(1, "Cain", "Marko", 37, false));
    Robolectric.addHttpResponseRule(HttpGet.METHOD_NAME, url, new TestHttpResponse(200, body));
    expectedException.expect(Is.isA(InvocationException.class));
    responseEndpoint.noDeserializer();
}
Also used : User(com.lonepulse.robozombie.model.User) TestHttpResponse(org.robolectric.tester.org.apache.http.TestHttpResponse) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 24 with User

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

the class SerializerEndpointTest method testSerializeXml.

/**
	 * <p>Test for {@link Serializers#XML}.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testSerializeXml() 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(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    serializerEndpoint.serializeXml(user);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(baos.toString())));
}
Also used : User(com.lonepulse.robozombie.model.User) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Persister(org.simpleframework.xml.core.Persister) Test(org.junit.Test)

Example 25 with User

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

the class SerializerEndpointTest method testSerializeJson.

/**
	 * <p>Test for {@link Serializers#JSON}.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testSerializeJson() throws ParseException, IOException {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/json";
    User user = new User(1, "Tenzen", "Yakushiji", 300, true);
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    serializerEndpoint.serializeJson(user);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(new Gson().toJson(user))));
}
Also used : User(com.lonepulse.robozombie.model.User) Gson(com.google.gson.Gson) 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