wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jra...@apache.org
Subject svn commit: r1027712 [3/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/internal/log/RequestsTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/log/RequestsTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/log/RequestsTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/log/RequestsTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,293 @@
+/*
+ * 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.internal.log;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.wink.common.internal.MultivaluedMapImpl;
+import org.apache.wink.server.handlers.HandlersChain;
+import org.apache.wink.server.handlers.MessageContext;
+import org.apache.wink.server.internal.log.Requests.LoggedServletInputStream;
+import org.apache.wink.server.internal.log.Requests.RequestWrapper;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.Sequence;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RequestsTest {
+
+    private Mockery mockContext = new Mockery() {
+                                    {
+                                        setImposteriser(ClassImposteriser.INSTANCE);
+                                    }
+                                };
+
+    /**
+     * The Requests object should do nothing.
+     */
+    @Test
+    public void testRequestsInitWithNull() {
+        Requests r = new Requests();
+        r.init(null);
+        mockContext.assertIsSatisfied();
+    }
+
+    /**
+     * The Requests object should do nothing.
+     */
+    @Test
+    public void testRequestsInitWithProperties() {
+        Requests r = new Requests();
+        final Properties props = mockContext.mock(Properties.class);
+        r.init(props);
+        mockContext.assertIsSatisfied();
+    }
+
+    @Before
+    public void setUp() {
+        Logger.getLogger("org.apache.wink").setLevel(Level.INFO);
+    }
+
+    /**
+     * The Requests object should register its wrapper inside of the Requests.
+     */
+    @Test
+    public void testRequestsLogStartupBehaviorWhenNoLoggerAtDebug() {
+        Requests r = new Requests();
+        r.init(null);
+        MessageContext context = mockContext.mock(MessageContext.class);
+        r.logStartRequest(context);
+        mockContext.assertIsSatisfied();
+    }
+
+    /**
+     * The Requests object should not log anything with debug not enabled.
+     * 
+     * @throws Throwable
+     */
+    @Test
+    public void testRequestsHandleRequestWithNoLoggerAtDebug() throws Throwable {
+        Requests r = new Requests();
+        r.init(null);
+        final MessageContext context = mockContext.mock(MessageContext.class);
+        final HandlersChain chain = mockContext.mock(HandlersChain.class);
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(chain).doChain(context);
+            }
+        });
+        r.handleRequest(context, chain);
+        mockContext.assertIsSatisfied();
+    }
+
+    /**
+     * The Requests object should register its wrapper inside of the Requests.
+     */
+    @Test
+    public void testRequestsLogStartupBehaviorWhenLoggerAtDebugWithNullWrapper() {
+        Logger.getLogger("org.apache.wink").setLevel(Level.FINE);
+        Requests r = new Requests();
+        r.init(null);
+        final MessageContext context = mockContext.mock(MessageContext.class);
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(context).getAttribute(HttpServletRequestWrapper.class);
+                will(returnValue(null));
+            }
+        });
+        r.logStartRequest(context);
+        mockContext.assertIsSatisfied();
+    }
+
+    /**
+     * The Requests object should register its wrapper inside of the Requests.
+     */
+    @Test
+    public void testRequestsLogStartupBehaviorWhenLoggerAtDebugWithWrapper() throws Exception {
+        Logger.getLogger("org.apache.wink").setLevel(Level.FINE);
+        Requests r = new Requests();
+        r.init(null);
+        final MessageContext context = mockContext.mock(MessageContext.class);
+        final HttpServletRequestWrapper requestWrapper =
+            mockContext.mock(HttpServletRequestWrapper.class);
+        final UriInfo uriInfo = mockContext.mock(UriInfo.class);
+        final HttpHeaders headers = mockContext.mock(HttpHeaders.class);
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(context).getAttribute(HttpServletRequestWrapper.class);
+                will(returnValue(requestWrapper));
+                oneOf(context).getUriInfo();
+                will(returnValue(uriInfo));
+                oneOf(uriInfo).getRequestUri();
+                will(returnValue(new URI("")));
+                oneOf(context).getHttpHeaders();
+                will(returnValue(headers));
+                oneOf(headers).getRequestHeaders();
+                will(returnValue(new MultivaluedMapImpl<String, String>()));
+
+                /*
+                 * these should actually be all the same objects but no easy way
+                 * to capture it
+                 */
+                oneOf(context).setAttribute(with(RequestWrapper.class),
+                                            with(any(RequestWrapper.class)));
+                oneOf(context).setAttribute(with(HttpServletRequest.class),
+                                            with(any(HttpServletRequest.class)));
+                oneOf(context).setAttribute(with(HttpServletRequestWrapper.class),
+                                            with(any(HttpServletRequestWrapper.class)));
+            }
+        });
+        r.logStartRequest(context);
+        mockContext.assertIsSatisfied();
+    }
+
+    /**
+     * This is a normal flow.
+     * 
+     * @throws Throwable
+     */
+    @Test
+    public void testRequestsHandleRequestWithLoggerAtDebug() throws Throwable {
+        Logger.getLogger("org.apache.wink").setLevel(Level.FINE);
+        Requests r = new Requests();
+        r.init(null);
+        final MessageContext context = mockContext.mock(MessageContext.class);
+        final HandlersChain chain = mockContext.mock(HandlersChain.class);
+
+        final HttpServletRequestWrapper requestWrapper =
+            mockContext.mock(HttpServletRequestWrapper.class);
+        final Sequence normalSequence = mockContext.sequence("normalSequence");
+        final RequestWrapper wrapper = mockContext.mock(RequestWrapper.class);
+        final LoggedServletInputStream inputStream =
+            mockContext.mock(LoggedServletInputStream.class);
+        final UriInfo uriInfo = mockContext.mock(UriInfo.class);
+        final HttpHeaders headers = mockContext.mock(HttpHeaders.class);
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(context).getAttribute(HttpServletRequestWrapper.class);
+                will(returnValue(requestWrapper));
+                inSequence(normalSequence);
+
+                oneOf(context).getUriInfo();
+                will(returnValue(uriInfo));
+                oneOf(uriInfo).getRequestUri();
+                will(returnValue(new URI("")));
+                oneOf(context).getHttpHeaders();
+                will(returnValue(headers));
+                oneOf(headers).getRequestHeaders();
+                will(returnValue(new MultivaluedMapImpl<String, String>()));
+
+                /*
+                 * these should actually be all the same objects but no easy way
+                 * to capture it
+                 */
+                oneOf(context).setAttribute(with(RequestWrapper.class),
+                                            with(any(RequestWrapper.class)));
+                inSequence(normalSequence);
+                oneOf(context).setAttribute(with(HttpServletRequest.class),
+                                            with(any(HttpServletRequest.class)));
+                inSequence(normalSequence);
+                oneOf(context).setAttribute(with(HttpServletRequestWrapper.class),
+                                            with(any(HttpServletRequestWrapper.class)));
+                inSequence(normalSequence);
+
+                oneOf(chain).doChain(context);
+                inSequence(normalSequence);
+
+                oneOf(context).getAttribute(RequestWrapper.class);
+                will(returnValue(wrapper));
+                inSequence(normalSequence);
+
+                oneOf(wrapper).getLoggedInputStream();
+                will(returnValue(inputStream));
+                inSequence(normalSequence);
+
+                oneOf(inputStream).getLoggedByteBufferLength();
+                will(returnValue(10));
+                inSequence(normalSequence);
+
+                oneOf(inputStream).getLoggedByteBuffer();
+                will(returnValue(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
+                inSequence(normalSequence);
+
+                oneOf(inputStream).getLoggedByteBufferLength();
+                will(returnValue(10));
+                inSequence(normalSequence);
+
+                oneOf(context).setAttribute(RequestWrapper.class, (RequestWrapper)null);
+                inSequence(normalSequence);
+            }
+        });
+
+        r.handleRequest(context, chain);
+        mockContext.assertIsSatisfied();
+    }
+
+    @Test
+    public void testRequestWrapperRandomCall() {
+        final HttpServletRequest request = mockContext.mock(HttpServletRequest.class);
+        RequestWrapper wrapper = new RequestWrapper(request);
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(request).getContentType();
+                will(returnValue("ABCD"));
+            }
+        });
+        assertEquals("ABCD", wrapper.getContentType());
+
+        mockContext.assertIsSatisfied();
+    }
+
+    @Test
+    public void testRequestWrapperGetInputStream() throws Exception {
+        final HttpServletRequest request = mockContext.mock(HttpServletRequest.class);
+        final ServletInputStream servletInputStream = mockContext.mock(ServletInputStream.class);
+        RequestWrapper wrapper = new RequestWrapper(request);
+
+        mockContext.checking(new Expectations() {
+            {
+                oneOf(request).getInputStream();
+                will(returnValue(servletInputStream));
+            }
+        });
+        ServletInputStream m = wrapper.getInputStream();
+        assertTrue(m instanceof LoggedServletInputStream);
+        assertSame((LoggedServletInputStream)m, wrapper.getLoggedInputStream());
+
+        mockContext.assertIsSatisfied();
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/MissingPathOrProviderWarningTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/MissingPathOrProviderWarningTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/MissingPathOrProviderWarningTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/registry/MissingPathOrProviderWarningTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.internal.registry;
+
+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.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests that a class that does not have a {@link Provider} or {@link Path} will
+ * cause a warning to be emitted.
+ */
+public class MissingPathOrProviderWarningTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class[] {TestResource.class};
+    }
+
+    public static class TestResource {
+
+        @GET
+        @Produces( {MediaType.APPLICATION_ATOM_XML})
+        public String getCollection() {
+            return "";
+        }
+
+    }
+
+    private InMemoryHandler handler;
+    private Logger          winkLogger = Logger.getLogger("org.apache.wink");
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        handler = new InMemoryHandler();
+        handler.setLevel(Level.INFO);
+
+        winkLogger.addHandler(handler);
+        winkLogger.setLevel(Level.INFO);
+        super.setUp();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        winkLogger.removeHandler(handler);
+    }
+
+    @Test
+    public void testMissingPathOrProvider() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals("The org.apache.wink.server.internal.registry.MissingPathOrProviderWarningTest$TestResource class is neither a resource nor a provider. The runtime is ignoring this class. It was returned from a javax.ws.rs.core.Application subclass. Add either a @javax.ws.rs.Path or a @javax.ws.rs.core.Provider annotation to the class.",
+                     records.get(1).getMessage());
+        assertEquals(Level.WARNING, records.get(1).getLevel());
+
+        assertEquals(4, records.size());
+    }
+
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugContextResolverThrowsExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugContextResolverThrowsExceptionTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugContextResolverThrowsExceptionTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugContextResolverThrowsExceptionTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * 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.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.wink.common.internal.log.LogUtils;
+import org.apache.wink.common.internal.providers.entity.xml.AbstractJAXBProvider;
+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 DebugContextResolverThrowsExceptionTest extends MockServletInvocationTest {
+    
+    @XmlAccessorType(XmlAccessType.FIELD)
+    @XmlType(name = "", propOrder = {
+        "arg0"
+    })
+    @XmlRootElement(name = "myJaxb")
+    public static class MyJaxb {
+
+        protected int arg0;
+
+        /**
+         * Gets the value of the arg0 property.
+         * 
+         */
+        public int getArg0() {
+            return arg0;
+        }
+
+        /**
+         * Sets the value of the arg0 property.
+         * 
+         */
+        public void setArg0(int value) {
+            this.arg0 = value;
+        }
+
+    }
+    
+    @Provider
+    @Produces( MediaType.APPLICATION_XML)
+    public static class MyContextResolver implements ContextResolver<JAXBContext> {
+
+        public JAXBContext getContext(Class<?> type) {
+            throw new RuntimeException("getContext");
+        }
+
+    }
+    
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {Resource.class, MyContextResolver.class};
+    }
+
+    @Path("jaxbresource")
+    public static class Resource {
+
+        @POST
+        @Path("jaxbelement")
+        public String post(MyJaxb myJaxb) {
+            return String.valueOf(myJaxb.getArg0());
+        }
+    }
+    
+    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 testgetContextException() throws Exception {
+        
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("POST",
+                                                        "/jaxbresource/jaxbelement",
+                                                        MediaType.TEXT_PLAIN,
+                                                        MediaType.APPLICATION_XML,
+                                                        "some_xml".getBytes());  // don't care what data this is, my context resolver is gonna throw exception anyway
+        
+        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> logRecordsContainingAbstractJAXBProvider = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record does not originate from AbstractJAXBProvider
+            if (record.getMessage().contains(AbstractJAXBProvider.class.getName())) {
+                logRecordsContainingAbstractJAXBProvider.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, logRecordsContainingAbstractJAXBProvider.size());
+        assertEquals(Level.FINE, logRecordsContainingAbstractJAXBProvider.get(0).getLevel());
+        String expectedString = "java.lang.RuntimeException with message \"getContext\" was encountered during invocation of method org.apache.wink.server.serviceability.DebugContextResolverThrowsExceptionTest$MyContextResolver.getContext( ";
+        assertTrue(logRecordsContainingAbstractJAXBProvider.get(0).getMessage().startsWith(expectedString));
+        assertTrue(logRecordsContainingAbstractJAXBProvider.get(0).getLoggerName().equals(RequestProcessor.class.getName()));  // make sure the RequestProcessor is who logged this record
+        assertTrue(logRecordsContainingAbstractJAXBProvider.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/DebugHandlerThrowsExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugHandlerThrowsExceptionTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugHandlerThrowsExceptionTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugHandlerThrowsExceptionTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * 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.Arrays;
+import java.util.List;
+import java.util.Properties;
+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.Produces;
+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.handlers.HandlersChain;
+import org.apache.wink.server.handlers.HandlersFactory;
+import org.apache.wink.server.handlers.MessageContext;
+import org.apache.wink.server.handlers.RequestHandler;
+import org.apache.wink.server.internal.RequestProcessor;
+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 DebugHandlerThrowsExceptionTest extends MockServletInvocationTest {
+
+    public static class MyRequestHandler implements RequestHandler {
+
+        public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable {
+            throw new RuntimeException("reqHandlerHR");
+        }
+
+        public void init(Properties props) {
+            // no need to test what happens if init throws exception, RestServlet.init will catch and log error, and servlet will be unavailable
+        }
+    }
+
+    public static class UserHandlersProvider extends HandlersFactory {
+
+        @Override
+        public List<? extends RequestHandler> getRequestHandlers() {
+            return Arrays.asList(new MyRequestHandler());
+        }
+
+    }
+
+    @Path("/hello")
+    public static class MyResource {
+
+        @GET
+        @Produces(MediaType.TEXT_PLAIN)
+        public String get() {
+            return "hello";
+        }
+
+    }
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource.class};
+    }
+    
+    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 testReqHandlerHRException() throws Exception {
+        
+        handler.getRecords().clear();
+        List<LogRecord> records = handler.getRecords();
+
+        MockHttpServletRequest request =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "/hello",
+                                                        MediaType.TEXT_PLAIN);
+        
+        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 handler
+        int logRecordsWithStackTrace = 0;
+
+        List<LogRecord> logRecordsContainingRequestProcessor = new ArrayList<LogRecord>();
+        
+        for (LogRecord record : records) {
+            // record originates from RequestProcessor
+            if (record.getLoggerName().equals(RequestProcessor.class.getName())) {
+                if (record.getLevel().equals(Level.FINE)) {
+                    logRecordsContainingRequestProcessor.add(record);
+                    if ((record.getThrown() != null) && LogUtils.stackToDebugString(record.getThrown()).contains(RequestProcessor.class.getName())) {
+                        logRecordsWithStackTrace++;
+                    }
+                }
+            }
+        }
+        
+        // stack trace of an exception that originated in a handler should only be logged once:
+        assertEquals(1, logRecordsWithStackTrace);
+        
+        int expectedRecords = 4;
+        assertEquals(expectedRecords, logRecordsContainingRequestProcessor.size());
+        
+        for (int i = 0; i < expectedRecords; i++) {
+            assertEquals(Level.FINE, logRecordsContainingRequestProcessor.get(i).getLevel());
+        }
+        
+        String newLine = System.getProperty("line.separator");
+        
+        assertEquals("Processing GET request to http://localhost:80/hello, source content type is null, acceptable media types include text/plain", logRecordsContainingRequestProcessor.get(0).getMessage());
+        String expectedString = "The following error occurred during the invocation of the handlers chain: RuntimeException with message 'reqHandlerHR' while processing GET request sent to http://localhost:80/hello";
+        assertTrue(logRecordsContainingRequestProcessor.get(1).getMessage().startsWith(expectedString));
+        assertNotNull(logRecordsContainingRequestProcessor.get(1).getThrown());
+        assertEquals("Registered JAX-RS resources: " + newLine + "  Path: hello; ClassMetadata: Class: org.apache.wink.server.serviceability.DebugHandlerThrowsExceptionTest$MyResource" + newLine + "  Path: ; ClassMetadata: Class: org.apache.wink.server.internal.resources.HtmlServiceDocumentResource", logRecordsContainingRequestProcessor.get(2).getMessage());
+        assertTrue(logRecordsContainingRequestProcessor.get(3).getMessage().startsWith("The following user-defined JAX-RS providers are registered: \nRawType: interface javax.ws.rs.ext.MessageBodyReader"));
+    }
+
+    @Override
+    protected String getPropertiesFile() {
+        return getClass().getName().replaceAll("\\.", "/") + ".properties";
+    }
+    
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleProvidersAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleProvidersAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleProvidersAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleProvidersAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,290 @@
+/*
+ * 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.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.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;
+
+public class DebugMultipleProvidersAppStartupTest 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");
+
+    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 a Provider is logged at the debug level.
+     */
+    public void testLogOneProvider() 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.DebugMultipleProvidersAppStartupTest$MyEntityReader was registered as a JAX-RS MessageBodyReader provider for java.lang.String Java types and custom2/type2 media types.";
+        assertEquals(provider1Message, records.get(11).getMessage());
+        assertEquals(Level.INFO, records.get(11).getLevel());
+        final String provider2Message =
+            "The class org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyEntityReader was registered as a JAX-RS MessageBodyReader provider for java.lang.String Java types and custom/* media types.";
+        assertEquals(provider2Message, records.get(12).getMessage());
+        assertEquals(Level.INFO, records.get(12).getLevel());
+        final String provider3Message =
+            "The class org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyEntityProvider was registered as a JAX-RS MessageBodyReader provider for all Java types and */* media types.";
+        assertEquals(provider3Message, records.get(13).getMessage());
+        assertEquals(Level.INFO, records.get(13).getLevel());
+        final String provider4Message =
+            "The class org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyEntityProvider was registered as a JAX-RS MessageBodyWriter provider for all Java types and text/plain media types.";
+        assertEquals(provider4Message, records.get(14).getMessage());
+        assertEquals(Level.INFO, records.get(14).getLevel());
+
+        final String provider5Message =
+            "The class org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyExceptionMapper was registered as a JAX-RS ExceptionMapper provider for java.lang.NullPointerException Java types.";
+        assertEquals(provider5Message, records.get(15).getMessage());
+        assertEquals(Level.INFO, records.get(15).getLevel());
+
+        final String provider6Message =
+            "The class org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyContextResolver was registered as a JAX-RS ContextResolver provider for java.lang.String Java types and */* media types.";
+        assertEquals(provider6Message, records.get(16).getMessage());
+        assertEquals(Level.INFO, records.get(16).getLevel());
+
+        assertEquals(Level.FINE, records.get(17).getLevel());
+        StringBuffer sb = new StringBuffer();
+        Formatter f = new Formatter(sb);
+        f.format("The following JAX-RS MessageBodyReader providers are registered:");
+        f.format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                 "Consumes Media Type",
+                 "Generic Type",
+                 "Custom?",
+                 "Provider Class");
+        f
+            .format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                    "custom2/type2",
+                    "String",
+                    "true",
+                    "org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyEntityReader");
+        f
+            .format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                    "custom/*",
+                    "String",
+                    "true",
+                    "org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyEntityReader");
+        f
+            .format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                    "*/*",
+                    "Object",
+                    "true",
+                    "org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyEntityProvider");
+        assertEquals(sb.toString(), records.get(17).getMessage());
+
+        assertEquals(Level.FINE, records.get(18).getLevel());
+        sb = new StringBuffer();
+        f = new Formatter(sb);
+        f.format("The following JAX-RS MessageBodyWriter providers are registered:");
+        f.format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                 "Produces Media Type",
+                 "Generic Type",
+                 "Custom?",
+                 "Provider Class");
+        f
+            .format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                    "text/plain",
+                    "Object",
+                    "true",
+                    "org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyEntityProvider");
+        assertEquals(sb.toString(), records.get(18).getMessage());
+
+        assertEquals(Level.FINE, records.get(19).getLevel());
+        sb = new StringBuffer();
+        f = new Formatter(sb);
+        f.format("The following JAX-RS ExceptionMapper providers are registered:");
+        f.format("%n%1$-25s %2$-8s %3$s", "Generic Type", "Custom?", "Provider Class");
+        f
+            .format("%n%1$-25s %2$-8s %3$s",
+                    "NullPointerException",
+                    "true",
+                    "org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyExceptionMapper");
+        assertEquals(sb.toString(), records.get(19).getMessage());
+
+        assertEquals(Level.FINE, records.get(20).getLevel());
+        sb = new StringBuffer();
+        f = new Formatter(sb);
+        f.format("The following JAX-RS ContextResolver providers are registered:");
+        f.format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                 "Produces Media Type",
+                 "Generic Type",
+                 "Custom?",
+                 "Provider Class");
+        f
+            .format("%n%1$-35s %2$-25s %3$-8s %4$s",
+                    "*/*",
+                    "String",
+                    "true",
+                    "org.apache.wink.server.serviceability.DebugMultipleProvidersAppStartupTest$MyContextResolver");
+        assertEquals(sb.toString(), records.get(20).getMessage());
+
+        assertEquals(21, records.size());
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleResourcesAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleResourcesAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleResourcesAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugMultipleResourcesAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,252 @@
+/*
+ * 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.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+/**
+ * Tests the debug information for multiple resources.
+ */
+public class DebugMultipleResourcesAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource1.class, MyResource2.class, MyResource3.class,
+            MyResource4.class};
+    }
+
+    @Path("/hello")
+    public static class MyResource1 {
+
+        @GET
+        public String get() {
+            return null;
+        }
+    }
+
+    @Path("/hello2")
+    public static class MyResource2 {
+
+        @DELETE
+        @Path("subpath")
+        public String get() {
+            return null;
+        }
+    }
+
+    @Path("/longpath/longpath/longpath")
+    public static class MyResource3 {
+
+        @Path("sublocator")
+        public String get() {
+            return null;
+        }
+    }
+
+    @Path("/somepath")
+    public static class MyResource4 {
+
+        @PUT
+        public String put(byte[] someBytes) {
+            return null;
+        }
+
+        @POST
+        @Path("subresource")
+        public String getSubresource(String someEntity) {
+            return null;
+        }
+
+        @Path("sublocator")
+        public String getSublocator(@QueryParam("q") String something) {
+            return 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();
+    }
+
+    /**
+     * Tests that the JAX-RS application sub-class init params is logged and
+     * other debug startup.
+     * 
+     * @throws Exception
+     */
+    public void testLogNoResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals("Configuration Settings:", records.get(0).getMessage());
+        assertEquals(Level.FINE, records.get(0).getLevel());
+
+        assertEquals("Request User Handlers: []", records.get(1).getMessage());
+        assertEquals(Level.FINE, records.get(1).getLevel());
+
+        assertEquals("Response User Handlers: []", records.get(2).getMessage());
+        assertEquals(Level.FINE, records.get(2).getLevel());
+
+        assertEquals("Error User Handlers: []", records.get(3).getMessage());
+        assertEquals(Level.FINE, records.get(3).getLevel());
+
+        assertTrue(records.get(4).getMessage(), records.get(4).getMessage()
+            .startsWith("MediaTypeMapper: "));
+        assertEquals(Level.FINE, records.get(4).getLevel());
+
+        assertTrue(records.get(5).getMessage(), records.get(5).getMessage()
+            .startsWith("AlternateShortcutMap: "));
+        assertEquals(Level.FINE, records.get(5).getLevel());
+
+        assertTrue(records.get(6).getMessage(), records.get(6).getMessage()
+            .startsWith("Properties: "));
+        assertEquals(Level.FINE, records.get(6).getLevel());
+
+        assertEquals("HttpMethodOverrideHeaders: []", records.get(7).getMessage());
+        assertEquals(Level.FINE, records.get(7).getLevel());
+
+        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(8).getMessage());
+        assertEquals(Level.INFO, records.get(8).getLevel());
+        assertEquals("The following JAX-RS application has been processed: org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication",
+                     records.get(9).getMessage());
+        assertEquals(Level.INFO, records.get(9).getLevel());
+
+        assertEquals("The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource3 with @Path(/longpath/longpath/longpath).",
+                     records.get(10).getMessage());
+        assertEquals(Level.INFO, records.get(10).getLevel());
+
+        assertEquals("The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource4 with @Path(/somepath).",
+                     records.get(11).getMessage());
+        assertEquals(Level.INFO, records.get(11).getLevel());
+
+        assertEquals("The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource2 with @Path(/hello2).",
+                     records.get(12).getMessage());
+        assertEquals(Level.INFO, records.get(12).getLevel());
+
+        assertEquals("The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource1 with @Path(/hello).",
+                     records.get(13).getMessage());
+        assertEquals(Level.INFO, records.get(13).getLevel());
+
+        StringBuffer resourceTable = new StringBuffer();
+        Formatter f = new Formatter(resourceTable);
+        f.format("Registered JAX-RS resources: %n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                 "Path",
+                 "HTTP Method",
+                 "Consumes",
+                 "Produces",
+                 "Resource Method");
+        f
+            .format("%n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                    "/longpath/longpath/longpath/sublocator",
+                    "(Sub-Locator)",
+                    "[*/*]",
+                    "[*/*]",
+                    "org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource3.get()");
+
+        f
+            .format("%n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                    "/somepath",
+                    "PUT",
+                    "[*/*]",
+                    "[*/*]",
+                    "org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource4.put(byte[])");
+        f
+            .format("%n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                    "/somepath/subresource",
+                    "POST",
+                    "[*/*]",
+                    "[*/*]",
+                    "org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource4.getSubresource(String)");
+        f
+            .format("%n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                    "/somepath/sublocator",
+                    "(Sub-Locator)",
+                    "[*/*]",
+                    "[*/*]",
+                    "org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource4.getSublocator(String)");
+        f
+            .format("%n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                    "/hello2/subpath",
+                    "DELETE",
+                    "[*/*]",
+                    "[*/*]",
+                    "org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource2.get()");
+
+        f
+            .format("%n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                    "/hello",
+                    "GET",
+                    "[*/*]",
+                    "[*/*]",
+                    "org.apache.wink.server.serviceability.DebugMultipleResourcesAppStartupTest$MyResource1.get()");
+
+        assertEquals(resourceTable.toString(), records.get(14).getMessage());
+        assertEquals(Level.FINE, records.get(14).getLevel());
+
+        assertEquals("There are no custom JAX-RS providers defined in the application.", records.get(15)
+            .getMessage());
+        assertEquals(Level.INFO, records.get(15).getLevel());
+
+        assertEquals(16, records.size());
+    }
+
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoMessageBodyWriter500Test.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoMessageBodyWriter500Test.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoMessageBodyWriter500Test.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoMessageBodyWriter500Test.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,141 @@
+/*
+ * 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.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 DebugNoMessageBodyWriter500Test 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");
+
+    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 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(21).getLevel());
+        assertTrue(records
+            .get(21)
+            .getMessage()
+            .indexOf("The system could not find a javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for the org.apache.wink.server.serviceability.DebugNoMessageBodyWriter500Test$MyObject type and") != -1 && records
+            .get(21)
+            .getMessage()
+            .indexOf("mediaType.  Ensure that a javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for the type and media type specified.") != -1);
+
+        assertEquals(30, 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/DebugNoProvidersAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoProvidersAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoProvidersAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoProvidersAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,123 @@
+/*
+ * 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 org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+public class DebugNoProvidersAppStartupTest  extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {};
+    }
+
+    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 the JAX-RS application sub-class init params is logged and
+     * other debug startup.
+     * 
+     * @throws Exception
+     */
+    public void testLogNoResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals("Configuration Settings:", records.get(0).getMessage());
+        assertEquals(Level.FINE, records.get(0).getLevel());
+
+        assertEquals("Request User Handlers: []", records.get(1).getMessage());
+        assertEquals(Level.FINE, records.get(1).getLevel());
+
+        assertEquals("Response User Handlers: []", records.get(2).getMessage());
+        assertEquals(Level.FINE, records.get(2).getLevel());
+
+        assertEquals("Error User Handlers: []", records.get(3).getMessage());
+        assertEquals(Level.FINE, records.get(3).getLevel());
+
+        assertTrue(records.get(4).getMessage(), records.get(4).getMessage()
+            .startsWith("MediaTypeMapper: "));
+        assertEquals(Level.FINE, records.get(4).getLevel());
+
+        assertTrue(records.get(5).getMessage(), records.get(5).getMessage()
+            .startsWith("AlternateShortcutMap: "));
+        assertEquals(Level.FINE, records.get(5).getLevel());
+
+        assertTrue(records.get(6).getMessage(), records.get(6).getMessage()
+            .startsWith("Properties: "));
+        assertEquals(Level.FINE, records.get(6).getLevel());
+
+        assertEquals("HttpMethodOverrideHeaders: []", records.get(7).getMessage());
+        assertEquals(Level.FINE, records.get(7).getLevel());
+
+        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(8).getMessage());
+        assertEquals(Level.INFO, records.get(8).getLevel());
+        assertEquals("The following JAX-RS application has been processed: org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication",
+                     records.get(9).getMessage());
+        assertEquals(Level.INFO, records.get(9).getLevel());
+
+        assertEquals("There are no @javax.ws.rs.Path annotated classes defined in the application.",
+                     records.get(10).getMessage());
+        assertEquals(Level.FINE, records.get(10).getLevel());
+        assertEquals("There are no custom JAX-RS providers defined in the application.", records.get(11)
+            .getMessage());
+        assertEquals(Level.INFO, records.get(11).getLevel());
+
+        assertEquals(12, records.size());
+    }
+
+
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoResourcesAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoResourcesAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoResourcesAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugNoResourcesAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,126 @@
+/*
+ * 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 org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+/**
+ * Tests the logger at debug level for basic application startup.
+ */
+public class DebugNoResourcesAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {};
+    }
+
+    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 the JAX-RS application sub-class init params is logged and
+     * other debug startup.
+     * 
+     * @throws Exception
+     */
+    public void testLogNoResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals("Configuration Settings:", records.get(0).getMessage());
+        assertEquals(Level.FINE, records.get(0).getLevel());
+
+        assertEquals("Request User Handlers: []", records.get(1).getMessage());
+        assertEquals(Level.FINE, records.get(1).getLevel());
+
+        assertEquals("Response User Handlers: []", records.get(2).getMessage());
+        assertEquals(Level.FINE, records.get(2).getLevel());
+
+        assertEquals("Error User Handlers: []", records.get(3).getMessage());
+        assertEquals(Level.FINE, records.get(3).getLevel());
+
+        assertTrue(records.get(4).getMessage(), records.get(4).getMessage()
+            .startsWith("MediaTypeMapper: "));
+        assertEquals(Level.FINE, records.get(4).getLevel());
+
+        assertTrue(records.get(5).getMessage(), records.get(5).getMessage()
+            .startsWith("AlternateShortcutMap: "));
+        assertEquals(Level.FINE, records.get(5).getLevel());
+
+        assertTrue(records.get(6).getMessage(), records.get(6).getMessage()
+            .startsWith("Properties: "));
+        assertEquals(Level.FINE, records.get(6).getLevel());
+
+        assertEquals("HttpMethodOverrideHeaders: []", records.get(7).getMessage());
+        assertEquals(Level.FINE, records.get(7).getLevel());
+
+        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(8).getMessage());
+        assertEquals(Level.INFO, records.get(8).getLevel());
+        assertEquals("The following JAX-RS application has been processed: org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication",
+                     records.get(9).getMessage());
+        assertEquals(Level.INFO, records.get(9).getLevel());
+
+        assertEquals("There are no @javax.ws.rs.Path annotated classes defined in the application.",
+                     records.get(10).getMessage());
+        assertEquals(Level.FINE, records.get(10).getLevel());
+        assertEquals("There are no custom JAX-RS providers defined in the application.", records.get(11)
+            .getMessage());
+        assertEquals(Level.INFO, records.get(11).getLevel());
+
+        assertEquals(12, records.size());
+    }
+
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneProviderOnlyAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneProviderOnlyAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneProviderOnlyAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneProviderOnlyAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,130 @@
+/*
+ * 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.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.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;
+
+public class DebugOneProviderOnlyAppStartupTest 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");
+
+    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 a Provider is logged at the debug level.
+     */
+    public void testLogOneProvider() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals(Level.INFO, records.get(11).getLevel());
+        assertEquals("The class org.apache.wink.server.serviceability.DebugOneProviderOnlyAppStartupTest$Provider1 was registered as a JAX-RS MessageBodyWriter provider for all Java types and */* media types.",
+                     records.get(11).getMessage());
+
+        assertEquals(Level.FINE, records.get(12).getLevel());
+        StringBuffer sb = new StringBuffer();
+        Formatter f = new Formatter(sb);
+        f.format("The following JAX-RS MessageBodyWriter providers are registered:%n");
+        f
+            .format("Produces Media Type                 Generic Type              Custom?  Provider Class%n");
+        f
+            .format("*/*                                 Object                    true     org.apache.wink.server.serviceability.DebugOneProviderOnlyAppStartupTest$Provider1");
+        assertEquals(sb.toString(), records.get(12).getMessage());
+
+        assertEquals(13, records.size());
+    }
+}

Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneResourceOnlyAppStartupTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneResourceOnlyAppStartupTest.java?rev=1027712&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneResourceOnlyAppStartupTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/serviceability/DebugOneResourceOnlyAppStartupTest.java Tue Oct 26 19:52:54 2010
@@ -0,0 +1,155 @@
+/*
+ * 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.Path;
+
+import org.apache.wink.logging.InMemoryHandler;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+
+public class DebugOneResourceOnlyAppStartupTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class<?>[] {MyResource1.class};
+    }
+
+    @Path("/hello")
+    public static class MyResource1 {
+        @GET
+        public String get() {
+            return 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();
+    }
+
+    /**
+     * Tests that the JAX-RS application sub-class init params is logged and
+     * other debug startup.
+     * 
+     * @throws Exception
+     */
+    public void testLogNoResource() throws Exception {
+        List<LogRecord> records = handler.getRecords();
+
+        assertEquals("Configuration Settings:", records.get(0).getMessage());
+        assertEquals(Level.FINE, records.get(0).getLevel());
+
+        assertEquals("Request User Handlers: []", records.get(1).getMessage());
+        assertEquals(Level.FINE, records.get(1).getLevel());
+
+        assertEquals("Response User Handlers: []", records.get(2).getMessage());
+        assertEquals(Level.FINE, records.get(2).getLevel());
+
+        assertEquals("Error User Handlers: []", records.get(3).getMessage());
+        assertEquals(Level.FINE, records.get(3).getLevel());
+
+        assertTrue(records.get(4).getMessage(), records.get(4).getMessage()
+            .startsWith("MediaTypeMapper: "));
+        assertEquals(Level.FINE, records.get(4).getLevel());
+
+        assertTrue(records.get(5).getMessage(), records.get(5).getMessage()
+            .startsWith("AlternateShortcutMap: "));
+        assertEquals(Level.FINE, records.get(5).getLevel());
+
+        assertTrue(records.get(6).getMessage(), records.get(6).getMessage()
+            .startsWith("Properties: "));
+        assertEquals(Level.FINE, records.get(6).getLevel());
+
+        assertEquals("HttpMethodOverrideHeaders: []", records.get(7).getMessage());
+        assertEquals(Level.FINE, records.get(7).getLevel());
+
+        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(8).getMessage());
+        assertEquals(Level.INFO, records.get(8).getLevel());
+        assertEquals("The following JAX-RS application has been processed: org.apache.wink.server.internal.servlet.MockServletInvocationTest$MockApplication",
+                     records.get(9).getMessage());
+        assertEquals(Level.INFO, records.get(9).getLevel());
+
+        assertEquals("The server has registered the JAX-RS resource class org.apache.wink.server.serviceability.DebugOneResourceOnlyAppStartupTest$MyResource1 with @Path(/hello).",
+                     records.get(10).getMessage());
+        assertEquals(Level.INFO, records.get(10).getLevel());
+
+        StringBuffer resourceTable = new StringBuffer();
+        Formatter f = new Formatter(resourceTable);
+        f.format("Registered JAX-RS resources: %n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                 "Path",
+                 "HTTP Method",
+                 "Consumes",
+                 "Produces",
+                 "Resource Method");
+        f
+            .format("%n%1$-80s %2$-13s %3$-20s %4$-20s %5$s",
+                    "/hello",
+                    "GET",
+                    "[*/*]",
+                    "[*/*]",
+                    "org.apache.wink.server.serviceability.DebugOneResourceOnlyAppStartupTest$MyResource1.get()");
+        
+        assertEquals(resourceTable.toString(), records.get(11).getMessage());
+        assertEquals(Level.FINE, records.get(11).getLevel());
+
+        assertEquals("There are no custom JAX-RS providers defined in the application.", records.get(12)
+            .getMessage());
+        assertEquals(Level.INFO, records.get(12).getLevel());
+
+        assertEquals(13, records.size());
+    }
+
+}



Mime
View raw message