wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jra...@apache.org
Subject svn commit: r1027712 [4/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/DebugProviderThrowsExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugProviderThrowsExceptionTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugProviderThrowsExceptionTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugProviderThrowsExceptionTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,391 @@
+/*******************************************************************************
+ * 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.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.wink.common.internal.log.LogUtils;
+import org.apache.wink.common.internal.registry.ProvidersRegistry;
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.RequestProcessor;
+import org.apache.wink.server.internal.handlers.FlushResultHandler;
+import org.apache.wink.server.internal.handlers.InvokeMethodHandler;
+import org.apache.wink.server.internal.registry.ServerInjectableFactory;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+/*
+ * 
+ * Test what is printed to the log when a resource class (from the developer's application) throws an exception.
+ * An exception may be thrown on purpose from a resource as part of normal transactions for this particular app,
+ * thus we don't want to report it to INFO due to the possibility of quickly filling up logs.  Instead, data is
+ * logged when DEBUG is turned on, and logged only once.
+ * 
+ */
+
+public class DebugProviderThrowsExceptionTest extends MockServletInvocationTest {
+
+    enum BAD_METHOD {
+        isReadable,
+        readFrom,
+        getSize,
+        isWriteable,
+        writeTo,
+    }
+    
+    static BAD_METHOD whichMethod;
+    
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource.class, MyProvider.class};
+    }
+    
+    @Path("/root")
+    public static class MyResource {
+
+        @POST
+        public String post(String input) {
+            return "";
+        }
+        
+    }
+
+    @Provider
+    public static class MyProvider implements MessageBodyReader<String>, MessageBodyWriter<String> {
+
+        public boolean isReadable(Class<?> type, Type genericType,
+                Annotation[] annotations, MediaType mediaType) {
+            if (whichMethod == BAD_METHOD.isReadable) {
+                throw new RuntimeException("isReadable");
+            }
+            return true;
+        }
+
+        public String readFrom(Class<String> type, Type genericType,
+                Annotation[] annotations, MediaType mediaType,
+                MultivaluedMap<String, String> httpHeaders,
+                InputStream entityStream) throws IOException {
+            if (whichMethod == BAD_METHOD.readFrom) { 
+                throw new RuntimeException("readFrom");
+            }
+            return "readFrom";
+        }
+
+        public long getSize(String t, Class<?> type, Type genericType,
+                Annotation[] annotations, MediaType mediaType) {
+            if (whichMethod == BAD_METHOD.getSize) { 
+                throw new RuntimeException("getSize");
+            }
+            return -1;
+        }
+
+        public boolean isWriteable(Class<?> type, Type genericType,
+                Annotation[] annotations, MediaType mediaType) {
+            if (whichMethod == BAD_METHOD.isWriteable) {
+                throw new RuntimeException("isWriteable");
+            }
+            return true;
+        }
+
+        public void writeTo(String t, Class<?> type, Type genericType,
+                Annotation[] annotations, MediaType mediaType,
+                MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
+                throws IOException {
+            if (whichMethod == BAD_METHOD.writeTo) { 
+                throw new RuntimeException("writeTo");
+            }
+            entityStream.write("writeTo".getBytes());
+        }
+
+    }
+    
+    private InMemoryHandler handler;
+
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    private Handler         consoleHandler;
+
+    @Override
+    protected void setUp() throws Exception {
+        Handler[] defaultHandlers = Logger.getLogger("").getHandlers();
+        if (defaultHandlers.length == 1) {
+            consoleHandler = defaultHandlers[0];
+            consoleHandler.setLevel(Level.FINE);
+        }
+
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.FINE);
+
+        winkLogger.setLevel(Level.FINE);
+        winkLogger.addHandler(handler);
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (consoleHandler != null) {
+            consoleHandler.setLevel(Level.INFO);
+        }
+        winkLogger.removeHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.tearDown();
+    }
+    
+    public void testIsReadableException() throws Exception {
+        whichMethod = BAD_METHOD.isReadable;
+        
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/root",
+                                                        MediaType.TEXT_PLAIN,
+                                                        MediaType.TEXT_PLAIN, "data".getBytes());
+        
+        try {
+            invoke(request);
+        } catch (Throwable t) {
+            // not checking what was thrown, just want to verify logs... so...
+        }
+        
+        // keep a count of how many logRecords contain the stack trace from the exception that originated from a provider
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingProvidersRegistry = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record does not originate from ProvidersRegistry
+            if (record.getMessage().contains(ProvidersRegistry.class.getName())) {
+                logRecordsContainingProvidersRegistry.add(record);
+                logRecordsWithStackTrace++;
+            } else if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(InvokeMethodHandler.class.getName())) {
+                logRecordsWithStackTrace++;
+            }
+        }
+        
+        // stack trace of an exception that originated in a resource should only be logged once:
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        assertEquals(1, logRecordsContainingProvidersRegistry.size());
+        assertEquals(Level.FINE, logRecordsContainingProvidersRegistry.get(0).getLevel());
+        String expectedString = "java.lang.RuntimeException with message \"isReadable\" was encountered during invocation of method org.apache.wink.server.serviceability.DebugProviderThrowsExceptionTest$MyProvider.isReadable( class java.lang.String, class java.lang.String, ";
+        assertTrue(logRecordsContainingProvidersRegistry.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingProvidersRegistry.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingProvidersRegistry.get(0).getMessage().contains("\tDEBUG_FRAME = "));  // make sure we have a stack printed with "DEBUG_FRAME = " instead of " at "
+    }
+    
+    public void testReadFromException() throws Exception {
+        whichMethod = BAD_METHOD.readFrom;
+        
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/root",
+                                                        MediaType.TEXT_PLAIN,
+                                                        MediaType.TEXT_PLAIN, "data".getBytes());
+        
+        try {
+            invoke(request);
+        } catch (Throwable t) {
+            // not checking what was thrown, just want to verify logs... so...
+        }
+        
+        // keep a count of how many logRecords contain the stack trace from the exception that originated from a provider
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingServerInjectableFactory = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record does not originate from ServerInjectableFactory
+            if (record.getMessage().contains(ServerInjectableFactory.class.getName())) {
+                logRecordsContainingServerInjectableFactory.add(record);
+                logRecordsWithStackTrace++;
+            } else if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(InvokeMethodHandler.class.getName())) {
+                logRecordsWithStackTrace++;
+            }
+        }
+        
+        // stack trace of an exception that originated in a resource should only be logged once:
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        assertEquals(1, logRecordsContainingServerInjectableFactory.size());
+        assertEquals(Level.FINE, logRecordsContainingServerInjectableFactory.get(0).getLevel());
+        String expectedString = "java.lang.RuntimeException with message \"readFrom\" was encountered during invocation of method org.apache.wink.server.serviceability.DebugProviderThrowsExceptionTest$MyProvider.readFrom( class java.lang.String, class java.lang.String, ";
+        assertTrue(logRecordsContainingServerInjectableFactory.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingServerInjectableFactory.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingServerInjectableFactory.get(0).getMessage().contains("\tDEBUG_FRAME = "));  // make sure we have a stack printed with "DEBUG_FRAME = " instead of " at "
+    }
+    
+    public void testGetSizeException() throws Exception {
+        whichMethod = BAD_METHOD.getSize;
+        
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/root",
+                                                        MediaType.TEXT_PLAIN,
+                                                        MediaType.TEXT_PLAIN, "data".getBytes());
+        
+        try {
+            invoke(request);
+        } catch (Throwable t) {
+            // not checking what was thrown, just want to verify logs... so...
+        }
+        
+        // keep a count of how many logRecords contain the stack trace from the exception that originated from a provider
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingFlushResultHandler = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record does not originate from FlushResultHandler
+            if (record.getMessage().contains(FlushResultHandler.class.getName())) {
+                logRecordsContainingFlushResultHandler.add(record);
+                logRecordsWithStackTrace++;
+            } else if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(InvokeMethodHandler.class.getName())) {
+                logRecordsWithStackTrace++;
+            }
+        }
+        
+        // stack trace of an exception that originated in a resource should only be logged once:
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        assertEquals(1, logRecordsContainingFlushResultHandler.size());
+        assertEquals(Level.FINE, logRecordsContainingFlushResultHandler.get(0).getLevel());
+        String expectedString = "java.lang.RuntimeException with message \"getSize\" was encountered during invocation of method org.apache.wink.server.serviceability.DebugProviderThrowsExceptionTest$MyProvider.getSize( ";
+        assertTrue(logRecordsContainingFlushResultHandler.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingFlushResultHandler.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingFlushResultHandler.get(0).getMessage().contains("\tDEBUG_FRAME = "));  // make sure we have a stack printed with "DEBUG_FRAME = " instead of " at "
+    }
+    
+    public void testIsWriteableException() throws Exception {
+        whichMethod = BAD_METHOD.isWriteable;
+        
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/root",
+                                                        MediaType.TEXT_PLAIN,
+                                                        MediaType.TEXT_PLAIN, "data".getBytes());
+        
+        try {
+            invoke(request);
+        } catch (Throwable t) {
+            // not checking what was thrown, just want to verify logs... so...
+        }
+        
+        // keep a count of how many logRecords contain the stack trace from the exception that originated from a provider
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingProvidersRegistry = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record does not originate from ProvidersRegistry
+            if (record.getMessage().contains(ProvidersRegistry.class.getName())) {
+                logRecordsContainingProvidersRegistry.add(record);
+                logRecordsWithStackTrace++;
+            } else if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(InvokeMethodHandler.class.getName())) {
+                logRecordsWithStackTrace++;
+            }
+        }
+        
+        // stack trace of an exception that originated in a resource should only be logged once:
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        assertEquals(1, logRecordsContainingProvidersRegistry.size());
+        assertEquals(Level.FINE, logRecordsContainingProvidersRegistry.get(0).getLevel());
+        String expectedString = "java.lang.RuntimeException with message \"isWriteable\" was encountered during invocation of method org.apache.wink.server.serviceability.DebugProviderThrowsExceptionTest$MyProvider.isWriteable( class java.lang.String, class java.lang.String, ";
+        assertTrue(logRecordsContainingProvidersRegistry.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingProvidersRegistry.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingProvidersRegistry.get(0).getMessage().contains("\tDEBUG_FRAME = "));  // make sure we have a stack printed with "DEBUG_FRAME = " instead of " at "
+    }
+    
+    public void testWriteToException() throws Exception {
+        whichMethod = BAD_METHOD.writeTo;
+        
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/root",
+                                                        MediaType.TEXT_PLAIN,
+                                                        MediaType.TEXT_PLAIN, "data".getBytes());
+        
+        try {
+            invoke(request);
+        } catch (Throwable t) {
+            // not checking what was thrown, just want to verify logs... so...
+        }
+        
+        // keep a count of how many logRecords contain the stack trace from the exception that originated from a provider
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingFlushResultHandler = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record does not originate from FlushResultHandler
+            if (record.getMessage().contains(FlushResultHandler.class.getName())) {
+                logRecordsContainingFlushResultHandler.add(record);
+                logRecordsWithStackTrace++;
+            } else if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(InvokeMethodHandler.class.getName())) {
+                logRecordsWithStackTrace++;
+            }
+        }
+        
+        // stack trace of an exception that originated in a resource should only be logged once:
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        assertEquals(1, logRecordsContainingFlushResultHandler.size());
+        assertEquals(Level.FINE, logRecordsContainingFlushResultHandler.get(0).getLevel());
+        String expectedString = "java.lang.RuntimeException with message \"writeTo\" was encountered during invocation of method org.apache.wink.server.serviceability.DebugProviderThrowsExceptionTest$MyProvider.writeTo( ";
+        assertTrue(logRecordsContainingFlushResultHandler.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingFlushResultHandler.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingFlushResultHandler.get(0).getMessage().contains("\tDEBUG_FRAME = "));  // make sure we have a stack printed with "DEBUG_FRAME = " instead of " at "
+    }
+    
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugResourceThrowsExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugResourceThrowsExceptionTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugResourceThrowsExceptionTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugResourceThrowsExceptionTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * 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.ArrayList;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.wink.common.internal.log.LogUtils;
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.RequestProcessor;
+import org.apache.wink.server.internal.handlers.InvokeMethodHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+/*
+ * 
+ * Test what is printed to the log when a resource class (from the developer's application) throws an exception.
+ * An exception may be thrown on purpose from a resource as part of normal transactions for this particular app,
+ * thus we don't want to report it to INFO due to the possibility of quickly filling up logs.  Instead, data is
+ * logged when DEBUG is turned on, and logged only once.
+ * 
+ */
+
+public class DebugResourceThrowsExceptionTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource.class};
+    }
+
+    @Path("/root")
+    public static class MyResource {
+
+        @GET
+        @Path("getRuntimeException")
+        public String getruntimeException() {
+            throw new NullPointerException("something was null");
+        }
+        
+        @GET
+        @Path("getwebappException")
+        public String getwebappexEmpty() {
+            throw new javax.ws.rs.WebApplicationException(new NullPointerException("nully null null"));
+        }
+        
+    }
+    
+    private InMemoryHandler handler;
+
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    private Handler         consoleHandler;
+
+    @Override
+    protected void setUp() throws Exception {
+        Handler[] defaultHandlers = Logger.getLogger("").getHandlers();
+        if (defaultHandlers.length == 1) {
+            consoleHandler = defaultHandlers[0];
+            consoleHandler.setLevel(Level.FINE);
+        }
+
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.FINE);
+
+        winkLogger.setLevel(Level.FINE);
+        winkLogger.addHandler(handler);
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (consoleHandler != null) {
+            consoleHandler.setLevel(Level.INFO);
+        }
+        winkLogger.removeHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.tearDown();
+    }
+    
+    public void testRuntimeException() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/root/getRuntimeException",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN, null);
+        
+        try {
+            invoke(request);
+        } catch (Throwable t) {
+            // not checking what was thrown, just want to verify logs... so...
+        }
+        
+        // keep a count of how many logRecords contain the stack trace from the exception that originated from a resource
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingInvokeMethodHandler = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record does not originate from InvokeMethodHandler
+            if (record.getMessage().contains(InvokeMethodHandler.class.getName())) {
+                logRecordsContainingInvokeMethodHandler.add(record);
+                logRecordsWithStackTrace++;
+            } else if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(InvokeMethodHandler.class.getName())) {
+                logRecordsWithStackTrace++;
+            }
+        }
+        
+        // stack trace of an exception that originated in a resource will be logged in RequestProcessor.logException only
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        assertEquals(1, logRecordsContainingInvokeMethodHandler.size());
+        assertEquals(Level.FINE, logRecordsContainingInvokeMethodHandler.get(0).getLevel());
+        String expectedString = "java.lang.NullPointerException with message \"something was null\" was encountered during invocation of method"
+                + " getruntimeException of declaring class org.apache.wink.server.serviceability.DebugResourceThrowsExceptionTest$MyResource";
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getMessage().contains(" with parameters "));  // make sure more info is spit out under debug
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getMessage().contains("\tDEBUG_FRAME = "));  // make sure we have a stack printed with "DEBUG_FRAME = " instead of " at "
+    }
+    
+    public void testWebAppException() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/root/getwebappException",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN, null);
+        
+        try {
+            invoke(request);
+        } catch (Throwable t) {
+            // not checking what was thrown, just want to verify logs... so...
+        }
+        
+        // keep a count of how many logRecords contain the stack trace from the exception that originated from a resource
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingInvokeMethodHandler = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            if (record.getMessage().contains(InvokeMethodHandler.class.getName())) {
+                logRecordsContainingInvokeMethodHandler.add(record);
+                logRecordsWithStackTrace++;
+            } else if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(InvokeMethodHandler.class.getName())) {
+                logRecordsWithStackTrace++;
+            }
+        }
+        
+        // stack trace of an exception that originated in a resource should only be logged once:
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        assertEquals(1, logRecordsContainingInvokeMethodHandler.size());
+        assertEquals(Level.FINE, logRecordsContainingInvokeMethodHandler.get(0).getLevel());
+        String expectedString = "javax.ws.rs.WebApplicationException with message \"java.lang.NullPointerException: nully null null\" was encountered during invocation of method"
+                + " getwebappexEmpty of declaring class org.apache.wink.server.serviceability.DebugResourceThrowsExceptionTest$MyResource";
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getMessage().contains(" with parameters "));  // make sure more info is spit out under debug
+        assertTrue(logRecordsContainingInvokeMethodHandler.get(0).getMessage().contains("\tDEBUG_FRAME = "));  // make sure we have a stack printed with "DEBUG_FRAME = " instead of " at "
+    }
+    
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleRequestTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleRequestTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleRequestTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,362 @@
+/*
+ * 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.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.log.Requests;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class DebugSimpleRequestTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource.class};
+    }
+
+    @Path("abcd")
+    public static class MyResource {
+
+        @GET
+        public String get() {
+            return "Hello world GET!";
+        }
+
+        @POST
+        public String get(String entity) {
+            return "Hello world!";
+        }
+    }
+
+    private InMemoryHandler handler;
+
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    private Handler         consoleHandler;
+
+    @Override
+    protected void setUp() throws Exception {
+        Handler[] defaultHandlers = Logger.getLogger("").getHandlers();
+        if (defaultHandlers.length == 1) {
+            consoleHandler = defaultHandlers[0];
+            consoleHandler.setLevel(Level.FINE);
+        }
+
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.FINE);
+
+        winkLogger.setLevel(Level.FINE);
+        winkLogger.addHandler(handler);
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (consoleHandler != null) {
+            consoleHandler.setLevel(Level.INFO);
+        }
+        winkLogger.removeHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.tearDown();
+    }
+
+    /**
+     * Tests that an empty entity request is still okay.
+     */
+    public void testEmptyRequestEntityStillOK() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        StringBuffer sb = new StringBuffer();
+        for (int c = 0; c < 1000; ++c) {
+            sb.append("Hello world!  Goodbye!");
+        }
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/abcd",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN,
+                                                        new byte[] {});
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("Hello world!", response.getContentAsString());
+
+        int isNoRequestEntityReadMsgCount = 0;
+        int countNumMessagesFromRequestsHandler = 0;
+        for (LogRecord record : records) {
+            if ("The request entity was not read from the HttpServletRequest.getInputStream()."
+                .equals(record.getMessage())) {
+                ++isNoRequestEntityReadMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Requests.class.getName()))) {
+                ++countNumMessagesFromRequestsHandler;
+            }
+        }
+
+        assertEquals(1, isNoRequestEntityReadMsgCount);
+        assertEquals(3, countNumMessagesFromRequestsHandler);
+    }
+
+    /**
+     * Tests that an empty entity request is still okay.
+     */
+    public void testNoRequestEntityExpectedStillOK() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        StringBuffer sb = new StringBuffer();
+        for (int c = 0; c < 1000; ++c) {
+            sb.append("Hello world!  Goodbye!");
+        }
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/abcd",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN,
+                                                        new byte[] {});
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("Hello world GET!", response.getContentAsString());
+
+        int isNoRequestEntityReadMsgCount = 0;
+        int countNumMessagesFromRequestsHandler = 0;
+        for (LogRecord record : records) {
+            if ("The request entity was not read from the HttpServletRequest.getInputStream()."
+                .equals(record.getMessage())) {
+                ++isNoRequestEntityReadMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Requests.class.getName()))) {
+                ++countNumMessagesFromRequestsHandler;
+            }
+        }
+
+        assertEquals(1, isNoRequestEntityReadMsgCount);
+        assertEquals(3, countNumMessagesFromRequestsHandler);
+    }
+
+    /**
+     * Tests that a request is sent but it is never read still works.
+     */
+    public void testRequestEntityNeverReadBecauseNoEntityParam() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        StringBuffer sb = new StringBuffer();
+        for (int c = 0; c < 1000; ++c) {
+            sb.append("Hello world!  Goodbye!");
+        }
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/abcd",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN,
+                                                        "Hello world!".getBytes());
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("Hello world GET!", response.getContentAsString());
+
+        int isNoRequestEntityReadMsgCount = 0;
+        int countNumMessagesFromRequestsHandler = 0;
+        for (LogRecord record : records) {
+            if ("The request entity was not read from the HttpServletRequest.getInputStream()."
+                .equals(record.getMessage())) {
+                ++isNoRequestEntityReadMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Requests.class.getName()))) {
+                ++countNumMessagesFromRequestsHandler;
+            }
+        }
+
+        assertEquals(1, isNoRequestEntityReadMsgCount);
+        assertEquals(3, countNumMessagesFromRequestsHandler);
+    }
+
+    /**
+     * Tests that a request entity is sent and output in the log.
+     */
+    public void testRequestEntityStringOutput() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/abcd",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN,
+                                                        "Hello this is the request!".getBytes());
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("Hello world!", response.getContentAsString());
+
+        int requestEntityAsStringMsgCount = 0;
+        int requestEntityContentAsStringMsgCount = 0;
+        int countNumMessagesFromRequestsHandler = 0;
+        for (LogRecord record : records) {
+            if ("The request entity as a String in the default encoding:".equals(record
+                .getMessage())) {
+                ++requestEntityAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if ("Hello this is the request!".equals(record.getMessage())) {
+                ++requestEntityContentAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Requests.class.getName()))) {
+                ++countNumMessagesFromRequestsHandler;
+            }
+        }
+
+        assertEquals(1, requestEntityAsStringMsgCount);
+        assertEquals(1, requestEntityContentAsStringMsgCount);
+        assertEquals(4, countNumMessagesFromRequestsHandler);
+    }
+
+    /**
+     * Tests that a request entity is sent and output in the log.
+     */
+    public void testMultipleRequestEntityStringOutput() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        for (int c = 0; c < 100; ++c) {
+            MockHttpServletRequest request =
+                MockRequestConstructor
+                    .constructMockRequest("POST",
+                                          "/abcd",
+                                          MediaType.WILDCARD,
+                                          MediaType.TEXT_PLAIN,
+                                          "Hello this is the request!".getBytes());
+
+            MockHttpServletResponse response = invoke(request);
+            assertEquals(200, response.getStatus());
+            assertEquals("Hello world!", response.getContentAsString());
+        }
+
+        int requestEntityAsStringMsgCount = 0;
+        int requestEntityContentAsStringMsgCount = 0;
+        int countNumMessagesFromRequestsHandler = 0;
+        for (LogRecord record : records) {
+            if ("The request entity as a String in the default encoding:".equals(record
+                .getMessage())) {
+                ++requestEntityAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if ("Hello this is the request!".equals(record.getMessage())) {
+                ++requestEntityContentAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Requests.class.getName()))) {
+                ++countNumMessagesFromRequestsHandler;
+            }
+        }
+
+        assertEquals(100, requestEntityAsStringMsgCount);
+        assertEquals(100, requestEntityContentAsStringMsgCount);
+        assertEquals(400, countNumMessagesFromRequestsHandler);
+    }
+
+    /**
+     * Tests that a request entity is broken up into sizable page breaks. This
+     * is mainly to flush out the buffer. (i.e. someone sending 1GB of data will
+     * not like us taking 1GB of memory to hold the string).
+     */
+    public void testPageBreak() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        StringBuffer sb = new StringBuffer();
+        /*
+         * 1 million characters but will only log up to 8192 total in 4096
+         * blocks by default
+         */
+        for (int c = 0; c < 100000; ++c) {
+            sb.append("1234567890");
+        }
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/abcd",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN,
+                                                        sb.toString().getBytes());
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("Hello world!", response.getContentAsString());
+
+        int requestEntityAsStringMsgCount = 0;
+        int requestEntityContentAsStringMsgCount = 0;
+        int requestEntityContentAsStringMsg2Count = 0;
+        int countNumMessagesFromRequestsHandler = 0;
+        StringBuffer expected = new StringBuffer();
+        for (int c = 1; c < 4097; ++c) {
+            expected.append(c % 10);
+        }
+
+        StringBuffer expected2 = new StringBuffer();
+        for (int c = 4097; c < 8193; ++c) {
+            expected2.append(c % 10);
+        }
+
+        for (LogRecord record : records) {
+            if ("The request entity as a String in the default encoding:".equals(record
+                .getMessage())) {
+                ++requestEntityAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (expected.toString().equals(record.getMessage())) {
+                ++requestEntityContentAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+                assertEquals(0, requestEntityContentAsStringMsg2Count);
+            }
+            if (expected2.toString().equals(record.getMessage())) {
+                ++requestEntityContentAsStringMsg2Count;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Requests.class.getName()))) {
+                ++countNumMessagesFromRequestsHandler;
+            }
+        }
+
+        assertEquals(1, requestEntityAsStringMsgCount);
+        assertEquals(1, requestEntityContentAsStringMsgCount);
+        assertEquals(1, requestEntityContentAsStringMsg2Count);
+        assertEquals(5, countNumMessagesFromRequestsHandler);
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleResponseTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleResponseTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleResponseTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugSimpleResponseTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,376 @@
+/*
+ * 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.Formatter;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.log.Responses;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class DebugSimpleResponseTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource.class, MyExceptionMapper.class};
+    }
+
+    @Provider
+    public static class MyExceptionMapper implements ExceptionMapper<NullPointerException> {
+
+        public Response toResponse(NullPointerException exception) {
+            return Response.ok("GOT A NPE").build();
+        }
+
+    }
+
+    @Path("abcd")
+    public static class MyResource {
+
+        @GET
+        public String get() {
+            return "Hello world GET!";
+        }
+
+        @POST
+        public String get(String entity) {
+            return "Hello world!";
+        }
+
+        @GET
+        @Path("emptyvoid")
+        public void emptyVoid() {
+
+        }
+
+        @GET
+        @Path("emptynull")
+        public Object emptyObj() {
+            return null;
+        }
+
+        @GET
+        @Path("emptyresponse")
+        public Response emptyResponse() {
+            return Response.noContent().build();
+        }
+
+        @GET
+        @Path("thrownNPE")
+        public Response NPEResponse() {
+            throw new NullPointerException();
+        }
+
+        @GET
+        @Path("responseWithHeaders")
+        public Response getHeaders() {
+            return Response.ok().header(HttpHeaders.CONTENT_ENCODING, "gzip")
+                .header(HttpHeaders.COOKIE, "abcd").header(HttpHeaders.SET_COOKIE, "lmnop")
+                .header(HttpHeaders.SET_COOKIE, "abcd").header(HttpHeaders.WWW_AUTHENTICATE,
+                                                               "realm=something").build();
+        }
+    }
+
+    private InMemoryHandler handler;
+
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    private Handler         consoleHandler;
+
+    @Override
+    protected void setUp() throws Exception {
+        Handler[] defaultHandlers = Logger.getLogger("").getHandlers();
+        if (defaultHandlers.length == 1) {
+            consoleHandler = defaultHandlers[0];
+            consoleHandler.setLevel(Level.FINE);
+        }
+
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.FINE);
+
+        winkLogger.setLevel(Level.FINE);
+        winkLogger.addHandler(handler);
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (consoleHandler != null) {
+            consoleHandler.setLevel(Level.INFO);
+        }
+        winkLogger.removeHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.tearDown();
+    }
+
+    /**
+     * Tests that an empty entity response is still okay.
+     */
+    public void testEmptyResponseEntityStillOK() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/abcd/emptyvoid",
+                                                        MediaType.WILDCARD);
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+
+        int isNoResponseEntityWrittenMsgCount = 0;
+        int countNumMessagesFromResponsesHandler = 0;
+        for (LogRecord record : records) {
+            if ("The response entity was not written to the HttpServletResponse.getOutputStream()."
+                .equals(record.getMessage())) {
+                ++isNoResponseEntityWrittenMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Responses.class.getName()))) {
+                ++countNumMessagesFromResponsesHandler;
+            }
+        }
+
+        assertEquals(1, isNoResponseEntityWrittenMsgCount);
+        assertEquals(2, countNumMessagesFromResponsesHandler);
+    }
+
+    /**
+     * Tests that an empty entity response is still okay.
+     */
+    public void testNullObjectStillOK() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/abcd/emptynull",
+                                                        MediaType.WILDCARD);
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+
+        int isNoResponseEntityWrittenMsgCount = 0;
+        int countNumMessagesFromResponsesHandler = 0;
+        for (LogRecord record : records) {
+            if ("The response entity was not written to the HttpServletResponse.getOutputStream()."
+                .equals(record.getMessage())) {
+                ++isNoResponseEntityWrittenMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Responses.class.getName()))) {
+                ++countNumMessagesFromResponsesHandler;
+            }
+        }
+
+        assertEquals(1, isNoResponseEntityWrittenMsgCount);
+        assertEquals(2, countNumMessagesFromResponsesHandler);
+    }
+
+    /**
+     * Tests that an empty entity response is still okay.
+     */
+    public void test204ResponseStillOK() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/abcd/emptyresponse",
+                                                        MediaType.WILDCARD);
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(204, response.getStatus());
+
+        int isNoResponseEntityWrittenMsgCount = 0;
+        int countNumMessagesFromResponsesHandler = 0;
+        for (LogRecord record : records) {
+            if ("The response entity was not written to the HttpServletResponse.getOutputStream()."
+                .equals(record.getMessage())) {
+                ++isNoResponseEntityWrittenMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Responses.class.getName()))) {
+                ++countNumMessagesFromResponsesHandler;
+            }
+        }
+
+        assertEquals(1, isNoResponseEntityWrittenMsgCount);
+        assertEquals(2, countNumMessagesFromResponsesHandler);
+    }
+
+    /**
+     * Tests that a response entity is sent and output in the log.
+     */
+    public void testResponseEntityStringOutput() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/abcd",
+                                                        MediaType.WILDCARD,
+                                                        MediaType.TEXT_PLAIN,
+                                                        "Hello this is the request!".getBytes());
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("Hello world!", response.getContentAsString());
+
+        int responseEntityAsStringMsgCount = 0;
+        int responseEntityContentAsStringMsgCount = 0;
+        int countNumMessagesFromResponsesHandler = 0;
+        for (LogRecord record : records) {
+            if ("The response entity as a String in the default encoding:".equals(record
+                .getMessage())) {
+                ++responseEntityAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if ("Hello world!".equals(record.getMessage())) {
+                ++responseEntityContentAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Responses.class.getName()))) {
+                ++countNumMessagesFromResponsesHandler;
+            }
+        }
+
+        assertEquals(1, responseEntityAsStringMsgCount);
+        assertEquals(1, responseEntityContentAsStringMsgCount);
+        assertEquals(3, countNumMessagesFromResponsesHandler);
+    }
+
+    /**
+     * Tests that a response entity is sent and output in the log.
+     */
+    public void testResponseEntityStringOutputViaException() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/abcd/thrownNPE",
+                                                        MediaType.WILDCARD);
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("GOT A NPE", response.getContentAsString());
+
+        int responseEntityAsStringMsgCount = 0;
+        int responseEntityContentAsStringMsgCount = 0;
+        int countNumMessagesFromResponsesHandler = 0;
+        int countErrorFlowMessage = 0;
+        for (LogRecord record : records) {
+            if ("The response entity as a String in the default encoding:".equals(record
+                .getMessage())) {
+                ++responseEntityAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if ("GOT A NPE".equals(record.getMessage())) {
+                ++responseEntityContentAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Responses.class.getName()))) {
+                ++countNumMessagesFromResponsesHandler;
+            }
+
+            if ("An error occurred when handling the initial request/response, so wrote the entity and headers in the error response handlers chain."
+                .equals(record.getMessage())) {
+                ++countErrorFlowMessage;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+        }
+
+        assertEquals(1, responseEntityAsStringMsgCount);
+        assertEquals(1, responseEntityContentAsStringMsgCount);
+        assertEquals(1, countErrorFlowMessage);
+        assertEquals(4, countNumMessagesFromResponsesHandler);
+    }
+
+    /**
+     * Tests that a response header is sent and output in the log.
+     */
+    public void testResponseHeadersOutput() throws Exception {
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/abcd/responseWithHeaders",
+                                                        MediaType.WILDCARD);
+
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(200, response.getStatus());
+        assertEquals("", response.getContentAsString());
+
+        int responseEntityNotWritten = 0;
+        int responseEntityContentAsStringMsgCount = 0;
+        int countNumMessagesFromResponsesHandler = 0;
+        int countHeadersMessage = 0;
+        StringBuilder headersOutput = new StringBuilder();
+        Formatter f = new Formatter(headersOutput);
+        f.format("The written response headers:");
+        f.format("%n%1$-30s%2$s", "Content-Encoding", "gzip");
+        f.format("%n%1$-30s%2$s", "Cookie", "abcd");
+        f.format("%n%1$-30s%2$s", "Set-Cookie", "lmnop");
+        f.format("%n%1$-30s%2$s", "Set-Cookie", "abcd");
+        f.format("%n%1$-30s%2$s", "WWW-Authenticate", "realm=something");
+
+        for (LogRecord record : records) {
+            if ("The response entity was not written to the HttpServletResponse.getOutputStream()."
+                .equals(record.getMessage())) {
+                ++responseEntityNotWritten;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if ("".equals(record.getMessage())) {
+                ++responseEntityContentAsStringMsgCount;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+            if (record.getLoggerName().equals((Responses.class.getName()))) {
+                ++countNumMessagesFromResponsesHandler;
+            }
+            if (headersOutput.toString().equals(record.getMessage())) {
+                ++countHeadersMessage;
+                assertEquals(Level.FINE, record.getLevel());
+            }
+        }
+
+        assertEquals(1, responseEntityNotWritten);
+        assertEquals(0, responseEntityContentAsStringMsgCount);
+        assertEquals(1, countHeadersMessage);
+        assertEquals(2, countNumMessagesFromResponsesHandler);
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleProvidersAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleProvidersAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleProvidersAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleProvidersAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,209 @@
+/*
+ * 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.InputStream;
+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.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.MessageBodyReader;
+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 the logging of multiple providers at INFO level.
+ */
+public class InfoMultipleProvidersAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyEntityProvider.class, MyEntityReader.class,
+            MyExceptionMapper.class, MyContextResolver.class};
+    }
+
+    @Provider
+    @Produces(MediaType.TEXT_PLAIN)
+    public static class MyEntityProvider implements MessageBodyReader<Object>,
+        MessageBodyWriter<Object> {
+
+        public boolean isReadable(Class<?> type,
+                                  Type genericType,
+                                  Annotation[] annotations,
+                                  MediaType mediaType) {
+            return false;
+        }
+
+        public Object readFrom(Class<Object> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType,
+                               MultivaluedMap<String, String> httpHeaders,
+                               InputStream entityStream) throws IOException {
+            return null;
+        }
+
+        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 {
+        }
+
+    }
+
+    @Provider
+    @Consumes( {"custom/*", "custom2/type2"})
+    public static class MyEntityReader implements MessageBodyReader<String> {
+
+        public boolean isReadable(Class<?> type,
+                                  Type genericType,
+                                  Annotation[] annotations,
+                                  MediaType mediaType) {
+            return false;
+        }
+
+        public String readFrom(Class<String> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType,
+                               MultivaluedMap<String, String> httpHeaders,
+                               InputStream entityStream) throws IOException {
+            return null;
+        }
+
+    }
+
+    @Provider
+    public static class MyExceptionMapper implements ExceptionMapper<NullPointerException> {
+
+        public Response toResponse(NullPointerException exception) {
+            return null;
+        }
+
+    }
+
+    @Provider
+    public static class MyContextResolver implements ContextResolver<String> {
+
+        public String getContext(Class<?> type) {
+            return null;
+        }
+
+    }
+
+    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 the INFO logging for multiple providers.
+     * 
+     * @throws Exception
+     */
+    public void testLogMultipleProviders() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+
+        /*
+         * This is actually a deterministic order for this particular test. The
+         * type of provider and the media type determine the order. In
+         * situations where there are no order (i.e. application/json versus
+         * application/custom), the test will be fairly random.
+         */
+        final String provider1Message =
+            "The class org.apache.wink.server.serviceability.InfoMultipleProvidersAppStartupTest$MyEntityReader was registered as a JAX-RS MessageBodyReader provider for java.lang.String Java types and custom2/type2 media types.";
+        assertEquals(provider1Message, records.get(2).getMessage());
+        assertEquals(Level.INFO, records.get(2).getLevel());
+        final String provider2Message =
+            "The class org.apache.wink.server.serviceability.InfoMultipleProvidersAppStartupTest$MyEntityReader was registered as a JAX-RS MessageBodyReader provider for java.lang.String Java types and custom/* media types.";
+        assertEquals(provider2Message, records.get(3).getMessage());
+        assertEquals(Level.INFO, records.get(3).getLevel());
+        final String provider3Message =
+            "The class org.apache.wink.server.serviceability.InfoMultipleProvidersAppStartupTest$MyEntityProvider was registered as a JAX-RS MessageBodyReader provider for all Java types and */* media types.";
+        assertEquals(provider3Message, records.get(4).getMessage());
+        assertEquals(Level.INFO, records.get(4).getLevel());
+        final String provider4Message =
+            "The class org.apache.wink.server.serviceability.InfoMultipleProvidersAppStartupTest$MyEntityProvider was registered as a JAX-RS MessageBodyWriter provider for all Java types and text/plain media types.";
+        assertEquals(provider4Message, records.get(5).getMessage());
+        assertEquals(Level.INFO, records.get(5).getLevel());
+
+        final String provider5Message =
+            "The class org.apache.wink.server.serviceability.InfoMultipleProvidersAppStartupTest$MyExceptionMapper was registered as a JAX-RS ExceptionMapper provider for java.lang.NullPointerException Java types.";
+        assertEquals(provider5Message, records.get(6).getMessage());
+        assertEquals(Level.INFO, records.get(6).getLevel());
+
+        final String provider6Message =
+            "The class org.apache.wink.server.serviceability.InfoMultipleProvidersAppStartupTest$MyContextResolver was registered as a JAX-RS ContextResolver provider for java.lang.String Java types and */* media types.";
+        assertEquals(provider6Message, records.get(7).getMessage());
+        assertEquals(Level.INFO, records.get(7).getLevel());
+
+        assertEquals(8, records.size());
+    }
+
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleResourcesAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleResourcesAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleResourcesAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoMultipleResourcesAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,115 @@
+/*
+ * 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.GET;
+import javax.ws.rs.Path;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+/**
+ * Tests that a message indicating multiple registered resources were added.
+ */
+public class InfoMultipleResourcesAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource1.class, MyResource2.class, MyResource3.class};
+    }
+
+    @Path("/hello")
+    public static class MyResource1 {
+
+    }
+
+    @Path("helloabcd")
+    public static class MyResource2 {
+        @GET
+        public void get() {
+
+        }
+    }
+
+    @Path("/hello2")
+    public static class MyResource3 {
+
+        @GET
+        @Path("more")
+        public void get() {
+
+        }
+    }
+
+    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 the INFO logging for multiple resources.
+     * 
+     * @throws Exception
+     */
+    public void testLogResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        /*
+         * This is actually a deterministic order. The @Path dictates when they
+         * are listed (i.e. JAX-RS @Path search order so the first resource
+         * check is listed first).
+         */
+        final String resource2Message =
+            "The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.InfoMultipleResourcesAppStartupTest$MyResource2 with @Path(helloabcd).";
+        assertEquals(resource2Message, records.get(2).getMessage());
+        assertEquals(Level.INFO, records.get(2).getLevel());
+        final String resource3Message =
+            "The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.InfoMultipleResourcesAppStartupTest$MyResource3 with @Path(/hello2).";
+        assertEquals(resource3Message, records.get(3).getMessage());
+        assertEquals(Level.INFO, records.get(3).getLevel());
+        final String resource1Message =
+            "The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.InfoMultipleResourcesAppStartupTest$MyResource1 with @Path(/hello).";
+        assertEquals(resource1Message, records.get(4).getMessage());
+        assertEquals(Level.INFO, records.get(4).getLevel());
+
+        assertEquals(6, records.size());
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoMessageBodyWriter500Test.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoMessageBodyWriter500Test.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoMessageBodyWriter500Test.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoMessageBodyWriter500Test.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,128 @@
+/*
+ * 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.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class InfoNoMessageBodyWriter500Test extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource.class, MyResourceMediaType.class};
+    }
+
+    public static class MyObject {
+
+    }
+
+    @Path("noWriterForJavaType")
+    public static class MyResource {
+        @GET
+        public Object get() {
+            return new MyObject();
+        }
+    }
+
+    @Path("noWriterForMediaType")
+    public static class MyResourceMediaType {
+        @GET
+        @Produces(MediaType.APPLICATION_JSON)
+        public Object get() {
+            return new DOMSource();
+        }
+    }
+
+    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 testLogNoWriterForJavaType() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "noWriterForJavaType",
+                                                        MediaType.WILDCARD);
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(500, response.getStatus());
+        assertEquals("", response.getContentAsString());
+
+        assertEquals(Level.SEVERE, records.get(5).getLevel());
+        assertTrue(records
+            .get(5)
+            .getMessage()
+            .indexOf("The system could not find a javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for the org.apache.wink.server.serviceability.InfoNoMessageBodyWriter500Test$MyObject type and") != -1 && records
+            .get(5)
+            .getMessage()
+            .indexOf("Ensure that a javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for the type and media type specified.") != -1);
+
+        assertEquals(7, records.size());
+    }
+
+    public void testLogNoWriterForMediaType() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "noWriterForMediaType",
+                                                        MediaType.WILDCARD);
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(500, response.getStatus());
+        assertEquals("", response.getContentAsString());
+
+        assertEquals(Level.SEVERE, records.get(5).getLevel());
+        assertEquals("The system could not find a javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for the javax.xml.transform.dom.DOMSource type and application/json mediaType.  Ensure that a javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for the type and media type specified.",
+                     records.get(5).getMessage());
+
+        assertEquals(7, records.size());
+    }
+
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoProvidersAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoProvidersAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoProvidersAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoProvidersAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,78 @@
+/*
+ * 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 org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+public class InfoNoProvidersAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {};
+    }
+
+    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 the JAX-RS application sub-class init params is logged and
+     * other normal startup.
+     * 
+     * @throws Exception
+     */
+    public void testLogNoProviders() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals("The system is using the org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication JAX-RS application class that is named in the javax.ws.rs.Application init-param initialization parameter.",
+                     records.get(0).getMessage());
+        assertEquals(Level.INFO, records.get(0).getLevel());
+        assertEquals("The following JAX-RS application has been processed: org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication",
+                     records.get(1).getMessage());
+        assertEquals(Level.INFO, records.get(1).getLevel());
+        assertEquals("There are no custom JAX-RS providers defined in the application.", records.get(2)
+            .getMessage());
+        assertEquals(Level.INFO, records.get(2).getLevel());
+        assertEquals(3, records.size());
+    }
+
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoResourcesAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoResourcesAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoResourcesAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/InfoNoResourcesAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,82 @@
+/*
+ * 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 org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+/**
+ * Tests what it is logged when there are no resources.
+ */
+public class InfoNoResourcesAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {};
+    }
+
+    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 the JAX-RS application sub-class init params is logged and
+     * other normal startup.
+     * 
+     * @throws Exception
+     */
+    public void testLogNoResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals("The system is using the org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication JAX-RS application class that is named in the javax.ws.rs.Application init-param initialization parameter.",
+                     records.get(0).getMessage());
+        assertEquals(Level.INFO, records.get(0).getLevel());
+        assertEquals("The following JAX-RS application has been processed: org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication",
+                     records.get(1).getMessage());
+        assertEquals(Level.INFO, records.get(1).getLevel());
+        assertEquals("There are no custom JAX-RS providers defined in the application.", records.get(2)
+            .getMessage());
+        assertEquals(Level.INFO, records.get(2).getLevel());
+        assertEquals(3, records.size());
+    }
+
+}



Mime
View raw message