aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuhong Yin2012-04-25 11:43:12 (EDT)
committerMichael Fiedler2012-04-25 15:00:31 (EDT)
commit0b4061cd9be51000d8d3ed6f5ae3cd2c4f633e3d (patch)
tree609f81bcbb1a0c3ba0c7c098a2c3e73b18606cbc
parentf04abfebbf0ba1068d37ae67e196891ab5cdca4e (diff)
downloadorg.eclipse.lyo.testsuite-0b4061cd9be51000d8d3ed6f5ae3cd2c4f633e3d.zip
org.eclipse.lyo.testsuite-0b4061cd9be51000d8d3ed6f5ae3cd2c4f633e3d.tar.gz
org.eclipse.lyo.testsuite-0b4061cd9be51000d8d3ed6f5ae3cd2c4f633e3d.tar.bz2
Bug 377193 - create test cases to support json for queries
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/oslcv2/SimplifiedQueryJsonTests.java153
1 files changed, 153 insertions, 0 deletions
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/oslcv2/SimplifiedQueryJsonTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/oslcv2/SimplifiedQueryJsonTests.java
new file mode 100644
index 0000000..fb23f4e
--- /dev/null
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/oslcv2/SimplifiedQueryJsonTests.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.eclipse.lyo.testsuite.oslcv2;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.parsers.ParserConfigurationException;
+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.JSONArtifact;
+import org.apache.wink.json4j.JSONException;
+import org.eclipse.lyo.testsuite.oslcv2.SimplifiedQueryBaseTests;
+import org.eclipse.lyo.testsuite.oslcv2.TestsBase;
+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.xml.sax.SAXException;
+
+/**
+ * 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 SimplifiedQueryJsonTests extends SimplifiedQueryBaseTests {
+
+ public SimplifiedQueryJsonTests(String thisUri) {
+ super(thisUri);
+ }
+
+ @Before
+ public void setup() throws IOException, ParserConfigurationException,
+ SAXException, XPathException {
+ super.setup();
+ }
+
+ @Parameters
+ public static Collection<Object[]> getAllDescriptionUrls()
+ throws IOException, ParserConfigurationException, SAXException,
+ XPathException {
+ // 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.
+ String v = "//oslc_v2:QueryCapability/oslc_v2:queryBase/@rdf:resource";
+ ArrayList<String> serviceUrls = getServiceProviderURLsUsingXML(null);
+ ArrayList<String> capabilityURLsUsingXML = TestsBase
+ .getCapabilityURLsUsingXML(v, serviceUrls, true);
+ return toCollection(capabilityURLsUsingXML);
+ }
+
+ protected void validateNonEmptyResponse(String query)
+ throws XPathExpressionException, IOException,
+ ParserConfigurationException, SAXException, JSONException {
+ String queryUrl = OSLCUtils.addQueryStringToURL(currentUrl, query);
+
+ // Send JSON request
+ HttpResponse response = OSLCUtils.getResponseFromUrl(setupBaseUrl,
+ queryUrl, basicCreds, OSLCConstants.CT_JSON, headers);
+
+ int statusCode = response.getStatusLine().getStatusCode();
+ if (HttpStatus.SC_OK != statusCode)
+ {
+ EntityUtils.consume(response.getEntity());
+ throw new IOException("Response code: " + statusCode + " for " + queryUrl);
+ }
+
+ String responseBody = EntityUtils.toString(response.getEntity());
+
+ //
+ // Validate JSON response
+ //
+ // TODO: add more detailed validation
+ assertTrue("query response is in Json format.", JSON.parse(responseBody) instanceof JSONArtifact);
+ }
+
+ @Test
+ public void validEqualsQueryContainsExpectedResource() throws IOException,
+ ParserConfigurationException, SAXException,
+ XPathExpressionException, JSONException {
+ String query = getQueryUrlForalidEqualsQueryContainsExpectedResources();
+ validateNonEmptyResponse(query);
+ }
+
+ @Test
+ public void validNotEqualQueryContainsExpectedResource()
+ throws IOException, SAXException, ParserConfigurationException,
+ XPathExpressionException, JSONException {
+ String query = getQueryUrlForValidNotEqualQueryContainsExpectedResources();
+ validateNonEmptyResponse(query);
+ }
+
+ @Test
+ public void validLessThanQueryContainsExpectedResources()
+ throws IOException, SAXException, ParserConfigurationException,
+ XPathExpressionException, JSONException {
+ String query = getQueryUrlForValidLessThanQueryContainsExpectedResources();
+ validateNonEmptyResponse(query);
+ }
+
+ @Test
+ public void validGreaterThanQueryContainsExpectedDefects()
+ throws IOException, SAXException, ParserConfigurationException,
+ XPathExpressionException, JSONException {
+ String query = getQueryUrlForValidGreaterThanQueryContainsExpectedResources();
+ validateNonEmptyResponse(query);
+ }
+
+ @Test
+ public void validCompoundQueryContainsExpectedResource()
+ throws IOException, SAXException, ParserConfigurationException,
+ XPathExpressionException, JSONException {
+ String query = getQueryUrlForValidCompoundQueryContainsExpectedResources();
+ validateNonEmptyResponse(query);
+ }
+
+ @Test
+ public void fullTextSearchContainsExpectedResults() throws IOException,
+ ParserConfigurationException, SAXException,
+ XPathExpressionException, JSONException {
+ String query = getQueryUrlForFullTextSearchContainsExpectedResults();
+ validateNonEmptyResponse(query);
+ }
+} \ No newline at end of file