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"));
}
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"));
}
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"));
}
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);
}
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 .");
}
Aggregations