You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2005/09/27 06:02:45 UTC

svn commit: r291814 [2/2] - in /beehive/trunk/netui: src/pageflow/org/apache/beehive/netui/pageflow/ src/pageflow/org/apache/beehive/netui/pageflow/internal/ test/ant/ test/src/junitTests/org/apache/beehive/netui/test/pageflow/ test/src/junitTests/org/...

Added: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/LoginTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/LoginTest.java?rev=291814&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/LoginTest.java (added)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/LoginTest.java Mon Sep 26 21:02:25 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.test.pageflow.login;
+
+import junit.framework.TestSuite;
+import junit.framework.Test;
+import org.apache.beehive.netui.test.pageflow.MockPageFlowTestCase;
+import org.apache.beehive.netui.test.util.config.TestXmlInputStreamResolver;
+import org.apache.beehive.netui.util.xml.XmlInputStreamResolver;
+
+/**
+ * Tests of swapping in a LoginHandler and accessing it through base class methods on FlowController.
+ */
+public class LoginTest
+        extends MockPageFlowTestCase
+{
+    /**
+     * Test successful login.
+     */
+    public void testLoginSuccess()
+    {
+        addUpdateExpression("actionForm.username", "goodusername");
+        addUpdateExpression("actionForm.password", "goodpassword");
+        runAction("login");
+        verifyForward("success");
+        verifyActionOutput("userPrincipal", new TestLoginHandler.UserPrincipal());
+        verifyActionOutput("isUserInGoodrole", Boolean.TRUE);
+        verifyActionOutput("isUserInBadrole", Boolean.FALSE);
+    }
+
+    /**
+     * Test unsuccessful login.
+     */
+    public void testLoginFailure()
+    {
+        addUpdateExpression("actionForm.username", "badusername");
+        addUpdateExpression("actionForm.password", "badpassword");
+        runAction("login");
+        verifyForwardPath("failure.doesnotexist");
+    }
+
+    /**
+     * Test logout.
+     */
+    public void testLogout()
+    {
+        runAction("logout");
+        verifyForward("success");
+        verifyActionOutput("userPrincipal", null);
+        verifyActionOutput("isUserInGoodrole", Boolean.FALSE);
+    }
+
+    protected XmlInputStreamResolver getOverrideConfigResolver() {
+        return new TestXmlInputStreamResolver("org/apache/beehive/netui/test/pageflow/login/test-beehive-netui-config.xml");
+    }
+
+    public LoginTest(String name)
+    {
+        super(name);
+    }
+
+    protected String getPageFlowClassName()
+    {
+        return LoginController.class.getName();
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite(LoginTest.class);
+    }
+}

Propchange: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/LoginTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/TestLoginHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/TestLoginHandler.java?rev=291814&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/TestLoginHandler.java (added)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/TestLoginHandler.java Mon Sep 26 21:02:25 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.test.pageflow.login;
+
+import org.apache.beehive.netui.pageflow.handler.BaseHandler;
+import org.apache.beehive.netui.pageflow.handler.LoginHandler;
+import org.apache.beehive.netui.pageflow.handler.FlowControllerHandlerContext;
+
+import javax.security.auth.login.LoginException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.security.Principal;
+
+public class TestLoginHandler extends BaseHandler implements LoginHandler
+{
+    static class UserPrincipal
+        implements Principal
+    {
+        public String getName() {
+            return "goodusername";
+        }
+
+        public boolean equals(Object obj) {
+            return obj != null && obj.getClass().getName().equals(UserPrincipal.class.getName());
+        }
+    }
+
+    public void login( FlowControllerHandlerContext context, String username, String password )
+        throws LoginException
+    {
+        if ( username.equals( "goodusername" ) && password.equals( "goodpassword" ) ) {
+            getSession( context ).setAttribute( "_principal", new UserPrincipal() );
+        }
+        else {
+            throw new LoginException( username );
+        }
+    }
+
+    public void logout( FlowControllerHandlerContext context, boolean invalidateSessions ) {
+        getSession( context ).removeAttribute( "_principal" );
+    }
+
+    public boolean isUserInRole( FlowControllerHandlerContext context, String roleName ) {
+        return getUserPrincipal(context) != null && roleName.equals("goodrole");
+    }
+
+    public Principal getUserPrincipal( FlowControllerHandlerContext context ) {
+        return ( Principal ) getSession( context ).getAttribute( "_principal" );
+    }
+
+    private static HttpSession getSession( FlowControllerHandlerContext context ) {
+        assert context.getRequest() instanceof HttpServletRequest;
+        return ( ( HttpServletRequest ) context.getRequest() ).getSession();
+    }
+}

Propchange: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/TestLoginHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/test-beehive-netui-config.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/test-beehive-netui-config.xml?rev=291814&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/test-beehive-netui-config.xml (added)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/test-beehive-netui-config.xml Mon Sep 26 21:02:25 2005
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<netui-config xmlns="http://beehive.apache.org/netui/2004/server/config">
+
+    <expression-languages>
+        <default-language>netuiel</default-language>
+        <expression-language>
+            <name>netuiel</name>
+            <factory-class>org.apache.beehive.netui.script.el.ExpressionEvaluatorImpl$NetUIELEngineFactory</factory-class>
+        </expression-language>
+    </expression-languages>
+
+    <pageflow-handlers>
+        <login-handler>
+            <handler-class>org.apache.beehive.netui.test.pageflow.login.TestLoginHandler</handler-class>
+        </login-handler>
+    </pageflow-handlers>
+
+</netui-config>

Propchange: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/login/test-beehive-netui-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native