wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jra...@apache.org
Subject svn commit: r1027712 [5/5] - in /incubator/wink/trunk: wink-client-apache-httpclient/ wink-client/ wink-common/ wink-common/src/main/java/org/apache/wink/common/internal/registry/ wink-common/src/main/resources/org/apache/wink/common/internal/i18n/ win...
Date Tue, 26 Oct 2010 19:52:56 GMT
Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneProviderOnlyAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneProviderOnlyAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneProviderOnlyAppStartupTest.java
(added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneProviderOnlyAppStartupTest.java
Tue Oct 26 19:52:54 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.wink.server.serviceability;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+/**
+ * Tests that a JAX-RS Provider is logged properly at the INFO level.
+ */
+public class InfoOneProviderOnlyAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {Provider1.class};
+    }
+
+    @Provider
+    public static class Provider1 implements MessageBodyWriter<Object> {
+
+        public long getSize(Object t,
+                            Class<?> type,
+                            Type genericType,
+                            Annotation[] annotations,
+                            MediaType mediaType) {
+            return 0;
+        }
+
+        public boolean isWriteable(Class<?> type,
+                                   Type genericType,
+                                   Annotation[] annotations,
+                                   MediaType mediaType) {
+            return false;
+        }
+
+        public void writeTo(Object t,
+                            Class<?> type,
+                            Type genericType,
+                            Annotation[] annotations,
+                            MediaType mediaType,
+                            MultivaluedMap<String, Object> httpHeaders,
+                            OutputStream entityStream) throws IOException {
+        }
+
+    }
+
+    private InMemoryHandler handler;
+
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    @Override
+    protected void setUp() throws Exception {
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.INFO);
+
+        winkLogger.setLevel(Level.INFO);
+        winkLogger.addHandler(handler);
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        winkLogger.removeHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.tearDown();
+    }
+
+    /**
+     * Tests that a Provider is logged at the INFO level.
+     */
+    public void testLogOneProvider() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals(Level.INFO, records.get(2).getLevel());
+        assertEquals("The class org.apache.wink.server.serviceability.InfoOneProviderOnlyAppStartupTest$Provider1
was registered as a JAX-RS MessageBodyWriter provider for all Java types and */* media types.",
+                     records.get(2).getMessage());
+
+        assertEquals(3, records.size());
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneResourceOnlyAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneResourceOnlyAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneResourceOnlyAppStartupTest.java
(added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoOneResourceOnlyAppStartupTest.java
Tue Oct 26 19:52:54 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.wink.server.serviceability;
+
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.Path;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+/**
+ * Tests that a message indicating 1 registered resource was added.
+ */
+public class InfoOneResourceOnlyAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {Res1.class};
+    }
+
+    @Path("/hello")
+    public static class Res1 {
+
+    }
+
+    private InMemoryHandler handler;
+
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    @Override
+    protected void setUp() throws Exception {
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.INFO);
+
+        winkLogger.setLevel(Level.INFO);
+        winkLogger.addHandler(handler);
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        winkLogger.removeHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.tearDown();
+    }
+
+    public void testLogResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals(Level.INFO, records.get(2).getLevel());
+        assertEquals("The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.InfoOneResourceOnlyAppStartupTest$Res1
with @Path(/hello).",
+                     records.get(2).getMessage());
+
+        assertEquals(4, records.size());
+    }
+}

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/ServiceabilityTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/ServiceabilityTest.java?rev=1027712&r1=1027711&r2=1027712&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/ServiceabilityTest.java
(original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/ServiceabilityTest.java
Tue Oct 26 19:52:54 2010
@@ -19,8 +19,8 @@
 
 package org.apache.wink.server.serviceability;
 
-import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.logging.LogRecord;
 
@@ -44,16 +44,16 @@ import org.springframework.mock.web.Mock
 import org.springframework.mock.web.MockHttpServletResponse;
 
 /**
- * 
- * When running this test in Eclipse or another IDE, make sure project wink-component-test-support
is first in the classpath
- * so that SLF4J picks up the SLF4J bridge provided from it.  Otherwise, you'll get no log
output to assert against.
- *
+ * When running this test in Eclipse or another IDE, make sure project
+ * wink-component-test-support is first in the classpath so that SLF4J picks up
+ * the SLF4J bridge provided from it. Otherwise, you'll get no log output to
+ * assert against.
  */
 public class ServiceabilityTest extends MockServletInvocationTest {
 
     @Override
     protected Class<?>[] getClasses() {
-        return new Class<?>[]{MyResource.class, MyContextResolver.class, MyContextResolver1.class};
+        return new Class<?>[] {MyResource.class, MyContextResolver.class, MyContextResolver1.class};
     }
 
     @Path("/root")
@@ -70,7 +70,7 @@ public class ServiceabilityTest extends 
         public String getHTML() {
             return "some html";
         }
-        
+
         @GET
         @Path("2")
         @Produces(MediaType.TEXT_PLAIN)
@@ -79,21 +79,21 @@ public class ServiceabilityTest extends 
         }
 
     }
-    
+
     // intentionally forgetting @Provider annotation as part of test
-    public static class MyContextResolver implements ContextResolver {
-        public Object getContext(Class type) {
+    public static class MyContextResolver implements ContextResolver<Object> {
+        public Object getContext(Class<?> type) {
             return null;
         }
     }
-    
+
     @Provider
-    public static class MyContextResolver1 implements ContextResolver {
-        public Object getContext(Class type) {
+    public static class MyContextResolver1 implements ContextResolver<Object> {
+        public Object getContext(Class<?> type) {
             return null;
         }
     }
-    
+
     public static class MyApp extends Application {
 
         @Override
@@ -102,7 +102,7 @@ public class ServiceabilityTest extends 
             classes.add(MyAppResource.class);
             return classes;
         }
-        
+
         @Path("/myapp")
         public static class MyAppResource {
             @GET
@@ -112,9 +112,9 @@ public class ServiceabilityTest extends 
                 return "some private text";
             }
         }
-        
+
     }
-    
+
     public static class MockAppValidator extends ApplicationValidator {
 
         @Override
@@ -126,9 +126,8 @@ public class ServiceabilityTest extends 
         public boolean isValidResource(Class<?> cls) {
             return true;
         }
-        
+
     }
-    
 
     @Override
     protected void setUp() throws Exception {
@@ -141,137 +140,147 @@ public class ServiceabilityTest extends 
         WinkLogHandler.clearRecords();
         super.tearDown();
     }
-    
+
     public void testGoodAppStartupInfoLogOutput() throws Exception {
         WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.INFO);
         MockAppValidator mockAppValidator = new MockAppValidator();
-        ResourceRegistry mockResourceRegistry = new ResourceRegistry(new LifecycleManagersRegistry(),
mockAppValidator);
-        ProvidersRegistry mockProvidersRegistry = new ProvidersRegistry(new LifecycleManagersRegistry(),
mockAppValidator);
-        ApplicationProcessor appProcessor = new ApplicationProcessor(new MyApp(), mockResourceRegistry,
mockProvidersRegistry, false);
+        ResourceRegistry mockResourceRegistry =
+            new ResourceRegistry(new LifecycleManagersRegistry(), mockAppValidator);
+        ProvidersRegistry mockProvidersRegistry =
+            new ProvidersRegistry(new LifecycleManagersRegistry(), mockAppValidator);
+        ApplicationProcessor appProcessor =
+            new ApplicationProcessor(new MyApp(), mockResourceRegistry, mockProvidersRegistry,
false);
         appProcessor.process();
         WinkLogHandler.turnLoggingCaptureOff();
-        ArrayList<LogRecord> records = WinkLogHandler.getRecords();
-        
-        assertEquals(3, records.size());
-        assertEquals("The following application has been processed: org.apache.wink.server.serviceability.ServiceabilityTest$MyApp",
records.get(0).getMessage());
-        assertEquals("Registered resources: \n" +
-                "  Path: myapp; ClassMetadata: Class: org.apache.wink.server.serviceability.ServiceabilityTest$MyApp$MyAppResource",
records.get(1).getMessage());
-        assertEquals("The following user-defined JAX-RS providers are registered: \n" +
-                "RawType: interface javax.ws.rs.ext.MessageBodyReader\n" +
-                "Data Map: {empty}\n" +
-                "RawType: interface javax.ws.rs.ext.MessageBodyWriter\n" +
-                "Data Map: {empty}\n" +
-                "RawType: interface javax.ws.rs.ext.ContextResolver\n" +
-                "Data Map: {empty}", records.get(2).getMessage());
+        List<LogRecord> records = WinkLogHandler.getRecords();
+
+        assertEquals(1, records.size());
+        assertEquals("The following JAX-RS application has been processed: org.apache.wink.server.serviceability.ServiceabilityTest$MyApp",
+                     records.get(0).getMessage());
     }
-    
+
     public void testGoodURLLogOutput1() throws Exception {
         WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG);
-        
+
         MockHttpServletRequest mockRequest =
             MockRequestConstructor.constructMockRequest("GET", "/root", MediaType.TEXT_PLAIN);
         MockHttpServletResponse mockResponse = invoke(mockRequest);
         assertEquals(200, mockResponse.getStatus());
         assertEquals("some text", mockResponse.getContentAsString());
-        
+
         WinkLogHandler.turnLoggingCaptureOff();
-        ArrayList<LogRecord> records = WinkLogHandler.getRecords();
-        
-        assertEquals(2, records.size());
-        assertEquals("Processing GET request to http://localhost:80/root, source content
type is null, acceptable media types include text/plain", records.get(0).getMessage());
+        List<LogRecord> records = WinkLogHandler.getRecords();
+
+        assertEquals(9, records.size());
+        assertEquals("Processing GET request to http://localhost:80/root, source content
type is null, acceptable media types include text/plain",
+                     records.get(0).getMessage());
     }
-    
+
     public void testGoodURLLogOutput2() throws Exception {
         WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG);
-        
+
         MockHttpServletRequest mockRequest =
             MockRequestConstructor.constructMockRequest("GET", "/root", MediaType.TEXT_HTML);
         MockHttpServletResponse mockResponse = invoke(mockRequest);
         assertEquals(200, mockResponse.getStatus());
         assertEquals("some html", mockResponse.getContentAsString());
-        
+
         WinkLogHandler.turnLoggingCaptureOff();
-        ArrayList<LogRecord> records = WinkLogHandler.getRecords();
-        
-        assertEquals(2, records.size());
-        assertEquals("Processing GET request to http://localhost:80/root, source content
type is null, acceptable media types include text/html", records.get(0).getMessage());
+        List<LogRecord> records = WinkLogHandler.getRecords();
+
+        assertEquals(9, records.size());
+        assertEquals("Processing GET request to http://localhost:80/root, source content
type is null, acceptable media types include text/html",
+                     records.get(0).getMessage());
     }
-    
+
     public void testGoodURLLogOutput3() throws Exception {
         WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG);
-        
+
         MockHttpServletRequest mockRequest =
             MockRequestConstructor.constructMockRequest("GET", "/root", MediaType.TEXT_PLAIN);
         mockRequest.setQueryString("param1=value1");
         MockHttpServletResponse mockResponse = invoke(mockRequest);
         assertEquals(200, mockResponse.getStatus());
         assertEquals("some text", mockResponse.getContentAsString());
-        
+
         WinkLogHandler.turnLoggingCaptureOff();
-        ArrayList<LogRecord> records = WinkLogHandler.getRecords();
-        
-        assertEquals(2, records.size());
-        assertEquals("Processing GET request to http://localhost:80/root?param1=value1, source
content type is null, acceptable media types include text/plain", records.get(0).getMessage());
+        List<LogRecord> records = WinkLogHandler.getRecords();
+
+        assertEquals(9, records.size());
+        assertEquals("Processing GET request to http://localhost:80/root?param1=value1, source
content type is null, acceptable media types include text/plain",
+                     records.get(0).getMessage());
     }
-    
+
     public void testGoodURLLogOutput4() throws Exception {
         WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG);
-        
+
         MockHttpServletRequest mockRequest =
             MockRequestConstructor.constructMockRequest("GET", "/root/2", MediaType.TEXT_PLAIN);
         MockHttpServletResponse mockResponse = invoke(mockRequest);
         assertEquals(200, mockResponse.getStatus());
         assertEquals("some text 2", mockResponse.getContentAsString());
-        
+
         WinkLogHandler.turnLoggingCaptureOff();
-        ArrayList<LogRecord> records = WinkLogHandler.getRecords();
-        
-        assertEquals(2, records.size());
-        assertEquals("Processing GET request to http://localhost:80/root/2, source content
type is null, acceptable media types include text/plain", records.get(0).getMessage());
+        List<LogRecord> records = WinkLogHandler.getRecords();
+
+        assertEquals(9, records.size());
+        assertEquals("Processing GET request to http://localhost:80/root/2, source content
type is null, acceptable media types include text/plain",
+                     records.get(0).getMessage());
     }
-    
+
     public void testBadURLLogOutput1() throws Exception {
         WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.INFO);
-        
+
         MockHttpServletRequest mockRequest =
             MockRequestConstructor.constructMockRequest("GET", "/root/BAD", MediaType.TEXT_PLAIN);
         MockHttpServletResponse mockResponse = invoke(mockRequest);
         assertEquals(404, mockResponse.getStatus());
-        
+
         WinkLogHandler.turnLoggingCaptureOff();
-        ArrayList<LogRecord> records = WinkLogHandler.getRecords();
-        
+        List<LogRecord> records = WinkLogHandler.getRecords();
+
         assertEquals(1, records.size());
-        assertEquals("The following error occurred during the invocation of the handlers
chain: WebApplicationException (404 - Not Found) while processing GET request sent to http://localhost:80/root/BAD",
records.get(0).getMessage());
-        assertNull(records.get(0).getThrown());  // when NOT in debug mode, exception should
NOT show up in the debug trace
+        assertEquals("The following error occurred during the invocation of the handlers
chain: WebApplicationException (404 - Not Found) with message 'null' while processing GET
request sent to http://localhost:80/root/BAD",
+                     records.get(0).getMessage());
+        assertNull(records.get(0).getThrown()); // when NOT in debug mode,
+                                                // exception should NOT show up
+                                                // in the debug trace
     }
-    
+
     public void testBadURLLogOutput2() throws Exception {
         WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG);
-        
+
         MockHttpServletRequest mockRequest =
             MockRequestConstructor.constructMockRequest("GET", "/root/BAD", MediaType.TEXT_PLAIN);
         MockHttpServletResponse mockResponse = invoke(mockRequest);
         assertEquals(404, mockResponse.getStatus());
-        
+
         WinkLogHandler.turnLoggingCaptureOff();
-        ArrayList<LogRecord> records = WinkLogHandler.getRecords();
-        
-        assertEquals(4, records.size());
-        assertEquals("Processing GET request to http://localhost:80/root/BAD, source content
type is null, acceptable media types include text/plain", records.get(0).getMessage());
-        assertEquals("The following error occurred during the invocation of the handlers
chain: WebApplicationException (404 - Not Found) while processing GET request sent to http://localhost:80/root/BAD",
records.get(1).getMessage());
-        assertNotNull(records.get(1).getThrown());  // when in debug mode, exception should
show up in the debug trace
-        assertEquals("Registered resources: \n" +
-                "  Path: root; ClassMetadata: Class: org.apache.wink.server.serviceability.ServiceabilityTest$MyResource\n"
+
-                "  Path: ; ClassMetadata: Class: org.apache.wink.server.internal.resources.HtmlServiceDocumentResource",
records.get(2).getMessage());
-        assertEquals("The following user-defined JAX-RS providers are registered: \n" +
-                "RawType: interface javax.ws.rs.ext.MessageBodyReader\nData Map: {empty}"
+
-                "\nRawType: interface javax.ws.rs.ext.MessageBodyWriter\nData Map: {empty}"
+
-                "\nRawType: interface javax.ws.rs.ext.ContextResolver\nData Map: \n" +
-                "MediaType key = */*\n" +
-                "ObjectFactory Set value = {\n" +
-                "  class org.apache.wink.server.serviceability.ServiceabilityTest$MyContextResolver1\n"
+
-                "}\n", records.get(3).getMessage());
+        List<LogRecord> records = WinkLogHandler.getRecords();
+
+        assertEquals(11, records.size());
+        assertEquals("Processing GET request to http://localhost:80/root/BAD, source content
type is null, acceptable media types include text/plain",
+                     records.get(0).getMessage());
+        assertEquals("The following error occurred during the invocation of the handlers
chain: WebApplicationException (404 - Not Found) with message 'null' while processing GET
request sent to http://localhost:80/root/BAD",
+                     records.get(5).getMessage());
+        assertNotNull(records.get(5).getThrown()); // when in debug mode,
+                                                   // exception should show up
+                                                   // in the debug trace
+        // assertEquals("Registered resources: \n" +
+        // "  Path: root; ClassMetadata: Class: org.apache.wink.server.serviceability.ServiceabilityTest$MyResource",
+        // records.get(2).getMessage());
+        // assertEquals("The following user-defined JAX-RS providers are registered: \n"
+        // +
+        // "RawType: interface javax.ws.rs.ext.ContextResolver\nData Map: \n" +
+        // "MediaType key = */*\n" +
+        // "ObjectFactory Set value = {\n" +
+        // "  class org.apache.wink.server.serviceability.ServiceabilityTest$MyContextResolver1\n"
+        // +
+        // "}\n" +
+        // "\nRawType: interface javax.ws.rs.ext.MessageBodyReader\nData Map: {empty}"
+        // +
+        // "\nRawType: interface javax.ws.rs.ext.MessageBodyWriter\nData Map: {empty}",
+        // records.get(3).getMessage());
     }
 
 }

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/WarnProviderDoesNotImplementInterfaceTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/WarnProviderDoesNotImplementInterfaceTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/WarnProviderDoesNotImplementInterfaceTest.java
(added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/WarnProviderDoesNotImplementInterfaceTest.java
Tue Oct 26 19:52:54 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.wink.server.serviceability;
+
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.ext.Provider;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+public class WarnProviderDoesNotImplementInterfaceTest extends MockServletInvocationTest
{
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {Provider1.class};
+    }
+
+    @Provider
+    public static class Provider1 {
+
+    }
+
+    private InMemoryHandler handler;
+
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    @Override
+    protected void setUp() throws Exception {
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.INFO);
+
+        winkLogger.setLevel(Level.INFO);
+        winkLogger.addHandler(handler);
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        winkLogger.removeHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.tearDown();
+    }
+
+    public void testLogResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals(Level.WARNING, records.get(1).getLevel());
+        assertEquals("The @javax.ws.rs.ext.Provider annotated class class org.apache.wink.server.serviceability.WarnProviderDoesNotImplementInterfaceTest$Provider1
does not implement a recognized Provider interface. The runtime is ignoring this class. Verify
that the class implements javax.ws.rs.ext.ContextResolver, javax.ws.rs.ext.ExceptionMapper,
javax.ws.rs.ext.MessageBodyReader, or javax.ws.rs.ext.MessageBodyWriter.",
+                     records.get(1).getMessage());
+
+        assertEquals(Level.INFO, records.get(3).getLevel());
+        assertEquals("There are no custom JAX-RS providers defined in the application.",
records.get(3)
+            .getMessage());
+
+        assertEquals(4, records.size());
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/serviceability/DebugHandlerThrowsExceptionTest.properties
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/serviceability/DebugHandlerThrowsExceptionTest.properties?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/serviceability/DebugHandlerThrowsExceptionTest.properties
(added)
+++ incubator/wink/trunk/wink-server/src/test/resources/org/apache/wink/server/serviceability/DebugHandlerThrowsExceptionTest.properties
Tue Oct 26 19:52:54 2010
@@ -0,0 +1,19 @@
+###############################################################################
+#     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.
+###############################################################################
+wink.handlersFactoryClass=org.apache.wink.server.serviceability.DebugHandlerThrowsExceptionTest$UserHandlersProvider



Mime
View raw message