Author: rwesten
Date: Mon Sep 10 08:03:28 2012
New Revision: 1382678
URL: http://svn.apache.org/viewvc?rev=1382678&view=rev
Log:
fix for STANBOL-727:
* the check of parameterised types now also considers parent classes.
* added unit tests to valudate the fix
additional minor changes:
* corrected a spelling error in a method name
* added "ldpath" parameter to the RESTful service documentation
Added:
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/parsers/
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/parsers/RepresetnationReaderTest.java
(with props)
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/utils/
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtilsTest.java
(with props)
Modified:
incubator/stanbol/trunk/entityhub/jersey/pom.xml
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/RepresentationReader.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl
Modified: incubator/stanbol/trunk/entityhub/jersey/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/pom.xml?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/pom.xml (original)
+++ incubator/stanbol/trunk/entityhub/jersey/pom.xml Mon Sep 10 08:03:28 2012
@@ -132,10 +132,10 @@
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.core</artifactId>
</dependency>
- <dependency>
+<!-- <dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>jaxrs.rdf.providers</artifactId>
- </dependency>
+ </dependency> -->
<dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>rdf.jena.serializer</artifactId>
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/RepresentationReader.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/RepresentationReader.java?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/RepresentationReader.java
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/RepresentationReader.java
Mon Sep 10 08:03:28 2012
@@ -101,30 +101,11 @@ public class RepresentationReader implem
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[]
annotations, MediaType mediaType) {
- boolean keyOK;
- boolean valueOK;
String mediaTypeWithoutParameter =
- mediaType.getType().toLowerCase()+'/'+
- mediaType.getSubtype().toLowerCase();
+ mediaType.getType().toLowerCase()+'/'+
+ mediaType.getSubtype().toLowerCase();
log.debug("isreadable: [genericType: {}| mediaType {}]",
genericType,mediaTypeWithoutParameter);
- //first check the parsed type
- if(genericType instanceof ParameterizedType &&
-
((ParameterizedType)genericType).getActualTypeArguments().length > 1){
- //both the raw type MUST BE compatible with Set and the
- //generic type MUST BE compatible with Representation
- //e.g to support method declarations like
- // public <T extends Collection> store(T<? extends Representation>
representations){...}
- keyOK = JerseyUtils.testType(Map.class,
((ParameterizedType)genericType).getRawType()) &&
- JerseyUtils.testType(String.class,
((ParameterizedType)genericType).getActualTypeArguments()[0]);
- valueOK = JerseyUtils.testType(Representation.class,
((ParameterizedType)genericType).getActualTypeArguments()[1]);
- } else if(genericType instanceof Class<?>){
- keyOK = Map.class.isAssignableFrom((Class<?>)genericType);
- valueOK = true; //not needed
- } else {//No Idea what that means
- keyOK = false;
- valueOK = false;
- }
//second the media type
boolean mediaTypeOK = (//the MimeTypes of Representations
supportedMediaTypes.contains(mediaTypeWithoutParameter) ||
@@ -132,8 +113,11 @@ public class RepresentationReader implem
MediaType.APPLICATION_FORM_URLENCODED.equals(mediaTypeWithoutParameter) ||
//and mime multipart
MediaType.MULTIPART_FORM_DATA.equals(mediaTypeWithoutParameter));
- log.debug(" > java-type: {}, media-type {}",keyOK,mediaTypeOK);
- return keyOK && valueOK && mediaTypeOK;
+ boolean typeOk = JerseyUtils.testParameterizedType(Map.class,
+ new Class[]{String.class,Representation.class}, genericType);
+ log.debug("type is {} for {} against Map<String,Representation>",
+ typeOk ? "compatible" : "incompatible" ,genericType);
+ return typeOk && mediaTypeOK;
}
@Override
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java
Mon Sep 10 08:03:28 2012
@@ -39,7 +39,7 @@ import static org.apache.stanbol.commons
import static
org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.getLDPathParseExceptionMessage;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.handleLDPathRequest;
-import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepairQueryLDPathProgram;
+import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepareQueryLDPathProgram;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.transformQueryResults;
import java.io.File;
@@ -610,7 +610,7 @@ public class EntityhubRootResource exten
//first prepare (only execute the query if the parameters are valid)
Program<Object> program;
try {
- program = prepairQueryLDPathProgram(ldpathProgramString,
selectedFields, backend, ldPath);
+ program = prepareQueryLDPathProgram(ldpathProgramString,
selectedFields, backend, ldPath);
} catch (LDPathParseException e) {
log.warn("Unable to parse LDPath program used as select for
Query:");
log.warn("FieldQuery: \n {}",query);
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
Mon Sep 10 08:03:28 2012
@@ -38,7 +38,7 @@ import static org.apache.stanbol.entityh
import static
org.apache.stanbol.entityhub.jersey.utils.JerseyUtils.createFieldQueryForFindRequest;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.getLDPathParseExceptionMessage;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.handleLDPathRequest;
-import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepairQueryLDPathProgram;
+import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepareQueryLDPathProgram;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.transformQueryResults;
import java.io.File;
@@ -652,7 +652,7 @@ public class ReferencedSiteRootResource
//first prepare (only execute the query if the parameters are valid)
Program<Object> program;
try {
- program = prepairQueryLDPathProgram(ldpathProgramString,
selectedFields, backend, ldPath);
+ program = prepareQueryLDPathProgram(ldpathProgramString,
selectedFields, backend, ldPath);
} catch (LDPathParseException e) {
log.warn("Unable to parse LDPath program used as select for
Query:");
log.warn("FieldQuery: \n {}",query);
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java
Mon Sep 10 08:03:28 2012
@@ -31,7 +31,7 @@ import static org.apache.stanbol.commons
import static
org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.getLDPathParseExceptionMessage;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.handleLDPathRequest;
-import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepairQueryLDPathProgram;
+import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepareQueryLDPathProgram;
import static
org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.transformQueryResults;
import java.io.File;
@@ -426,7 +426,7 @@ public class SiteManagerRootResource ext
//first prepare (only execute the query if the parameters are valid)
Program<Object> program;
try {
- program = prepairQueryLDPathProgram(ldpathProgramString,
selectedFields, backend, ldPath);
+ program = prepareQueryLDPathProgram(ldpathProgramString,
selectedFields, backend, ldPath);
} catch (LDPathParseException e) {
log.warn("Unable to parse LDPath program used as select for a
Query to the '/sites' endpoint:");
log.warn("FieldQuery: \n {}",query);
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java
Mon Sep 10 08:03:28 2012
@@ -27,6 +27,7 @@ import static org.apache.clerezza.rdf.co
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.net.URLDecoder;
@@ -59,6 +60,8 @@ import org.apache.stanbol.entityhub.serv
import
org.apache.stanbol.entityhub.servicesapi.query.TextConstraint.PatternType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.api.representation.Form;
/**
* Utility methods used by several of the RESTful service endpoints of the
* Entityhub.
@@ -250,7 +253,7 @@ public final class JerseyUtils {
* @param genericType the required class
* @return if the generic type is compatible with the required class
*/
- public static boolean testType(Class<?> required, Type genericType) {
+ public static boolean testType(Class<?> required, Type type) {
//for the examples let assume that a Set is the raw type and the
//requested generic type is a Representation with the following class
//hierarchy:
@@ -260,18 +263,15 @@ public final class JerseyUtils {
// -> InMemoryRepresentation
// -> InputStream
// -> Collection<T>
- boolean typeOK;
- if(genericType instanceof Class<?>){
- //OK
- // Set<Representation>
- // Set<Object>
- //NOT OK
- // Set<RdfRepresentation>
- // Set<InputStream>
- typeOK = ((Class<?>)genericType).isAssignableFrom(required);
- } else if(genericType instanceof WildcardType){
+ boolean typeOK = false;
+// while(type != null && !typeOK){
+// types.add(type);
+ if(type instanceof Class<?>){
+ typeOK = required.isAssignableFrom((Class<?>) type);
+ type = ((Class<?>)type).getGenericSuperclass();
+ } else if(type instanceof WildcardType){
//In cases <? super {class}>, <? extends {class}, <?>
- WildcardType wildcardSetType = (WildcardType) genericType;
+ WildcardType wildcardSetType = (WildcardType) type;
if(wildcardSetType.getLowerBounds().length > 0){
Type lowerBound = wildcardSetType.getLowerBounds()[0];
//OK
@@ -297,18 +297,66 @@ public final class JerseyUtils {
// Set<?>
typeOK = true;
}
- } else if(required.isArray() && genericType instanceof
GenericArrayType){
+ } else if(required.isArray() && type instanceof GenericArrayType){
//In case the required type is an array we need also to support
//possible generic Array specifications
- GenericArrayType arrayType = (GenericArrayType)genericType;
+ GenericArrayType arrayType = (GenericArrayType)type;
typeOK = testType(required.getComponentType(),
arrayType.getGenericComponentType());
+ } else if(type instanceof ParameterizedType){
+ ParameterizedType pType = ((ParameterizedType)type);
+ typeOK = pType.getRawType() instanceof Class<?> &&
+ required.isAssignableFrom((Class<?>)pType.getRawType());
+ type = null;
} else {
//GenericArrayType but !required.isArray() -> incompatible
//TypeVariable -> no variables define -> incompatible
typeOK = false;
+// type = null; //end
}
+// }
return typeOK;
}
+ /**
+ * Tests the parsed type against the raw type and parsed Type parameters.
+ * This allows e.g. to check for <code>Map<String,Number></code> but
+ * also works with classes that extend generic types such as
+ * <code>Dummy extends {@link HashMap}<String,String></code>.
+ * @param rawType the raw type to test against
+ * @param parameterTypes the types of the parameters
+ * @param type the type to test
+ * @return if the type is compatible or not
+ */
+ public static boolean testParameterizedType(Class<?> rawType, Class<?>[]
parameterTypes, Type type) {
+ // first check the raw type
+ if (!testType(rawType, type)) {
+ return false;
+ }
+ while (type != null) {
+ // types.add(type);
+ Type[] parameters = null;
+ if (type instanceof ParameterizedType) {
+ parameters = ((ParameterizedType)
type).getActualTypeArguments();
+ // the number of type arguments MUST BE the same as parameter
types
+ if (parameters.length == parameterTypes.length) {
+ boolean compatible = true;
+ // All parameters MUST BE compatible!
+ for (int i = 0; compatible && i < parameters.length; i++) {
+ compatible = testType(parameterTypes[i],
parameters[i]);
+ }
+ if (compatible) {
+ return true;
+ }
+ } // else check parent types
+
+ } // else not parameterised
+ if (type instanceof Class<?>) {
+ type = ((Class<?>) type).getGenericSuperclass();
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
/**
* This Method is intended to parse form data from
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java
Mon Sep 10 08:03:28 2012
@@ -257,7 +257,7 @@ public class LDPathHelper {
* @throws IllegalStateException if the fields selected by the LDPath
* program conflict with the fields selected by the query.
*/
- public static Program<Object> prepairQueryLDPathProgram(String
ldpathProgram,
+ public static Program<Object> prepareQueryLDPathProgram(String
ldpathProgram,
Set<String> selectedFields,
AbstractBackend backend,
EntityhubLDPath ldPath) throws
LDPathParseException {
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_find.ftl
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_find.ftl?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_find.ftl
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_find.ftl
Mon Sep 10 08:03:28 2012
@@ -40,6 +40,8 @@
<li>limit: The maximum number of returned Entities
(optional)</li>
<li>offset: The offset of the first returned Entity
(default: 0)</li>
<li>select: A list of fields included for returned
Entities (optional)</li>
+ <li>ldpath: The LDPath program executed for entities
selected by the find query (optionally).
+ The LDPath program needs to be URLEncoded.</li>
</ul>
</td>
</tr>
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl
Mon Sep 10 08:03:28 2012
@@ -43,6 +43,8 @@
information to return for Entities selected by the /find
request</li>
<li>limit: optionally the maximum number of results</li>
<li>offset: optionally the offset of first result</li>
+ <li>ldpath: The LDPath program executed for entities selected by
the find query (optionally).
+ The LDPath program needs to be URLEncoded.</li>
</ul>
</td>
</tr>
Modified:
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl?rev=1382678&r1=1382677&r2=1382678&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl
(original)
+++
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl
Mon Sep 10 08:03:28 2012
@@ -40,6 +40,8 @@
<li>lang: optionally the language of the parsed name can be
defined</li>
<li>limit: optionally the maximum number of results</li>
<li>offset: optionally the offset of first result</li>
+ <li>ldpath: The LDPath program executed for entities selected by
the find query (optionally).
+ The LDPath program needs to be URLEncoded.</li>
</ul>
</td>
</tr>
Added:
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/parsers/RepresetnationReaderTest.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/parsers/RepresetnationReaderTest.java?rev=1382678&view=auto
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/parsers/RepresetnationReaderTest.java
(added)
+++
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/parsers/RepresetnationReaderTest.java
Mon Sep 10 08:03:28 2012
@@ -0,0 +1,28 @@
+package org.apache.stanbol.entityhub.jersey.parsers;
+
+import javax.ws.rs.core.MediaType;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.jersey.api.representation.Form;
+
+public class RepresetnationReaderTest {
+
+ Logger log = LoggerFactory.getLogger(RepresetnationReaderTest.class);
+
+ RepresentationReader reader = new RepresentationReader();
+
+ /**
+ * Tests the bug reported by STANBOL-727
+ */
+ @Test
+ public void testIsReadable(){
+ //NOTE the use of com.sun.* API for unit testing
+ Class<Form> formClass = com.sun.jersey.api.representation.Form.class;
+ boolean state = reader.isReadable(formClass, formClass, null,
MediaType.APPLICATION_FORM_URLENCODED_TYPE);
+ Assert.assertFalse(state);
+ }
+}
Propchange:
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/parsers/RepresetnationReaderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtilsTest.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtilsTest.java?rev=1382678&view=auto
==============================================================================
---
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtilsTest.java
(added)
+++
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtilsTest.java
Mon Sep 10 08:03:28 2012
@@ -0,0 +1,44 @@
+package org.apache.stanbol.entityhub.jersey.utils;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests added mainly in response to the bug reported by STANBOL-727
+ * @author Rupert Westenthaler
+ *
+ */
+public class JerseyUtilsTest {
+
+ private static class TestMap extends HashMap<String,Collection<? extends
Number>>{
+ private static final long serialVersionUID = 1L;
+ }
+ /**
+ * Tests some combination for Test
+ */
+ @Test
+ public void testType(){
+ Assert.assertTrue(JerseyUtils.testType(Map.class, HashMap.class));
+ Assert.assertFalse(JerseyUtils.testType(Map.class, HashSet.class));
+ Assert.assertTrue(JerseyUtils.testType(Map.class, new
HashMap<String,String>().getClass()));
+ Map<String,Collection<? extends Number>> genericMapTest = new
TestMap();
+ Assert.assertTrue(JerseyUtils.testType(Map.class,
genericMapTest.getClass()));
+ Assert.assertFalse(JerseyUtils.testType(Set.class,
genericMapTest.getClass()));
+ //test a parsed Type
+ Assert.assertTrue(JerseyUtils.testType(Map.class,
TestMap.class.getGenericSuperclass()));
+ }
+
+ @Test
+ public void testParameterisedType() {
+ //NOTE: this can not check for Collection<String>!!
+ Assert.assertTrue(JerseyUtils.testParameterizedType(Map.class,
+ new Class[]{String.class,Collection.class}, TestMap.class));
+ }
+
+}
Propchange:
incubator/stanbol/trunk/entityhub/jersey/src/test/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtilsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain