Skip to content

Instantly share code, notes, and snippets.

@aslakknutsen
Created April 19, 2013 08:41
Show Gist options
  • Save aslakknutsen/5418988 to your computer and use it in GitHub Desktop.
Save aslakknutsen/5418988 to your computer and use it in GitHub Desktop.
Warp + REST + Rest Assured
package org.ced.web.rest.conference.test;
import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import java.io.File;
import java.net.URL;
import java.util.Date;
import org.ced.domain.Repository;
import org.ced.domain.conference.model.Conference;
import org.ced.domain.conference.model.Duration;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.arquillian.warp.Activity;
import org.jboss.arquillian.warp.Inspection;
import org.jboss.arquillian.warp.Warp;
import org.jboss.arquillian.warp.WarpTest;
import org.jboss.arquillian.warp.servlet.BeforeServlet;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.jayway.restassured.filter.log.ResponseLoggingFilter;
import com.jayway.restassured.http.ContentType;
@WarpTest @RunAsClient
@RunWith(Arquillian.class)
public class ConferenceResourceTestCase {
@Deployment
public static WebArchive deploy() {
return ConferenceRestDeployments.conference()
.addAsWebInfResource(new File("src/test/resources/beans.xml"));
}
@ArquillianResource
private URL baseURI;
@Test
public void shouldBeAbleToGetAll() throws Exception {
final Conference conference = new Conference();
conference.setName("Name");
conference.setTagLine("TagName");
conference.setDuration(new Duration(new Date(), new Date()));
Warp.initiate(new Activity() {
@Override
public void perform() {
given().
contentType(ContentType.JSON).
filter(ResponseLoggingFilter.responseLogger()).
then().
contentType(ContentType.JSON).
body("name", equalTo(conference.getName())).
body("tagLine", equalTo(conference.getTagLine())).
body("start", equalTo(conference.getDuration().getStart())).
body("end", equalTo(conference.getDuration().getEnd())).
when().
get(baseURI + "api/conference/{id}", conference.getId());
}
}).inspect(new SetupConference(conference));
}
public static class SetupConference extends Inspection {
private static final long serialVersionUID = 1L;
private Conference conference;
public SetupConference(Conference conference) {
this.conference = conference;
}
@BeforeServlet
public void store(Repository<Conference> repository) {
repository.store(conference);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment