/aerie/test/aerie/servlet/UriParserTest.java
http://aerie.googlecode.com/ · Java · 128 lines · 86 code · 18 blank · 24 comment · 0 complexity · d064f9d03eab1e4bf3c76dcc429a7ab3 MD5 · raw file
- /**
- * Copyright (c) 2006 George Malamidis, nutrun.com
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this
- * software and associated documentation files (the "Software"), to deal in the Software
- * without restriction, including without limitation the rights to use, copy, modify,
- * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies
- * or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
- * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- /**
- * $Author$
- * $Rev$
- */
- package aerie.servlet;
- import aerie.context.AerieContext;
- import junit.framework.TestCase;
- public class UriParserTest extends TestCase {
- private AerieContext context;
- protected void setUp() {
- context = new AerieContext();
- }
- public void testShouldExtractControllerFromUri() {
- context.path = "";
- context.webAppContext = "";
- String uri = "/controller/action/1";
- assertEquals("controller", new UriParser(uri, context).extractController());
- }
- public void testShouldDefaultToWelcomeControllerIfControllerNotFoundInUri() {
- context.welcomeController = "welcome";
- context.path = "";
- context.webAppContext = "";
- assertEquals("welcome", new UriParser("/", context).extractController());
- }
- public void testShouldHaveWelcomeControllerForNonDefaultWebAppContext() {
- context.path = "";
- context.welcomeController = "welcome";
- context.webAppContext = "/webAppContext";
- assertEquals("welcome", new UriParser("/webAppContext", context).extractController());
- }
- public void testShouldHaveWelcomeControllerForNonRootContextPath() {
- context.path = "private";
- context.welcomeController = "welcome";
- context.webAppContext = "";
- assertEquals("private/welcome", new UriParser("/private", context).extractController());
- }
- public void testShouldExtractActionFromUri() {
- context.path = "";
- context.webAppContext = "";
- assertEquals("action", new UriParser("/controller/action/1", context).extractAction());
- }
- public void testshouldDefaultToIndexIfNoActionInUri() {
- context.path = "";
- context.webAppContext = "";
- assertEquals("index", new UriParser("/controller", context).extractAction());
- }
- public void testShouldExtractParameterFromUri() {
- context.path = "";
- context.webAppContext = "";
- assertEquals("1", new UriParser("/controller/action/1", context).extractParameter());
- }
- public void testShouldReturnNullIfNoParameterInUri() {
- context.path = "";
- context.webAppContext = "";
- assertNull(new UriParser("/controller", context).extractParameter());
- }
- public void testShouldHandleUriWithNonRootWebAppContext() {
- context.path = "";
- context.webAppContext = "/context";
- assertEquals("controller", new UriParser("/context/controller", context).extractController());
- assertEquals("action", new UriParser("/context/controller/action", context).extractAction());
- assertEquals("1", new UriParser("/context/controller/action/1", context).extractParameter());
- }
- public void testShouldHandleUriWithNonRootContextPath() {
- context.path = "private";
- context.webAppContext = "";
- assertEquals("private/controller", new UriParser("/private/controller", context).extractController());
- assertEquals("action", new UriParser("/private/controller/action", context).extractAction());
- assertEquals("1", new UriParser("/private/controller/action/1", context).extractParameter());
- }
- public void testShouldHandleUriWithCompositeContextPath() {
- context.path = "/private/users";
- context.webAppContext = "";
- assertEquals("/private/users/controller", new UriParser("/private/users/controller", context).extractController());
- assertEquals("action", new UriParser("/private/users/controller/action", context).extractAction());
- assertEquals("1", new UriParser("/private/users/controller/action/1", context).extractParameter());
- }
- public void testShouldHandleUriWithNonRootContextPathAndNonRootWebAppContext() {
- context.path = "path";
- context.webAppContext = "/context";
- assertEquals("path/controller", new UriParser("/context/path/controller", context).extractController());
- assertEquals("action", new UriParser("/context/path/controller/action", context).extractAction());
- assertEquals("1", new UriParser("/context/path/controller/action/1", context).extractParameter());
- }
- public void testShouldLowerCaseController() {
- context.path = "";
- context.webAppContext = "";
- assertEquals("controller", new UriParser("/Controller", context).extractController());
- }
- }