tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkoli...@apache.org
Subject svn commit: r1150652 - in /tomcat/trunk/test/org/apache/catalina/deploy: TestSecurityConstraint.java TestWebXml.java TestWebXmlOrdering.java
Date Mon, 25 Jul 2011 12:04:33 GMT
Author: kkolinko
Date: Mon Jul 25 12:04:32 2011
New Revision: 1150652

URL: http://svn.apache.org/viewvc?rev=1150652&view=rev
Log:
Converted tests in org.apache.catalina.deploy to JUnit 4.

1) textXXX() -> @Test added
2) protected setUp() -> @Before public setUp()
3) in TestSecurityConstraint: There is no assertEquals(boolean, boolean) method in JUnit 4,
so those calls were replaced with assertTrue() and assertFalse().

Modified:
    tomcat/trunk/test/org/apache/catalina/deploy/TestSecurityConstraint.java
    tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java
    tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java

Modified: tomcat/trunk/test/org/apache/catalina/deploy/TestSecurityConstraint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/deploy/TestSecurityConstraint.java?rev=1150652&r1=1150651&r2=1150652&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/deploy/TestSecurityConstraint.java (original)
+++ tomcat/trunk/test/org/apache/catalina/deploy/TestSecurityConstraint.java Mon Jul 25 12:04:32
2011
@@ -25,9 +25,14 @@ import javax.servlet.ServletSecurityElem
 import javax.servlet.annotation.ServletSecurity;
 import javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
-public class TestSecurityConstraint extends TestCase {
+import org.junit.Test;
+
+public class TestSecurityConstraint {
 
     private static final String URL_PATTERN = "/test";
     private static final String ROLE1 = "R1";
@@ -35,6 +40,7 @@ public class TestSecurityConstraint exte
     /**
      * Uses the examples in SRV.13.4 as the basis for these tests
      */
+    @Test
     public void testCreateConstraints() {
         
         ServletSecurityElement element;
@@ -59,9 +65,8 @@ public class TestSecurityConstraint exte
         result = SecurityConstraint.createConstraints(element, URL_PATTERN);
 
         assertEquals(1, result.length);
-        assertEquals(false, result[0].getAuthConstraint());
-        assertEquals(true,
-                result[0].findCollections()[0].findPattern(URL_PATTERN));
+        assertFalse(result[0].getAuthConstraint());
+        assertTrue(result[0].findCollections()[0].findPattern(URL_PATTERN));
         assertEquals(0, result[0].findCollections()[0].findMethods().length);
         assertEquals(ServletSecurity.TransportGuarantee.CONFIDENTIAL.name(),
                 result[0].getUserConstraint());
@@ -73,9 +78,8 @@ public class TestSecurityConstraint exte
         result = SecurityConstraint.createConstraints(element, URL_PATTERN);
 
         assertEquals(1, result.length);
-        assertEquals(true, result[0].getAuthConstraint());
-        assertEquals(true,
-                result[0].findCollections()[0].findPattern(URL_PATTERN));
+        assertTrue(result[0].getAuthConstraint());
+        assertTrue(result[0].findCollections()[0].findPattern(URL_PATTERN));
         assertEquals(0, result[0].findCollections()[0].findMethods().length);
         assertEquals(ServletSecurity.TransportGuarantee.NONE.name(),
                 result[0].getUserConstraint());
@@ -87,11 +91,10 @@ public class TestSecurityConstraint exte
         result = SecurityConstraint.createConstraints(element, URL_PATTERN);
 
         assertEquals(1, result.length);
-        assertEquals(true, result[0].getAuthConstraint());
+        assertTrue(result[0].getAuthConstraint());
         assertEquals(1, result[0].findAuthRoles().length);
-        assertEquals(true, result[0].findAuthRole(ROLE1));
-        assertEquals(true,
-                result[0].findCollections()[0].findPattern(URL_PATTERN));
+        assertTrue(result[0].findAuthRole(ROLE1));
+        assertTrue(result[0].findCollections()[0].findPattern(URL_PATTERN));
         assertEquals(0, result[0].findCollections()[0].findMethods().length);
         assertEquals(ServletSecurity.TransportGuarantee.NONE.name(),
                 result[0].getUserConstraint());
@@ -115,11 +118,10 @@ public class TestSecurityConstraint exte
         
         assertEquals(2, result.length);
         for (int i = 0; i < 2; i++) {
-            assertEquals(true, result[i].getAuthConstraint());
+            assertTrue(result[i].getAuthConstraint());
             assertEquals(1, result[i].findAuthRoles().length);
-            assertEquals(true, result[i].findAuthRole(ROLE1));
-            assertEquals(true,
-                    result[i].findCollections()[0].findPattern(URL_PATTERN));
+            assertTrue(result[i].findAuthRole(ROLE1));
+            assertTrue(result[i].findCollections()[0].findPattern(URL_PATTERN));
             assertEquals(1, result[i].findCollections()[0].findMethods().length);
             String method = result[i].findCollections()[0].findMethods()[0];
             if ("GET".equals(method)) {
@@ -147,16 +149,15 @@ public class TestSecurityConstraint exte
         
         assertEquals(2, result.length);
         for (int i = 0; i < 2; i++) {
-            assertEquals(true,
-                    result[i].findCollections()[0].findPattern(URL_PATTERN));
+            assertTrue(result[i].findCollections()[0].findPattern(URL_PATTERN));
             if (result[i].findCollections()[0].findMethods().length == 1) {
                 assertEquals("GET",
                         result[i].findCollections()[0].findMethods()[0]);
-                assertEquals(false, result[i].getAuthConstraint());
+                assertFalse(result[i].getAuthConstraint());
             } else if (result[i].findCollections()[0].findOmittedMethods().length == 1) {
                 assertEquals("GET",
                         result[i].findCollections()[0].findOmittedMethods()[0]);
-                assertEquals(true, result[i].getAuthConstraint());
+                assertTrue(result[i].getAuthConstraint());
                 assertEquals(1, result[i].findAuthRoles().length);
                 assertEquals(ROLE1, result[i].findAuthRoles()[0]);
             } else {
@@ -182,17 +183,16 @@ public class TestSecurityConstraint exte
         
         assertEquals(2, result.length);
         for (int i = 0; i < 2; i++) {
-            assertEquals(true,
-                    result[i].findCollections()[0].findPattern(URL_PATTERN));
+            assertTrue(result[i].findCollections()[0].findPattern(URL_PATTERN));
             if (result[i].findCollections()[0].findMethods().length == 1) {
                 assertEquals("TRACE",
                         result[i].findCollections()[0].findMethods()[0]);
-                assertEquals(true, result[i].getAuthConstraint());
+                assertTrue(result[i].getAuthConstraint());
                 assertEquals(0, result[i].findAuthRoles().length);
             } else if (result[i].findCollections()[0].findOmittedMethods().length == 1) {
                 assertEquals("TRACE",
                         result[i].findCollections()[0].findOmittedMethods()[0]);
-                assertEquals(true, result[i].getAuthConstraint());
+                assertTrue(result[i].getAuthConstraint());
                 assertEquals(1, result[i].findAuthRoles().length);
                 assertEquals(ROLE1, result[i].findAuthRoles()[0]);
             } else {

Modified: tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java?rev=1150652&r1=1150651&r2=1150652&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java (original)
+++ tomcat/trunk/test/org/apache/catalina/deploy/TestWebXml.java Mon Jul 25 12:04:32 2011
@@ -17,13 +17,16 @@
 
 package org.apache.catalina.deploy;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
 
 /**
  * Test case for {@link WebXml}.
  */
-public class TestWebXml extends TestCase {
+public class TestWebXml {
 
+    @Test
     public void testParseVersion() {
         
         WebXml webxml = new WebXml();
@@ -70,7 +73,8 @@ public class TestWebXml extends TestCase
         assertEquals(2, webxml.getMajorVersion());
         assertEquals(500, webxml.getMinorVersion());
     }
-    
+
+    @Test
     public void testParsePublicIdVersion22() {
         
         WebXml webxml = new WebXml();
@@ -82,6 +86,7 @@ public class TestWebXml extends TestCase
         assertEquals("2.2", webxml.getVersion());
     }
 
+    @Test
     public void testParsePublicIdVersion23() {
         
         WebXml webxml = new WebXml();
@@ -93,6 +98,7 @@ public class TestWebXml extends TestCase
         assertEquals("2.3", webxml.getVersion());
     }
 
+    @Test
     public void testParsePublicIdVersion24() {
         
         WebXml webxml = new WebXml();
@@ -104,6 +110,7 @@ public class TestWebXml extends TestCase
         assertEquals("2.4", webxml.getVersion());
     }
 
+    @Test
     public void testParsePublicIdVersion25() {
         
         WebXml webxml = new WebXml();
@@ -115,6 +122,7 @@ public class TestWebXml extends TestCase
         assertEquals("2.5", webxml.getVersion());
     }
 
+    @Test
     public void testParsePublicIdVersion30() {
         
         WebXml webxml = new WebXml();

Modified: tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java?rev=1150652&r1=1150651&r2=1150652&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java (original)
+++ tomcat/trunk/test/org/apache/catalina/deploy/TestWebXmlOrdering.java Mon Jul 25 12:04:32
2011
@@ -23,12 +23,17 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Test case for {@link WebXml} fragment ordering.
  */
-public class TestWebXmlOrdering extends TestCase {
+public class TestWebXmlOrdering {
     private WebXml app;
     private WebXml a;
     private WebXml b;
@@ -38,9 +43,8 @@ public class TestWebXmlOrdering extends 
     private WebXml f;
     private Map<String,WebXml> fragments;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() throws Exception {
         app = new WebXml();
         a = new WebXml();
         a.setName("a");
@@ -63,6 +67,7 @@ public class TestWebXmlOrdering extends 
         fragments.put("f",f);
     }
 
+    @Test
     public void testOrderWebFragmentsAbsolute() {
         app.addAbsoluteOrdering("c");
         app.addAbsoluteOrdering("a");
@@ -81,6 +86,7 @@ public class TestWebXmlOrdering extends 
         assertFalse(iter.hasNext());
     }
 
+    @Test
     public void testOrderWebFragmentsAbsolutePartial() {
         app.addAbsoluteOrdering("c");
         app.addAbsoluteOrdering("a");
@@ -93,6 +99,7 @@ public class TestWebXmlOrdering extends 
         assertFalse(iter.hasNext());
     }
 
+    @Test
     public void testOrderWebFragmentsAbsoluteOthersStart() {
         app.addAbsoluteOrdering(WebXml.ORDER_OTHERS);
         app.addAbsoluteOrdering("b");
@@ -117,6 +124,7 @@ public class TestWebXmlOrdering extends 
         assertFalse(iter.hasNext());
     }
 
+    @Test
     public void testOrderWebFragmentsAbsoluteOthersMiddle() {
         app.addAbsoluteOrdering("b");
         app.addAbsoluteOrdering(WebXml.ORDER_OTHERS);
@@ -142,6 +150,7 @@ public class TestWebXmlOrdering extends 
         assertFalse(iter.hasNext());
     }
 
+    @Test
     public void testWebFragmentsAbsoluteWrongFragmentName() {
         app.addAbsoluteOrdering("a");
         app.addAbsoluteOrdering("z");
@@ -149,7 +158,8 @@ public class TestWebXmlOrdering extends 
         assertEquals(1,ordered.size());
         assertEquals(fragments.get("a"),ordered.toArray()[0]);
     }
-    
+
+    @Test
     public void testOrderWebFragmentsAbsoluteOthersEnd() {
         app.addAbsoluteOrdering("b");
         app.addAbsoluteOrdering("d");
@@ -175,6 +185,7 @@ public class TestWebXmlOrdering extends 
         assertFalse(iter.hasNext());
     }
 
+    @Test
     public void testOrderWebFragmentsRelative1() {
         // First example from servlet spec
         a.addAfterOrderingOthers();
@@ -194,7 +205,8 @@ public class TestWebXmlOrdering extends 
         assertEquals(c,iter.next());
         assertEquals(a,iter.next());
     }
-    
+
+    @Test
     public void testOrderWebFragmentsRelative2() {
         // Second example - use fragment a for no-id fragment
         a.addAfterOrderingOthers();
@@ -216,7 +228,8 @@ public class TestWebXmlOrdering extends 
         assertEquals(c,iter.next());
         assertEquals(d,iter.next());
     }
-    
+
+    @Test
     public void testOrderWebFragmentsRelative3() {
         // Third example from spec
         a.addAfterOrdering("b");
@@ -235,7 +248,8 @@ public class TestWebXmlOrdering extends 
         assertEquals(b,iter.next());
         assertEquals(a,iter.next());
     }
-    
+
+    @Test
     public void testOrderWebFragmentsrelativeCircular() {
         a.addBeforeOrdering("b");
         b.addBeforeOrdering("a");



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message