archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1296210 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent: AbstractArchivaTest.java AbstractSeleniumTest.java
Date Fri, 02 Mar 2012 14:03:41 GMT
Author: olamy
Date: Fri Mar  2 14:03:41 2012
New Revision: 1296210

URL: http://svn.apache.org/viewvc?rev=1296210&view=rev
Log:
more cleanup on it js

Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java?rev=1296210&r1=1296209&r2=1296210&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
Fri Mar  2 14:03:41 2012
@@ -1,8 +1,6 @@
 package org.apache.archiva.web.test.parent;
 
 import org.apache.archiva.web.test.tools.ArchivaSeleniumRunner;
-import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 
@@ -36,13 +34,6 @@ public abstract class AbstractArchivaTes
 
     protected String fullname;
 
-    @Override
-    @After
-    public void close()
-        throws Exception
-    {
-        super.close();
-    }
 
     @Override
     @Before
@@ -53,49 +44,6 @@ public abstract class AbstractArchivaTes
         assertAdminCreated();
     }
 
-    public void assertAdminCreated()
-        throws Exception
-    {
-        initializeArchiva( System.getProperty( "baseUrl" ), System.getProperty( "browser"
),
-                           Integer.getInteger( "maxWaitTimeInMs" ), System.getProperty( "seleniumHost",
"localhost" ),
-                           Integer.getInteger( "seleniumPort", 4444 ) );
-    }
-
-    public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs, String
seleniumHost,
-                                   int seleniumPort )
-        throws Exception
-    {
-
-        super.open( baseUrl, browser, seleniumHost, seleniumPort, Integer.toString( maxWaitTimeInMs
) );
-
-        getSelenium().open( baseUrl );
-
-        waitPage();
-
-        // if not admin user created create one
-        if ( isElementVisible( "create-admin-link" ) )
-        {
-            Assert.assertFalse( getSelenium().isVisible( "login-link-a" ) );
-            Assert.assertFalse( getSelenium().isVisible( "register-link-a" ) );
-            clickLinkWithLocator( "create-admin-link-a", false );
-            assertCreateAdmin();
-            String fullname = getProperty( "ADMIN_FULLNAME" );
-            String username = getAdminUsername();
-            String mail = getProperty( "ADMIN_EMAIL" );
-            String password = getProperty( "ADMIN_PASSWORD" );
-            submitAdminData( fullname, mail, password );
-            assertUserLoggedIn( username );
-            clickLinkWithLocator( "logout-link-a" );
-        }
-        else
-        {
-            Assert.assertTrue( getSelenium().isVisible( "login-link-a" ) );
-            Assert.assertTrue( getSelenium().isVisible( "register-link-a" ) );
-            login( getAdminUsername(), getAdminPassword() );
-        }
-
-    }
-
     protected static String getErrorMessageText()
     {
         return getSelenium().getText( "//ul[@class='errorMessage']/li/span" );
@@ -131,56 +79,6 @@ public abstract class AbstractArchivaTes
         return basedir;
     }
 
-    public String getAdminUsername()
-    {
-        String adminUsername = getProperty( "ADMIN_USERNAME" );
-        return adminUsername;
-    }
-
-    public String getAdminPassword()
-    {
-        String adminPassword = getProperty( "ADMIN_PASSWORD" );
-        return adminPassword;
-    }
-
-    public void assertCreateAdmin()
-    {
-        assertElementPresent( "user-create" );
-        assertFieldValue( "admin", "username" );
-        assertElementPresent( "fullname" );
-        assertElementPresent( "password" );
-        assertElementPresent( "confirmPassword" );
-        assertElementPresent( "email" );
-    }
-
-    public void submitAdminData( String fullname, String email, String password )
-    {
-        setFieldValue( "fullname", fullname );
-        setFieldValue( "email", email );
-        setFieldValue( "password", password );
-        setFieldValue( "confirmPassword", password );
-        clickButtonWithLocator( "user-create-form-register-button" );
-        //submit();
-    }
-
-    // Go to Login Page
-    public void goToLoginPage()
-    {
-        getSelenium().open( baseUrl );
-        waitPage();
-        // are we already logged in ?
-        if ( isElementVisible( "logout-link" ) ) //isElementPresent( "logoutLink" ) )
-        {
-            // so logout
-            clickLinkWithLocator( "logout-link-a", false );
-            clickLinkWithLocator( "login-link-a" );
-        }
-        else if ( isElementVisible( "login-link-a" ) )
-        {
-            clickLinkWithLocator( "login-link-a" );
-        }
-        assertLoginModal();
-    }
 
     public void submitUserData( String username, String password, boolean rememberme, boolean
success )
     {
@@ -203,15 +101,6 @@ public abstract class AbstractArchivaTes
         }
     }
 
-    public void assertLoginModal()
-    {
-        assertElementPresent( "user-login-form" );
-        Assert.assertTrue( isElementVisible( "register-link" ) );
-        assertElementPresent( "user-login-form-username" );
-        assertElementPresent( "user-login-form-password" );
-        assertButtonWithIdPresent( "modal-login-ok" );
-    }
-
     // User Management
     public void goToUserManagementPage()
     {
@@ -339,74 +228,6 @@ public abstract class AbstractArchivaTes
 
     }
 
-    public void login( String username, String password )
-    {
-        login( username, password, true, "Login Page" );
-    }
-
-    public void login( String username, String password, boolean valid, String assertReturnPage
)
-    {
-        if ( isElementVisible( "login-link-a" ) )//isElementPresent( "loginLink" ) )
-        {
-            goToLoginPage();
-
-            submitLoginPage( username, password, false, valid, assertReturnPage );
-        }
-        if ( valid )
-        {
-            assertUserLoggedIn( username );
-        }
-    }
-
-    public void submitLoginPage( String username, String password )
-    {
-        submitLoginPage( username, password, false, true, "Login Page" );
-    }
-
-    public void submitLoginPage( String username, String password, boolean validUsernamePassword
)
-    {
-        submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
-    }
-
-    public void submitLoginPage( String username, String password, boolean rememberMe, boolean
validUsernamePassword,
-                                 String assertReturnPage )
-    {
-        clickLinkWithLocator( "login-link-a", false );
-        setFieldValue( "user-login-form-username", username );
-        setFieldValue( "user-login-form-password", password );
-        /*
-        if ( rememberMe )
-        {
-            checkField( "rememberMe" );
-        }*/
-
-        clickButtonWithLocator( "modal-login-ok" );
-        if ( validUsernamePassword )
-        {
-            assertUserLoggedIn( username );
-        }
-        /*
-        else
-        {
-            if ( "Login Page".equals( assertReturnPage ) )
-            {
-                assertLoginPage();
-            }
-            else
-            {
-                assertPage( assertReturnPage );
-            }
-        }*/
-    }
-
-    protected void assertUserLoggedIn( String username )
-    {
-        Assert.assertFalse( isElementVisible( "login-link" ) );
-        Assert.assertTrue( isElementVisible( "logout-link" ) );
-        Assert.assertFalse( isElementVisible( "register-link" ) );
-        Assert.assertFalse( isElementVisible( "create-admin-link" ) );
-    }
-
     // User Roles
     public void assertUserRoleCheckBoxPresent( String value )
     {

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java?rev=1296210&r1=1296209&r2=1296210&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
Fri Mar  2 14:03:41 2012
@@ -22,14 +22,11 @@ package org.apache.archiva.web.test.pare
 import com.thoughtworks.selenium.DefaultSelenium;
 import com.thoughtworks.selenium.Selenium;
 import org.apache.archiva.web.test.tools.AfterSeleniumFailure;
-import org.apache.commons.io.IOUtils;
+import org.junit.After;
 import org.junit.Assert;
 
 import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.Iterator;
@@ -52,9 +49,7 @@ public abstract class AbstractSeleniumTe
 
     private static ThreadLocal<Selenium> selenium = new ThreadLocal<Selenium>();
 
-    public static Properties p;
-
-    private final static String PROPERTIES_SEPARATOR = "=";
+    public Properties p;
 
     public void open()
         throws Exception
@@ -63,6 +58,21 @@ public abstract class AbstractSeleniumTe
         p.load( this.getClass().getClassLoader().getResourceAsStream( "test.properties" )
);
     }
 
+
+    /**
+     * Close selenium session.
+     */
+    @After
+    public void close()
+        throws Exception
+    {
+        if ( getSelenium() != null )
+        {
+            getSelenium().stop();
+            selenium.set( null );
+        }
+    }
+
     /**
      * Initialize selenium
      */
@@ -91,6 +101,49 @@ public abstract class AbstractSeleniumTe
         }
     }
 
+    public void assertAdminCreated()
+        throws Exception
+    {
+        initializeArchiva( System.getProperty( "baseUrl" ), System.getProperty( "browser"
),
+                           Integer.getInteger( "maxWaitTimeInMs" ), System.getProperty( "seleniumHost",
"localhost" ),
+                           Integer.getInteger( "seleniumPort", 4444 ) );
+    }
+
+    public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs, String
seleniumHost,
+                                   int seleniumPort )
+        throws Exception
+    {
+
+        open( baseUrl, browser, seleniumHost, seleniumPort, Integer.toString( maxWaitTimeInMs
) );
+
+        getSelenium().open( baseUrl );
+
+        waitPage();
+
+        // if not admin user created create one
+        if ( isElementVisible( "create-admin-link" ) )
+        {
+            Assert.assertFalse( getSelenium().isVisible( "login-link-a" ) );
+            Assert.assertFalse( getSelenium().isVisible( "register-link-a" ) );
+            clickLinkWithLocator( "create-admin-link-a", false );
+            assertCreateAdmin();
+            String fullname = getProperty( "ADMIN_FULLNAME" );
+            String username = getAdminUsername();
+            String mail = getProperty( "ADMIN_EMAIL" );
+            String password = getProperty( "ADMIN_PASSWORD" );
+            submitAdminData( fullname, mail, password );
+            assertUserLoggedIn( username );
+            clickLinkWithLocator( "logout-link-a" );
+        }
+        else
+        {
+            Assert.assertTrue( getSelenium().isVisible( "login-link-a" ) );
+            Assert.assertTrue( getSelenium().isVisible( "register-link-a" ) );
+            login( getAdminUsername(), getAdminPassword() );
+        }
+
+    }
+
     public static Selenium getSelenium()
     {
         return selenium == null ? null : selenium.get();
@@ -101,48 +154,139 @@ public abstract class AbstractSeleniumTe
         return p.getProperty( key );
     }
 
-    protected String getEscapeProperty( String key )
+    public String getAdminUsername()
     {
-        InputStream input = this.getClass().getClassLoader().getResourceAsStream( "test.properties"
);
-        String value = null;
-        List<String> lines;
-        try
+        String adminUsername = getProperty( "ADMIN_USERNAME" );
+        return adminUsername;
+    }
+
+    public String getAdminPassword()
+    {
+        String adminPassword = getProperty( "ADMIN_PASSWORD" );
+        return adminPassword;
+    }
+
+    public void submitAdminData( String fullname, String email, String password )
+    {
+        setFieldValue( "fullname", fullname );
+        setFieldValue( "email", email );
+        setFieldValue( "password", password );
+        setFieldValue( "confirmPassword", password );
+        clickButtonWithLocator( "user-create-form-register-button" );
+    }
+
+    public void login( String username, String password )
+    {
+        login( username, password, true, "Login Page" );
+    }
+
+    public void login( String username, String password, boolean valid, String assertReturnPage
)
+    {
+        if ( isElementVisible( "login-link-a" ) )//isElementPresent( "loginLink" ) )
         {
-            lines = IOUtils.readLines( input );
+            goToLoginPage();
+
+            submitLoginPage( username, password, false, valid, assertReturnPage );
         }
-        catch ( IOException e )
+        if ( valid )
         {
-            lines = new ArrayList<String>();
+            assertUserLoggedIn( username );
         }
-        for ( String l : lines )
+    }
+
+    // Go to Login Page
+    public void goToLoginPage()
+    {
+        getSelenium().open( baseUrl );
+        waitPage();
+        // are we already logged in ?
+        if ( isElementVisible( "logout-link" ) ) //isElementPresent( "logoutLink" ) )
         {
-            if ( l != null && l.startsWith( key ) )
-            {
-                int indexSeparator = l.indexOf( PROPERTIES_SEPARATOR );
-                value = l.substring( indexSeparator + 1 ).trim();
-                break;
-            }
+            // so logout
+            clickLinkWithLocator( "logout-link-a", false );
+            clickLinkWithLocator( "login-link-a" );
         }
-        return value;
+        else if ( isElementVisible( "login-link-a" ) )
+        {
+            clickLinkWithLocator( "login-link-a" );
+        }
+        assertLoginModal();
     }
 
-    /**
-     * Close selenium session.
-     */
-    public void close()
-        throws Exception
+
+    public void assertLoginModal()
     {
-        if ( getSelenium() != null )
+        assertElementPresent( "user-login-form" );
+        Assert.assertTrue( isElementVisible( "register-link" ) );
+        assertElementPresent( "user-login-form-username" );
+        assertElementPresent( "user-login-form-password" );
+        assertButtonWithIdPresent( "modal-login-ok" );
+    }
+
+
+    public void submitLoginPage( String username, String password )
+    {
+        submitLoginPage( username, password, false, true, "Login Page" );
+    }
+
+    public void submitLoginPage( String username, String password, boolean validUsernamePassword
)
+    {
+        submitLoginPage( username, password, false, validUsernamePassword, "Login Page" );
+    }
+
+    public void submitLoginPage( String username, String password, boolean rememberMe, boolean
validUsernamePassword,
+                                 String assertReturnPage )
+    {
+        clickLinkWithLocator( "login-link-a", false );
+        setFieldValue( "user-login-form-username", username );
+        setFieldValue( "user-login-form-password", password );
+        /*
+        if ( rememberMe )
         {
-            getSelenium().stop();
-            selenium.set( null );
+            checkField( "rememberMe" );
+        }*/
+
+        clickButtonWithLocator( "modal-login-ok" );
+        if ( validUsernamePassword )
+        {
+            assertUserLoggedIn( username );
         }
+        /*
+        else
+        {
+            if ( "Login Page".equals( assertReturnPage ) )
+            {
+                assertLoginPage();
+            }
+            else
+            {
+                assertPage( assertReturnPage );
+            }
+        }*/
     }
 
     // *******************************************************
     // Auxiliar methods. This method help us and simplify test.
     // *******************************************************
 
+    protected void assertUserLoggedIn( String username )
+    {
+        Assert.assertFalse( isElementVisible( "login-link" ) );
+        Assert.assertTrue( isElementVisible( "logout-link" ) );
+        Assert.assertFalse( isElementVisible( "register-link" ) );
+        Assert.assertFalse( isElementVisible( "create-admin-link" ) );
+    }
+
+    public void assertCreateAdmin()
+    {
+        assertElementPresent( "user-create" );
+        assertFieldValue( "admin", "username" );
+        assertElementPresent( "fullname" );
+        assertElementPresent( "password" );
+        assertElementPresent( "confirmPassword" );
+        assertElementPresent( "email" );
+    }
+
     public void assertFieldValue( String fieldValue, String fieldName )
     {
         assertElementPresent( fieldName );



Mime
View raw message