Index: org/apache/catalina/deploy/TestFilterDef.java =================================================================== --- org/apache/catalina/deploy/TestFilterDef.java (revision 0) +++ org/apache/catalina/deploy/TestFilterDef.java (working copy) @@ -0,0 +1,47 @@ +/* + * 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.catalina.deploy; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Test case for {@link FiterDef} + */ +public class TestFilterDef { + + @Test(expected = IllegalArgumentException.class) + public void testSetFilterNameNull() { + new FilterDef().setFilterName(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetFilterNameEmptyString() { + new FilterDef().setFilterName(""); + } + + @Test + public void testSetFilterName() { + FilterDef filterDef = new FilterDef(); + filterDef.setFilterName("test"); + assertEquals("'test' is expected as filter name", + "test", filterDef.getFilterName()); + } + +} Property changes on: org/apache/catalina/deploy/TestFilterDef.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: org/apache/catalina/deploy/TestServletDef.java =================================================================== --- org/apache/catalina/deploy/TestServletDef.java (revision 0) +++ org/apache/catalina/deploy/TestServletDef.java (working copy) @@ -0,0 +1,47 @@ +/* + * 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.catalina.deploy; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Test case for {@link ServletDef} + */ +public class TestServletDef { + + @Test(expected = IllegalArgumentException.class) + public void testSetServletNameNull() { + new ServletDef().setServletName(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetServletNameEmptyString() { + new ServletDef().setServletName(""); + } + + @Test + public void testSetServletName() { + ServletDef servletDef = new ServletDef(); + servletDef.setServletName("test"); + assertEquals("'test' is expected as servlet name", + "test", servletDef.getServletName()); + } + +} Property changes on: org/apache/catalina/deploy/TestServletDef.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: org/apache/catalina/core/TestApplicationContext.java =================================================================== --- org/apache/catalina/core/TestApplicationContext.java (revision 1429246) +++ org/apache/catalina/core/TestApplicationContext.java (working copy) @@ -18,6 +18,9 @@ import java.io.File; +import javax.servlet.Filter; +import javax.servlet.Servlet; +import javax.servlet.ServletContext; import javax.servlet.http.HttpServletResponse; import org.junit.Assert; @@ -69,4 +72,40 @@ Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertTrue(res.toString().contains("

OK

")); } + + + @Test(expected = IllegalArgumentException.class) + public void testAddFilterWithFilterNameNull() { + getServletContext().addFilter(null, (Filter) null); + } + + + @Test(expected = IllegalArgumentException.class) + public void testAddFilterWithFilterNameEmptyString() { + getServletContext().addFilter("", (Filter) null); + } + + + @Test(expected = IllegalArgumentException.class) + public void testAddServletWithServletNameNull() { + getServletContext().addServlet(null, (Servlet) null); + } + + + @Test(expected = IllegalArgumentException.class) + public void testAddServletWithServletNameEmptyString() { + getServletContext().addServlet("", (Servlet) null); + } + + + private ServletContext getServletContext() { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + // app dir is relative to server home + StandardContext standardContext = + (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + + return standardContext.getServletContext(); + } }