wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r818322 - in /incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers: ProvidersContextResolverTest.java entity/ProvidersMessageBodyTest.java
Date Thu, 24 Sep 2009 00:05:28 GMT
Author: bluk
Date: Thu Sep 24 00:05:28 2009
New Revision: 818322

URL: http://svn.apache.org/viewvc?rev=818322&view=rev
Log:
Change Providers unit test to setup priorities

Thanks Mike Rheinheimer for the tests
and initial implementation and Michael Elman
for the generalized implementation.

See [WINK-193] and [WINK-167]

Modified:
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/ProvidersContextResolverTest.java
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/ProvidersMessageBodyTest.java

Modified: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/ProvidersContextResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/ProvidersContextResolverTest.java?rev=818322&r1=818321&r2=818322&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/ProvidersContextResolverTest.java
(original)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/ProvidersContextResolverTest.java
Thu Sep 24 00:05:28 2009
@@ -42,6 +42,10 @@
     private static final String  STRING2 = "String2";
     private static final String  STRING3 = "String3";
     private static final String  STRING4 = "String4";
+    private static final String  STRING5 = "String5";
+    private static final String  STRING6 = "String6";
+    private static final String  STRING7 = "String7";
+
     private static final String  ATOM    = "Atom";
     private static final byte[]  BYTE    = new byte[0];
     private static final Integer _12345  = new Integer(12345);
@@ -84,6 +88,30 @@
     }
 
     @Provider
+    public static class StringContextResolver5 implements ContextResolver<String> {
+
+        public String getContext(Class<?> type) {
+            return STRING5;
+        }
+    }
+
+    @Provider
+    public static class StringContextResolver6 implements ContextResolver<String> {
+
+        public String getContext(Class<?> type) {
+            return STRING6;
+        }
+    }
+
+    @Provider
+    public static class StringContextResolver7 implements ContextResolver<String> {
+
+        public String getContext(Class<?> type) {
+            return STRING7;
+        }
+    }
+
+    @Provider
     @Produces(MediaType.APPLICATION_FORM_URLENCODED)
     // intentionally using a MediaType with a '-' to exercise regex code
     public static class MyContextResolver implements ContextResolver<MyClass> {
@@ -271,4 +299,18 @@
             .getContext(String.class));
     }
 
+    public void testContextResolverPrioritySort() {
+        ProvidersRegistry providers = createProvidersRegistryImpl();
+        // note: the order these are added is important to the test
+        assertTrue(providers.addProvider(new StringContextResolver5(), 0.5));
+        assertTrue(providers.addProvider(new StringContextResolver6(), 0.6));
+        assertTrue(providers.addProvider(new StringContextResolver7(), 0.4));
+
+        // StringContextResolver3 has the highest priority (0.2) even though
+        // StringContextResolver2
+        // more closely matches based on the media type in @Produces
+
+        assertSame(STRING6, providers.getContextResolver(String.class, null, null)
+            .getContext(String.class));
+    }
 }

Modified: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/ProvidersMessageBodyTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/ProvidersMessageBodyTest.java?rev=818322&r1=818321&r2=818322&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/ProvidersMessageBodyTest.java
(original)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/ProvidersMessageBodyTest.java
Thu Sep 24 00:05:28 2009
@@ -35,6 +35,7 @@
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
 
+import org.apache.wink.common.WinkApplication;
 import org.apache.wink.common.annotations.Scope;
 import org.apache.wink.common.annotations.Scope.ScopeType;
 import org.apache.wink.common.internal.application.ApplicationValidator;
@@ -118,16 +119,16 @@
         FileProvider fileProvider = new FileProvider();
         IntegerMessageBodyProvider objectMessageBodyProvider = new IntegerMessageBodyProvider();
 
-        providers.addProvider(byteArrayProvider);
-        providers.addProvider(inputStreamProvider);
+        providers.addProvider(byteArrayProvider, WinkApplication.SYSTEM_PRIORITY);
+        providers.addProvider(inputStreamProvider, WinkApplication.SYSTEM_PRIORITY);
         providers.addProvider(string2Provider);
-        providers.addProvider(stringProvider);
-        providers.addProvider(fileProvider);
+        providers.addProvider(stringProvider, WinkApplication.SYSTEM_PRIORITY);
+        providers.addProvider(fileProvider, WinkApplication.SYSTEM_PRIORITY);
         providers.addProvider(objectMessageBodyProvider);
 
         assertEquals(byteArrayProvider, providers
             .getMessageBodyReader(byte[].class, null, null, MediaType.APPLICATION_JSON_TYPE,
null));
-        assertEquals(stringProvider, providers.getMessageBodyReader(String.class,
+        assertEquals(string2Provider, providers.getMessageBodyReader(String.class,
                                                                     null,
                                                                     null,
                                                                     MediaType.WILDCARD_TYPE,
@@ -141,12 +142,13 @@
                                   null,
                                   MediaType.APPLICATION_ATOM_XML_TYPE,
                                   null));
-        // string2Provider is favored over stringProvider because it is a user-defined provider
-//        assertEquals(string2Provider, providers.getMessageBodyWriter(String.class,
-//                                                                    null,
-//                                                                    null,
-//                                                                    MediaType.WILDCARD_TYPE,
-//                                                                    null));
+        // string2Provider is favored over stringProvider because it is a
+        // user-defined provider
+        assertEquals(string2Provider, providers.getMessageBodyWriter(String.class,
+                                                                     null,
+                                                                     null,
+                                                                     MediaType.WILDCARD_TYPE,
+                                                                     null));
         assertEquals(fileProvider, providers
             .getMessageBodyWriter(File.class, null, null, MediaType.APPLICATION_SVG_XML_TYPE,
null));
 



Mime
View raw message