| author | Samuel Padgett | 2011-11-09 14:46:35 (EST) |
|---|---|---|
| committer | Michael Fiedler | 2011-11-11 12:54:56 (EST) |
| commit | 7633e12937f90c22c1a2398be84151a225a39734 (patch) (side-by-side diff) | |
| tree | 1e0392a7d742097354ccef0318eae164da4ad542 | |
| parent | bbee50e7e47b59905836040c11fe30555ba1c4ca (diff) | |
| download | org.eclipse.lyo.testsuite-7633e12937f90c22c1a2398be84151a225a39734.zip org.eclipse.lyo.testsuite-7633e12937f90c22c1a2398be84151a225a39734.tar.gz org.eclipse.lyo.testsuite-7633e12937f90c22c1a2398be84151a225a39734.tar.bz2 | |
Bug 363375 - Test suite requires oslc:totalCount even though the spec
says it's optional
Conflicts:
org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java
2 files changed, 108 insertions, 105 deletions
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java index 0fcf2a2..723328e 100644 --- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java +++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java @@ -13,8 +13,8 @@ * * Steve Speicher - initial API and implementation *******************************************************************************/ -package org.eclipse.lyo.testsuite.server.oslcv2tests;
-
+package org.eclipse.lyo.testsuite.server.oslcv2tests; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -51,46 +51,46 @@ import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; -
-/**
- * This class provides JUnit tests for the basic validation of query factories
- * as specified in the OSLC version 2 spec. This version of the query tests only
- * tests the basic status code and form of the query responses, as without
- * shapes implemented it is difficult to represent the needed various templates
- * of different change request types and to query for the templates.
- */
-@RunWith(Parameterized.class)
-public class SimplifiedQueryRdfXmlTests extends SimplifiedQueryBaseTests {
-
- public SimplifiedQueryRdfXmlTests(String thisUri) {
- super(thisUri);
- }
-
- @Before
- public void setup() throws IOException, ParserConfigurationException,
- SAXException, XPathException {
- super.setup();
- }
-
- @Parameters
- public static Collection<Object[]> getAllDescriptionUrls()
- throws IOException {
- Properties setupProps = SetupProperties.setup(null);
- ArrayList<String> serviceUrls = getServiceProviderURLsUsingRdfXml(setupProps.getProperty("baseUri"),
- onlyOnce);
- ArrayList<String> capabilityURLsUsingRdfXml = TestsBase
- .getCapabilityURLsUsingRdfXml(OSLCConstants.QUERY_BASE_PROP,
- serviceUrls, true);
- return toCollection(capabilityURLsUsingRdfXml);
- }
-
- protected void validateNonEmptyResponse(String query)
- throws IOException {
- HttpResponse response = OSLCUtils.getResponseFromUrl(setupBaseUrl,
- currentUrl + query, basicCreds, OSLCConstants.CT_RDF, headers);
- assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
-
- Model queryModel = ModelFactory.createDefaultModel();
+ +/** + * This class provides JUnit tests for the basic validation of query factories + * as specified in the OSLC version 2 spec. This version of the query tests only + * tests the basic status code and form of the query responses, as without + * shapes implemented it is difficult to represent the needed various templates + * of different change request types and to query for the templates. + */ +@RunWith(Parameterized.class) +public class SimplifiedQueryRdfXmlTests extends SimplifiedQueryBaseTests { + + public SimplifiedQueryRdfXmlTests(String thisUri) { + super(thisUri); + } + + @Before + public void setup() throws IOException, ParserConfigurationException, + SAXException, XPathException { + super.setup(); + } + + @Parameters + public static Collection<Object[]> getAllDescriptionUrls() + throws IOException { + Properties setupProps = SetupProperties.setup(null); + ArrayList<String> serviceUrls = getServiceProviderURLsUsingRdfXml(setupProps.getProperty("baseUri"), + onlyOnce); + ArrayList<String> capabilityURLsUsingRdfXml = TestsBase + .getCapabilityURLsUsingRdfXml(OSLCConstants.QUERY_BASE_PROP, + serviceUrls, true); + return toCollection(capabilityURLsUsingRdfXml); + } + + protected void validateNonEmptyResponse(String query) + throws IOException { + HttpResponse response = OSLCUtils.getResponseFromUrl(setupBaseUrl, + currentUrl + query, basicCreds, OSLCConstants.CT_RDF, headers); + assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); + + Model queryModel = ModelFactory.createDefaultModel(); queryModel.read(response.getEntity().getContent(), OSLCUtils.absoluteUrlFromRelative(setupBaseUrl, currentUrl), OSLCConstants.JENA_RDF_XML); @@ -98,9 +98,9 @@ public class SimplifiedQueryRdfXmlTests extends SimplifiedQueryBaseTests { Resource resultsRes = queryModel.getResource(currentUrl); assertTrue("Expected a results resource with URI: " + currentUrl, queryModel.contains(resultsRes, null)); -
- // oslc:ResponseInfo if optional, validate it if one exists
- Resource respInfoType = queryModel.createResource(OSLCConstants.RESP_INFO_TYPE);
+ + // oslc:ResponseInfo if optional, validate it if one exists + Resource respInfoType = queryModel.createResource(OSLCConstants.RESP_INFO_TYPE); ResIterator resIter = queryModel.listSubjectsWithProperty(RDF.type, respInfoType); while (resIter.hasNext()) { Resource responseInfoRes = resIter.nextResource(); @@ -108,58 +108,60 @@ public class SimplifiedQueryRdfXmlTests extends SimplifiedQueryBaseTests { "Response info URI should match the request URI (with query parameters)", currentUrl + query, responseInfoRes.getURI()); - Property countMember = queryModel.getProperty(OSLCConstants.TOTAL_COUNT_PROP);
- StmtIterator stmts = responseInfoRes.listProperties(countMember); - List<?> stmtsList = stmts.toList(); - Statement stmt = (Statement) stmtsList.get(0); - assertTrue("Expected oslc:totalCount property", stmtsList.size() == 1);
- int totalCount = Integer.parseInt(stmt.getObject().toString());
- assertTrue("Expected oslc:totalCount > 0",
- totalCount > 0);
-
+ Property countMember = queryModel.getProperty(OSLCConstants.TOTAL_COUNT_PROP); + stmts = queryModel.listStatements(responseInfoRes, countMember, (RDFNode)null); + stmtsList = stmts.toList(); + if (!stmtsList.isEmpty()) { + assertEquals("More than one oslc:totalCount property", 1, stmtsList.size()); + Statement stmt = (Statement) stmtsList.get(0); + int totalCount = Integer.parseInt(stmt.getObject().toString()); + assertTrue("Expected oslc:totalCount > 0", + totalCount > 0); + } + stmts = queryModel.listStatements(resultsRes, RDFS.member, (RDFNode)null); - stmtsList = stmts.toList();
- assertNotNull("Expected > 1 rdfs:member(s)", stmtsList.size() > 0);
+ stmtsList = stmts.toList(); + assertNotNull("Expected > 1 rdfs:member(s)", stmtsList.size() > 0); } - }
-
- @Test
- public void validEqualsQueryContainsExpectedResource() throws IOException {
- String query = getQueryUrlForalidEqualsQueryContainsExpectedResources();
- validateNonEmptyResponse(query);
- }
-
- @Test
- public void validNotEqualQueryContainsExpectedResource()
- throws IOException {
- String query = getQueryUrlForValidNotEqualQueryContainsExpectedResources();
- validateNonEmptyResponse(query);
- }
-
- @Test
- public void validLessThanQueryContainsExpectedResources()
- throws IOException {
- String query = getQueryUrlForValidLessThanQueryContainsExpectedResources();
- validateNonEmptyResponse(query);
- }
-
- @Test
- public void validGreaterThanQueryContainsExpectedDefects()
- throws IOException {
- String query = getQueryUrlForValidGreaterThanQueryContainsExpectedResources();
- validateNonEmptyResponse(query);
- }
-
- @Test
- public void validCompoundQueryContainsExpectedResource()
- throws IOException {
- String query = getQueryUrlForValidCompoundQueryContainsExpectedResources();
- validateNonEmptyResponse(query);
- }
-
- @Test
- public void fullTextSearchContainsExpectedResults() throws IOException {
- String query = getQueryUrlForFullTextSearchContainsExpectedResults();
- validateNonEmptyResponse(query);
- }
+ } + + @Test + public void validEqualsQueryContainsExpectedResource() throws IOException { + String query = getQueryUrlForalidEqualsQueryContainsExpectedResources(); + validateNonEmptyResponse(query); + } + + @Test + public void validNotEqualQueryContainsExpectedResource() + throws IOException { + String query = getQueryUrlForValidNotEqualQueryContainsExpectedResources(); + validateNonEmptyResponse(query); + } + + @Test + public void validLessThanQueryContainsExpectedResources() + throws IOException { + String query = getQueryUrlForValidLessThanQueryContainsExpectedResources(); + validateNonEmptyResponse(query); + } + + @Test + public void validGreaterThanQueryContainsExpectedDefects() + throws IOException { + String query = getQueryUrlForValidGreaterThanQueryContainsExpectedResources(); + validateNonEmptyResponse(query); + } + + @Test + public void validCompoundQueryContainsExpectedResource() + throws IOException { + String query = getQueryUrlForValidCompoundQueryContainsExpectedResources(); + validateNonEmptyResponse(query); + } + + @Test + public void fullTextSearchContainsExpectedResults() throws IOException { + String query = getQueryUrlForFullTextSearchContainsExpectedResults(); + validateNonEmptyResponse(query); + } }
\ No newline at end of file diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryXmlTests.java index 25c3ea7..f2571cb 100644 --- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryXmlTests.java +++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryXmlTests.java @@ -83,14 +83,15 @@ public class SimplifiedQueryXmlTests extends SimplifiedQueryBaseTests { protected void validateNonEmptyResponse(String query)
throws XPathExpressionException, IOException,
- ParserConfigurationException, SAXException {
+ ParserConfigurationException, SAXException { + String queryUrl = OSLCUtils.addQueryStringToURL(currentUrl, query);
HttpResponse response = OSLCUtils.getResponseFromUrl(setupBaseUrl,
- currentUrl + query, basicCreds, OSLCConstants.CT_XML, headers); + queryUrl, basicCreds, OSLCConstants.CT_XML, headers); int statusCode = response.getStatusLine().getStatusCode(); if (HttpStatus.SC_OK != statusCode) { EntityUtils.consume(response.getEntity()); - throw new IOException("Response code: " + statusCode + " for " + currentUrl + query); + throw new IOException("Response code: " + statusCode + " for " + queryUrl); } String responseBody = EntityUtils.toString(response.getEntity()); @@ -102,13 +103,13 @@ public class SimplifiedQueryXmlTests extends SimplifiedQueryBaseTests { // Only test oslc:ResponseInfo if found
if (results != null) {
assertEquals("Expended ResponseInfo/@rdf:about to equal request URL",
- currentUrl + query, results.getNodeValue());
+ queryUrl, results.getNodeValue());
results = (Node) OSLCUtils.getXPath().evaluate("//oslc:totalCount",
doc, XPathConstants.NODE);
- assertNotNull("Expected oslc:totalCount", results);
- int totalCount = Integer.parseInt(results.getTextContent());
- assertTrue("Expected oslc:totalCount > 0",
- totalCount > 0);
+ if (results != null) { + int totalCount = Integer.parseInt(results.getTextContent()); + assertTrue("Expected oslc:totalCount > 0", totalCount > 0); + } NodeList resultList = (NodeList) OSLCUtils.getXPath().evaluate(
"//rdf:Description/rdfs:member", doc, XPathConstants.NODESET);
|

