aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Padgett2011-11-09 09:27:48 (EST)
committerMichael Fiedler2011-11-09 09:27:48 (EST)
commit3b7bd8bfc109a6071c7be3d4f5eaea992d0eb715 (patch)
treed74fc414c1a19d889bbbe5ffb060d72b1bda4eee
parent6e40ee24b761a4952683932d126a91a29c86e8f4 (diff)
downloadorg.eclipse.lyo.testsuite-3b7bd8bfc109a6071c7be3d4f5eaea992d0eb715.zip
org.eclipse.lyo.testsuite-3b7bd8bfc109a6071c7be3d4f5eaea992d0eb715.tar.gz
org.eclipse.lyo.testsuite-3b7bd8bfc109a6071c7be3d4f5eaea992d0eb715.tar.bz2
Bug362810 - Add precondition failed tests for incorrect ETags when
updating resources
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateBaseTests.java103
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateJsonTests.java9
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateRdfXmlTests.java10
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateXmlTests.java8
4 files changed, 91 insertions, 39 deletions
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateBaseTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateBaseTests.java
index c009a4d..a15b834 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateBaseTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateBaseTests.java
@@ -139,15 +139,8 @@ public class CreationAndUpdateBaseTests extends TestsBase {
protected void createResourceAndUpdateIt(String contentType, String accept,
String newContent, String updateContent) throws IOException {
- // Issue post request using the provided template
- HttpResponse resp = OSLCUtils.postDataToUrl(currentUrl, basicCreds,
- accept, contentType, newContent, headers);
-
- EntityUtils.consume(resp.getEntity());
- assertEquals(HttpStatus.SC_CREATED, resp.getStatusLine()
- .getStatusCode());
- Header location = resp.getFirstHeader("Location");
- assertFalse(location == null);
+ HttpResponse resp = createResource(contentType, accept, newContent);
+ Header location = getRequiredLocationHeader(resp);
Header eTag = resp.getFirstHeader("ETag");
Header lastModified = resp.getFirstHeader("Last-Modified");
@@ -195,23 +188,11 @@ public class CreationAndUpdateBaseTests extends TestsBase {
protected void updateCreatedResourceWithInvalidContent(String contentType,
String accept, String content, String invalidContent)
throws IOException {
- // Issue post request using the provided template
- HttpResponse resp = OSLCUtils.postDataToUrl(currentUrl, basicCreds,
- accept, contentType, content, headers);
-
- // Assert the response gave a 201 Created
- EntityUtils.consume(resp.getEntity());
- assertEquals(HttpStatus.SC_CREATED, resp.getStatusLine()
- .getStatusCode());
- Header location = resp.getFirstHeader("Location");
+ HttpResponse resp = createResource(contentType, accept, content);
+ Header location = getRequiredLocationHeader(resp);
Header eTag = resp.getFirstHeader("ETag");
Header lastModified = resp.getFirstHeader("Last-Modified");
- // Assert that we were given a Location header pointing to the resource
- assertNotNull(
- "Expected 201-Created to return non-null Location header",
- location);
-
// Ignore ETag and Last-Modified for these tests
int size = headers.length;
if( eTag != null ) size++;
@@ -249,20 +230,11 @@ public class CreationAndUpdateBaseTests extends TestsBase {
protected void updateCreatedResourceWithBadType(String contentType,
String accept, String createContent, String updateContent,
String badType) throws IOException {
- HttpResponse resp = OSLCUtils.postDataToUrl(currentUrl, basicCreds,
- accept, contentType, createContent, headers);
-
- // Assert the response gave a 201 Created
- EntityUtils.consume(resp.getEntity());
- assertEquals(HttpStatus.SC_CREATED, resp.getStatusLine()
- .getStatusCode());
- Header location = resp.getFirstHeader("Location");
+ HttpResponse resp = createResource(contentType, accept, createContent);
+ Header location = getRequiredLocationHeader(resp);
Header eTag = resp.getFirstHeader("ETag");
Header lastModified = resp.getFirstHeader("Last-Modified");
- // Assert that we were given a Location header pointing to the resource
- assertFalse("Expected Location header on 201-Created", location == null);
-
// Ignore eTag and Last-Modified for this test
int size = headers.length;
if( eTag != null ) size++;
@@ -294,6 +266,65 @@ public class CreationAndUpdateBaseTests extends TestsBase {
if (resp != null && resp.getEntity() != null)
EntityUtils.consume(resp.getEntity());
- }
-
+ }
+
+ private HttpResponse createResource(String contentType, String accept,
+ String createContent) throws IOException {
+ HttpResponse resp = OSLCUtils.postDataToUrl(currentUrl, basicCreds,
+ accept, contentType, createContent, headers);
+
+ // Assert the response gave a 201 Created
+ EntityUtils.consume(resp.getEntity());
+ assertEquals(HttpStatus.SC_CREATED, resp.getStatusLine()
+ .getStatusCode());
+ return resp;
+ }
+
+ private Header getRequiredLocationHeader(HttpResponse resp) {
+ Header location = resp.getFirstHeader("Location");
+
+ // Assert that we were given a Location header pointing to the resource
+ assertNotNull(
+ "Expected 201-Created to return non-null Location header",
+ location);
+
+ return location;
+ }
+
+ protected void updateCreatedResourceWithFailedPrecondition(String contentType,
+ String accept, String createContent, String updateContent) throws IOException {
+ HttpResponse resp = createResource(contentType, accept, createContent);
+ Header location = getRequiredLocationHeader(resp);
+ Header eTag = resp.getFirstHeader("ETag");
+ Header lastModified = resp.getFirstHeader("Last-Modified");
+
+ assertTrue("Either ETag("+eTag+") or Last-Modified("+lastModified+") must not be null", eTag != null || lastModified != null ) ;
+
+ int size = headers.length + 1;
+ Header[] putHeaders = new Header[size];
+ int i=0;
+ for(;i<headers.length;i++){
+ putHeaders[i] = headers[i];
+ }
+ if( eTag != null ) {
+ putHeaders[i++] = new BasicHeader("If-Match", "Bogus");
+ } else if( lastModified != null ) {
+ putHeaders[i++] = new BasicHeader("If-Unmodified-Since", "Tue, 15 Nov 1994 12:45:26 GMT");
+ }
+
+ // Now, go to the url of the new change request and update it.
+ resp = OSLCUtils.putDataToUrl(location.getValue(), basicCreds, accept,
+ contentType, updateContent, putHeaders);
+ if (resp != null && resp.getEntity() != null)
+ EntityUtils.consume(resp.getEntity());
+
+ assertEquals(HttpStatus.SC_PRECONDITION_FAILED, resp.getStatusLine()
+ .getStatusCode());
+
+ // Clean up after the test by attempting to delete the created resource
+ resp = OSLCUtils.deleteFromUrl(location.getValue(), basicCreds, "");
+
+ if (resp != null && resp.getEntity() != null)
+ EntityUtils.consume(resp.getEntity());
+ }
}
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateJsonTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateJsonTests.java
index fd19e05..85ad090 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateJsonTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateJsonTests.java
@@ -99,5 +99,12 @@ public class CreationAndUpdateJsonTests extends CreationAndUpdateBaseTests {
OSLCConstants.CT_JSON, jsonCreateTemplate, jsonUpdateTemplate,
"invalid/type");
}
-
+
+ @Test
+ public void updateCreatedResourceWithFailedPrecondition()
+ throws IOException {
+ updateCreatedResourceWithFailedPrecondition(OSLCConstants.CT_JSON,
+ OSLCConstants.CT_JSON, jsonCreateTemplate,
+ jsonUpdateTemplate);
+ }
}
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateRdfXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateRdfXmlTests.java
index 94bec03..184b640 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateRdfXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateRdfXmlTests.java
@@ -101,7 +101,13 @@ public class CreationAndUpdateRdfXmlTests extends CreationAndUpdateBaseTests {
updateCreatedResourceWithBadType(OSLCConstants.CT_RDF,
OSLCConstants.CT_RDF, rdfXmlCreateTemplate,
rdfXmlUpdateTemplate, "invalid/type");
+ }
+
+ @Test
+ public void updateCreatedResourceWithFailedPrecondition()
+ throws IOException {
+ updateCreatedResourceWithFailedPrecondition(OSLCConstants.CT_RDF,
+ OSLCConstants.CT_RDF, rdfXmlCreateTemplate,
+ rdfXmlUpdateTemplate);
}
-
- // TODO: Add GET and PUT tests for ETag and/or Last-Modified
}
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateXmlTests.java
index 3fca1e4..01b6950 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/CreationAndUpdateXmlTests.java
@@ -95,5 +95,13 @@ public class CreationAndUpdateXmlTests extends CreationAndUpdateBaseTests {
updateCreatedResourceWithBadType(OSLCConstants.CT_XML,
OSLCConstants.CT_XML, xmlCreateTemplate, xmlUpdateTemplate,
"invalid/type");
+ }
+
+ @Test
+ public void updateCreatedResourceWithFailedPrecondition()
+ throws IOException {
+ updateCreatedResourceWithFailedPrecondition(OSLCConstants.CT_XML,
+ OSLCConstants.CT_XML, xmlCreateTemplate,
+ xmlUpdateTemplate);
}
}