cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r636586 [2/3] - in /incubator/cxf/trunk: distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/server/ distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/ distribution/src/main/release/samples/jax_rs/...
Date Thu, 13 Mar 2008 00:20:47 GMT
Copied: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImpl.java (from r636320, incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImpl.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImpl.java?p2=incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImpl.java&p1=incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImpl.java&r1=636320&r2=636586&rev=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImpl.java Wed Mar 12 17:20:41 2008
@@ -19,57 +19,37 @@
 
 package org.apache.cxf.jaxrs.provider;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 
-import javax.ws.rs.ConsumeMime;
-import javax.ws.rs.ProduceMime;
+import javax.ws.rs.core.CacheControl;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response.Builder;
+import javax.ws.rs.core.NewCookie;
+import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.Variant.VariantListBuilder;
-import javax.ws.rs.ext.HeaderProvider;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.ProviderFactory;
-
-import org.apache.cxf.jaxrs.JAXRSUtils;
+import javax.ws.rs.ext.RuntimeDelegate;
 
 
-public class ProviderFactoryImpl extends ProviderFactory {
-    protected List<MessageBodyReader> defaultMessageReaders = new ArrayList<MessageBodyReader>();
-    protected List<MessageBodyWriter> defaultMessageWriters = new ArrayList<MessageBodyWriter>();
-    protected List<MessageBodyReader> userMessageReaders = new ArrayList<MessageBodyReader>();
-    protected List<MessageBodyWriter> userMessageWriters = new ArrayList<MessageBodyWriter>();
-    
-    protected List<HeaderProvider> headerProviders = new ArrayList<HeaderProvider>();    
-
-    public ProviderFactoryImpl() {
-        // TODO : this needs to be done differently,
-        // we need to use cxf-jaxrs-extensions
-        setProviders(defaultMessageReaders,
-                     defaultMessageWriters,
-                     new JSONProvider(),
-                     new BinaryDataProvider(),
-                     new JAXBElementProvider(),
-                     new StringProvider(),
-                     new SourceProvider(),
-                     new AtomFeedProvider(),
-                     new AtomEntryProvider(),
-                     new FormEncodingReaderProvider());
-        headerProviders.add(new MediaTypeHeaderProvider());
-        headerProviders.add(new CacheControlHeaderProvider());
-        headerProviders.add(new EntityTagHeaderProvider());
-        headerProviders.add(new CookieHeaderProvider());
+public class RuntimeDelegateImpl extends RuntimeDelegate {
+    protected Map<Class, HeaderDelegate> headerProviders 
+        = new HashMap<Class, HeaderDelegate>();    
+
+    public RuntimeDelegateImpl() {
+        headerProviders.put(MediaType.class, new MediaTypeHeaderProvider());
+        headerProviders.put(CacheControl.class, new CacheControlHeaderProvider());
+        headerProviders.put(EntityTag.class, new EntityTagHeaderProvider());
+        headerProviders.put(Cookie.class, new CookieHeaderProvider());
+        headerProviders.put(NewCookie.class, new NewCookieHeaderProvider());
     }
     
     
     
     public <T> T createInstance(Class<T> type) {
-        if (type.isAssignableFrom(Builder.class)) {
-            return type.cast(new BuilderImpl());
+        if (type.isAssignableFrom(ResponseBuilder.class)) {
+            return type.cast(new ResponseBuilderImpl());
         } 
         if (type.isAssignableFrom(UriBuilder.class)) {
             return type.cast(new UriBuilderImpl());
@@ -80,257 +60,32 @@
         return null;
     }
    
+    
+    @SuppressWarnings("unchecked")
     @Override
-    public <T> MessageBodyReader<T> createMessageBodyReader(Class<T> bodyType, MediaType mediaType) {
-        // Try user provided providers
-        MessageBodyReader<T> mr = chooseMessageReader(userMessageReaders, 
-                                                      bodyType,
-                                                      mediaType);
-        
-        //If none found try the default ones
-        if (mr == null) {
-            mr = chooseMessageReader(defaultMessageReaders,
-                                     bodyType,
-                                     mediaType);
-        }     
-        
-        return mr;
+    public <T> HeaderDelegate<T> createHeaderDelegate(Class<T> type) {
+        return headerProviders.get(type);
     }
 
+
+
     @Override
-    public <T> MessageBodyWriter<T> createMessageBodyWriter(Class<T> bodyType, MediaType mediaType) {
-        // Try user provided providers
-        MessageBodyWriter<T> mw = chooseMessageWriter(userMessageWriters,
-                                                      bodyType,
-                                                      mediaType);
-        
-        //If none found try the default ones
-        if (mw == null) {
-            mw = chooseMessageWriter(defaultMessageWriters,
-                                     bodyType,
-                                     mediaType);
-        }     
-        
-        return mw;
-    }
-    
-    
-    @SuppressWarnings("unchecked")
-    public <T> HeaderProvider<T> createHeaderProvider(Class<T> type) {
-        for (HeaderProvider<T> hp : headerProviders) {
-            if (hp.supports(type)) {
-                return hp;
-            }
-        }     
-        
-        return null;
-    }
-    
-       
-    private void setProviders(List<MessageBodyReader> readers, 
-                              List<MessageBodyWriter> writers, 
-                              Object... providers) {
-        
-        for (Object o : providers) {
-            if (MessageBodyReader.class.isAssignableFrom(o.getClass())) {
-                readers.add((MessageBodyReader)o); 
-            }
-            
-            if (MessageBodyWriter.class.isAssignableFrom(o.getClass())) {
-                writers.add((MessageBodyWriter)o); 
-            }
-        }
-        
-        sortReaders(readers);
-        sortWriters(writers);
-    }
-    
-    /*
-     * sorts the available providers according to the media types they declare
-     * support for. Sorting of media types follows the general rule: x/y < * x < *,
-     * i.e. a provider that explicitly lists a media types is sorted before a
-     * provider that lists *. Quality parameter values are also used such that
-     * x/y;q=1.0 < x/y;q=0.7.
-     */    
-    private void sortReaders(List<MessageBodyReader> entityProviders) {
-        Collections.sort(entityProviders, new MessageBodyReaderComparator());
-    }
-    
-    private void sortWriters(List<MessageBodyWriter> entityProviders) {
-        Collections.sort(entityProviders, new MessageBodyWriterComparator());
-    }
-    
-        
-    
-    /**
-     * Choose the first body reader provider that matches the requestedMimeType 
-     * for a sorted list of Entity providers
-     * Returns null if none is found.
-     * @param <T>
-     * @param messageBodyReaders
-     * @param type
-     * @param requestedMimeType
-     * @return
-     */
-    private <T> MessageBodyReader<T> chooseMessageReader(
-        List<MessageBodyReader> readers, Class<T> type, MediaType mediaType) {
-        for (MessageBodyReader<T> ep : readers) {
-            
-            if (!ep.isReadable(type)) {
-                continue;
-            }
-            
-            List<MediaType> supportedMediaTypes =
-                JAXRSUtils.getConsumeTypes(ep.getClass().getAnnotation(ConsumeMime.class));
-            
-            List<MediaType> availableMimeTypes = 
-                JAXRSUtils.intersectMimeTypes(Collections.singletonList(mediaType),
-                                              supportedMediaTypes);
-
-            if (availableMimeTypes.size() != 0) {
-                return ep;
-            }
-        }     
-        
-        return null;
-        
-    }
-    
-        
-    /**
-     * Choose the first body writer provider that matches the requestedMimeType 
-     * for a sorted list of Entity providers
-     * Returns null if none is found.
-     * @param <T>
-     * @param messageBodyWriters
-     * @param type
-     * @param requestedMimeType
-     * @return
-     */
-    private <T> MessageBodyWriter<T> chooseMessageWriter(
-        List<MessageBodyWriter> writers, Class<T> type, MediaType mediaType) {
-        for (MessageBodyWriter<T> ep : writers) {
-            if (!ep.isWriteable(type)) {
-                continue;
-            }
-            List<MediaType> supportedMediaTypes =
-                JAXRSUtils.getProduceTypes(ep.getClass().getAnnotation(ProduceMime.class));
-            
-            List<MediaType> availableMimeTypes = 
-                JAXRSUtils.intersectMimeTypes(Collections.singletonList(mediaType),
-                                              supportedMediaTypes);
-
-            if (availableMimeTypes.size() != 0) {
-                return ep;
-            }
-        }     
-        
-        return null;
-        
-    }
-    
-        
-    public boolean registerUserEntityProvider(Object o) {
-        setProviders(userMessageReaders, userMessageWriters, o);
-        return true;
-    }
-    
-    public boolean deregisterUserEntityProvider(Object o) {
-        boolean result = false;
-        if (o instanceof MessageBodyReader) {
-            result = userMessageReaders.remove(o);
-        }
-        return o instanceof MessageBodyReader 
-               ? result && userMessageWriters.remove(o) : result;
-                                               
-    }
-    
-    public List<MessageBodyReader> getDefaultMessageReaders() {
-        return defaultMessageReaders;
+    public ResponseBuilder createResponseBuilder() {
+        return new ResponseBuilderImpl();
     }
 
-    public List<MessageBodyWriter> getDefaultMessageWriters() {
-        return defaultMessageWriters;
-    }
-    
-    public List<MessageBodyReader> getUserMessageReaders() {
-        return userMessageReaders;
-    }
-    
-    public List<MessageBodyWriter> getUserMessageWriters() {
-        return userMessageWriters;
-    }
 
-    /**
-     * Use for injection of entityProviders
-     * @param entityProviders the entityProviders to set
-     */
-    public void setUserEntityProviders(List<?> userProviders) {
-        setProviders(userMessageReaders,
-                     userMessageWriters,
-                     userProviders.toArray());
+
+    @Override
+    public UriBuilder createUriBuilder() {
+        return new UriBuilderImpl();
     }
 
-    private static class MessageBodyReaderComparator 
-        implements Comparator<MessageBodyReader> {
-        
-        public int compare(MessageBodyReader e1, MessageBodyReader e2) {
-            ConsumeMime c = e1.getClass().getAnnotation(ConsumeMime.class);
-            String[] mimeType1 = {"*/*"};
-            if (c != null) {
-                mimeType1 = c.value();               
-            }
-            
-            ConsumeMime c2 = e2.getClass().getAnnotation(ConsumeMime.class);
-            String[] mimeType2 = {"*/*"};
-            if (c2 != null) {
-                mimeType2 = c2.value();               
-            }
-    
-            return compareString(mimeType1[0], mimeType2[0]);
-            
-        }
 
-        private int compareString(String str1, String str2) {
-            if (!str1.startsWith("*/") && str2.startsWith("*/")) {
-                return -1;
-            } else if (str1.startsWith("*/") && !str2.startsWith("*/")) {
-                return 1;
-            } 
-            
-            return str1.compareTo(str2);
-        }
-    }
-    
-    private static class MessageBodyWriterComparator 
-        implements Comparator<MessageBodyWriter> {
-        
-        public int compare(MessageBodyWriter e1, MessageBodyWriter e2) {
-            ProduceMime c = e1.getClass().getAnnotation(ProduceMime.class);
-            String[] mimeType1 = {"*/*"};
-            if (c != null) {
-                mimeType1 = c.value();               
-            }
-            
-            ProduceMime c2 = e2.getClass().getAnnotation(ProduceMime.class);
-            String[] mimeType2 = {"*/*"};
-            if (c2 != null) {
-                mimeType2 = c2.value();               
-            }
-    
-            return compareString(mimeType1[0], mimeType2[0]);
-            
-        }
-        
-        private int compareString(String str1, String str2) {
-            if (!str1.startsWith("*/") && str2.startsWith("*/")) {
-                return -1;
-            } else if (str1.startsWith("*/") && !str2.startsWith("*/")) {
-                return 1;
-            } 
-            
-            return str1.compareTo(str2);
-        }
+
+    @Override
+    public VariantListBuilder createVariantListBuilder() {
+        return new VariantListBuilderImpl(); 
     }
     
 

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java?rev=636586&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java (added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java Wed Mar 12 17:20:41 2008
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider;
+
+import java.security.Principal;
+
+import javax.ws.rs.core.SecurityContext;
+
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.message.Message;
+
+public class SecurityContextImpl implements SecurityContext {
+
+    private Message m;
+    
+    public SecurityContextImpl(Message m) {
+        this.m = m;
+    }
+
+    // TODO
+    public String getAuthenticationScheme() {
+        if (m.get(AuthorizationPolicy.class) != null) {
+            return SecurityContext.BASIC_AUTH;
+        }
+        return "Unknown scheme";
+    }
+
+    public Principal getUserPrincipal() {
+        org.apache.cxf.security.SecurityContext sc = 
+            (org.apache.cxf.security.SecurityContext)m.get(SecurityContext.class);
+        return sc == null ? null : sc.getUserPrincipal();
+    }
+
+    //  TODO
+    public boolean isSecure() {
+        return false;
+    }
+
+    public boolean isUserInRole(String role) {
+        org.apache.cxf.security.SecurityContext sc = 
+            (org.apache.cxf.security.SecurityContext)m.get(SecurityContext.class);
+        return sc == null ? false : sc.isUserInRole(role);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java?rev=636586&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java (added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java Wed Mar 12 17:20:41 2008
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.message.Message;
+
+/**
+ * SystemQueryHandler is capable of dealing with query extensions
+ * starting from _, for example, _contentType
+ *
+ */
+    
+public interface SystemQueryHandler {
+    
+    Response handleSystemQuery(Message m, MultivaluedMap<String, String> queries);
+    boolean supports(MultivaluedMap<String, String> queries);
+
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriBuilderImpl.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriBuilderImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriBuilderImpl.java Wed Mar 12 17:20:41 2008
@@ -165,12 +165,6 @@
     }
 
     @Override
-    public UriBuilder replacePath(String p) throws IllegalArgumentException {
-        paths = JAXRSUtils.getPathSegments(p, false);
-        return this;
-    }
-
-    @Override
     public UriBuilder replaceQueryParams(String q) throws IllegalArgumentException {
         this.query = JAXRSUtils.getStructuredParams(q, "&", true);
         return this;
@@ -233,6 +227,18 @@
             }
         }
         return b.length() > 0 ? b.toString() : null;
+    }
+
+    @Override
+    public boolean isEncode() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public UriBuilder replacePath(String... segments) throws IllegalArgumentException {
+        // TODO Auto-generated method stub
+        return null;
     }
     
     

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImpl.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/VariantListBuilderImpl.java Wed Mar 12 17:20:41 2008
@@ -32,7 +32,6 @@
 
 public class VariantListBuilderImpl extends VariantListBuilder {
     
-    private Set<String> charsets = new HashSet<String>();
     private Set<String> encodings = new HashSet<String>();
     private Set<String> languages = new HashSet<String>();
     private Set<MediaType> mediaTypes = new HashSet<MediaType>();
@@ -57,12 +56,6 @@
     }
 
     @Override
-    public VariantListBuilder charsets(String... csets) {
-        charsets.addAll(Arrays.asList(csets));
-        return this;
-    }
-
-    @Override
     public VariantListBuilder encodings(String... encs) {
         encodings.addAll(Arrays.asList(encs));
         return this;
@@ -89,17 +82,42 @@
         mediaTypes.clear();
         languages.clear();
         encodings.clear();
-        charsets.clear();
     }
     
     private void addVariants() {
+        if (mediaTypes.size() > 0) {
+            handleMediaTypes();
+        } else if (languages.size() > 0) {
+            handleLanguages(null);
+        } else if (encodings.size() > 0) {
+            for (String enc : encodings) {
+                variants.add(new Variant(null, null, enc));
+            }
+        } 
+    }
+    
+    private void handleMediaTypes() {
         for (MediaType type : mediaTypes) {
-            for (String lang : languages) {
-                for (String charset : charsets) {
-                    for (String enc : encodings) {
-                        variants.add(new Variant(type, lang, charset, enc));
-                    }
+            if (languages.size() > 0) {
+                handleLanguages(type);
+            } else if (encodings.size() > 0) {
+                for (String enc : encodings) {
+                    variants.add(new Variant(type, null, enc));
                 }
+            } else {
+                variants.add(new Variant(type, null, null));
+            }
+        }
+    }
+    
+    private void handleLanguages(MediaType type) {
+        for (String lang : languages) {
+            if (encodings.size() > 0) {
+                for (String enc : encodings) {
+                    variants.add(new Variant(type, lang, enc));
+                }    
+            } else {
+                variants.add(new Variant(type, lang, null));
             }
         }
     }

Copied: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/resources/META-INF/services/javax.ws.rs.ext.RuntimeDelegate (from r636320, incubator/cxf/trunk/rt/frontend/jaxrs/src/main/resources/META-INF/services/javax.ws.rs.ext.ProviderFactory)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/resources/META-INF/services/javax.ws.rs.ext.RuntimeDelegate?p2=incubator/cxf/trunk/rt/frontend/jaxrs/src/main/resources/META-INF/services/javax.ws.rs.ext.RuntimeDelegate&p1=incubator/cxf/trunk/rt/frontend/jaxrs/src/main/resources/META-INF/services/javax.ws.rs.ext.ProviderFactory&r1=636320&r2=636586&rev=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/resources/META-INF/services/javax.ws.rs.ext.ProviderFactory (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/resources/META-INF/services/javax.ws.rs.ext.RuntimeDelegate Wed Mar 12 17:20:41 2008
@@ -1 +1 @@
-org.apache.cxf.jaxrs.provider.ProviderFactoryImpl
\ No newline at end of file
+org.apache.cxf.jaxrs.provider.RuntimeDelegateImpl
\ No newline at end of file

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBeanTest.java Wed Mar 12 17:20:41 2008
@@ -19,6 +19,7 @@
 package org.apache.cxf.jaxrs;
 
 import java.util.List;
+import java.util.Set;
 
 import javax.ws.rs.core.MultivaluedMap;
 
@@ -53,32 +54,16 @@
         assertTrue(template.match("/bookstore/books/123", values));     
         assertFalse(rootCri.hasSubResources());   
         MethodDispatcher md = rootCri.getMethodDispatcher();
-        assertEquals(5, md.getOperationResourceInfos().size());  
-        for (OperationResourceInfo ori : md.getOperationResourceInfos()) {
-            if ("getBook".equals(ori.getMethod().getName())) {
-                assertEquals("GET", ori.getHttpMethod());
-                assertNotNull(ori.getURITemplate());
-                assertFalse(ori.isSubResourceLocator());
-            } else if ("getBookJSON".equals(ori.getMethod().getName())) {
-                assertEquals("GET", ori.getHttpMethod());
-                assertNotNull(ori.getURITemplate());
-                assertFalse(ori.isSubResourceLocator());
-            } else if ("addBook".equals(ori.getMethod().getName())) {
-                assertEquals("POST", ori.getHttpMethod());
-                assertNotNull(ori.getURITemplate());
-                assertFalse(ori.isSubResourceLocator());
-            } else if ("updateBook".equals(ori.getMethod().getName())) {
-                assertEquals("PUT", ori.getHttpMethod());
-                assertNotNull(ori.getURITemplate());
-                assertFalse(ori.isSubResourceLocator());
-            } else if ("deleteBook".equals(ori.getMethod().getName())) {
-                assertEquals("DELETE", ori.getHttpMethod());
-                assertNotNull(ori.getURITemplate());
-                assertFalse(ori.isSubResourceLocator());
-            } else {
-                fail("unexpected OperationResourceInfo" + ori.getMethod().getName());
-            }
-        }
+        assertEquals(7, md.getOperationResourceInfos().size());  
+        Set<OperationResourceInfo> ops = md.getOperationResourceInfos();
+        assertTrue("No operation found", verifyOp(ops, "getBook", "GET", false));
+        assertTrue("No operation found", verifyOp(ops, "getBookStoreInfo", "GET", false));
+        assertTrue("No operation found", verifyOp(ops, "getBooks", "GET", false));
+        assertTrue("No operation found", verifyOp(ops, "getBookJSON", "GET", false));
+        assertTrue("No operation found", verifyOp(ops, "addBook", "POST", false));
+        assertTrue("No operation found", verifyOp(ops, "updateBook", "PUT", false));
+        assertTrue("No operation found", verifyOp(ops, "deleteBook", "DELETE", false));
+        
     }
 
     @Test
@@ -124,7 +109,7 @@
         // Verify sub-resource ClassResourceInfo: Book
         assertEquals(1, rootCri.getSubClassResourceInfo().size());
         ClassResourceInfo subCri = rootCri.getSubClassResourceInfo().get(0);        
-        assertEquals(subCri.getURITemplate().getValue(), "/");
+        assertNull(subCri.getURITemplate());
         assertEquals(org.apache.cxf.jaxrs.resources.Book.class, subCri.getResourceClass());
         MethodDispatcher subMd = subCri.getMethodDispatcher();
         assertEquals(2, subMd.getOperationResourceInfos().size());
@@ -139,4 +124,18 @@
         assertNotNull(subOri2.getURITemplate());
     }
 
+    private boolean verifyOp(Set<OperationResourceInfo> ops,
+                             String opName, 
+                             String httpMethod, 
+                             boolean isSubresource) {
+        for (OperationResourceInfo ori : ops) {
+            if (opName.equals(ori.getMethod().getName())) {
+                assertEquals(httpMethod, ori.getHttpMethod());
+                assertNotNull(ori.getURITemplate());
+                assertEquals(isSubresource, ori.isSubResourceLocator());
+                return true;
+            }
+        }
+        return false;
+    }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java Wed Mar 12 17:20:41 2008
@@ -26,9 +26,10 @@
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
 import javax.ws.rs.ProduceMime;
 import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.HttpContext;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -48,15 +49,16 @@
 import org.easymock.classextension.IMocksControl;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSUtilsTest extends Assert {
     
     public class Customer {
         
-        @HttpContext private UriInfo uriInfo;
-        @HttpContext private HttpHeaders headers;
-        @HttpContext private Request request;
+        @Context private UriInfo uriInfo;
+        @Context private HttpHeaders headers;
+        @Context private Request request;
         
         public UriInfo getUriInfo() {
             return uriInfo;
@@ -92,14 +94,21 @@
         }
         
         @ProduceMime("text/xml")   
-        public void testMultipleQuery(@QueryParam("query") 
-                                      String queryString, @QueryParam("query2") String queryString2) {
+        public void testMultipleQuery(@QueryParam("query")  String queryString, 
+                                      @QueryParam("query2") String queryString2,
+                                      @QueryParam("query3") String queryString3) {
             // complete
         }
         
-        public void testParams(@HttpContext UriInfo info,
-                               @HttpContext HttpHeaders hs,
-                               @HttpContext Request r,
+        @ProduceMime("text/xml")   
+        public void testMatrixParam(@MatrixParam("p1")  String queryString, 
+                                    @MatrixParam("p2") String queryString2) {
+            // complete
+        }
+        
+        public void testParams(@Context UriInfo info,
+                               @Context HttpHeaders hs,
+                               @Context Request r,
                                @HeaderParam("Foo") String h) {
             // complete
         }
@@ -116,90 +125,133 @@
         sf.create();        
         List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
 
-        MultivaluedMap<String, String> values = new MetadataMap<String, String>(); 
         String contentTypes = "*/*";
         String acceptContentTypes = "*/*";
 
         //If acceptContentTypes does not specify a specific Mime type, the  
         //method is declared with a most specific ProduceMime type is selected.
         OperationResourceInfo ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123/",
-                                                                       "GET", values, contentTypes,
-                                                                       acceptContentTypes);       
+             "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);       
         assertNotNull(ori);
         assertEquals("getBookJSON", ori.getMethod().getName());
         
         //test
         acceptContentTypes = "application/json";
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123/",
-                                                                       "GET", values, contentTypes,
-                                                                       acceptContentTypes);        
+        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
+             "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
         assertNotNull(ori);
         assertEquals("getBookJSON", ori.getMethod().getName());
         
         //test 
         acceptContentTypes = "application/xml";
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123/",
-                                                                       "GET", values, contentTypes,
-                                                                       acceptContentTypes);        
+        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
+              "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
         assertNotNull(ori);
         assertEquals("getBook", ori.getMethod().getName());
         
+        //test 
+        acceptContentTypes = "application/xml";
+        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
+                      "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
+        assertNotNull(ori);
+        assertEquals("getBooks", ori.getMethod().getName());
+        
         //test find POST
         ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-                                                                       "POST", values, contentTypes,
-                                                                       acceptContentTypes);       
+                 "POST", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);       
         assertNotNull(ori);
         assertEquals("addBook", ori.getMethod().getName());
         
         //test find PUT
         ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-                                                                       "PUT", values, contentTypes,
-                                                                       acceptContentTypes);  
+            "PUT", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);  
         assertEquals("updateBook", ori.getMethod().getName());
         
         //test find DELETE
         ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
-                                                                       "DELETE", values, contentTypes,
-                                                                       acceptContentTypes);        
+             "DELETE", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
         assertNotNull(ori);
         assertEquals("deleteBook", ori.getMethod().getName());     
         
     }
     
     @Test
-    @org.junit.Ignore
+    public void testFindTargetResourceClassWithTemplates() throws Exception {
+        JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
+        sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStoreTemplates.class);
+        sf.create();        
+        List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
+
+        String contentTypes = "*/*";
+        String acceptContentTypes = "*/*";
+
+        //If acceptContentTypes does not specify a specific Mime type, the  
+        //method is declared with a most specific ProduceMime type is selected.
+        MetadataMap<String, String> values = new MetadataMap<String, String>();
+        OperationResourceInfo ori = JAXRSUtils.findTargetResourceClass(resources, "/1/2/",
+             "GET", values, contentTypes, acceptContentTypes);       
+        assertNotNull(ori);
+        assertEquals("getBooks", ori.getMethod().getName());
+        assertEquals("Only the first {id} should've been picked up", 2, values.size());
+        assertEquals("Only the first {id} should've been picked up", 1, values.get("id").size());
+        assertEquals("Only the first {id} should've been picked up", 1, 
+                     values.get(URITemplate.RIGHT_HAND_VALUE).size());
+        assertEquals("Only the first {id} should've been picked up", "1", values.getFirst("id"));
+        
+        values = new MetadataMap<String, String>();
+        ori = JAXRSUtils.findTargetResourceClass(resources, "/2",
+             "POST", values, contentTypes, acceptContentTypes);       
+        assertNotNull(ori);
+        assertEquals("updateBookStoreInfo", ori.getMethod().getName());
+        assertEquals("Only the first {id} should've been picked up", 2, values.size());
+        assertEquals("Only the first {id} should've been picked up", 1, values.get("id").size());
+        assertEquals("Only the first {id} should've been picked up", 1, 
+                     values.get(URITemplate.RIGHT_HAND_VALUE).size());
+        assertEquals("Only the first {id} should've been picked up", "2", values.getFirst("id"));
+        
+        values = new MetadataMap<String, String>();
+        ori = JAXRSUtils.findTargetResourceClass(resources, "/3/4",
+             "PUT", values, contentTypes, acceptContentTypes);       
+        assertNotNull(ori);
+        assertEquals("updateBook", ori.getMethod().getName());
+        assertEquals("Only the first {id} should've been picked up", 3, values.size());
+        assertEquals("Only the first {id} should've been picked up", 1, values.get("id").size());
+        assertEquals("Only the first {id} should've been picked up", 1, values.get("bookId").size());
+        assertEquals("Only the first {id} should've been picked up", 1, 
+                     values.get(URITemplate.RIGHT_HAND_VALUE).size());
+        assertEquals("Only the first {id} should've been picked up", "3", values.getFirst("id"));
+        assertEquals("Only the first {id} should've been picked up", "4", values.getFirst("bookId"));
+    }
+    
+    @Test
+    @Ignore
     public void testFindTargetResourceClassWithSubResource() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
         sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStore.class);
         sf.create();        
         List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
 
-        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
         String contentTypes = "*/*";
         String acceptContentTypes = "*/*";
 
         OperationResourceInfo ori = JAXRSUtils.findTargetResourceClass(resources,
-                                                                       "/bookstore/books/123/chapter/1",
-                                                                       "GET", values, contentTypes,
+            "/bookstore/books/123/chapter/1", "GET", new MetadataMap<String, String>(), contentTypes,
                                                                        acceptContentTypes);       
         assertNotNull(ori);
         assertEquals("getBook", ori.getMethod().getName());
         
         ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-                                                                       "POST", values, contentTypes,
-                                                                       acceptContentTypes);      
+            "POST", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);      
         assertNotNull(ori);
         assertEquals("addBook", ori.getMethod().getName());
         
         ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-                                                                       "PUT", values, contentTypes,
-                                                                       acceptContentTypes);        
+             "PUT", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
         assertNotNull(ori);
         assertEquals("updateBook", ori.getMethod().getName());
         
         ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
-                                                                       "DELETE", values, contentTypes,
-                                                                       acceptContentTypes);        
+            "DELETE", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
         assertNotNull(ori);
         assertEquals("deleteBook", ori.getMethod().getName());
     }
@@ -405,16 +457,36 @@
     
     @Test
     public void testMultipleQueryParameters() throws Exception {
-        Class[] argType = {String.class, String.class};
+        Class[] argType = {String.class, String.class, String.class};
         Method m = Customer.class.getMethod("testMultipleQuery", argType);
         MessageImpl messageImpl = new MessageImpl();
         
-        messageImpl.put(Message.QUERY_STRING, "query=first&query2=second");
+        messageImpl.put(Message.QUERY_STRING, "query=first&query2=second&query3");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null), 
                                                            null, messageImpl);
-        assertEquals("First Query Parameter of multiple was not matched correctly", "first", params.get(0));
+        assertEquals("First Query Parameter of multiple was not matched correctly", "first", 
+                     params.get(0));
         assertEquals("Second Query Parameter of multiple was not matched correctly", 
-                     "second", params.get(1));    
+                     "second", params.get(1));
+        assertEquals("Third Query Parameter of multiple was not matched correctly", 
+                     "", params.get(2));
+    }
+    
+    @Test
+    public void testMatrixParameters() throws Exception {
+        Class[] argType = {String.class, String.class};
+        Method m = Customer.class.getMethod("testMatrixParam", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        
+        messageImpl.put(Message.PATH_INFO, "/foo/bar;p1=1;p2");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null), 
+                                                           null, messageImpl);
+        assertEquals("2 Matrix params should've been identified", 2, params.size());
+        
+        assertEquals("First Matrix Parameter of multiple was not matched correctly", 
+                     "1", params.get(0));
+        assertEquals("Second Matrix Parameter of multiple was not matched correctly", 
+                     "", params.get(1));
     }
     
     @Test
@@ -435,21 +507,21 @@
         md.bind(ori2, Customer.class.getMethod("getItPlain", new Class[]{}));
         cri.setMethodDispatcher(md);
         
-        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", null, 
-                                               "*/*", "text/plain");
+        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", 
+                                              new MetadataMap<String, String>(), "*/*", "text/plain");
         
         assertSame(ori, ori2);
         
-        ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", null, 
+        ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", new MetadataMap<String, String>(), 
                                               "*/*", "text/xml");
                          
         assertSame(ori, ori1);
         
-        ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", null, 
+        ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", new MetadataMap<String, String>(), 
                                           "*/*", "*,text/plain,text/xml");
                      
         assertSame(ori, ori2);
-        ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", null, 
+        ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", new MetadataMap<String, String>(), 
                                           "*/*", "*,x/y,text/xml,text/plain");
                      
         assertSame(ori, ori2);

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java Wed Mar 12 17:20:41 2008
@@ -22,7 +22,7 @@
 import java.lang.reflect.Field;
 import java.util.List;
 
-import javax.ws.rs.core.HttpContext;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.UriInfo;
 
@@ -32,8 +32,8 @@
 public class ClassResourceInfoTest extends Assert {
     
     private static class TestClass {
-        @HttpContext UriInfo u;
-        @HttpContext HttpHeaders h;
+        @Context UriInfo u;
+        @Context HttpHeaders h;
         int i;
     }
     

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java Wed Mar 12 17:20:41 2008
@@ -25,6 +25,7 @@
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.ProduceMime;
+import javax.ws.rs.core.MediaType;
 
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
@@ -54,11 +55,13 @@
     @Test
     public void testWriteTo() throws Exception {
         InputStream is = getClass().getResourceAsStream("atomEntry.xml");
-        Entry simple = afd.readFrom(Entry.class, null, null, is);
+        Entry simple = afd.readFrom(Entry.class, 
+                                    MediaType.parse("application/atom+xml;type=entry"), null, is);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        afd.writeTo(simple, null, null, bos);
+        afd.writeTo(simple, MediaType.parse("application/atom+xml;type=entry"), null, bos);
         ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
-        Entry simpleCopy = afd.readFrom(Entry.class, null, null, bis);
+        Entry simpleCopy = afd.readFrom(Entry.class, 
+                                        MediaType.parse("application/atom+xml"), null, bis);
         assertEquals("Wrong entry title", 
                      "Atom-Powered Robots Run Amok", simpleCopy.getTitle());
         assertEquals("Wrong entry title", 
@@ -81,10 +84,15 @@
     
     @Test
     public void testAnnotations() {
-        assertEquals("application/atom+xml",
-                     afd.getClass().getAnnotation(ProduceMime.class).value()[0]);
-        assertEquals("application/atom+xml",
-                     afd.getClass().getAnnotation(ConsumeMime.class).value()[0]);
+        String[] values = afd.getClass().getAnnotation(ProduceMime.class).value();
+        assertEquals("3 types can be produced", 3, values.length);
+        assertTrue("application/atom+xml".equals(values[0])
+                   && "application/atom+xml;type=entry".equals(values[1])
+                   && "application/json".equals(values[2]));
+        values = afd.getClass().getAnnotation(ConsumeMime.class).value();
+        assertEquals("2 types can be consumed", 2, values.length);
+        assertTrue("application/atom+xml".equals(values[0])
+                   && "application/atom+xml;type=entry".equals(values[1]));
     }
     
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java Wed Mar 12 17:20:41 2008
@@ -79,10 +79,15 @@
     
     @Test
     public void testAnnotations() {
-        assertEquals("application/atom+xml",
-                     afd.getClass().getAnnotation(ProduceMime.class).value()[0]);
-        assertEquals("application/atom+xml",
-                     afd.getClass().getAnnotation(ConsumeMime.class).value()[0]);
+        String[] values = afd.getClass().getAnnotation(ProduceMime.class).value();
+        assertEquals("3 types can be produced", 3, values.length);
+        assertTrue("application/atom+xml".equals(values[0])
+                   && "application/atom+xml;type=feed".equals(values[1])
+                   && "application/json".equals(values[2]));
+        values = afd.getClass().getAnnotation(ConsumeMime.class).value();
+        assertEquals("2 types can be consumed", 2, values.length);
+        assertTrue("application/atom+xml".equals(values[0])
+                   && "application/atom+xml;type=feed".equals(values[1]));
     }
     
 }

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CacheControlHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CacheControlHeaderProviderTest.java?rev=636586&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CacheControlHeaderProviderTest.java (added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CacheControlHeaderProviderTest.java Wed Mar 12 17:20:41 2008
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider;
+
+import javax.ws.rs.core.CacheControl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CacheControlHeaderProviderTest extends Assert {
+    
+    
+        
+    @Test
+    public void testFromSimpleString() {
+        CacheControl c = CacheControl.parse(
+            "public;must-revalidate");
+        assertTrue(c.isPublic() && !c.isPrivate() && !c.isNoStore()
+                   && c.isMustRevalidate() && !c.isProxyRevalidate());
+        assertTrue(!c.isNoCache()
+                   && !c.isNoTransform() && c.getNoCacheFields().size() == 0
+                   && c.getPrivateFields().size() == 0);
+    }
+    
+    @Test
+    public void testFromComplexString() {
+        CacheControl c = CacheControl.parse(
+            "private=\"foo\";no-cache=\"bar\";no-store;no-transform;"
+            + "must-revalidate;proxy-revalidate;max-age=2;s-maxage=3");
+        assertTrue(!c.isPublic() && c.isPrivate() && c.isNoStore()
+                   && c.isMustRevalidate() && c.isProxyRevalidate() && c.isNoCache());
+        assertTrue(c.isNoTransform() && c.getNoCacheFields().size() == 1
+                   && c.getPrivateFields().size() == 1);
+        assertEquals("foo", c.getPrivateFields().get(0));
+        assertEquals("bar", c.getNoCacheFields().get(0));
+        
+    }
+    
+    
+    @Test
+    public void testToString() {
+        String s = "private=\"foo\";no-cache=\"bar\";no-store;no-transform;"
+            + "must-revalidate;proxy-revalidate;max-age=2;s-maxage=3";
+        String parsed = CacheControl.parse(s).toString();
+        assertEquals(s, parsed);       
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CacheControlHeaderProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CacheControlHeaderProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/CookieHeaderProviderTest.java Wed Mar 12 17:20:41 2008
@@ -26,11 +26,7 @@
 
 public class CookieHeaderProviderTest extends Assert {
     
-    @Test
-    public void testSupports() {
-        assertTrue(new CookieHeaderProvider().supports(Cookie.class));
-    }
-    
+        
     @Test
     public void testFromSimpleString() {
         Cookie c = Cookie.parse("foo=bar");

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/EntityTagHeaderProviderTest.java Wed Mar 12 17:20:41 2008
@@ -26,29 +26,27 @@
 
 public class EntityTagHeaderProviderTest extends Assert {
     
-    @Test
-    public void testSupports() {
-        assertTrue(new EntityTagHeaderProvider().supports(EntityTag.class));
-    }
-    
+      
     @Test
     public void testFromString() {
-        EntityTag tag = EntityTag.parse("");
+        EntityTag tag = EntityTag.parse("\"\"");
         assertTrue(!tag.isWeak() && "".equals(tag.getValue()));
         tag = EntityTag.parse("W/");
         assertTrue(tag.isWeak() && "".equals(tag.getValue()));
-        tag = EntityTag.parse("W/12345");
+        tag = EntityTag.parse("W/\"12345\"");
         assertTrue(tag.isWeak() && "12345".equals(tag.getValue()));
-        tag = EntityTag.parse("12345");
+        tag = EntityTag.parse("\"12345\"");
         assertTrue(!tag.isWeak() && "12345".equals(tag.getValue()));
     }
     
     @Test
     public void testToString() {
         EntityTag tag = new EntityTag("");
-        assertEquals("", tag.toString());
+        assertEquals("\"\"", tag.toString());
         tag = new EntityTag("", true);
-        assertEquals("W/", tag.toString());
+        assertEquals("W/\"\"", tag.toString());
+        tag = new EntityTag("bar");
+        assertEquals("\"bar\"", tag.toString());
         
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/MediaTypeHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/MediaTypeHeaderProviderTest.java?rev=636586&r1=636585&r2=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/MediaTypeHeaderProviderTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/MediaTypeHeaderProviderTest.java Wed Mar 12 17:20:41 2008
@@ -19,12 +19,10 @@
 
 package org.apache.cxf.jaxrs.provider;
 
-import java.text.ParseException;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.MediaType;
 
 import org.junit.Assert;
@@ -60,7 +58,7 @@
         try {
             new MediaTypeHeaderProvider().fromString("texthtml");
             fail("Parse exception must've been thrown");
-        } catch (ParseException pe) {
+        } catch (IllegalArgumentException pe) {
             // expected
         }
         
@@ -71,7 +69,7 @@
         try {
             new MediaTypeHeaderProvider().fromString("text/html;*");
             fail("Parse exception must've been thrown");
-        } catch (ParseException pe) {
+        } catch (IllegalArgumentException pe) {
             // expected
         }
     }
@@ -87,16 +85,6 @@
         MediaType expected = new MediaType("text", "html", params);
         
         assertEquals("Media type was not parsed correctly", expected, m);
-    }
-    
-    @Test
-    public void testSupports() {
-        MediaTypeHeaderProvider provider = 
-            new MediaTypeHeaderProvider();
-        
-        assertTrue(provider.supports(MediaType.class));
-        // I think we should have a single default header provider
-        assertFalse(provider.supports(EntityTag.class));
     }
     
     @Test

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NewCookieHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NewCookieHeaderProviderTest.java?rev=636586&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NewCookieHeaderProviderTest.java (added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NewCookieHeaderProviderTest.java Wed Mar 12 17:20:41 2008
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider;
+
+import javax.ws.rs.core.NewCookie;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NewCookieHeaderProviderTest extends Assert {
+    
+        
+    @Test
+    public void testFromSimpleString() {
+        NewCookie c = NewCookie.parse("foo=bar");
+        assertTrue("bar".equals(c.getValue())
+                   && "foo".equals(c.getName()));
+    }
+    
+        
+    @Test
+    public void testFromComplexString() {
+        NewCookie c = 
+            NewCookie.parse("foo=bar;Comment=comment;Path=path;Max-Age=10;Domain=domain;Secure;Version=1");
+        assertTrue("bar".equals(c.getValue())
+                   && "foo".equals(c.getName())
+                   && 1 == c.getVersion()
+                   && "path".equals(c.getPath())
+                   && "domain".equals(c.getDomain())
+                   && "comment".equals(c.getComment())
+                   && 10 == c.getMaxAge());
+    }
+    
+    @Test
+    public void testToString() {
+        NewCookie c = new NewCookie("foo", "bar", "path", "domain", "comment", 2, true);
+        assertEquals("foo=bar;Comment=comment;Domain=domain;Max-Age=2;Path=path;Secure;Version=1", 
+                     c.toString());
+               
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NewCookieHeaderProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NewCookieHeaderProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java (from r636320, incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?p2=incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java&p1=incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java&r1=636320&r2=636586&rev=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java Wed Mar 12 17:20:41 2008
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.cxf.jaxrs.provider;
 
 import java.io.File;
@@ -26,17 +27,10 @@
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.ProduceMime;
-import javax.ws.rs.core.CacheControl;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.Variant.VariantListBuilder;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.ProviderFactory;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.abdera.model.Entry;
@@ -47,45 +41,17 @@
 import org.junit.Before;
 import org.junit.Test;
 
-public class ProviderFactoryImplTest extends Assert {
-
-    @Before
-    public void setUp() throws Exception {
+public class ProviderFactoryTest extends Assert {
 
-    }
     
-    @Test
-    public void testCreateInstance() throws Exception {
-        assertSame(BuilderImpl.class,
-                   new ProviderFactoryImpl().
-                       createInstance(Response.Builder.class).getClass());
-        assertSame(UriBuilderImpl.class,
-                   new ProviderFactoryImpl().
-                       createInstance(UriBuilder.class).getClass());
-        assertSame(VariantListBuilderImpl.class,
-                   new ProviderFactoryImpl().
-                       createInstance(VariantListBuilder.class).getClass());
-    }
-    
-    @Test
-    public void testCreateHeaderProvider() throws Exception {
-        assertSame(MediaTypeHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(MediaType.class).getClass());
-        assertSame(EntityTagHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(EntityTag.class).getClass());
-        assertSame(CacheControlHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(CacheControl.class).getClass());
-        assertSame(CookieHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(Cookie.class).getClass());
+    @Before
+    public void setUp() {
+        ProviderFactory.getInstance().clearUserMessageProviders();
     }
     
     @Test
     public void testSortEntityProviders() throws Exception {
-        ProviderFactoryImpl pf = new ProviderFactoryImpl();
+        ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserEntityProvider(new TestStringProvider());
         pf.registerUserEntityProvider(new StringProvider());
         
@@ -125,7 +91,7 @@
         
         MessageBodyReader reader = ProviderFactory.getInstance()
             .createMessageBodyReader(type, mType);
-        assertTrue(errorMessage, provider == reader.getClass());
+        assertSame(errorMessage, provider, reader.getClass());
     
         MessageBodyWriter writer = ProviderFactory.getInstance()
             .createMessageBodyWriter(type, mType);
@@ -152,7 +118,7 @@
     
     @Test
     public void testGetStringProviderUsingProviderDeclaration() throws Exception {
-        ProviderFactoryImpl pf = (ProviderFactoryImpl)ProviderFactory.getInstance();
+        ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserEntityProvider(new TestStringProvider());
         verifyProvider(String.class, TestStringProvider.class, "text/html");
     }    
@@ -165,7 +131,7 @@
     
     @Test
     public void testRegisterCustomJSONEntityProvider() throws Exception {
-        ProviderFactoryImpl pf = (ProviderFactoryImpl)ProviderFactory.getInstance();
+        ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserEntityProvider(new CustomJSONProvider());
         verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomJSONProvider.class, 
                        "application/json", "User-registered provider was not returned first");
@@ -173,7 +139,7 @@
     
     @Test
     public void testRegisterCustomEntityProvider() throws Exception {
-        ProviderFactoryImpl pf = (ProviderFactoryImpl)ProviderFactory.getInstance();
+        ProviderFactory pf = (ProviderFactory)ProviderFactory.getInstance();
         pf.registerUserEntityProvider(new CustomWidgetProvider());
         
         verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomWidgetProvider.class, 

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestImplTest.java?rev=636586&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestImplTest.java (added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestImplTest.java Wed Mar 12 17:20:41 2008
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.ws.rs.core.EntityTag;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.apache.cxf.jaxrs.MetadataMap;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class RequestImplTest extends Assert {
+    
+    private Message m;
+    private MultivaluedMap<String, String> metadata;
+    
+    @Before
+    public void setUp() {
+        m = new MessageImpl();
+        metadata = new MetadataMap<String, String>();
+        m.put(Message.PROTOCOL_HEADERS, metadata);
+    }
+    
+    @After
+    public void tearUp() {
+        m = null;
+        metadata.clear();
+    }
+    
+    @Test
+    public void testWeakEtags() {
+        metadata.putSingle("If-Match", new EntityTag("123", true).toString());
+        
+        ResponseBuilder rb = 
+            new RequestImpl(m).evaluatePreconditions(new EntityTag("123"));
+        assertNotNull("Strict compararison is required", rb);
+        Response r = rb.build();
+        assertEquals("If-Match precondition was not met", 412, r.getStatus());
+        assertEquals("Response should include ETag", 
+                     "\"123\"", r.getMetadata().getFirst("ETag"));
+    }
+    
+    @Test
+    public void testStrictEtags() {
+        metadata.putSingle("If-Match", new EntityTag("123").toString());
+        
+        ResponseBuilder rb = 
+            new RequestImpl(m).evaluatePreconditions(new EntityTag("123"));
+        assertNull("Precondition must be met", rb);
+    }
+    
+    @Test
+    public void testStarEtags() {
+        metadata.putSingle("If-Match", "*");
+        
+        ResponseBuilder rb = 
+            new RequestImpl(m).evaluatePreconditions(new EntityTag("123"));
+        assertNull("Precondition must be met", rb);
+    }
+    
+    @Test
+    public void testBeforeDate() throws Exception {
+        metadata.putSingle("If-Modified-Since", "Sat, 29 Oct 1994 19:43:31 GMT");
+        Date serverDate = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
+            .parse("Sun, 29 Oct 1994 19:43:31 GMT");
+        
+        ResponseBuilder rb = 
+            new RequestImpl(m).evaluatePreconditions(serverDate);
+        assertNull("Precondition must be met", rb);
+    }
+    
+    @Test
+    @Ignore
+    public void testAfterDate() throws Exception {
+        metadata.putSingle("If-Modified-Since", "Sat, 29 Oct 1994 19:43:31 GMT");
+        Date serverDate = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
+            .parse("Fri, 28 Oct 1994 19:43:31 GMT");
+        
+        
+        ResponseBuilder rb = 
+            new RequestImpl(m).evaluatePreconditions(serverDate);
+        assertNotNull("Precondition is not met", rb);
+        
+        Response r = rb.build();
+        assertEquals("If-Modified-Since precondition was not met", 304, r.getStatus());
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ResponseBuilderImplTest.java (from r636320, incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BuilderImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ResponseBuilderImplTest.java?p2=incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ResponseBuilderImplTest.java&p1=incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BuilderImplTest.java&r1=636320&r2=636586&rev=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BuilderImplTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ResponseBuilderImplTest.java Wed Mar 12 17:20:41 2008
@@ -28,7 +28,7 @@
 import org.junit.Test;
 
 
-public class BuilderImplTest extends Assert {
+public class ResponseBuilderImplTest extends Assert {
 
         
     @Test

Copied: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImplTest.java (from r636320, incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImplTest.java?p2=incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImplTest.java&p1=incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java&r1=636320&r2=636586&rev=636586&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryImplTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RuntimeDelegateImplTest.java Wed Mar 12 17:20:41 2008
@@ -18,275 +18,58 @@
  */
 package org.apache.cxf.jaxrs.provider;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-
-import javax.ws.rs.ConsumeMime;
-import javax.ws.rs.ProduceMime;
 import javax.ws.rs.core.CacheControl;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
+import javax.ws.rs.core.NewCookie;
+import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.Variant.VariantListBuilder;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.ProviderFactory;
-import javax.xml.bind.annotation.XmlRootElement;
+import javax.ws.rs.ext.RuntimeDelegate;
 
-import org.apache.abdera.model.Entry;
-import org.apache.abdera.model.Feed;
-import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.jaxrs.JAXRSUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
-public class ProviderFactoryImplTest extends Assert {
-
-    @Before
-    public void setUp() throws Exception {
+public class RuntimeDelegateImplTest extends Assert {
 
+    @Test
+    public void testRuntimeDelegate() throws Exception {
+        RuntimeDelegate rd = RuntimeDelegate.getInstance();
+        assertSame(rd.getClass(), RuntimeDelegateImpl.class);
     }
     
     @Test
     public void testCreateInstance() throws Exception {
-        assertSame(BuilderImpl.class,
-                   new ProviderFactoryImpl().
-                       createInstance(Response.Builder.class).getClass());
+        assertSame(ResponseBuilderImpl.class,
+                   new RuntimeDelegateImpl().
+                       createInstance(ResponseBuilder.class).getClass());
         assertSame(UriBuilderImpl.class,
-                   new ProviderFactoryImpl().
+                   new RuntimeDelegateImpl().
                        createInstance(UriBuilder.class).getClass());
         assertSame(VariantListBuilderImpl.class,
-                   new ProviderFactoryImpl().
+                   new RuntimeDelegateImpl().
                        createInstance(VariantListBuilder.class).getClass());
     }
     
     @Test
     public void testCreateHeaderProvider() throws Exception {
         assertSame(MediaTypeHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(MediaType.class).getClass());
+                   new RuntimeDelegateImpl().
+                       createHeaderDelegate(MediaType.class).getClass());
         assertSame(EntityTagHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(EntityTag.class).getClass());
+                   new RuntimeDelegateImpl().
+                       createHeaderDelegate(EntityTag.class).getClass());
         assertSame(CacheControlHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(CacheControl.class).getClass());
+                   new RuntimeDelegateImpl().
+                       createHeaderDelegate(CacheControl.class).getClass());
         assertSame(CookieHeaderProvider.class,
-                   new ProviderFactoryImpl().
-                       createHeaderProvider(Cookie.class).getClass());
-    }
-    
-    @Test
-    public void testSortEntityProviders() throws Exception {
-        ProviderFactoryImpl pf = new ProviderFactoryImpl();
-        pf.registerUserEntityProvider(new TestStringProvider());
-        pf.registerUserEntityProvider(new StringProvider());
-        
-        List<MessageBodyReader> readers = pf.getUserMessageReaders();
-
-        assertTrue(indexOf(readers, TestStringProvider.class) 
-                   < indexOf(readers, StringProvider.class));
-        
-        List<MessageBodyWriter> writers = pf.getUserMessageWriters();
-
-        assertTrue(indexOf(writers, TestStringProvider.class) 
-                   < indexOf(writers, StringProvider.class));
-        
-        //REVISIT the compare algorithm
-        //assertTrue(indexOf(providers, JSONProvider.class) < indexOf(providers, TestStringProvider.class));
-    }
-    
-    @Test
-    public void testGetStringProvider() throws Exception {
-        verifyProvider(String.class, StringProvider.class, "text/html");
-    }
-    
-    @Test
-    public void testGetBinaryProvider() throws Exception {
-        verifyProvider(byte[].class, BinaryDataProvider.class, "*/*");
-        verifyProvider(InputStream.class, BinaryDataProvider.class, "image/png");
-        MessageBodyWriter writer = ProviderFactory.getInstance()
-            .createMessageBodyWriter(File.class, JAXRSUtils.ALL_TYPES);
-        assertTrue(BinaryDataProvider.class == writer.getClass());
+                   new RuntimeDelegateImpl().
+                       createHeaderDelegate(Cookie.class).getClass());
+        assertSame(NewCookieHeaderProvider.class,
+                   new RuntimeDelegateImpl().
+                       createHeaderDelegate(NewCookie.class).getClass());
     }
     
-    private void verifyProvider(Class<?> type, Class<?> provider, String mediaType,
-                                String errorMessage) 
-        throws Exception {
-        
-        MediaType mType = MediaType.parse(mediaType);
-        
-        MessageBodyReader reader = ProviderFactory.getInstance()
-            .createMessageBodyReader(type, mType);
-        assertTrue(errorMessage, provider == reader.getClass());
     
-        MessageBodyWriter writer = ProviderFactory.getInstance()
-            .createMessageBodyWriter(type, mType);
-        assertTrue(errorMessage, provider == writer.getClass());
-    }
-    
-    
-    private void verifyProvider(Class<?> type, Class<?> provider, String mediaType) 
-        throws Exception {
-        verifyProvider(type, provider, mediaType, "Unexpected provider found");
-        
-    }
-       
-    @Test
-    public void testGetStringProviderWildCard() throws Exception {
-        verifyProvider(String.class, StringProvider.class, "text/*");
-    }
-    
-    @Test
-    public void testGetAtomProvider() throws Exception {
-        verifyProvider(Entry.class, AtomEntryProvider.class, "application/atom+xml");
-        verifyProvider(Feed.class, AtomFeedProvider.class, "application/atom+xml");
-    }
-    
-    @Test
-    public void testGetStringProviderUsingProviderDeclaration() throws Exception {
-        ProviderFactoryImpl pf = (ProviderFactoryImpl)ProviderFactory.getInstance();
-        pf.registerUserEntityProvider(new TestStringProvider());
-        verifyProvider(String.class, TestStringProvider.class, "text/html");
-    }    
-    
-    @Test
-    public void testGetJSONProviderConsumeMime() throws Exception {
-        verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, JSONProvider.class, 
-                       "application/json");
-    }
-    
-    @Test
-    public void testRegisterCustomJSONEntityProvider() throws Exception {
-        ProviderFactoryImpl pf = (ProviderFactoryImpl)ProviderFactory.getInstance();
-        pf.registerUserEntityProvider(new CustomJSONProvider());
-        verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomJSONProvider.class, 
-                       "application/json", "User-registered provider was not returned first");
-    }
-    
-    @Test
-    public void testRegisterCustomEntityProvider() throws Exception {
-        ProviderFactoryImpl pf = (ProviderFactoryImpl)ProviderFactory.getInstance();
-        pf.registerUserEntityProvider(new CustomWidgetProvider());
-        
-        verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomWidgetProvider.class, 
-                       "application/widget", "User-registered provider was not returned first");
-    }
-    
-    private int indexOf(List<? extends Object> providers, Class providerType) {
-        int index = 0;
-        for (Object p : providers) {
-            if (p.getClass().isAssignableFrom(providerType)) {
-                break;
-            }
-            index++;
-        }
-        return index;
-    }
-    
-    @ConsumeMime("text/html")
-    @ProduceMime("text/html")
-    private final class TestStringProvider 
-        implements MessageBodyReader<String>, MessageBodyWriter<String>  {
-
-        public boolean isReadable(Class<?> type) {
-            return type == String.class;
-        }
-        
-        public boolean isWriteable(Class<?> type) {
-            return type == String.class;
-        }
-        
-        public long getSize(String s) {
-            return s.length();
-        }
-
-        public String readFrom(Class<String> type, MediaType m, MultivaluedMap<String, String> headers,
-                               InputStream is) {
-            try {
-                return IOUtils.toString(is);
-            } catch (IOException e) {
-                // TODO: better exception handling
-            }
-            return null;
-        }
-
-        public void writeTo(String obj, MediaType m, MultivaluedMap<String, Object> headers, 
-                            OutputStream os) {
-            try {
-                os.write(obj.getBytes());
-            } catch (IOException e) {
-                // TODO: better exception handling
-            }
-        }
-
-    }
-    
-    @ConsumeMime("application/json")
-    @ProduceMime("application/json")
-    private final class CustomJSONProvider 
-        implements MessageBodyReader<String>, MessageBodyWriter<String>  {
-
-        public boolean isReadable(Class<?> type) {
-            return type.getAnnotation(XmlRootElement.class) != null;
-        }
-        
-        public boolean isWriteable(Class<?> type) {
-            return type.getAnnotation(XmlRootElement.class) != null;
-        }
-        
-        public long getSize(String s) {
-            return s.length();
-        }
-
-        public String readFrom(Class<String> type, MediaType m, MultivaluedMap<String, String> headers,
-                               InputStream is) {    
-            //Dummy
-            return null;
-        }
-
-        public void writeTo(String obj, MediaType m, MultivaluedMap<String, Object> headers, 
-                            OutputStream os) {
-            //Dummy
-        }
-
-    }
-    
-    @ConsumeMime("application/widget")
-    @ProduceMime("application/widget")
-    private final class CustomWidgetProvider
-        implements MessageBodyReader<String>, MessageBodyWriter<String>  {
-
-        public boolean isReadable(Class<?> type) {
-            return type.getAnnotation(XmlRootElement.class) != null;
-        }
-        
-        public boolean isWriteable(Class<?> type) {
-            return type.getAnnotation(XmlRootElement.class) != null;
-        }
-        
-        public long getSize(String s) {
-            return s.length();
-        }
-
-
-        public String readFrom(Class<String> type, MediaType m, MultivaluedMap<String, String> headers,
-                               InputStream is) {    
-            //Dummy
-            return null;
-        }
-
-        public void writeTo(String obj, MediaType m, MultivaluedMap<String, Object> headers, 
-                            OutputStream os) {
-            //Dummy
-        }
-
-    }
 }



Mime
View raw message