summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Padgett2011-11-09 11:12:56 (EST)
committer Michael Fiedler2011-11-11 13:00:51 (EST)
commita9cee85de2facc57c2323593896181233b02b052 (patch)
treea10425d2d1b4352d25e967e5e48aba33996c8d02
parent7633e12937f90c22c1a2398be84151a225a39734 (diff)
downloadorg.eclipse.lyo.testsuite-a9cee85de2facc57c2323593896181233b02b052.zip
org.eclipse.lyo.testsuite-a9cee85de2facc57c2323593896181233b02b052.tar.gz
org.eclipse.lyo.testsuite-a9cee85de2facc57c2323593896181233b02b052.tar.bz2
Bug 363344 - Test suite does not handle service URIs with query
parameters Conflicts: org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestXmlTests.java5
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java5
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderXmlTests.java5
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java40
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCUtils.java170
5 files changed, 159 insertions, 66 deletions
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestXmlTests.java
index 0c1e12b..b89473b 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestXmlTests.java
@@ -113,8 +113,9 @@ public class ChangeRequestXmlTests extends TestsBase {
query = query + "oslc.where=" + URLEncoder.encode(where, "UTF-8") + "&oslc.pageSize=1";
ArrayList<String> results = new ArrayList<String>();
- for (String queryBase : capabilityURLsUsingXML) {
- HttpResponse resp = OSLCUtils.getResponseFromUrl(setupBaseUrl, queryBase + query, basicCreds,
+ for (String queryBase : capabilityURLsUsingXML) {
+ String queryUrl = OSLCUtils.addQueryStringToURL(queryBase, query);
+ HttpResponse resp = OSLCUtils.getResponseFromUrl(setupBaseUrl, queryUrl, basicCreds,
OSLCConstants.CT_XML, headers);
String respBody = EntityUtils.toString(resp.getEntity());
EntityUtils.consume(resp.getEntity());
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java
index 00c2015..0910fc8 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java
@@ -173,8 +173,9 @@ public class ServiceProviderRdfXmlTests extends TestsBase {
HttpResponse baseResp = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, basicCreds,
OSLCConstants.CT_XML, headers);
String baseRespValue = EntityUtils.toString(baseResp.getEntity());
-
- HttpResponse parameterResp = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl + "?oslc_cm:query", basicCreds,
+
+ String modifiedUrl = OSLCUtils.addParameterToURL(currentUrl, "oslc.where", "dcterms:identifier=\"1\"");
+ HttpResponse parameterResp = OSLCUtils.getResponseFromUrl(setupBaseUrl, modifiedUrl, basicCreds,
OSLCConstants.CT_XML, headers);
String parameterRespValue = EntityUtils.toString(parameterResp.getEntity());
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderXmlTests.java
index 7e057e6..97328bc 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderXmlTests.java
@@ -137,8 +137,9 @@ public class ServiceProviderXmlTests extends TestsBase {
OSLCConstants.CT_XML, headers);
String baseRespValue = EntityUtils.toString(baseResp.getEntity());
EntityUtils.consume(baseResp.getEntity());
-
- HttpResponse parameterResp = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl + "?oslc_cm:query", basicCreds,
+
+ String modifiedUrl = OSLCUtils.addParameterToURL(currentUrl, "oslc.where", "dcterms:identifier=\"1\"");
+ HttpResponse parameterResp = OSLCUtils.getResponseFromUrl(setupBaseUrl, modifiedUrl, basicCreds,
OSLCConstants.CT_XML, headers);
String parameterRespValue = EntityUtils.toString(parameterResp.getEntity());
EntityUtils.consume(parameterResp.getEntity());
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 723328e..ded4f6c 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
@@ -45,12 +45,9 @@ import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
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
@@ -86,8 +83,9 @@ public class SimplifiedQueryRdfXmlTests extends SimplifiedQueryBaseTests {
protected void validateNonEmptyResponse(String query)
throws IOException {
+ String queryUrl = OSLCUtils.addQueryStringToURL(currentUrl, query);
HttpResponse response = OSLCUtils.getResponseFromUrl(setupBaseUrl,
- currentUrl + query, basicCreds, OSLCConstants.CT_RDF, headers);
+ queryUrl, basicCreds, OSLCConstants.CT_RDF, headers);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
Model queryModel = ModelFactory.createDefaultModel();
@@ -95,34 +93,34 @@ public class SimplifiedQueryRdfXmlTests extends SimplifiedQueryBaseTests {
OSLCUtils.absoluteUrlFromRelative(setupBaseUrl, currentUrl),
OSLCConstants.JENA_RDF_XML);
EntityUtils.consume(response.getEntity());
- Resource resultsRes = queryModel.getResource(currentUrl);
- assertTrue("Expected a results resource with URI: " + currentUrl,
- queryModel.contains(resultsRes, null));
+ Resource responseInfoRes = (Resource) queryModel.getResource(queryUrl);
+ assumeNotNull("Expended ResponseInfo/@rdf:about to equal request URL", responseInfoRes);
+ Resource resultsRes = (Resource) queryModel.getResource(currentUrl);
+ assumeNotNull(resultsRes);
// 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();
- assertEquals(
- "Response info URI should match the request URI (with query parameters)",
- currentUrl + query, responseInfoRes.getURI());
+ Property rdfType = queryModel.getProperty(OSLCConstants.RDF_TYPE_PROP);
+ StmtIterator stmts = queryModel.listStatements(responseInfoRes, rdfType, respInfoType);
+ List<?> stmtsList = stmts.toList();
+ if (stmtsList.size() > 0) {
+ assertTrue("Expected ResponseInfo type for request URL",
+ stmtsList.size() > 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",
+ 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);
- }
- stmts = queryModel.listStatements(resultsRes, RDFS.member, (RDFNode)null);
+ Property rdfsMember = queryModel.getProperty(OSLCConstants.RDFS_MEMBER);
+ stmts = queryModel.listStatements(resultsRes, rdfsMember, (RDFNode)null);
stmtsList = stmts.toList();
assertNotNull("Expected > 1 rdfs:member(s)", stmtsList.size() > 0);
- }
+ }
}
@Test
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCUtils.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCUtils.java
index 1a9ead5..e28ed56 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCUtils.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCUtils.java
@@ -15,46 +15,51 @@
*******************************************************************************/
package org.eclipse.lyo.testsuite.server.util;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.StringReader;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.util.Scanner;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.http.Header;
-import org.apache.http.HttpResponse;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.Credentials;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.protocol.BasicHttpContext;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Scanner;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.http.Header;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
+import org.junit.Assert;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
public class OSLCUtils {
@@ -299,5 +304,92 @@ public class OSLCUtils {
//Get the response and return it
HttpResponse response = httpclient.execute(httppost);
EntityUtils.consume(response.getEntity());
+ }
+
+ /**
+ * Adds a query string to the end of a URL, handling the case where the URL
+ * already has query parameters.
+ *
+ * @param url
+ * the URL to modify. It may or may not already have query
+ * parameters.
+ * @param queryString
+ * the query string, starting with a '?'. For instance,
+ * "?oslc.properties=dcterms%3Aidentifier". Parameter values must
+ * already be encoded.
+ * @return the new URL
+ */
+ public static String addQueryStringToURL(String url, String queryString) {
+ Assert.assertTrue("queryString must begin with a '?'",
+ queryString.startsWith("?"));
+ if (url.indexOf('?') == -1) {
+ return url + queryString;
+ }
+
+ return url + '&' + queryString.substring(1);
+ }
+
+ /**
+ * Adds query parameter values to a URL.
+ *
+ * @param url
+ * the URL to modify
+ * @param params
+ * a map of query parameters as name/value pairs
+ * @return the new URL
+ * @throws UnsupportedEncodingException
+ * on errors encoding the values
+ */
+ public static String addParametersToURL(String url,
+ Map<String, String> queryParameters)
+ throws UnsupportedEncodingException {
+ StringBuffer updatedUrl = new StringBuffer(url);
+ if (url.indexOf('?') == -1) {
+ updatedUrl.append('?');
+ } else {
+ updatedUrl.append('&');
+ }
+
+ boolean first = true;
+ for (Entry<String, String> next : queryParameters.entrySet()) {
+ if (!first) {
+ updatedUrl.append("&");
+ }
+ updatedUrl.append(URLEncoder.encode(next.getKey(), "UTF-8"));
+ updatedUrl.append("=");
+ updatedUrl.append(URLEncoder.encode(next.getValue(), "UTF-8"));
+ first = false;
+ }
+
+ return updatedUrl.toString();
+ }
+
+ /**
+ * Adds a single query parameter to a URL.
+ *
+ * @param url
+ * the URL to modify
+ * @param name
+ * the parameter name
+ * @param value
+ * the parameter value
+ * @return the new URL
+ * @throws UnsupportedEncodingException
+ * on errors encoding the values
+ */
+ public static String addParameterToURL(String url, String name, String value)
+ throws UnsupportedEncodingException {
+ StringBuffer updatedUrl = new StringBuffer(url);
+ if (url.indexOf('?') == -1) {
+ updatedUrl.append('?');
+ } else {
+ updatedUrl.append('&');
+ }
+
+ updatedUrl.append(URLEncoder.encode(name, "UTF-8"));
+ updatedUrl.append("=");
+ updatedUrl.append(URLEncoder.encode(value, "UTF-8"));
+
+ return updatedUrl.toString();
}
}