[jboss-cvs] JBossAS SVN: r83263 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584: web and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 22 05:17:20 EST 2009


Author: wolfc
Date: 2009-01-22 05:17:20 -0500 (Thu, 22 Jan 2009)
New Revision: 83263

Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java
Log:
JBPAPP-584: unit test retention of the option

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java	2009-01-22 10:07:10 UTC (rev 83262)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/unit/DynamicSecurityUnitTestCase.java	2009-01-22 10:17:20 UTC (rev 83263)
@@ -64,6 +64,46 @@
    }
    
    /**
+    * Make sure that we can retain the option in one session.
+    */
+   public void testRetainOption() throws Exception
+   {
+      HttpClient client = new HttpClient();
+      client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("Bill", "jbpapp584"));
+      String host = System.getProperty("jboss.bind.address", "localhost");
+      GetMethod method = new GetMethod();
+      // do work on company A
+      {
+         method.setURI(new HttpURL("http://" + host + ":8080/jbpapp584/MyServlet?option=CompanyA"));
+         int responseCode = client.executeMethod(method);
+         String actual = method.getResponseBodyAsString();
+         
+         assertEquals("Http request failed " + actual, HttpServletResponse.SC_OK, responseCode);
+         
+         String expected = "org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal\r\nBill\r\nUser\r\nCompanyA\r\n";
+         assertEquals(expected, actual);
+      }
+      // make sure we're in a HttpSession
+      Cookie cookies[] = client.getState().getCookies();
+      assertEquals(1, cookies.length);
+      Cookie cookie = cookies[0];
+      assertEquals("JSESSIONID", cookie.getName());
+      // do more work on company A
+      {
+         // do not specify the option, it must have been retained
+         method.setURI(new HttpURL("http://" + host + ":8080/jbpapp584/MyServlet"));
+         int responseCode = client.executeMethod(method);
+         String actual = method.getResponseBodyAsString();
+         
+         assertEquals("Http request failed " + actual, HttpServletResponse.SC_OK, responseCode);
+         
+         String expected = "org.jboss.ejb3.test.jbpapp584.jaas.MyPrincipal\r\nBill\r\nUser\r\nCompanyA\r\n";
+         assertEquals(expected, actual);
+      }
+      method.releaseConnection();
+   }
+   
+   /**
     * Make sure that we can switch options in one session.
     */
    public void testSwitchOption() throws Exception

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java	2009-01-22 10:07:10 UTC (rev 83262)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp584/web/MyServlet.java	2009-01-22 10:17:20 UTC (rev 83263)
@@ -56,8 +56,10 @@
       // do a blatant cast and ignore the consequences
       MyPrincipal p = (MyPrincipal) req.getUserPrincipal();
       
+      // only set the option if specified, else leave it as be
       String option = req.getParameter("option");
-      p.setOption(option);
+      if(option != null)
+         p.setOption(option);
       
       String results[] = bean.getResults();
       for(String result : results)




More information about the jboss-cvs-commits mailing list