You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2011/07/29 12:38:33 UTC

svn commit: r1152160 - in /incubator/stanbol/trunk: entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/ entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/ integration-tests/src/test/java/org/apache/stan...

Author: rwesten
Date: Fri Jul 29 10:38:31 2011
New Revision: 1152160

URL: http://svn.apache.org/viewvc?rev=1152160&view=rev
Log:
STANBOL-299: Improved Integration Test, Added Tests for Entity retrieval for ReferencedSite and SiteManager.

* Bow nearly all of the data sent in Responses is validated 
* Most of that is to validate the JSON serialiser, but is also checks some semantic requirements (e.g. if the metadata of an Entity are about the Entity)
* Corrected a bug that prevented the validation of /find query tests
* Moved all the methods that asserted JSON formatted responses to a Utility class. Not they can be used similar than the org.junit.Assert class
* Added test for retrieval of Entities to the ReferencedSiteFieldQueryTest and the SitesManagerFieldQueryTest. Because they now cover the whole interface of the ReferencedSite and SiteManager RESTful service I renamed than to ReferencedSiteTest and SitesManagerTest and moved them directly into the itegration-tests package of the Entityhub

still open:
* Test for the specific services of the Entityhub (full CRUD and lookup)
* Entity mappings
* specifics tests of the RDF serialisations. 

Added:
    incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java   (with props)
    incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/DbpediaDefaultdataConstants.java   (with props)
    incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ReferencedSiteTest.java   (contents, props changed)
      - copied, changed from r1151863, incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/ReferencedSiteFieldQueryTest.java
    incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/SitesManagerTest.java   (contents, props changed)
      - copied, changed from r1151863, incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/SitesManagerFieldQueryTest.java
Removed:
    incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/ReferencedSiteFieldQueryTest.java
    incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/SitesManagerFieldQueryTest.java
Modified:
    incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/FindQueryTestCase.java
    incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java
    incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java
    incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/EntityHubTest.java
    incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/DbpediaQueryTest.java

Added: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java?rev=1152160&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java (added)
+++ incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java Fri Jul 29 10:38:31 2011
@@ -0,0 +1,252 @@
+package org.apache.stanbol.entityhub.test.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.stanbol.commons.testing.http.RequestExecutor;
+import org.apache.stanbol.entityhub.test.query.QueryTestCase;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+
+/**
+ * Utilities for asserting JSON responses encoded in the Entityhub JSON format.
+ * The intended usage is similar to Ass
+ * @author Rupert Westenthaler.
+ *
+ */
+public class AssertEntityhubJson {
+    
+    private AssertEntityhubJson(){/*noinstances*/}
+
+    /**
+     * Validates Results of a Query (/find or /query requests) based on the
+     * data defined by the test case
+     * @param re the {@link RequestExecutor} used for the test case
+     * @param test the query test case
+     * @throws JSONException in case the {@link RequestExecutor#getContent()} are
+     * no valid JSON. NOTE that the contents are only parsed if the
+     * {@link QueryTestCase#getExpectedStatus()} is a 2xx status code.
+     */
+    public static void assertQueryResults(RequestExecutor re, QueryTestCase test) throws JSONException{
+        re.assertStatus(test.getExpectedStatus());
+        re.assertContentType("application/json"); //currently only application/json is supported
+        if(!test.expectsSuccess()){
+            return; //no further checks for tests that expect failure
+        }
+        JSONObject jso = new JSONObject(re.getContent());
+        JSONArray results = jso.getJSONArray("results");
+        if(test.expectesResults()){
+            assertTrue("Missing Results for Query: \n "+test,
+                results.length() > 0);
+        } else {
+            assertTrue("Unexpected Results for Query:\n "+test,
+                results.length() == 0);
+        }
+        Set<String> expectedIds;
+        if(test.getExpectedResultIds() != null && !test.getExpectedResultIds().isEmpty()){
+            expectedIds = new HashSet<String>(test.getExpectedResultIds());
+        } else {
+            expectedIds = null;
+        }
+        
+        //iterate over the results
+        //General NOTE:
+        //  use opt**(..) methods to avoid JSON Exception. We want to parse
+        //  everything and than do asserts!
+        for(int i=0;i<results.length();i++){
+            JSONObject result = results.getJSONObject(i);
+            String id = result.optString("id", null);
+            assertNotNull("ID missing for an Result", id);
+            if(expectedIds != null){
+                expectedIds.remove(id); //not all results must be in the list
+            }
+            if(test.getProhibitedResultIds() != null){
+                assertFalse("Prohibited Result '"+id+"' found!",
+                    test.getProhibitedResultIds().contains(id));
+            }
+            assertRepresentation(result,test.getRequiredFields(),test.getAllowedFields());
+        }
+        if(expectedIds != null){ // if there where expected results check that all where found
+            assertTrue("The following expected results where missing in the Response: \n "+expectedIds,
+                expectedIds.isEmpty());
+        }
+    }
+
+    /**
+     * Asserts that the Query is present in the response and if so returns the
+     * query
+     * @param content the returned content
+     * @return the query as contained in the response
+     * @throws JSONException on any Error while parsing the JSON query from the
+     * parsed content
+     */
+    public static JSONObject assertResponseQuery(String content) throws JSONException {
+        assertNotNull("The content of the Response is NULL",content);
+        JSONObject jResult = new JSONObject(content);
+        JSONObject jQuery = jResult.optJSONObject("query");
+        assertNotNull("Result does not contain the processed Query",jQuery);
+        return jQuery;
+    }
+
+    /**
+     * Asserts that the selected JSONArray of the field query returned within
+     * the result list contains parsed selected fields
+     * @param jQuery the query e.g. as returned by 
+     * {@link #assertQueryResults(RequestExecutor, QueryTestCase)}
+     * @return the selected fields for further processing
+     * @throws JSONException on any error while parsing the JSON
+     */
+    public static JSONArray assertSelectedField(JSONObject jQuery,String...selected) throws JSONException {
+        Set<String> selectedSet = new HashSet<String>();
+        if(selected == null || selected.length == 0) {
+            selectedSet = Collections.emptySet();
+        } else {
+            selectedSet = new HashSet<String>(Arrays.asList(selected));
+        }
+        JSONArray jSelected = jQuery.optJSONArray("selected");
+        assertNotNull("Result Query is missing the 'selected' property",jSelected);
+        assertTrue("Result Query is expected to have at least a single selected field",
+            jSelected.length() > 0);
+        boolean found = false;
+        for(int i=0;i<jSelected.length() && !found;i++){
+            String selectedField = jSelected.optString(i,null);
+            assertNotNull("Selected array contains a NULL element \n"+jSelected.toString(4),
+                selectedField);
+            selectedSet.remove(selectedField);
+        }
+        assertTrue("Fields "+selectedSet+" are not selected by\n"+jSelected.toString(4),
+            selectedSet.isEmpty());
+        return jSelected;
+    }
+
+    /**
+     * Asserts that the parsed Stirng is an valid Entity. This Method only tests
+     * for the Entity properties use 
+     * {@link #assertRepresentation(JSONObject, Collection, Collection)} to check for
+     * required/optional fields of the representation and metadata
+     * @param content the content e.g. as returned by an request to the 
+     * Entityhub
+     * @param to test the id or <code>null</code> to skip this test
+     * @param to test the site or <code>null</code> to skip this test
+     * @return the parsed Entity typically used for further tests
+     */
+    public static JSONObject assertEntity(String content,String id, String site) throws JSONException {
+        assertNotNull("The content to parse the Entity from is NULL",content);
+        JSONObject jEntity = new JSONObject(content);
+        if(id != null){
+            assertEquals("Entity has the wrong ID", id,jEntity.optString("id", null));
+        } else {
+            id = jEntity.optString("id", null);
+            assertNotNull("ID of the Entity MUST NOT be NULL",id);
+        }
+        if(site != null){
+            assertEquals("Entity has the wrong Site", site, jEntity.optString("site",null));
+        }
+        
+        assertTrue("Representation is missing",jEntity.has("representation"));
+        JSONObject jRepresentation = jEntity.getJSONObject("representation");
+        assertNotNull("Representation is not an JSON Object",jRepresentation);
+        assertEquals("Representation MUST have the same ID as the the Entity",
+            id,jEntity.optString("id", null));
+        
+        assertTrue("Metadata are missing",jEntity.has("metadata"));
+        JSONObject jMetadata = jEntity.getJSONObject("metadata");
+        assertNotNull("Metadata is not an JSON Object",jMetadata);
+        Map<String,Set<List<String>>> metadata = assertRepresentation(jMetadata, Arrays.asList(
+            "http://www.iks-project.eu/ontology/rick/model/isChached",
+            "http://www.iks-project.eu/ontology/rick/model/about",
+            "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),null);
+        assertTrue("The Metadata of an Entity MUST BE about the Entity",
+            metadata.get("http://www.iks-project.eu/ontology/rick/model/about")
+                .contains(Arrays.asList(id,"xsd:anyURI")));
+        return jEntity;
+    }
+
+    /**
+     * Asserts a JSONObject that represents a Representation for allowed and
+     * required fields. Any field that is not required or optional will cause
+     * an assertion to fail. Any required field that is missing will also fail
+     * this test.
+     * @param jRepresentation
+     * @param required
+     * @param optional
+     * @return the values of the Representation with the fields as key and the
+     * values as value. The values contain the string value at index '0' and the 
+     * xsd:datatype or xml:lang or <code>null</code> (if none) at index '1'
+     */
+    public static Map<String,Set<List<String>>> assertRepresentation(JSONObject jRepresentation, Collection<String> required,Collection<String> optional) throws JSONException {
+        Set<String> checkRequiredFields = new HashSet<String>(); //copy over the required fields
+        if(required != null && !required.isEmpty()){
+            checkRequiredFields.addAll(required);
+        }
+        checkRequiredFields.add("id"); //the "id" is required by all representations
+        Map<String,Set<List<String>>> valueMap = new HashMap<String,Set<List<String>>>();
+        for(Iterator<?> keys = jRepresentation.keys(); keys.hasNext();){
+            Object key = keys.next();
+            assertFalse("Duplicate 'field' "+key,valueMap.containsKey(key));
+            if(checkRequiredFields == null || !checkRequiredFields.remove(key)){
+                //process key
+                if(optional != null){
+                    assertTrue("Field "+key+" is not an expected one: \n" +
+                    		" required: "+required+"\n"+
+                    		" optional: "+optional+"\n"+
+                    		" representation: "+jRepresentation.toString(4),
+                        optional.contains(key));
+                }
+            }
+            if(!"id".equals(key)){
+                Set<List<String>> values = new HashSet<List<String>>();
+                JSONArray jValues = jRepresentation.getJSONArray(key.toString());
+                assertTrue("Fields MUST contain at least a single value!",jValues.length() > 0);
+                for(int i=0;i<jValues.length();i++){
+                    JSONObject fieldValue = jValues.optJSONObject(i);
+                    assertNotNull("Values for field "+key+" does contain an value " +
+                    		"that is not an JSONObject "+jValues.optString(i),
+                    		fieldValue);
+                    String[] value = new String[2];
+                    value[0] = fieldValue.optString("value");
+                    value[1] = null;
+                    assertNotNull("All Field-values MUST have the 'value' property",value[0]);
+                    assertFalse("All Field-values MUST not be empty",value[0].isEmpty());
+                    if(fieldValue.has("xsd:datatype")){
+                        value[1] = fieldValue.getString("xsd:datatype");
+                        assertFalse("The 'xsd:datatype' (if present) MUST NOT be empty",value[1].isEmpty());
+                    }
+                    if(fieldValue.has("xml:lang")){
+                        assertNull("Field-values MUST NOT have both 'xsd:datatype' and 'xml:lang' defined!",
+                            value[1]);
+                        value[1] = fieldValue.getString("xml:lang");
+                        assertFalse("The 'xml:lang' (if present) MUST NOT be empty",value[1].isEmpty());
+                    }
+                    assertFalse("Duplicate value "+value+" for field "+key,
+                        values.contains(value));
+                    values.add(Arrays.asList(value));
+                    //both xsd:datatype and xml:lang are optional depending on the
+                    //type of the value. Therefore it can not be tested
+                    //the 'type' property is deprecated
+                }
+                valueMap.put(key.toString(), values);
+            }
+        }
+        if(checkRequiredFields != null){
+            assertTrue("Missing required Fields "+checkRequiredFields,
+                checkRequiredFields.isEmpty());
+        }
+        return valueMap;
+    }
+
+}

Propchange: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/FindQueryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/FindQueryTestCase.java?rev=1152160&r1=1152159&r2=1152160&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/FindQueryTestCase.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/FindQueryTestCase.java Fri Jul 29 10:38:31 2011
@@ -1,10 +1,17 @@
 package org.apache.stanbol.entityhub.test.query;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 
 public class FindQueryTestCase extends QueryTestCase {
 
+    /**
+     * If {@link #getField()} set this field is expected to be used as default
+     * search field (rdfs:label)
+     */
+    public static final String DEFAULT_SEARCH_FIELD = "http://www.w3.org/2000/01/rdf-schema#label";
+    
     private final String text;
     private String language;
     private String field;
@@ -66,6 +73,12 @@ public class FindQueryTestCase extends Q
                               Collection<String> prohibitedResultIds){
         super(status,expectedResultIds,prohibitedResultIds);
         this.text = text;
+        //For queries that should succeed
+        if(expectsSuccess()){
+            //add the default search field (needed to correctly init that the
+            //default search field is required to be included in results
+            setField(null);
+        }
     }
     /**
      * @return the language
@@ -92,6 +105,9 @@ public class FindQueryTestCase extends Q
      */
     public final void setField(String field) {
         this.field = field;
+        //set also the new field as required for results!
+        setRequiredFields(Arrays.asList(
+            field == null ? DEFAULT_SEARCH_FIELD : field));
     }
     /**
      * Getter for the offset of this query
@@ -140,7 +156,7 @@ public class FindQueryTestCase extends Q
         StringBuilder sb = new StringBuilder();
         addParam(sb,"name",text);
         addParam(sb, "field", field);
-        addParam(sb, "language", language);
+        addParam(sb, "lang", language);
         addParam(sb, "offset", offset);
         addParam(sb, "limit", limit);
         return sb.toString();

Modified: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java?rev=1152160&r1=1152159&r2=1152160&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java Fri Jul 29 10:38:31 2011
@@ -1,16 +1,14 @@
 package org.apache.stanbol.entityhub.test.query;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertTrue;
+import static org.apache.stanbol.entityhub.test.it.AssertEntityhubJson.assertResponseQuery;
+import static org.apache.stanbol.entityhub.test.it.AssertEntityhubJson.assertSelectedField;
+import static org.apache.stanbol.entityhub.test.it.AssertEntityhubJson.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
 import java.util.UUID;
 import java.util.Map.Entry;
 
@@ -98,129 +96,10 @@ public abstract class QueryTestBase exte
             request.withHeader(header.getKey(), header.getValue());
         }
         request.withContent(test.getContent());
-        return executor.execute(request);
+        RequestExecutor re = executor.execute(request);
+        assertQueryResults(re, test);
+        return re;
     }
-    /**
-     * Validates Results of a Query (/find or /query requests) based on the
-     * data defined by the test case
-     * @param re the {@link RequestExecutor} used for the test case
-     * @param test the query test case
-     * @throws JSONException in case the {@link RequestExecutor#getContent()} are
-     * no valid JSON. NOTE that the contents are only parsed if the
-     * {@link QueryTestCase#getExpectedStatus()} is a 2xx status code.
-     */
-    protected void assertQueryResults(RequestExecutor re, QueryTestCase test) throws JSONException{
-        re.assertStatus(test.getExpectedStatus());
-        re.assertContentType("application/json"); //currently only application/json is supported
-        if(!test.expectsSuccess()){
-            return; //no further checks for tests that expect failure
-        }
-        JSONObject jso = new JSONObject(re.getContent());
-        JSONArray results = jso.getJSONArray("results");
-        if(test.expectesResults()){
-            assertTrue("Missing Results for Query: \n "+test,
-                results.length() > 0);
-        } else {
-            assertTrue("Unexpected Results for Query:\n "+test,
-                results.length() == 0);
-        }
-        Set<String> expectedIds;
-        if(test.getExpectedResultIds() != null && !test.getExpectedResultIds().isEmpty()){
-            expectedIds = new HashSet<String>(test.getExpectedResultIds());
-        } else {
-            expectedIds = null;
-        }
-        
-        //iterate over the results
-        //General NOTE:
-        //  use opt**(..) methods to avoid JSON Exception. We want to parse
-        //  everything and than do asserts!
-        for(int i=0;i<results.length();i++){
-            JSONObject result = results.getJSONObject(i);
-            String id = result.optString("id", null);
-            assertNotNull("ID missing for an Result", id);
-            if(expectedIds != null && expectedIds.remove(id)){ //not all results must be in the list
-                log.info("  > expected result: {}",id);
-            } else {
-                log.debug("  > result: {}",id);
-            }
-            if(test.getProhibitedResultIds() != null){
-                assertFalse("Prohibited Result '"+id+"' found!",
-                    test.getProhibitedResultIds().contains(id));
-            }
-            Set<String> checkRequiredFields; //copy over the required fields
-            if(test.getRequiredFields() != null && !test.getRequiredFields().isEmpty()){
-                checkRequiredFields = new HashSet<String>(test.getRequiredFields());
-            } else {
-                checkRequiredFields = null;
-            }
-            for(Iterator<?> keys = result.keys(); keys.hasNext();){
-                Object key = keys.next();
-                //process key
-                assertTrue("Field "+key+" is not an expected one",
-                    test.getAllowedFields().contains(key));
-                if(checkRequiredFields != null && checkRequiredFields.remove(key)){
-                    log.info("     - required field {}", key);
-                } else {
-                    log.debug("     - optional field {}", key);
-                }
-            }
-            if(checkRequiredFields != null){
-                assertTrue("Missing required Fields "+checkRequiredFields,
-                    checkRequiredFields.isEmpty());
-            }
-        }
-        if(expectedIds != null){ // if there where expected results check that all where found
-            assertTrue("The following expected results where missing in the Response: \n "+expectedIds,
-                expectedIds.isEmpty());
-        }
-    }
-    /**
-     * Asserts that the Query is present in the response and if so returns the
-     * query
-     * @param content the returned content
-     * @return the query as contained in the response
-     * @throws JSONException on any Error while parsing the JSON query from the
-     * parsed content
-     */
-    protected JSONObject assertResponseQuery(String content) throws JSONException {
-        assertNotNull("The content of the Response is NULL",content);
-        JSONObject jResult = new JSONObject(content);
-        JSONObject jQuery = jResult.optJSONObject("query");
-        assertNotNull("Result does not contain the processed Query",jQuery);
-        return jQuery;
-    }
-    /**
-     * Asserts that the selected JSONArray of the field query returned within
-     * the result list contains parsed selected fields
-     * @param jQuery the query e.g. as returned by 
-     * {@link #assertQueryResults(RequestExecutor, QueryTestCase)}
-     * @return the selected fields for further processing
-     * @throws JSONException on any error while parsing the JSON
-     */
-    protected JSONArray assertSelectedField(JSONObject jQuery,String...selected) throws JSONException {
-        Set<String> selectedSet = new HashSet<String>();
-        if(selected == null || selected.length == 0) {
-            selectedSet = Collections.emptySet();
-        } else {
-            selectedSet = new HashSet<String>(Arrays.asList(selected));
-        }
-        JSONArray jSelected = jQuery.optJSONArray("selected");
-        assertNotNull("Result Query is missing the 'selected' property",jSelected);
-        assertTrue("Result Query is expected to have at least a single selected field",
-            jSelected.length() > 0);
-        boolean found = false;
-        for(int i=0;i<jSelected.length() && !found;i++){
-            String selectedField = jSelected.optString(i,null);
-            assertNotNull("Selected array contains a NULL element \n"+jSelected.toString(4),
-                selectedField);
-            selectedSet.remove(selectedField);
-        }
-        assertTrue("Fields "+selectedSet+" are not selected by\n"+jSelected.toString(4),
-            selectedSet.isEmpty());
-        return jSelected;
-    }    
-    
     /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      *  Find Query Test Methods:
      * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Modified: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java?rev=1152160&r1=1152159&r2=1152160&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java Fri Jul 29 10:38:31 2011
@@ -15,7 +15,6 @@ public abstract class QueryTestCase {
      */
     public static final Set<String> DEFAULT_RESULT_FIELDS = 
         Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
-            "id",
             "http://www.iks-project.eu/ontology/rick/query/score")));
 
     public static final Map<? extends String,? extends String> DEFAULT_HEADER;
@@ -73,8 +72,7 @@ public abstract class QueryTestCase {
     /**
      * Setter for the required fields
      * @param requiredFields
-     * @throws IllegalArgumentException In case a parsed required field is not
-     * contained in the {@link #getAllowedFields()} or the 
+     * @throws IllegalArgumentException In case the 
      * {@link #getExpectedStatus()} is not an 2xx code
      */
     protected final void setRequiredFields(Collection<String> requiredFields) {
@@ -82,14 +80,6 @@ public abstract class QueryTestCase {
             throw new IllegalArgumentException("Required fields can only be set" +
             		"if the expected status of a test case has a 2xx code");
         }
-        if(requiredFields != null){ //check if the required are in the list
-            if(!allowedFields.containsAll(requiredFields)){
-                throw new IllegalArgumentException(String.format(
-                    "Based on the parsed Query only the Fields %s are expected, but" +
-                    "%s are parsed as required one!",
-                    allowedFields,requiredFields));
-            }
-        }
         this.requiredFields = requiredFields;
     }
     /**
@@ -201,6 +191,6 @@ public abstract class QueryTestCase {
             }
             sb.append(']');
         }
-        return super.toString();
+        return sb.toString();
     }
 }

Added: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/DbpediaDefaultdataConstants.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/DbpediaDefaultdataConstants.java?rev=1152160&view=auto
==============================================================================
--- incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/DbpediaDefaultdataConstants.java (added)
+++ incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/DbpediaDefaultdataConstants.java Fri Jul 29 10:38:31 2011
@@ -0,0 +1,38 @@
+package org.apache.stanbol.entityhub.it;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class DbpediaDefaultdataConstants {
+    
+    private DbpediaDefaultdataConstants() { /* no instances */}
+    
+    public static final String DBPEDIA_SITE_ID = "dbpedia";
+    public static final String DBPEDIA_SITE_PATH = "/entityhub/site/"+DBPEDIA_SITE_ID;
+
+    
+    public static final Set<String> DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS;
+    public static final Set<String> DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS;
+    static {
+        Set<String> required = new HashSet<String>();
+        required.add("http://www.w3.org/2000/01/rdf-schema#label");
+        required.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
+        required.add("http://www.iks-project.eu/ontology/rick/model/entityRank");
+        DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS = Collections.unmodifiableSet(required);
+
+        Set<String> optional = new HashSet<String>();
+        optional.add("http://purl.org/dc/terms/subject");
+        optional.add("http://xmlns.com/foaf/0.1/depiction");
+        optional.add("http://dbpedia.org/ontology/populationTotal");
+        optional.add("http://www.w3.org/2003/01/geo/wgs84_pos#lat");
+        optional.add("http://www.w3.org/2003/01/geo/wgs84_pos#long");
+        optional.add("http://www.w3.org/2003/01/geo/wgs84_pos#alt");
+        optional.add("http://dbpedia.org/ontology/birthDate");
+        optional.add("http://dbpedia.org/ontology/deathDate");
+        optional.add("http://xmlns.com/foaf/0.1/homepage");
+        DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS = Collections.unmodifiableSet(optional);
+    }
+
+
+}

Propchange: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/DbpediaDefaultdataConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/EntityHubTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/EntityHubTest.java?rev=1152160&r1=1152159&r2=1152160&view=diff
==============================================================================
--- incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/EntityHubTest.java (original)
+++ incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/EntityHubTest.java Fri Jul 29 10:38:31 2011
@@ -16,18 +16,17 @@
  */
 package org.apache.stanbol.entityhub.it;
 
-import static junit.framework.Assert.*;
+import static junit.framework.Assert.assertNotSame;
 
 import java.util.ArrayList;
-import java.util.Collections;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.stanbol.commons.testing.http.RequestExecutor;
 import org.apache.stanbol.entityhub.test.it.EntityhubTestBase;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONObject;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 //inherit from EnhancerTestBase, but we more care about the entityhub readiness than engine's one.
 public final class EntityHubTest extends EntityhubTestBase {

Copied: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ReferencedSiteTest.java (from r1151863, incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/ReferencedSiteFieldQueryTest.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ReferencedSiteTest.java?p2=incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ReferencedSiteTest.java&p1=incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/ReferencedSiteFieldQueryTest.java&r1=1151863&r2=1152160&rev=1152160&view=diff
==============================================================================
--- incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/ReferencedSiteFieldQueryTest.java (original)
+++ incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ReferencedSiteTest.java Fri Jul 29 10:38:31 2011
@@ -1,15 +1,55 @@
-package org.apache.stanbol.entityhub.it.query;
+package org.apache.stanbol.entityhub.it;
 
-public final class ReferencedSiteFieldQueryTest extends DbpediaQueryTest {
-    public static final String REFERENCED_SITE = "dbpedia";
-    public static final String REFERENCED_SITE_PATH = "/entityhub/site/"+REFERENCED_SITE;
+import static org.apache.stanbol.entityhub.it.DbpediaDefaultdataConstants.DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS;
+import static org.apache.stanbol.entityhub.it.DbpediaDefaultdataConstants.DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS;
+import static org.apache.stanbol.entityhub.it.DbpediaDefaultdataConstants.DBPEDIA_SITE_ID;
+import static org.apache.stanbol.entityhub.it.DbpediaDefaultdataConstants.DBPEDIA_SITE_PATH;
+import static org.apache.stanbol.entityhub.test.it.AssertEntityhubJson.assertEntity;
+import static org.apache.stanbol.entityhub.test.it.AssertEntityhubJson.assertRepresentation;
+
+import java.io.IOException;
+
+import org.apache.stanbol.commons.testing.http.RequestExecutor;
+import org.apache.stanbol.entityhub.it.query.DbpediaQueryTest;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.junit.Test;
+
+/**
+ * Tests of the ReferencedSite RESTful service of the Entityhub based on the
+ * DBpedia.org default data set.<p>
+ * Note that the tests for the query interfaces are defined by 
+ * {@link DbpediaQueryTest} because they are shared with
+ * {@link SitesManagerTest}.
+ * @author Rupert Westenthaler
+ *
+ */
+public final class ReferencedSiteTest extends DbpediaQueryTest {
 
     /**
      * Executes the {@link DbpediaQueryTest} on the 'dbpedia' referenced
      * site (assuming the default dataset
      */
-    public ReferencedSiteFieldQueryTest() {
-        super(REFERENCED_SITE_PATH, REFERENCED_SITE);
+    public ReferencedSiteTest() {
+        super(DBPEDIA_SITE_PATH, DBPEDIA_SITE_ID);
+    }
+    /**
+     * Tests retrieval of Entities
+     * @throws IOException
+     * @throws JSONException
+     */
+    @Test
+    public void testRetrievel() throws IOException, JSONException {
+        String id = "http://dbpedia.org/resource/Paris";
+        RequestExecutor re = executor.execute(
+            builder.buildGetRequest(DBPEDIA_SITE_PATH+"/entity",
+                "id",id)
+            .withHeader("Accept", "application/json"));
+        re.assertStatus(200);
+        JSONObject jEntity = assertEntity(re.getContent(), id, DBPEDIA_SITE_ID);
+        assertRepresentation(jEntity.getJSONObject("representation"), 
+            DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS, 
+            DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS);
     }
 
 }

Propchange: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ReferencedSiteTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/SitesManagerTest.java (from r1151863, incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/SitesManagerFieldQueryTest.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/SitesManagerTest.java?p2=incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/SitesManagerTest.java&p1=incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/SitesManagerFieldQueryTest.java&r1=1151863&r2=1152160&rev=1152160&view=diff
==============================================================================
--- incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/SitesManagerFieldQueryTest.java (original)
+++ incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/SitesManagerTest.java Fri Jul 29 10:38:31 2011
@@ -1,6 +1,33 @@
-package org.apache.stanbol.entityhub.it.query;
+package org.apache.stanbol.entityhub.it;
 
-public final class SitesManagerFieldQueryTest extends DbpediaQueryTest {
+import static org.apache.stanbol.entityhub.it.DbpediaDefaultdataConstants.DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS;
+import static org.apache.stanbol.entityhub.it.DbpediaDefaultdataConstants.DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS;
+import static org.apache.stanbol.entityhub.test.it.AssertEntityhubJson.assertEntity;
+import static org.apache.stanbol.entityhub.test.it.AssertEntityhubJson.assertRepresentation;
+
+import java.io.IOException;
+
+import org.apache.stanbol.commons.testing.http.RequestExecutor;
+import org.apache.stanbol.entityhub.it.query.DbpediaQueryTest;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.junit.Test;
+
+/**
+ * Tests of the ReferencedSiteManager RESTful service of the Entityhub based on the
+ * DBpedia.org default data set.<p>
+ * Note that the tests for the query interfaces are defined by 
+ * {@link DbpediaQueryTest} because they are shared with
+ * {@link SitesManagerTest}.<p>
+ * TODO: We would need at least a second ReferencedSite to be up and running to
+ * really test the ReferencedSiteManager! However in that case one would need
+ * to be carefully about breaking the assumptions within the 
+ * {@link DbpediaQueryTest} with results from other ReferencedSites. 
+ * 
+ * @author Rupert Westenthaler
+ *
+ */
+public final class SitesManagerTest extends DbpediaQueryTest {
 
     public static final String SITES_MANAGER_PATH = "/entityhub/sites";
 
@@ -8,8 +35,27 @@ public final class SitesManagerFieldQuer
      * Executes the {@link DbpediaQueryTest} on the Entityhub Sites Manager
      * service (/entityhub/sites)
      */
-    public SitesManagerFieldQueryTest() {
+    public SitesManagerTest() {
         super(SITES_MANAGER_PATH, null);
     }
+    /**
+     * Tests retrieval of Entities
+     * @throws IOException
+     * @throws JSONException
+     */
+    @Test
+    public void testRetrievel() throws IOException, JSONException {
+        String id = "http://dbpedia.org/resource/Paris";
+        RequestExecutor re = executor.execute(
+            builder.buildGetRequest(SITES_MANAGER_PATH+"/entity",
+                "id",id)
+            .withHeader("Accept", "application/json"));
+        re.assertStatus(200);
+        //do not check for the site of the entity, because this might change
+        JSONObject jEntity = assertEntity(re.getContent(), id, null);
+        assertRepresentation(jEntity.getJSONObject("representation"), 
+            DBPEDIA_DEFAULTDATA_REQUIRED_FIELDS, 
+            DBPEDIA_DEFAULTDATA_OPTIONAL_FIELDS);
+    }
 
 }

Propchange: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/SitesManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/DbpediaQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/DbpediaQueryTest.java?rev=1152160&r1=1152159&r2=1152160&view=diff
==============================================================================
--- incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/DbpediaQueryTest.java (original)
+++ incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/DbpediaQueryTest.java Fri Jul 29 10:38:31 2011
@@ -3,6 +3,8 @@ package org.apache.stanbol.entityhub.it.
 import java.io.IOException;
 import java.util.Arrays;
 
+import org.apache.stanbol.entityhub.it.ReferencedSiteTest;
+import org.apache.stanbol.entityhub.it.SitesManagerTest;
 import org.apache.stanbol.entityhub.test.query.FieldQueryTestCase;
 import org.apache.stanbol.entityhub.test.query.FindQueryTestCase;
 import org.apache.stanbol.entityhub.test.query.QueryTestBase;
@@ -18,8 +20,8 @@ import org.slf4j.LoggerFactory;
  * This test cases are used to test both the ReferencedSiteManager and 
  * the ReferencedSite. This is also the reason why having this abstract super
  * class defining the tests.
- * @see ReferencedSiteFieldQueryTest
- * @see SitesManagerFieldQueryTest
+ * @see ReferencedSiteTest
+ * @see SitesManagerTest
  * @author Rupert Westenthaler
  *
  */
@@ -116,7 +118,7 @@ public abstract class DbpediaQueryTest e
         test.setLanguage("en");
         executeQuery(test);
         //now the same search with wildcards
-        test = new FindQueryTestCase("ABC*",
+        test = new FindQueryTestCase("cia*",
             Arrays.asList(
                 "http://dbpedia.org/resource/CIA",
                 "http://dbpedia.org/resource/Ciara",