@Test public void testCustomFieldParameter() throws IOException, JSONException { FindQueryTestCase test = new FindQueryTestCase("non_existant_"+UUID.randomUUID().toString(), false); String testField = "http://www.test.org/test#test_"+UUID.randomUUID(); test.setField(testField); RequestExecutor re = executeQuery(test); JSONObject jQuery = assertResponseQuery(re.getContent()); assertSelectedField(jQuery, testField); }
pw.println(executor.getResponse().getEntity().getContentType().getValue()); pw.println("Content:"); pw.println(executor.getContent());
String content = executor.execute(req).assertStatus(200).assertContentType("application/json").getContent(); log.info("JSON content:\n\n {} \n\n",content); JSONObject json = new JSONObject(content);
return null; //no further checks for tests that expect failure JSONObject jso = new JSONObject(re.getContent()); if(log.isDebugEnabled()){ log.debug("Assert Results: {}",jso.toString(2));
@Test public void testOffsetNegativeNumber() throws IOException, JSONException { FieldQueryTestCase test = new FieldQueryTestCase( "{"+ "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'offset': '-3', " + "'limit': '3', " + "'constraints': [{ " + "'type': 'reference', "+ "'field': 'http:\\/\\/www.test.org\\/test#non-existing-field', "+ "'value': 'http:\\/\\/www.test.org\\/test#NonExistingValue', "+ "}]"+ "}", false); //success but no result //now execute the test RequestExecutor re = executeQuery(test); JSONObject jQuery = assertResponseQuery(re.getContent()); assertTrue("Result Query does not contain offset property",jQuery.has("offset")); assertTrue("Returned offset is != 0",jQuery.getInt("offset") == 0); } @Test
@Test public void testLimitNegativeNumber() throws IOException, JSONException { FieldQueryTestCase test = new FieldQueryTestCase( "{"+ "'selected': [ 'http:\\/\\/www.test.org\\/test#field'], " + "'offset': '0', " + "'limit': '-1', " + "'constraints': [{ " + "'type': 'reference', "+ "'field': 'http:\\/\\/www.test.org\\/test#non-existing-field', "+ "'value': 'http:\\/\\/www.test.org\\/test#NonExistingValue', "+ "}]"+ "}", false); //success but no result //now execute the test RequestExecutor re = executeQuery(test); //test the of the limit was set correctly set to the default (> 0) JSONObject jQuery = assertResponseQuery(re.getContent()); assertTrue("Result Query does not contain Limit property",jQuery.has("limit")); assertTrue("Returned limit is <= 0",jQuery.getInt("limit") > 0); } @Test
@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," + "}]" + "}", false); //expect BadRequest //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")); } }
@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'" + "}]," + "}", false); //expect BadRequest //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")); } @Test
@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', " + "}]" + "}", false); //expect BadRequest //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")); } @Test
FindQueryTestCase test = new FindQueryTestCase("non_existant_"+UUID.randomUUID().toString(), false); RequestExecutor re = executeQuery(test); JSONObject jQuery = assertResponseQuery(re.getContent()); assertTrue("Result Query does not contain Limit property",jQuery.has("limit")); assertTrue("Returned limit is <= 0",jQuery.getInt("limit") > 0);