package org.datavaultplatform.webapp;

import org.testng.Assert;
import org.testng.annotations.Test;

import org.datavaultplatform.webapp.page.DepositPage;
import org.datavaultplatform.webapp.page.FirstRunPage;
import org.datavaultplatform.webapp.page.LoginPage;
import org.datavaultplatform.webapp.page.VaultsPage;

public class DepositFT extends BaseFT {
    @Test
    public void testDeposit() throws Exception {
        // This test currently assumes one of two things:
        // * It's the first time this user has logged-in, they have no storage or vaults defined, and so we create a local filestore and a vault called "My Vault"
        // * It's not the first time they've logged in and both of those things have happened already
        // Any other circumstance, it'll fail, e.g. they've defined a vault with a different name, or added SFTP storage etc.
        driver.get(host + "/datavault-webapp/");
        LoginPage page = new LoginPage(driver);
        page = page.typeUsername("user1")
                   .typePassword("password1");

        VaultsPage vaultsPage = null;
        try {
            vaultsPage = page.submitLogin();
        }
        catch(IllegalStateException e) {
            FirstRunPage firstRunPage = new FirstRunPage(driver);
            if (! firstRunPage.isStorageDefined() ) {
                firstRunPage = firstRunPage.clickDefineStorage()
                                           .clickAddLocalFilestore()
                                           .submitLocalFilestoreDialog()
                                           .submit();
            }
            Assert.assertTrue(firstRunPage.isStorageDefined());
            if ( !firstRunPage.isVaultDefined() ) {
                vaultsPage = firstRunPage.clickAddVault()
                                         .addSampleVault()
                                         .clickMyVaults();
            }
        }

        DepositPage depositPage = vaultsPage.clickVault("My Vault")
                                            .clickDeposit()
                                            .depositFirstLocalFile();

        depositPage.waitForStatus("Complete");
        depositPage.logout("user1");
    }
}

@@ -387,16 +387,24 @@
 tDeposit
+FirstRun
 () throw
@@ -460,41 +460,9 @@
 mes 
-one of two things:%0A        // * I
+i
 t's 
@@ -621,224 +621,87 @@
  // 
-* It's not the first time they've logged in and both of those things have happened already%0A        // Any other circumstance, it'll fail, e.g. they've defined a vault with a different name, or added SFTP storage etc.
+Any other circumstance, it'll fail, e.g. they've already created storage/vaults
 %0A   
@@ -896,96 +896,129 @@
     
-VaultsPage vaultsPage = null;%0A        try %7B%0A            vaultsPage = page.submitLogin
+FirstRunPage firstRunPage = page.submitLoginExpectingFirstRun();%0A        firstRunPage = firstRunPage.clickDefineStorage
 ()
-;
 %0A   
@@ -1022,26 +1022,24 @@
         
-%7D%0A
         
 catch(Il
@@ -1034,125 +1034,191 @@
     
-catch(IllegalStateException e) %7B%0A            FirstRunPage firstRunPage = new FirstRunPage(driver);%0A            if (! 
+                   .clickAddLocalFilestore()%0A                                   .submitLocalFilestoreDialog()%0A                                   .submit();%0A%0A        Assert.assertTrue(
 firs
@@ -1236,36 +1236,34 @@
 StorageDefined()
- ) %7B
+);
 %0A               
@@ -1255,32 +1255,33 @@
         
-        firstRun
+VaultsPage vaults
 Page = f
@@ -1301,91 +1301,188 @@
 lick
-DefineStorage()%0A                                           .clickAddLocalFilestore(
+AddVault()%0A                                 .addSampleVault()%0A                                 .clickMyVaults();%0A%0A        DepositPage depositPage = vaultsPage.clickVault(%22My Vault%22
 )%0A  
@@ -1526,35 +1526,22 @@
     
-.submitLocalFilestoreDialog
+ .clickDeposit
 ()%0A 
@@ -1586,27 +1586,44 @@
     
-.submit
+ .depositFirstLocalFile
 ();%0A
+%0A
         
     
@@ -1622,187 +1622,364 @@
     
+depositPage.waitForStatus(%22Complete%22);%0A
     
-%7D%0A
     
+depositPage.logout(%22user1%22);%0A
     
+%7D%0A%0A
     
-Assert.assertTrue(firstRunPage.isStorageDefined());%0A            if ( !firstRunPage.isVaultDefined() ) %7B%0A                vaultsPage = firstRunPage.clickAdd
+@Test(dependsOnMethods=%7B%22testDepositFirstRun%22%7D, alwaysRun=true)%0A    public void testDeposit() throws Exception %7B%0A        // This test currently assumes it's not the first time this user has logged in and they have created a local filestore and a vault called %22My 
 Vault
-()
+%22
 %0A   
@@ -1987,126 +1987,321 @@
     
-                                 .addSampleVault()%0A                                         .clickMyVaults(
+// Any other circumstance, it'll fail, e.g. they've defined a vault with a different name, or added SFTP storage etc.%0A        driver.get(host + %22/datavault-webapp/%22);%0A        LoginPage page = new LoginPage(driver);%0A        page = page.typeUsername(%22user1%22)%0A                   .typePassword(%22password1%22
 );%0A
+%0A
         
     
@@ -2300,24 +2300,51 @@
     
-    %7D%0A        %7D%0A
+VaultsPage vaultsPage = page.submitLogin();
 %0A   

Split out first-run test