aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuhong Yin2012-01-10 10:00:54 (EST)
committerMichael Fiedler2012-01-10 15:31:09 (EST)
commitb8a3b4cb416d3cd64b41e2749388298c98c3782e (patch)
treeda39880e50326bf52e8fec15fda4cf0e49733e4b
parent5b11231a04a917514417f2a544d0d91bb9b4488b (diff)
downloadorg.eclipse.lyo.testsuite-b8a3b4cb416d3cd64b41e2749388298c98c3782e.zip
org.eclipse.lyo.testsuite-b8a3b4cb416d3cd64b41e2749388298c98c3782e.tar.gz
org.eclipse.lyo.testsuite-b8a3b4cb416d3cd64b41e2749388298c98c3782e.tar.bz2
Bug 367036 - Add JSON tests to the testsuite
-rw-r--r--org.eclipse.lyo.testsuite.server/.classpath15
-rw-r--r--org.eclipse.lyo.testsuite.server/.project58
-rw-r--r--org.eclipse.lyo.testsuite.server/config/cq/cq-setupv2.properties4
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/DynamicSuiteBuilder.java6
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestJsonTests.java324
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestXmlTests.java2
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/TestsBase.java102
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java17
8 files changed, 483 insertions, 45 deletions
diff --git a/org.eclipse.lyo.testsuite.server/.classpath b/org.eclipse.lyo.testsuite.server/.classpath
index 595a5bf..7973c95 100644
--- a/org.eclipse.lyo.testsuite.server/.classpath
+++ b/org.eclipse.lyo.testsuite.server/.classpath
@@ -1,7 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.lyo.testsuite.server/.project b/org.eclipse.lyo.testsuite.server/.project
index 777db77..a551490 100644
--- a/org.eclipse.lyo.testsuite.server/.project
+++ b/org.eclipse.lyo.testsuite.server/.project
@@ -1,29 +1,29 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.lyo.testsuite.server</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.lyo.testsuite.server</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.lyo.testsuite.server/config/cq/cq-setupv2.properties b/org.eclipse.lyo.testsuite.server/config/cq/cq-setupv2.properties
index 7fae563..de6296a 100644
--- a/org.eclipse.lyo.testsuite.server/config/cq/cq-setupv2.properties
+++ b/org.eclipse.lyo.testsuite.server/config/cq/cq-setupv2.properties
@@ -30,13 +30,13 @@ version1Properties=config/cq/cq-setupv1.properties
##CHANGE REQUEST TEST PROPERTIES##
#The where clause used to find records in the change request tests
-changeRequestsWhere=dcterms:identifier > "0"
+#changeRequestsWhere=dcterms:identifier > "0"
##QUERY PROPERTIES##
#The query parameter that should be used to test equality
queryEqualityProperty=dcterms:identifier
#The parameter value used with the parameter to test equality (record with this value should exist in the system)
-queryEqualityValue=33554438
+queryEqualityValue=33554433
#The query parameter that should be used to test equality
queryComparisonProperty=dcterms:identifier
#The parameter value used with the parameter to test comparisons (should split the results into two non-empty sets)
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/DynamicSuiteBuilder.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/DynamicSuiteBuilder.java
index 6c2d9b4..1434454 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/DynamicSuiteBuilder.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/DynamicSuiteBuilder.java
@@ -76,7 +76,8 @@ public class DynamicSuiteBuilder
if (OSLCConstants.OSLC_CM_V2.equals(testVersions)) {
testsToRun.add(org.eclipse.lyo.testsuite.server.oslcv2tests.CreationAndUpdateJsonTests.class);
testsToRun.add(org.eclipse.lyo.testsuite.server.oslcv2tests.ChangeRequestXmlTests.class);
- testsToRun.add(org.eclipse.lyo.testsuite.server.oslcv2tests.ChangeRequestRdfXmlTests.class);
+ testsToRun.add(org.eclipse.lyo.testsuite.server.oslcv2tests.ChangeRequestRdfXmlTests.class);
+ testsToRun.add(org.eclipse.lyo.testsuite.server.oslcv2tests.ChangeRequestJsonTests.class);
}
}
testsToRun.add(org.eclipse.lyo.testsuite.server.oslcv2tests.CreationAndUpdateRdfXmlTests.class);
@@ -92,7 +93,8 @@ public class DynamicSuiteBuilder
testsToRun.add(CreationAndUpdateTests.class);
testsToRun.add(QueryTests.class);
testsToRun.add(OAuthTests.class);
- }
+ }
+
//Return array of test classes
return testsToRun.toArray(new Class<?>[0]);
}
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestJsonTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestJsonTests.java
new file mode 100644
index 0000000..350b126
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestJsonTests.java
@@ -0,0 +1,324 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Yuhong Yin - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lyo.testsuite.server.oslcv2tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeNotNull;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.bind.DatatypeConverter;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathException;
+import javax.xml.xpath.XPathExpressionException;
+
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.http.HttpResponse;
+import org.apache.http.util.EntityUtils;
+import org.apache.wink.json4j.JSON;
+import org.apache.wink.json4j.JSONArray;
+import org.apache.wink.json4j.JSONArtifact;
+import org.apache.wink.json4j.JSONException;
+import org.apache.wink.json4j.JSONObject;
+import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
+import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+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.Resource;
+import com.hp.hpl.jena.rdf.model.Selector;
+import com.hp.hpl.jena.rdf.model.SimpleSelector;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+
+
+/**
+ * This class provides JUnit tests for the validation of a change request returned by accessing the change
+ * request's URL directly. It runs the equality query from the properties file and grabs the first result
+ * to test against, checking the relationship of elements in the JSON representation of the change request.
+ */
+@RunWith(Parameterized.class)
+public class ChangeRequestJsonTests extends TestsBase {
+ private HttpResponse response;
+ private String responseBody;
+ private JSONObject doc;
+
+ public ChangeRequestJsonTests(String thisUrl)
+ throws IOException, ParserConfigurationException, SAXException, XPathExpressionException, NullPointerException, JSONException
+ {
+ super(thisUrl);
+
+ // If currentUrl is null, it means that the query didn't match any
+ // records. This isn't exactly a failure, but there's nothing more we
+ // can test.
+ assumeNotNull(currentUrl);
+ response = OSLCUtils.getResponseFromUrl(setupBaseUrl, currentUrl, basicCreds,
+ OSLCConstants.CT_JSON, headers);
+ responseBody = EntityUtils.toString(response.getEntity());
+ int sc = response.getStatusLine().getStatusCode();
+
+ // Some records in the system might not be accessible to this user. This
+ // isn't a failure, but there's nothing more we can test.
+ assumeTrue(sc != HttpStatus.SC_FORBIDDEN && sc != HttpStatus.SC_UNAUTHORIZED);
+
+ // Make sure the request succeeded before continuing.
+ assertEquals(HttpStatus.SC_OK, sc);
+
+ //Get JSON doc from response
+ JSONArtifact userData = JSON.parse(responseBody);
+
+ if (userData instanceof JSONArtifact) {
+ doc = (JSONObject)userData;
+ }
+
+ }
+
+ @Before
+ public void setup()
+ throws IOException, ParserConfigurationException, SAXException, XPathException
+ {
+ super.setup();
+ }
+
+ @Parameters
+ public static Collection<Object[]> getAllDescriptionUrls()
+ throws IOException, NullPointerException, XPathException, ParserConfigurationException, SAXException, JSONException
+ {
+ //Checks the ServiceProviderCatalog at the specified baseUrl of the REST service in order to grab all urls
+ //to other ServiceProvidersCatalogs contained within it, recursively, in order to find the URLs of all
+ //query factories of the REST service.
+
+ ArrayList<String> serviceUrls = getServiceProviderURLsUsingJson(setupProps.getProperty("baseUri"), onlyOnce);
+
+ ArrayList<String> capabilityURLsUsingJson = getCapabilityURLsUsingJson(OSLCConstants.QUERY_BASE_PROP, serviceUrls, true);
+
+ String where = setupProps.getProperty("changeRequestsWhere");
+ if (where == null) {
+ String queryProperty = setupProps.getProperty("queryEqualityProperty");
+ String queryPropertyValue = setupProps.getProperty("queryEqualityValue");
+ where = queryProperty + "=\"" + queryPropertyValue + "\"";
+ }
+
+ String additionalParameters = setupProps.getProperty("queryAdditionalParameters");
+ String query = (additionalParameters.length() == 0) ? "?" : "?" + additionalParameters + "&";
+ query = query + "oslc.where=" + URLEncoder.encode(where, "UTF-8") + "&oslc.pageSize=1";
+
+ ArrayList<String> results = new ArrayList<String>();
+ for (String queryBaseUri : capabilityURLsUsingJson) {
+
+ String queryUrl = OSLCUtils.addQueryStringToURL(queryBaseUri, query);
+
+ HttpResponse resp = OSLCUtils.getResponseFromUrl(setupBaseUrl, queryUrl, basicCreds,
+ OSLCConstants.CT_JSON, headers);
+
+ String respBody = EntityUtils.toString(resp.getEntity());
+
+ // Parse the response
+ JSONArtifact userData = null;
+ try {
+ userData = JSON.parse(respBody);
+ }
+ catch (JSONException e) {
+ // parsing error - we imply the response is not in JSON format
+
+ }
+
+ JSONObject resultJson = null;
+ if (userData instanceof JSONArtifact) {
+ resultJson = (JSONObject)userData;
+ }
+
+ JSONArray s = null;
+ if ( resultJson.containsKey("oslc:results") ) {
+ s = (JSONArray)resultJson.get("oslc:results");
+ }
+ else if ( resultJson.containsKey("rdfs:member") ) {
+ s = (JSONArray)resultJson.getJSONArray("rdfs:member");
+ }
+
+ JSONObject r = (JSONObject) s.get(0);
+ String one = null;
+
+ if ( r.containsKey("rdf:resource") ) {
+ one = r.getString("rdf:resource");
+ }
+ else if ( r.containsKey("rdf:about") ) {
+ one = r.getString("rdf:about");
+ }
+
+ results.add(one);
+
+ if (!results.isEmpty() && onlyOnce)
+ break;
+ }
+
+ return toCollection(results);
+ }
+
+ @Test
+ //
+ // Verify that the Change Request has one and only one dcterms:title
+ //
+ public void changeRequestHasOneTitle() throws JSONException
+ {
+ assertTrue(doc.get(OSLCConstants.DCTERMS_TITLE) instanceof String);
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneDescription() throws JSONException
+ {
+ if ( doc.containsKey(OSLCConstants.DCTERMS_DESC) ) {
+ assertTrue(doc.get(OSLCConstants.DCTERMS_DESC) instanceof String);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneIdentifier() throws JSONException
+ {
+ if ( doc.containsKey(OSLCConstants.DCTERMS_ID) ) {
+ assertTrue( (doc.get(OSLCConstants.DCTERMS_ID) instanceof String) ||
+ (doc.get(OSLCConstants.DCTERMS_ID) instanceof Integer));
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneName() throws JSONException
+ {
+ if ( doc.containsKey(OSLCConstants.DCTERMS_NAME) ) {
+ assertTrue(doc.get(OSLCConstants.DCTERMS_NAME) instanceof String);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneCreatedDate() throws JSONException
+ {
+ if ( doc.containsKey(OSLCConstants.DCTERMS_CREATED) ) {
+ assertTrue(doc.get(OSLCConstants.DCTERMS_CREATED) instanceof String);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneModifiedDate() throws JSONException
+ {
+ if ( doc.containsKey(OSLCConstants.DCTERMS_MODIFIED) ) {
+ assertTrue(doc.get(OSLCConstants.DCTERMS_MODIFIED) instanceof String);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneDiscussion() throws JSONException
+ {
+ if ( doc.containsKey("oslc:discussion") ) {
+ assertTrue(doc.get("oslc:discussion") instanceof JSONObject);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneInstanceShape() throws JSONException
+ {
+ if ( doc.containsKey("oslc:instanceShape") ) {
+ assertTrue(doc.get("oslc:instanceShape") instanceof JSONObject);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneCloseDate() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:closedDate") ) {
+ assertTrue(doc.get("oslc_cm:closedDate") instanceof String);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneStatus() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:status") ) {
+ assertTrue(doc.get("oslc_cm:status") instanceof String);
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneClosedElement() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:closed") ) {
+ assertTrue( (doc.get("oslc_cm:closed") instanceof Boolean) ||
+ (doc.get("oslc_cm:closed") instanceof String));
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostInProgressElement() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:inprogress") ) {
+ assertTrue( (doc.get("oslc_cm:inprogress") instanceof Boolean) ||
+ (doc.get("oslc_cm:inprogress") instanceof String));
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneFixedElement() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:fixed") ) {
+ assertTrue( (doc.get("oslc_cm:fixed") instanceof Boolean) ||
+ (doc.get("oslc_cm:fixed") instanceof String));
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneApprovedElement() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:approved") ) {
+ assertTrue( (doc.get("oslc_cm:approved") instanceof Boolean) ||
+ (doc.get("oslc_cm:approved") instanceof String));
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneReviewedElement() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:reviewed") ) {
+ assertTrue( (doc.get("oslc_cm:reviewed") instanceof Boolean) ||
+ (doc.get("oslc_cm:reviewed") instanceof String));
+ }
+ }
+
+ @Test
+ public void changeRequestHasAtMostOneVerifiedElement() throws JSONException
+ {
+ if ( doc.containsKey("oslc_cm:verified") ) {
+ assertTrue( (doc.get("oslc_cm:verified") instanceof Boolean) ||
+ (doc.get("oslc_cm:verified") instanceof String));
+ }
+ }
+}
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 b89473b..5576731 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
@@ -139,7 +139,7 @@ public class ChangeRequestXmlTests extends TestsBase {
}
@Test
- public void changeRequestHasOneDcTitle() throws XPathExpressionException
+ public void changeRequestHasOneTitle() throws XPathExpressionException
{
// All change requests have exactly one title.
NodeList titles = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_cm_v2:ChangeRequest/dc:title",
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/TestsBase.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/TestsBase.java
index 36ba72a..acf38af 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/TestsBase.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/TestsBase.java
@@ -35,6 +35,12 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
+import org.apache.wink.json4j.JSON;
+import org.apache.wink.json4j.JSONArray;
+import org.apache.wink.json4j.JSONArtifact;
+import org.apache.wink.json4j.JSONException;
+import org.apache.wink.json4j.JSONObject;
+//import org.apache.wink.json4j.compat.JSONArray;
import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
import org.eclipse.lyo.testsuite.server.util.RDFUtils;
@@ -474,5 +480,99 @@ public class TestsBase {
System.out.println(s.toString());
}
}
-
+
+ public static ArrayList<String> getServiceProviderURLsUsingJson(String inBaseURL)
+ throws IOException, XPathException, ParserConfigurationException,
+ SAXException {
+ return getServiceProviderURLsUsingXML(inBaseURL, onlyOnce);
+ }
+
+ public static ArrayList<String> getServiceProviderURLsUsingJson(String inBaseURL, boolean dontGoDeep)
+ throws IOException, XPathException, ParserConfigurationException,
+ SAXException, NullPointerException, JSONException {
+
+ staticSetup();
+
+ // ArrayList to contain the urls from all SPCs
+ ArrayList<String> data = new ArrayList<String>();
+
+ String base=null;
+ if (inBaseURL == null)
+ base = setupBaseUrl;
+ else
+ base = inBaseURL;
+
+ // If we are given a shortcut, then use it and skip the rest
+ if (useThisServiceProvider != null && useThisServiceProvider.length() > 0) {
+ data.add(useThisServiceProvider);
+ return data;
+ }
+
+ HttpResponse resp = OSLCUtils.getResponseFromUrl(base, base,
+ basicCreds, OSLCConstants.CT_JSON, headers);
+ assertEquals("Failed to retrieve ServiceProviders at: "+inBaseURL, HttpStatus.SC_OK, resp.getStatusLine().getStatusCode());
+
+ String respBody = EntityUtils.toString(resp.getEntity());
+
+ // Create mapping of JSON variables
+ JSONArtifact userData = JSON.parse(respBody);
+ JSONObject resultJson = null;
+ if (userData instanceof JSONArtifact) {
+ resultJson = (JSONObject)userData;
+ }
+
+ JSONArray results = (JSONArray)resultJson.get("oslc:serviceProvider");
+
+ // Now walk through the array to get a list of service providers
+ for (int i = 0; i < results.length(); i++) {
+ JSONObject serviceProviderJSON = (JSONObject) results.get(i);
+ String serviceProvider = (String)serviceProviderJSON.get("rdf:about");
+ data.add(serviceProvider);
+ }
+
+ return data;
+ }
+
+ public static ArrayList<String> getCapabilityURLsUsingJson(String xpathStmt,
+ ArrayList<String> serviceUrls, boolean useDefaultUsage) throws IOException,
+ ParserConfigurationException, SAXException,
+ XPathExpressionException, NullPointerException, JSONException {
+
+ // Collection to contain the creationFactory urls from all SPs
+ ArrayList<String> data = new ArrayList<String>();
+
+ for (String base : serviceUrls) {
+ HttpResponse resp = OSLCUtils.getResponseFromUrl(base, base,
+ basicCreds, OSLCConstants.CT_JSON, headers);
+ assertEquals("Failed to retrieve ServiceProviders at: " +base, HttpStatus.SC_OK, resp.getStatusLine().getStatusCode());
+
+ String respBody = EntityUtils.toString(resp.getEntity());
+
+ // Create mapping of JSON variables
+ JSONArtifact userData = JSON.parse(respBody);
+ JSONObject resultJson = null;
+ if (userData instanceof JSONArtifact) {
+ resultJson = (JSONObject)userData;
+ }
+ JSONArray s = (JSONArray)resultJson.get("oslc:service");
+
+ for (int i = 0; i < s.length(); i++) {
+ JSONObject serviceProviderJson = (JSONObject) s.get(i);
+ try {
+ JSONArray u = (JSONArray)serviceProviderJson.get("oslc:queryCapability");
+ JSONObject u1 = (JSONObject) u.get(0);
+
+ JSONObject q = (JSONObject) u1.get("oslc:queryBase");
+ String queryBase = q.getString("rdf:resource");
+
+ data.add(queryBase);
+ }
+ catch (JSONException e) {
+ //ignore
+ }
+ }
+ }
+
+ return data;
+ }
}
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java
index 58d34fa..4fb7129 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java
@@ -19,7 +19,8 @@ package org.eclipse.lyo.testsuite.server.util;
public interface OSLCConstants {
static String RFC_DATE_FORMAT = "yyyy-MM-dd'T'h:m:ss.S'Z'";
- static String DC = "http://purl.org/dc/terms/";
+ static String DC = "http://purl.org/dc/terms/";
+ static String DCTERMS ="dcterms:";
static String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
static String RDFS = "http://www.w3.org/2000/01/rdf-schema#";
static String ATOM = "http://www.w3.org/2005/Atom";
@@ -91,7 +92,7 @@ public interface OSLCConstants {
public static final String RDF_TYPE_PROP = RDF + "type";
public static final String RDFS_MEMBER = RDFS + "member";
- // DCTERMS
+ // DCTERMS URIs
public static final String DC_TITLE_PROP = DC + "title";
public static final String DC_DESC_PROP = DC + "description";
public static final String DC_TYPE_PROP = DC + "type";
@@ -100,5 +101,15 @@ public interface OSLCConstants {
public static final String DC_NAME_PROP = DC + "name";
public static final String DC_CREATED_PROP = DC + "created";
public static final String DC_MODIFIED_PROP = DC + "modified";
-
+
+ // DCTERMSs
+ public static final String DCTERMS_TITLE = DCTERMS + "title";
+ public static final String DCTERMS_DESC = DCTERMS + "description";
+ public static final String DCTERMS_TYPE = DCTERMS + "type";
+ public static final String DCTERMS_PUBLISHER = DCTERMS + "publisher";
+ public static final String DCTERMS_ID = DCTERMS + "identifier";
+ public static final String DCTERMS_NAME = DCTERMS + "name";
+ public static final String DCTERMS_CREATED = DCTERMS + "created";
+ public static final String DCTERMS_MODIFIED = DCTERMS + "modified";
+
}