Search in sources :

Example 16 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class QueryTestBase method testDefaultRangeConstraintDatatypeProperty.

@Test
public void testDefaultRangeConstraintDatatypeProperty() throws IOException, JSONException {
    FieldQueryTestCase test = new FieldQueryTestCase("{" + "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'constraints': [{ " + "'type': 'range', " + "'field': 'http:\\/\\/www.test.org\\/test#field', " + "'lowerBound': 1000," + "'inclusive': true," + "}]" + "}", //expect BadRequest
    false);
    //now execute the test
    RequestExecutor re = executeQuery(test);
    JSONObject jQuery = assertResponseQuery(re.getContent());
    JSONArray jConstraints = jQuery.optJSONArray("constraints");
    assertNotNull("Result Query does not contain the constraints Array", jConstraints);
    assertTrue("Result Query Constraint Array does not contain the expected Constraint", jConstraints.length() == 1);
    JSONObject jConstraint = jConstraints.optJSONObject(0);
    assertNotNull("Constraint Array does not contain JSONObjects", jConstraint);
    assertTrue("Returned Query does not contain the default data type", jConstraint.has("datatype"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 17 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class QueryTestBase method testDefaultTextConstraintPatternTypeProperty.

@Test
public void testDefaultTextConstraintPatternTypeProperty() throws IOException, JSONException {
    FieldQueryTestCase test = new FieldQueryTestCase("{" + "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'constraints': [{ " + "'type': 'text', " + "'text': 'Paris', " + "'field': 'http:\\/\\/www.test.org\\/test#field', " + "}]" + "}", //expect BadRequest
    false);
    //now execute the test
    RequestExecutor re = executeQuery(test);
    JSONObject jQuery = assertResponseQuery(re.getContent());
    JSONArray jConstraints = jQuery.optJSONArray("constraints");
    assertNotNull("Result Query does not contain the constraints Array", jConstraints);
    assertTrue("Result Query Constraint Array does not contain the expected Constraint", jConstraints.length() == 1);
    JSONObject jConstraint = jConstraints.optJSONObject(0);
    assertNotNull("Constraint Array does not contain JSONObjects", jConstraint);
    assertTrue("The 'patternType' property MUST BE set for returned TextConstraints", jConstraint.has("patternType"));
    assertEquals("Default for patternType MUST BE 'none'", "none", jConstraint.getString("patternType"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 18 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class QueryTestBase method testValueConstraintDefaultDataType.

@Test
public void testValueConstraintDefaultDataType() throws IOException, JSONException {
    FieldQueryTestCase test = new FieldQueryTestCase("{" + "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'constraints': [{ " + "'type': 'value'," + "'value': 'Paris'," + "'field': 'http:\\/\\/www.test.org\\/test#field'" + "}]," + "}", //expect BadRequest
    false);
    //now execute the test
    RequestExecutor re = executeQuery(test);
    JSONObject jQuery = assertResponseQuery(re.getContent());
    JSONArray jConstraints = jQuery.optJSONArray("constraints");
    assertNotNull("Result Query does not contain the constraints Array", jConstraints);
    assertTrue("Result Query Constraint Array does not contain the expected Constraint", jConstraints.length() == 1);
    JSONObject jConstraint = jConstraints.optJSONObject(0);
    assertNotNull("Constraint Array does not contain JSONObjects", jConstraint);
    assertTrue("Returned Query does not contain the default data type", jConstraint.has("datatype"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 19 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class HttpQueryHeaderGetTest method testRemovalOfAccept.

@Test
public void testRemovalOfAccept() throws IOException, JSONException {
    //now test the removal of headers
    //first a normal request with application/rdf+xml
    String id = "http://dbpedia.org/resource/Paris";
    RequestExecutor re = executor.execute(builder.buildGetRequest(DBPEDIA_SITE_PATH + "/entity", "id", id, "header_Accept", //empty value to remove
    "").withHeader("Accept", //MUST override the rdf+xml
    "application/rdf+xml"));
    re.assertStatus(200);
    //The default format (JSON) is expected
    assertEntity(re.getContent(), id, DBPEDIA_SITE_ID);
}
Also used : RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) Test(org.junit.Test)

Example 20 with RequestExecutor

use of org.apache.stanbol.commons.testing.http.RequestExecutor in project stanbol by apache.

the class HttpQueryHeaderGetTest method testSetAccept.

@Test
public void testSetAccept() throws IOException {
    //first a normal request with application/rdf+xml
    String id = "http://dbpedia.org/resource/Paris";
    RequestExecutor re = executor.execute(builder.buildGetRequest(DBPEDIA_SITE_PATH + "/entity", "id", id, "header_Accept", //parse the rdf+nt format as query parameter
    "text/rdf+nt"));
    re.assertStatus(200);
    re.assertContentType("text/rdf+nt");
    re.assertContentContains("<http://dbpedia.org/resource/Paris> " + "<http://www.w3.org/2000/01/rdf-schema#label> " + "\"Paris\"@en .");
}
Also used : RequestExecutor(org.apache.stanbol.commons.testing.http.RequestExecutor) Test(org.junit.Test)

Aggregations

RequestExecutor (org.apache.stanbol.commons.testing.http.RequestExecutor)31 Test (org.junit.Test)18 JSONObject (org.codehaus.jettison.json.JSONObject)12 HttpDelete (org.apache.http.client.methods.HttpDelete)7 ArrayList (java.util.ArrayList)4 Request (org.apache.stanbol.commons.testing.http.Request)4 JSONArray (org.codehaus.jettison.json.JSONArray)4 HttpPut (org.apache.http.client.methods.HttpPut)3 InputStream (java.io.InputStream)2 List (java.util.List)2 Set (java.util.Set)2 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)2 DbpediaQueryTest (org.apache.stanbol.entityhub.it.query.DbpediaQueryTest)2 Before (org.junit.Before)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 TreeSet (java.util.TreeSet)1 ZipEntry (java.util.zip.ZipEntry)1