package com.autonomy.abc.topnavbar.login;

import com.autonomy.abc.config.ABCTestBase;
import com.autonomy.abc.config.TestConfig;
import com.autonomy.abc.selenium.config.ApplicationType;
import org.junit.Test;
import org.openqa.selenium.Platform;

/*
 * TODO Possibly make sure a gritter with 'Signed in' comes up, correct colour circle etc. May be difficult to do considering it occurs during tryLogIn()
 */
public class LoginPageHostedITCase extends ABCTestBase {

    public LoginPageHostedITCase(TestConfig config, String browser, ApplicationType type, Platform platform) {
        super(config, browser, type, platform);
    }

    @Override
    public void baseSetUp(){
        regularSetUp();
    }

    private void setLoginType(String type){
        System.setProperty("com.autonomy.loginType", type);
    }

    private void setUsernameAndPassword(String username,String password){
        System.setProperty("com.autonomy.username",username);
        System.setProperty("com.autonomy.password",password);
    }

    @Test
    public void testAPIKeyLogin(){
        String apiKey = "";
        setLoginType("apikey");
        System.setProperty("com.autonomy.apikey", apiKey);
        tryLogIn();
    }

    @Test
    public void testGoogleLogin(){
        setLoginType("google");
        setUsernameAndPassword("", "");
        tryLogIn();
    }

    @Test
    public void testTwitterLogin(){
        setLoginType("twitter");
        setUsernameAndPassword("hodtesting", "5cUdPhYM");
        tryLogIn();
    }

    @Test
    public void testFacebookLogin(){
        setLoginType("facebook");
        setUsernameAndPassword("matthew.williamson@hpe.com", "vdPAuTGU");
        tryLogIn();
    }

    @Test
    public void testYahooLogin(){
        setLoginType("yahoo");
        setUsernameAndPassword("", "");
        tryLogIn();
    }

    @Test
    public void testOpenIDLogin(){
        String url = "";
        setLoginType("openid");
        System.setProperty("com.autonomy.url", url);
        tryLogIn();
    }

    @Test
    public void testHPPassportLogin(){
        setLoginType("passport");
        setUsernameAndPassword("", "");
        tryLogIn();
    }
}

@@ -704,324 +704,8 @@
  %7D%0A%0A
-    private void setLoginType(String type)%7B%0A        System.setProperty(%22com.autonomy.loginType%22, type);%0A    %7D%0A%0A    private void setUsernameAndPassword(String username,String password)%7B%0A        System.setProperty(%22com.autonomy.username%22,username);%0A        System.setProperty(%22com.autonomy.password%22,password);%0A    %7D%0A%0A
     
@@ -756,140 +756,30 @@
     
- String apiKey = %22%22;%0A        se
+tes
 tLogin
-Type
 (%22api
+_
 key%22);%0A
-        System.setProperty(%22com.autonomy.apikey%22, apiKey);%0A        tryLogIn();%0A
     
@@ -834,28 +834,25 @@
         
+te
 s
-e
 tLogin
-Type
 (%22google
@@ -859,68 +859,8 @@
 %22);%0A
-        setUsernameAndPassword(%22%22, %22%22);%0A        tryLogIn();%0A
     
@@ -916,28 +916,25 @@
         
+te
 s
-e
 tLogin
-Type
 (%22twitte
@@ -942,86 +942,8 @@
 %22);%0A
-        setUsernameAndPassword(%22hodtesting%22, %225cUdPhYM%22);%0A        tryLogIn();%0A
     
@@ -1000,28 +1000,25 @@
         
+te
 s
-e
 tLogin
-Type
 (%22facebo
@@ -1027,102 +1027,8 @@
 %22);%0A
-        setUsernameAndPassword(%22matthew.williamson@hpe.com%22, %22vdPAuTGU%22);%0A        tryLogIn();%0A
     
@@ -1082,28 +1082,25 @@
         
+te
 s
-e
 tLogin
-Type
 (%22yahoo%22
@@ -1110,43 +1110,55 @@
     
+%7D%0A%0A
     
-setUsernameAndPassword(%22%22, %22%22);
+@Test%0A    public void testOpenIDLogin()%7B
 %0A   
@@ -1159,32 +1159,42 @@
 )%7B%0A        t
-ryLogI
+estLogi
 n(
+%22open_id%22
 );%0A    %7D%0A%0A  
@@ -1213,38 +1213,42 @@
 public void test
-OpenID
+HPPassport
 Login()%7B%0A       
@@ -1252,61 +1252,38 @@
     
-String url = %22%22;%0A        setLoginType(%22openid
+testLogin(%22hp_passport
 %22);%0A    
     
@@ -1282,56 +1282,55 @@
     
+%7D%0A%0A
     
-System.setProperty(%22com.autonomy.url%22, url);
+private void testLogin(String account) %7B
 %0A   
@@ -1341,166 +1341,173 @@
  try
-LogIn();
+ %7B
 %0A    
-%7D%0A%0A
     
-@Test%0A    public void testHPPassportLogin()%7B%0A        setLoginType(%22passport%22);%0A        setUsernameAndPassw
+    loginAs(config.getUser(account));%0A        %7D catch (Exception e) %7B%0A            throw new AssertionErr
 or
-d
 (%22
-%22, %22%22);%0A        tryLogIn();
+unable to log in as %22 + account, e);%0A        %7D
 %0A   

Fix tests for login page to read from config (works in theory, but config/accounts are not properly set up)