summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpmcmahan2012-10-17 16:09:06 (EDT)
committer pmcmahan2012-10-17 16:09:06 (EDT)
commitfccd92e1b3106585e1834e6f55f9cde33df00034 (patch)
tree997ce5109f64d9ba33f79dc13f7a381fad1e47c9
parent413da59dc4c1516dc65a2827544e7eeb4feb9e8f (diff)
downloadorg.eclipse.lyo.client-fccd92e1b3106585e1834e6f55f9cde33df00034.zip
org.eclipse.lyo.client-fccd92e1b3106585e1834e6f55f9cde33df00034.tar.gz
org.eclipse.lyo.client-fccd92e1b3106585e1834e6f55f9cde33df00034.tar.bz2
-rw-r--r--org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/OslcClient.java25
-rw-r--r--org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/resources/TestCase.java2
-rw-r--r--org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RQMFormSample.java55
-rw-r--r--org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RTCFormSample.java59
4 files changed, 120 insertions, 21 deletions
diff --git a/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/OslcClient.java b/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/OslcClient.java
index 138e901..a417c99 100644
--- a/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/OslcClient.java
+++ b/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/OslcClient.java
@@ -153,6 +153,19 @@ public class OslcClient {
}
/**
+ * Create (POST) an artifact to a URL - usually an OSLC Creation Factory
+ * @param url
+ * @param artifact
+ * @param mediaType
+ * @param acceptType
+ * @return
+ */
+ public ClientResponse createResource(final String url, final Object artifact, String mediaType, String acceptType) {
+ RestClient restClient = new RestClient(clientConfig);
+ return restClient.resource(url).contentType(mediaType).accept(acceptType).header(OSLCConstants.OSLC_CORE_VERSION,"2.0").post(artifact);
+ }
+
+ /**
* Update (PUT) an artifact to a URL - usually the URL for an existing OSLC artifact
* @param url
* @param artifact
@@ -164,6 +177,18 @@ public class OslcClient {
return restClient.resource(url).contentType(mediaType).header(OSLCConstants.OSLC_CORE_VERSION,"2.0").put(artifact);
}
+ /**
+ * Update (PUT) an artifact to a URL - usually the URL for an existing OSLC artifact
+ * @param url
+ * @param artifact
+ * @param mediaType
+ * @param acceptType
+ * @return
+ */
+ public ClientResponse updateResource(final String url, final Object artifact, String mediaType, String acceptType) {
+ RestClient restClient = new RestClient(clientConfig);
+ return restClient.resource(url).contentType(mediaType).accept(acceptType).header(OSLCConstants.OSLC_CORE_VERSION,"2.0").put(artifact);
+ }
/**
* Create a Wink Resource for the given OslcQuery object
diff --git a/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/resources/TestCase.java b/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/resources/TestCase.java
index 9b5fb40..6c218f3 100644
--- a/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/resources/TestCase.java
+++ b/org.eclipse.lyo.client.java/src/main/java/org/eclipse/lyo/client/oslc/resources/TestCase.java
@@ -154,7 +154,7 @@ public final class TestCase
@OslcTitle("Tests Change Request")
public Link[] getTestsChangeRequests()
{
- return usesTestScripts.toArray(new Link[usesTestScripts.size()]);
+ return testsChangeRequests.toArray(new Link[testsChangeRequests.size()]);
}
@OslcDescription("Test Script used by the Test Case.")
diff --git a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RQMFormSample.java b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RQMFormSample.java
index 1528c56..47f903b 100644
--- a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RQMFormSample.java
+++ b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RQMFormSample.java
@@ -19,34 +19,38 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.apache.wink.client.ClientResponse;
+import org.eclipse.lyo.client.exception.RootServicesException;
import org.eclipse.lyo.client.oslc.OSLCConstants;
import org.eclipse.lyo.client.oslc.OslcClient;
import org.eclipse.lyo.client.oslc.jazz.JazzFormAuthClient;
import org.eclipse.lyo.client.oslc.jazz.JazzRootServicesHelper;
-import org.eclipse.lyo.client.exception.RootServicesException;
import org.eclipse.lyo.client.oslc.resources.OslcQuery;
import org.eclipse.lyo.client.oslc.resources.OslcQueryParameters;
import org.eclipse.lyo.client.oslc.resources.OslcQueryResult;
+import org.eclipse.lyo.client.oslc.resources.TestCase;
import org.eclipse.lyo.client.oslc.resources.TestResult;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.ParseException;
+import org.eclipse.lyo.oslc4j.core.model.Link;
+import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
/**
* Samples of logging in to Rational Quality Manager and running OSLC operations
*
* - run an OLSC TestResult query and retrieve OSLC TestResults and de-serialize them as Java objects
* - retrieve an OSLC TestResult and print it as XML
- * - (future) create a new TestCase
- * - (future) update an existing TestCase
+ * - create a new TestCase
+ * - update an existing TestCase
*
*/
public class RQMFormSample {
@@ -132,7 +136,38 @@ public class RQMFormSample {
processRawResponse(rawResponse);
rawResponse.consumeContent();
- //SCENARIO C: RQM TestCase creation and update...TBD
+ //SCENARIO C: RQM TestCase creation and update
+ TestCase testcase = new TestCase();
+ testcase.setTitle("Accessibility verification using a screen reader");
+ testcase.setDescription("This test case uses a screen reader application to ensure that the web browser content fully complies with accessibility standards");
+ testcase.addTestsChangeRequest(new Link(new URI("http://cmprovider/changerequest/1"), "Implement accessibility in Pet Store application"));
+
+ //Get the Creation Factory URL for test cases so that we can create a test case
+ String testcaseCreation = client.lookupCreationFactory(
+ serviceProviderUrl, OSLCConstants.OSLC_QM_V2,
+ testcase.getRdfTypes()[0].toString());
+
+ //Create the test case
+ ClientResponse creationResponse = client.createResource(
+ testcaseCreation, testcase,
+ OslcMediaType.APPLICATION_RDF_XML);
+ creationResponse.consumeContent();
+ String testcaseLocation = creationResponse.getHeaders().getFirst(HttpHeaders.LOCATION);
+ System.out.println("Test Case created a location " + testcaseLocation);
+
+ //Get the test case from the service provider and update its title property
+ testcase = client.getResource(testcaseLocation,
+ OslcMediaType.APPLICATION_RDF_XML).getEntity(
+ TestCase.class);
+ testcase.setTitle(testcase.getTitle() + " (updated)");
+
+ //Create a partial update URL so that only the title will be updated.
+ //Assuming (for readability) that the test case URL does not already contain a '?'
+ String updateUrl = testcase.getAbout() + "?oslc.properties=dcterms:title";
+
+ //Update the test case at the service provider
+ client.updateResource(updateUrl, testcase,
+ OslcMediaType.APPLICATION_RDF_XML).consumeContent();
}
diff --git a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RTCFormSample.java b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RTCFormSample.java
index 694afb6..eff863c 100644
--- a/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RTCFormSample.java
+++ b/org.eclipse.lyo.samples.clients/src/main/java/org/eclipse/lyo/client/oslc/samples/RTCFormSample.java
@@ -19,12 +19,18 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.apache.wink.client.ClientResponse;
-import org.eclipse.lyo.client.exception.JazzAuthFailedException;
import org.eclipse.lyo.client.exception.RootServicesException;
import org.eclipse.lyo.client.oslc.OSLCConstants;
import org.eclipse.lyo.client.oslc.OslcClient;
@@ -34,12 +40,8 @@ import org.eclipse.lyo.client.oslc.resources.ChangeRequest;
import org.eclipse.lyo.client.oslc.resources.OslcQuery;
import org.eclipse.lyo.client.oslc.resources.OslcQueryParameters;
import org.eclipse.lyo.client.oslc.resources.OslcQueryResult;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.ParseException;
+import org.eclipse.lyo.oslc4j.core.model.Link;
+import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
/**
* Samples of logging in to Rational Team Concert and running OSLC operations
@@ -47,8 +49,8 @@ import org.apache.commons.cli.ParseException;
*
* - run an OLSC ChangeRequest query and retrieve OSLC ChangeRequests and de-serialize them as Java objects
* - retrieve an OSLC ChangeRequest and print it as XML
- * - (future) create a new ChangeRequest
- * - (future) update an existing ChangeRequest
+ * - create a new ChangeRequest
+ * - update an existing ChangeRequest
*
*/
public class RTCFormSample {
@@ -134,8 +136,45 @@ public class RTCFormSample {
processRawResponse(rawResponse);
rawResponse.consumeContent();
- //SCENARIO C: RTC Workitem creation and update...TBD
+ //SCENARIO C: RTC Workitem creation and update
+ ChangeRequest changeRequest = new ChangeRequest();
+ changeRequest.setTitle("Implement accessibility in Pet Store application");
+ changeRequest.setDescription("Image elements must provide a description in the 'alt' attribute for consumption by screen readers.");
+ changeRequest.addTestedByTestCase(new Link(new URI("http://qmprovider/testcase/1"), "Accessibility verification using a screen reader"));
+ changeRequest.addDctermsType("task");
+
+ //Get the Creation Factory URL for change requests so that we can create one
+ String changeRequestCreation = client.lookupCreationFactory(
+ serviceProviderUrl, OSLCConstants.OSLC_CM_V2,
+ changeRequest.getRdfTypes()[0].toString());
+
+ //Create the change request
+ ClientResponse creationResponse = client.createResource(
+ changeRequestCreation, changeRequest,
+ OslcMediaType.APPLICATION_RDF_XML,
+ OslcMediaType.APPLICATION_RDF_XML);
+ String changeRequestLocation = creationResponse.getHeaders().getFirst(HttpHeaders.LOCATION);
+ creationResponse.consumeContent();
+ System.out.println("Change Request created a location " + changeRequestLocation);
+
+
+ //Get the change request from the service provider and update its title property
+ changeRequest = client.getResource(changeRequestLocation,
+ OslcMediaType.APPLICATION_RDF_XML).getEntity(
+ ChangeRequest.class);
+ changeRequest.setTitle(changeRequest.getTitle() + " (updated)");
+
+ //Create a partial update URL so that only the title will be updated.
+ //Assuming (for readability) that the change request URL does not already contain a '?'
+ String updateUrl = changeRequest.getAbout() + "?oslc.properties=dcterms:title";
+
+ //Update the change request at the service provider
+ ClientResponse updateResponse = client.updateResource(
+ updateUrl, changeRequest,
+ OslcMediaType.APPLICATION_RDF_XML,
+ OslcMediaType.APPLICATION_RDF_XML);
+ updateResponse.consumeContent();
}
} catch (RootServicesException re) {