Forked from aslakknutsen/ConferenceResourceTestCase.java
Last active
December 16, 2015 10:19
-
-
Save lfryc/5419084 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | |
WarpRest | |
.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