[jboss-cvs] JBossAS SVN: r71036 - in branches/JBPAPP_4_2_0_GA_CP/testsuite/src: main/org/jboss/test/web/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 19 21:13:40 EDT 2008


Author: stan.silvert at jboss.com
Date: 2008-03-19 21:13:40 -0400 (Wed, 19 Mar 2008)
New Revision: 71036

Added:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/jdk15/org/jboss/test/jsf/webapp/LoggingTest.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/web/html/jsftest/index.jsp
Log:
JBPAPP-682


Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/jdk15/org/jboss/test/jsf/webapp/LoggingTest.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/jdk15/org/jboss/test/jsf/webapp/LoggingTest.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/jdk15/org/jboss/test/jsf/webapp/LoggingTest.java	2008-03-20 01:13:40 UTC (rev 71036)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.jsf.webapp;
+
+import com.sun.faces.util.FacesLogger;
+import org.apache.log4j.*;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * This class simulates the kind of logging that the JSF implementation
+ * does.  
+ *
+ * @author Stan Silvert
+ */
+public class LoggingTest {
+    
+   private ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+   /**
+    * Constructor sets up an in-memory Log4J appender.  Log messages
+    * logged with the java.util.logging package should end up in this
+    * appender.
+    */
+   public LoggingTest()
+   {
+      Appender appender = new WriterAppender(new SimpleLayout(), out);
+      Logger log4jLogger = Logger.getLogger("javax.enterprise.resource.webcontainer.jsf");
+      log4jLogger.addAppender(appender);
+   }
+
+   /**
+    * Send java.util.logging messages using the same java.util Loggers
+    * that the JSF impl uses.
+    * 
+    * During the JUnit test, levels are set on the loggers so that
+    * some messages will pass thorough to log4j and 
+    * captured by the WriterAppender.  Others will not.
+    */
+   public void sendLogMessages()
+   {
+      java.util.logging.Logger julLogger = FacesLogger.RENDERKIT.getLogger();
+      julLogger.severe("Logged SEVERE message in RENDERKIT_LOGGER<br/>"); // not logged 
+
+      julLogger = FacesLogger.TAGLIB.getLogger();
+      julLogger.severe("Logged SEVERE message in TAGLIB_LOGGER<br/>"); // not logged
+
+      julLogger = FacesLogger.APPLICATION.getLogger();
+      julLogger.severe("Logged SEVERE message in APPLICATION_LOGGER<br/>"); // logged
+      julLogger.warning("Logged WARNING message in APPLICATION_LOGGER<br/>"); // not logged
+
+      julLogger = FacesLogger.CONTEXT.getLogger();
+      julLogger.warning("Logged WARNING message in CONTEXT_LOGGER<br/>"); // logged
+      julLogger.info("Logged INFO message in CONTEXT_LOGGER<br/>"); // not logged
+
+      julLogger = FacesLogger.CONFIG.getLogger();
+      julLogger.info("Logged INFO message in CONFIG_LOGGER<br/>"); // logged 
+      julLogger.fine("Logged FINE message in CONFIG_LOGGER<br/>"); // not logged
+
+      julLogger = FacesLogger.LIFECYCLE.getLogger();
+      julLogger.fine("Logged FINE message in LIFECYCLE_LOGGER<br/>"); // logged
+      julLogger.finer("Logged FINER message in LIFECYCLE_LOGGER<br/>"); // not logged
+
+      julLogger = FacesLogger.TIMING.getLogger();
+      julLogger.finer("Logged FINER message in TIMING_LOGGER<br/>"); // logged
+      julLogger.finest("Logged FINEST message in TIMING_LOGGER<br/>"); // logged
+
+      julLogger = FacesLogger.MANAGEDBEAN.getLogger();
+      julLogger.finest("Logged FINEST message in MANAGEDBEAN_LOGGER Logger<br/>"); // logged
+   }
+
+   /**
+    * Return the contents of the in-memory Log4J appender.
+    */
+   public String getLoggedMessages()
+   {
+      return out.toString();
+   }
+}

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java	2008-03-20 01:12:59 UTC (rev 71035)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/web/test/JSFIntegrationUnitTestCase.java	2008-03-20 01:13:40 UTC (rev 71036)
@@ -21,9 +21,9 @@
 */
 package org.jboss.test.web.test;
 
-//import java.net.HttpURLConnection;
+import com.sun.faces.util.FacesLogger;
+
 import java.net.URL;
-//import javax.management.ObjectName;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -48,9 +48,33 @@
  */
 public class JSFIntegrationUnitTestCase extends JBossTestCase
 {
-   private String baseURL = HttpUtils.getBaseURL(); 
-   private HttpClient client = new HttpClient();
-   
+   // Call Log4jService to set logging levels for the JSF impl before the WAR
+   // is deployed
+   public static void setLoggingLevels() throws Exception
+   {
+      HttpClient client = new HttpClient();
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.MANAGEDBEAN.getLoggerName(), "ALL")));
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.TAGLIB.getLoggerName(), "FATAL")));
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.APPLICATION.getLoggerName(), "ERROR")));
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.CONTEXT.getLoggerName(), "WARN")));
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.CONFIG.getLoggerName(), "INFO")));
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.LIFECYCLE.getLoggerName(), "DEBUG")));
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.TIMING.getLoggerName(), "TRACE")));
+      client.executeMethod(new GetMethod(makeSetLoggerCmd(FacesLogger.RENDERKIT.getLoggerName(), "OFF")));
+   }
+
+   private static String makeSetLoggerCmd(String log4jLogger, String log4jPriority)
+   {
+      String baseURL = HttpUtils.getBaseURL();
+      return baseURL + 
+             "jmx-console/HtmlAdaptor?" +
+             "action=invokeOp&" +
+             "name=jboss.system:type=Log4jService,service=Logging&" +
+             "methodIndex=1&" +
+             "arg0=" + log4jLogger + "&" +
+             "arg1=" + log4jPriority;
+   }
+
    public JSFIntegrationUnitTestCase(String name)
    {
       super(name);
@@ -60,8 +84,9 @@
     */
    public void testJSFIntegrated() throws Exception
    {
+      HttpClient client = new HttpClient();
       client.executeMethod(makeRequest());
-
+      
       HttpMethodBase result = makeRequest();
 
       // need to hit it twice with the same session for test to pass
@@ -83,6 +108,22 @@
 
       // Tests enum support 
       assertTrue(contains(responseBody, "JBoss Color selection is PURPLE"));
+
+      // Test logging
+      assertFalse(contains(responseBody, "Logged SEVERE message in RENDERKIT_LOGGER"));
+      assertFalse(contains(responseBody, "Logged SEVERE message in TAGLIB_LOGGER"));
+      assertTrue(contains(responseBody, "Logged SEVERE message in APPLICATION_LOGGER"));
+      assertFalse(contains(responseBody, "Logged WARNING message in APPLICATION_LOGGER"));
+      assertTrue(contains(responseBody, "Logged WARNING message in CONTEXT_LOGGER"));
+      assertFalse(contains(responseBody, "Logged INFO message in CONTEXT_LOGGER"));
+      assertTrue(contains(responseBody, "Logged INFO message in CONFIG_LOGGER"));
+      assertFalse(contains(responseBody, "Logged FINE message in CONFIG_LOGGER"));
+      assertTrue(contains(responseBody, "Logged FINE message in LIFECYCLE_LOGGER"));
+      assertFalse(contains(responseBody, "Logged FINER message in LIFECYCLE_LOGGER"));
+      assertTrue(contains(responseBody, "Logged FINER message in TIMING_LOGGER"));
+      assertTrue(contains(responseBody, "Logged FINEST message in TIMING_LOGGER"));
+      assertTrue(contains(responseBody, "Logged FINEST message in MANAGEDBEAN_LOGGER"));
+      
    }   
 
    private boolean contains(String base, String target) {
@@ -90,11 +131,15 @@
    }
 
    private GetMethod makeRequest() {
+      String baseURL = HttpUtils.getBaseURL();
       return new GetMethod(baseURL+"jbosstest-jsf/index.jsf");
    }
 
    public static Test suite() throws Exception
    {
+      // need to set up the JSF loggers before the WAR is deployed
+      setLoggingLevels();
+      
       TestSuite suite = new TestSuite();
       suite.addTest(new TestSuite(JSFIntegrationUnitTestCase.class));
 

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/web/html/jsftest/index.jsp
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/web/html/jsftest/index.jsp	2008-03-20 01:12:59 UTC (rev 71035)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/web/html/jsftest/index.jsp	2008-03-20 01:13:40 UTC (rev 71036)
@@ -1,5 +1,6 @@
 <%@page contentType="text/html"%>
 <%@page pageEncoding="UTF-8"%>
+<%@page import="org.jboss.test.jsf.webapp.*" %>
 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
@@ -20,7 +21,7 @@
          <%
                // I think that the fact I need to do this constitutes a bug in JSTL
                if (session.getAttribute("mySessionBean") == null) {
-                    session.setAttribute("mySessionBean", new org.jboss.test.jsf.webapp.MySessionBean()); 
+                    session.setAttribute("mySessionBean", new MySessionBean()); 
                }
           %>
           
@@ -38,5 +39,13 @@
                            /></h3>
      </f:view>
  
+       <font color="red"><h1>Logging Test</h1></font>
+       <h3>
+       <%
+           LoggingTest loggingTest = new LoggingTest();
+           loggingTest.sendLogMessages();
+           out.println(loggingTest.getLoggedMessages());
+        %>
+       </h3>
     </body>
 </html>




More information about the jboss-cvs-commits mailing list