Commits

Micha Kops committed 235fe55

Example for setting headers added

Comments (0)

Files changed (2)

src/main/java/com/hascode/ra_samples/RestAssuredSampleService.java

 import java.util.List;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 		return "Ok";
 	}
 
+	@GET
+	@Produces(MediaType.TEXT_PLAIN)
+	@Path("/header/print")
+	public String printHeader(@HeaderParam("myparam") final String headerParam) {
+		return headerParam;
+	}
+
 }

src/test/java/it/RestAssuredSampleServiceIT.java

 
 import java.io.InputStream;
 
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.jayway.restassured.path.json.JsonPath;
 	 * Tutorial note: The JSON returned is this
 	 * <code>{"email":"test@hascode.com","firstName":"Tim","id":"1","lastName":"Testerman"}</code>
 	 */
-	@Ignore
 	@Test
 	public void testGetSingleUser() {
 		expect().statusCode(200)
 	 * Tutorial note: The JSON returned is this
 	 * <code>{"email":"test@hascode.com","firstName":"Tim","id":"1","lastName":"Testerman"}</code>
 	 */
-	@Ignore
 	@Test
 	public void testGetSingleUserProgrammatic() {
 		Response res = get("/ra/service/single-user");
 		assertEquals("1", jp.get("id"));
 	}
 
-	@Ignore
 	@Test
 	public void testGetSingleUserAsXml() {
 		expect().statusCode(200)
 				.get("/ra/service/single-user/xml");
 	}
 
-	@Ignore
 	@Test
 	public void testGetPersons() {
 		expect().statusCode(200)
 				.when().get("/ra/service/persons/xml");
 	}
 
-	@Ignore
 	@Test
 	public void testGetSingleUserAgainstSchema() {
 		InputStream xsd = getClass().getResourceAsStream("/user.xsd");
 				.get("/ra/service/single-user/xml");
 	}
 
-	@Ignore
 	@Test
 	public void testCreateuser() {
 		final String email = "test@hascode.com";
 				.get("/ra/service/user/create");
 	}
 
-	@Ignore
 	@Test
 	public void testStatusNotFound() {
 		expect().statusCode(404).when().get("/ra/service/status/notfound");
 				.authentication().basic("admin", "admin")
 				.get("/ra/service/secure/person");
 	}
+
+	@Test
+	public void testSetRequestHeaders() {
+		expect().body(equalTo("TEST")).when().with().header("myparam", "TEST")
+				.get("/ra/service/header/print");
+		expect().body(equalTo("foo")).when().with().header("myparam", "foo")
+				.get("/ra/service/header/print");
+	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.