tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tveron...@apache.org
Subject svn commit: r1546606 - in /tomee/tomee/trunk/examples: testing-security-2/src/test/java/org/superbiz/injection/secure/ testing-security-3/src/test/java/org/superbiz/injection/secure/ testing-security-4/src/test/java/org/superbiz/injection/secure/ testi...
Date Fri, 29 Nov 2013 16:52:36 GMT
Author: tveronezi
Date: Fri Nov 29 16:52:36 2013
New Revision: 1546606

URL: http://svn.apache.org/r1546606
Log:
cosmetic

Modified:
    tomee/tomee/trunk/examples/testing-security-2/src/test/java/org/superbiz/injection/secure/MovieTest.java
    tomee/tomee/trunk/examples/testing-security-3/src/test/java/org/superbiz/injection/secure/MovieTest.java
    tomee/tomee/trunk/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
    tomee/tomee/trunk/examples/testing-security/src/test/java/org/superbiz/injection/secure/MovieTest.java

Modified: tomee/tomee/trunk/examples/testing-security-2/src/test/java/org/superbiz/injection/secure/MovieTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/testing-security-2/src/test/java/org/superbiz/injection/secure/MovieTest.java?rev=1546606&r1=1546605&r2=1546606&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/testing-security-2/src/test/java/org/superbiz/injection/secure/MovieTest.java
(original)
+++ tomee/tomee/trunk/examples/testing-security-2/src/test/java/org/superbiz/injection/secure/MovieTest.java
Fri Nov 29 16:52:36 2013
@@ -16,7 +16,10 @@
  */
 package org.superbiz.injection.secure;
 
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 
 import javax.ejb.EJB;
 import javax.ejb.EJBAccessException;
@@ -27,13 +30,15 @@ import java.util.List;
 import java.util.Properties;
 
 //START SNIPPET: code
-public class MovieTest extends TestCase {
+public class MovieTest {
 
     @EJB
     private Movies movies;
 
-    protected void setUp() throws Exception {
+    private EJBContainer container;
 
+    @Before
+    public void setUp() throws Exception {
         // Uncomment this line to set the login/logout functionality on Debug
         //System.setProperty("log4j.category.OpenEJB.security", "debug");
 
@@ -42,9 +47,16 @@ public class MovieTest extends TestCase 
         p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
         p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
 
-        EJBContainer.createEJBContainer(p).getContext().bind("inject", this);
+        this.container = EJBContainer.createEJBContainer(p);
+        this.container.getContext().bind("inject", this);
     }
 
+    @After
+    public void tearDown() {
+        this.container.close();
+    }
+
+    @Test
     public void testAsManager() throws Exception {
         Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
@@ -59,18 +71,19 @@ public class MovieTest extends TestCase 
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
             List<Movie> list = movies.getMovies();
-            assertEquals("List.size()", 3, list.size());
+            Assert.assertEquals("List.size()", 3, list.size());
 
             for (Movie movie : list) {
                 movies.deleteMovie(movie);
             }
 
-            assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
+            Assert.assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
         } finally {
             context.close();
         }
     }
 
+    @Test
     public void testAsEmployee() throws Exception {
         Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
@@ -85,48 +98,46 @@ public class MovieTest extends TestCase 
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
             List<Movie> list = movies.getMovies();
-            assertEquals("List.size()", 3, list.size());
+            Assert.assertEquals("List.size()", 3, list.size());
 
             for (Movie movie : list) {
                 try {
                     movies.deleteMovie(movie);
-                    fail("Employees should not be allowed to delete");
+                    Assert.fail("Employees should not be allowed to delete");
                 } catch (EJBAccessException e) {
                     // Good, Employees cannot delete things
                 }
             }
 
             // The list should still be three movies long
-            assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
+            Assert.assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
         } finally {
             context.close();
         }
     }
 
+    @Test
     public void testUnauthenticated() throws Exception {
         try {
             movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
-            fail("Unauthenticated users should not be able to add movies");
+            Assert.fail("Unauthenticated users should not be able to add movies");
         } catch (EJBAccessException e) {
             // Good, guests cannot add things
         }
 
         try {
             movies.deleteMovie(null);
-            fail("Unauthenticated users should not be allowed to delete");
+            Assert.fail("Unauthenticated users should not be allowed to delete");
         } catch (EJBAccessException e) {
             // Good, Unauthenticated users cannot delete things
         }
 
         try {
             // Read access should be allowed
-
-            List<Movie> list = movies.getMovies();
-
+            movies.getMovies();
         } catch (EJBAccessException e) {
-            fail("Read access should be allowed");
+            Assert.fail("Read access should be allowed");
         }
-
     }
 }
 //END SNIPPET: code

Modified: tomee/tomee/trunk/examples/testing-security-3/src/test/java/org/superbiz/injection/secure/MovieTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/testing-security-3/src/test/java/org/superbiz/injection/secure/MovieTest.java?rev=1546606&r1=1546605&r2=1546606&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/testing-security-3/src/test/java/org/superbiz/injection/secure/MovieTest.java
(original)
+++ tomee/tomee/trunk/examples/testing-security-3/src/test/java/org/superbiz/injection/secure/MovieTest.java
Fri Nov 29 16:52:36 2013
@@ -16,7 +16,10 @@
  */
 package org.superbiz.injection.secure;
 
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 
 import javax.ejb.EJB;
 import javax.ejb.EJBAccessException;
@@ -28,30 +31,39 @@ import java.util.List;
 import java.util.Properties;
 
 //START SNIPPET: code
-public class MovieTest extends TestCase {
+public class MovieTest {
 
     @EJB
     private Movies movies;
 
+    private EJBContainer container;
+
     private Context getContext(String user, String pass) throws NamingException {
         Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
         p.setProperty("openejb.authentication.realmName", "ServiceProviderLogin");
         p.put(Context.SECURITY_PRINCIPAL, user);
         p.put(Context.SECURITY_CREDENTIALS, pass);
-
         return new InitialContext(p);
     }
 
-    protected void setUp() throws Exception {
+    @Before
+    public void setUp() throws Exception {
         Properties p = new Properties();
         p.put("movieDatabase", "new://Resource?type=DataSource");
         p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
         p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
 
-        EJBContainer.createEJBContainer(p).getContext().bind("inject", this);
+        this.container = EJBContainer.createEJBContainer(p);
+        this.container.getContext().bind("inject", this);
+    }
+
+    @After
+    public void tearDown() {
+        this.container.close();
     }
 
+    @Test
     public void testAsManager() throws Exception {
         final Context context = getContext("paul", "michelle");
 
@@ -61,18 +73,19 @@ public class MovieTest extends TestCase 
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
             List<Movie> list = movies.getMovies();
-            assertEquals("List.size()", 3, list.size());
+            Assert.assertEquals("List.size()", 3, list.size());
 
             for (Movie movie : list) {
                 movies.deleteMovie(movie);
             }
 
-            assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
+            Assert.assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
         } finally {
             context.close();
         }
     }
 
+    @Test
     public void testAsEmployee() throws Exception {
         final Context context = getContext("eddie", "jump");
 
@@ -82,61 +95,60 @@ public class MovieTest extends TestCase 
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
             List<Movie> list = movies.getMovies();
-            assertEquals("List.size()", 3, list.size());
+            Assert.assertEquals("List.size()", 3, list.size());
 
             for (Movie movie : list) {
                 try {
                     movies.deleteMovie(movie);
-                    fail("Employees should not be allowed to delete");
+                    Assert.fail("Employees should not be allowed to delete");
                 } catch (EJBAccessException e) {
                     // Good, Employees cannot delete things
                 }
             }
 
             // The list should still be three movies long
-            assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
+            Assert.assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
         } finally {
             context.close();
         }
     }
 
+    @Test
     public void testUnauthenticated() throws Exception {
         try {
             movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
-            fail("Unauthenticated users should not be able to add movies");
+            Assert.fail("Unauthenticated users should not be able to add movies");
         } catch (EJBAccessException e) {
             // Good, guests cannot add things
         }
 
         try {
             movies.deleteMovie(null);
-            fail("Unauthenticated users should not be allowed to delete");
+            Assert.fail("Unauthenticated users should not be allowed to delete");
         } catch (EJBAccessException e) {
             // Good, Unauthenticated users cannot delete things
         }
 
         try {
             // Read access should be allowed
-
-            List<Movie> list = movies.getMovies();
-
+            movies.getMovies();
         } catch (EJBAccessException e) {
-            fail("Read access should be allowed");
+            Assert.fail("Read access should be allowed");
         }
-
     }
 
+    @Test
     public void testLoginFailure() throws NamingException {
         try {
             getContext("eddie", "panama");
-            fail("supposed to have a login failure here");
+            Assert.fail("supposed to have a login failure here");
         } catch (javax.naming.AuthenticationException e) {
             //expected
         }
 
         try {
             getContext("jimmy", "foxylady");
-            fail("supposed to have a login failure here");
+            Assert.fail("supposed to have a login failure here");
         } catch (javax.naming.AuthenticationException e) {
             //expected
         }

Modified: tomee/tomee/trunk/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java?rev=1546606&r1=1546605&r2=1546606&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
(original)
+++ tomee/tomee/trunk/examples/testing-security-4/src/test/java/org/superbiz/injection/secure/MovieTest.java
Fri Nov 29 16:52:36 2013
@@ -16,7 +16,10 @@
  */
 package org.superbiz.injection.secure;
 
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 
 import javax.ejb.EJB;
 import javax.ejb.EJBAccessException;
@@ -28,11 +31,13 @@ import java.util.List;
 import java.util.Properties;
 
 //START SNIPPET: code
-public class MovieTest extends TestCase {
+public class MovieTest {
 
     @EJB
     private Movies movies;
 
+    private EJBContainer container;
+
     private Context getContext(String user, String pass) throws NamingException {
         Properties p = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
@@ -43,7 +48,8 @@ public class MovieTest extends TestCase 
         return new InitialContext(p);
     }
 
-    protected void setUp() throws Exception {
+    @Before
+    public void setUp() throws Exception {
         final ClassLoader ctxCl = Thread.currentThread().getContextClassLoader();
         System.setProperty("openejb.ScriptLoginModule.scriptURI", ctxCl.getResource("loginscript.js").toExternalForm());
 
@@ -52,9 +58,16 @@ public class MovieTest extends TestCase 
         p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
         p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
 
-        EJBContainer.createEJBContainer(p).getContext().bind("inject", this);
+        this.container = EJBContainer.createEJBContainer(p);
+        this.container.getContext().bind("inject", this);
+    }
+
+    @After
+    public void tearDown() {
+        this.container.close();
     }
 
+    @Test
     public void testAsManager() throws Exception {
         final Context context = getContext("paul", "michelle");
 
@@ -64,18 +77,19 @@ public class MovieTest extends TestCase 
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
             List<Movie> list = movies.getMovies();
-            assertEquals("List.size()", 3, list.size());
+            Assert.assertEquals("List.size()", 3, list.size());
 
             for (Movie movie : list) {
                 movies.deleteMovie(movie);
             }
 
-            assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
+            Assert.assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
         } finally {
             context.close();
         }
     }
 
+    @Test
     public void testAsEmployee() throws Exception {
         final Context context = getContext("eddie", "jump");
 
@@ -85,61 +99,60 @@ public class MovieTest extends TestCase 
             movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
             List<Movie> list = movies.getMovies();
-            assertEquals("List.size()", 3, list.size());
+            Assert.assertEquals("List.size()", 3, list.size());
 
             for (Movie movie : list) {
                 try {
                     movies.deleteMovie(movie);
-                    fail("Employees should not be allowed to delete");
+                    Assert.fail("Employees should not be allowed to delete");
                 } catch (EJBAccessException e) {
                     // Good, Employees cannot delete things
                 }
             }
 
             // The list should still be three movies long
-            assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
+            Assert.assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
         } finally {
             context.close();
         }
     }
 
+    @Test
     public void testUnauthenticated() throws Exception {
         try {
             movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
-            fail("Unauthenticated users should not be able to add movies");
+            Assert.fail("Unauthenticated users should not be able to add movies");
         } catch (EJBAccessException e) {
             // Good, guests cannot add things
         }
 
         try {
             movies.deleteMovie(null);
-            fail("Unauthenticated users should not be allowed to delete");
+            Assert.fail("Unauthenticated users should not be allowed to delete");
         } catch (EJBAccessException e) {
             // Good, Unauthenticated users cannot delete things
         }
 
         try {
             // Read access should be allowed
-
-            List<Movie> list = movies.getMovies();
-
+            movies.getMovies();
         } catch (EJBAccessException e) {
-            fail("Read access should be allowed");
+            Assert.fail("Read access should be allowed");
         }
-
     }
 
+    @Test
     public void testLoginFailure() throws NamingException {
         try {
             getContext("eddie", "panama");
-            fail("supposed to have a login failure here");
+            Assert.fail("supposed to have a login failure here");
         } catch (javax.naming.AuthenticationException e) {
             //expected
         }
 
         try {
             getContext("jimmy", "foxylady");
-            fail("supposed to have a login failure here");
+            Assert.fail("supposed to have a login failure here");
         } catch (javax.naming.AuthenticationException e) {
             //expected
         }

Modified: tomee/tomee/trunk/examples/testing-security/src/test/java/org/superbiz/injection/secure/MovieTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/testing-security/src/test/java/org/superbiz/injection/secure/MovieTest.java?rev=1546606&r1=1546605&r2=1546606&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/testing-security/src/test/java/org/superbiz/injection/secure/MovieTest.java
(original)
+++ tomee/tomee/trunk/examples/testing-security/src/test/java/org/superbiz/injection/secure/MovieTest.java
Fri Nov 29 16:52:36 2013
@@ -16,7 +16,10 @@
  */
 package org.superbiz.injection.secure;
 
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 
 import javax.annotation.security.RunAs;
 import javax.ejb.EJB;
@@ -29,7 +32,7 @@ import java.util.concurrent.Callable;
 
 //START SNIPPET: code
 
-public class MovieTest extends TestCase {
+public class MovieTest {
 
     @EJB
     private Movies movies;
@@ -40,15 +43,25 @@ public class MovieTest extends TestCase 
     @EJB(name = "EmployeeBean")
     private Caller employee;
 
-    protected void setUp() throws Exception {
+    private EJBContainer container;
+
+    @Before
+    public void setUp() throws Exception {
         Properties p = new Properties();
         p.put("movieDatabase", "new://Resource?type=DataSource");
         p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
         p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
 
-        EJBContainer.createEJBContainer(p).getContext().bind("inject", this);
+        this.container = EJBContainer.createEJBContainer(p);
+        this.container.getContext().bind("inject", this);
+    }
+
+    @After
+    public void tearDown() {
+        this.container.close();
     }
 
+    @Test
     public void testAsManager() throws Exception {
         manager.call(new Callable() {
             public Object call() throws Exception {
@@ -58,18 +71,19 @@ public class MovieTest extends TestCase 
                 movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
                 List<Movie> list = movies.getMovies();
-                assertEquals("List.size()", 3, list.size());
+                Assert.assertEquals("List.size()", 3, list.size());
 
                 for (Movie movie : list) {
                     movies.deleteMovie(movie);
                 }
 
-                assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
+                Assert.assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
                 return null;
             }
         });
     }
 
+    @Test
     public void testAsEmployee() throws Exception {
         employee.call(new Callable() {
             public Object call() throws Exception {
@@ -79,35 +93,36 @@ public class MovieTest extends TestCase 
                 movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
 
                 List<Movie> list = movies.getMovies();
-                assertEquals("List.size()", 3, list.size());
+                Assert.assertEquals("List.size()", 3, list.size());
 
                 for (Movie movie : list) {
                     try {
                         movies.deleteMovie(movie);
-                        fail("Employees should not be allowed to delete");
+                        Assert.fail("Employees should not be allowed to delete");
                     } catch (EJBAccessException e) {
                         // Good, Employees cannot delete things
                     }
                 }
 
                 // The list should still be three movies long
-                assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
+                Assert.assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
                 return null;
             }
         });
     }
 
+    @Test
     public void testUnauthenticated() throws Exception {
         try {
             movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
-            fail("Unauthenticated users should not be able to add movies");
+            Assert.fail("Unauthenticated users should not be able to add movies");
         } catch (EJBAccessException e) {
             // Good, guests cannot add things
         }
 
         try {
             movies.deleteMovie(null);
-            fail("Unauthenticated users should not be allowed to delete");
+            Assert.fail("Unauthenticated users should not be allowed to delete");
         } catch (EJBAccessException e) {
             // Good, Unauthenticated users cannot delete things
         }
@@ -115,16 +130,15 @@ public class MovieTest extends TestCase 
         try {
             // Read access should be allowed
 
-            List<Movie> list = movies.getMovies();
+            movies.getMovies();
 
         } catch (EJBAccessException e) {
-            fail("Read access should be allowed");
+            Assert.fail("Read access should be allowed");
         }
 
     }
 
     public static interface Caller {
-
         public <V> V call(Callable<V> callable) throws Exception;
     }
 
@@ -136,21 +150,17 @@ public class MovieTest extends TestCase 
     @Stateless
     @RunAs("Manager")
     public static class ManagerBean implements Caller {
-
         public <V> V call(Callable<V> callable) throws Exception {
             return callable.call();
         }
-
     }
 
     @Stateless
     @RunAs("Employee")
     public static class EmployeeBean implements Caller {
-
         public <V> V call(Callable<V> callable) throws Exception {
             return callable.call();
         }
-
     }
 
 }



Mime
View raw message