/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.adullact.iparapheur.it;

/**
 *
 * @author vbarousse
 */
public class AdministrationTest extends ParapheurIntegrationTestCase {

    public void testChangePassword() {
        selenium.open(CONTEXT_PATH + "/faces/jsp/parapheur/login.jsp");
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Console d'administration");
        selenium.waitForPageToLoad("30000");
        selenium.click("_idJsp6");
        selenium.waitForPageToLoad("30000");
        selenium.click("users:_idJsp11");
        selenium.waitForPageToLoad("30000");
        selenium.click("//img[@alt='Changer le mot de passe']");
        selenium.waitForPageToLoad("30000");
        selenium.type("edit-pass:password", "password");
        selenium.type("edit-pass:confirm", "password");
        selenium.click("edit-pass:ok-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
        selenium.type("loginForm:user-name", "SampleUser");
        selenium.type("loginForm:user-password", "password");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Console d'administration");
        selenium.waitForPageToLoad("30000");
        selenium.click("_idJsp6");
        selenium.waitForPageToLoad("30000");
        selenium.click("users:_idJsp11");
        selenium.waitForPageToLoad("30000");
        selenium.click("//img[@alt='Changer le mot de passe']");
        selenium.waitForPageToLoad("30000");
        selenium.type("edit-pass:password", "secret");
        selenium.type("edit-pass:confirm", "secret");
        selenium.click("edit-pass:ok-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
        selenium.type("loginForm:user-name", "SampleUser");
        selenium.type("loginForm:user-password", "secret");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
    }

    public void testDeleteUser() {
        selenium.open(CONTEXT_PATH + "/faces/jsp/parapheur/parapheur.jsp");
        String loginPageTitle = selenium.getTitle();
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Console d'administration");
        selenium.waitForPageToLoad("30000");
        selenium.click("_idJsp6");
        selenium.waitForPageToLoad("30000");
        selenium.click("_idJsp6");
        selenium.waitForPageToLoad("30000");
        selenium.type("person-props:firstName", "UserToDelete");
        selenium.type("person-props:lastName", "UserToDelete");
        selenium.type("person-props:email", "user.to.delete@example.com");
        selenium.click("person-props:next-button");
        selenium.waitForPageToLoad("30000");
        selenium.type("user-props:userName", "UserToDelete");
        selenium.type("user-props:password", "secret");
        selenium.type("user-props:confirm", "secret");
        selenium.click("user-props:next-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("person-props:_idJsp16");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
        selenium.type("loginForm:user-name", "UserToDelete");
        selenium.type("loginForm:user-password", "secret");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Console d'administration");
        selenium.waitForPageToLoad("30000");
        selenium.click("_idJsp6");
        selenium.waitForPageToLoad("30000");
        selenium.click("users:_idJsp11");
        selenium.waitForPageToLoad("30000");
        selenium.click("//td[text()=\"UserToDelete\"]/../..//img[@alt='Supprimer']");
        selenium.waitForPageToLoad("30000");
        selenium.click("delete-user:_idJsp14");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
        selenium.type("loginForm:user-name", "UserToDelete");
        selenium.type("loginForm:user-password", "secret");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        assertEquals(loginPageTitle, selenium.getTitle());
    }

    public void testDeleteDossier() {
        selenium.open(CONTEXT_PATH + "/faces/jsp/parapheur/login.jsp");
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Constituer un nouveau dossier");
        selenium.waitForPageToLoad("30000");
        selenium.type("infos:name", "test-delete-dossier");
        selenium.fireEvent("infos:name", "keyup");
        selenium.click("infos:next-button-infos");
        selenium.waitForPageToLoad("30000");
        selenium.type("alfFileInput", getTempFile().getAbsolutePath());
        selenium.click("//input[@value='Valider']");
        selenium.waitForPageToLoad("30000");
        selenium.click("add-content-upload-end:next-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("ajout_circuit:select_soustypesmetier-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("ajout_circuit:next-button-circuit");
        selenium.waitForPageToLoad("30000");
        selenium.click("person-props:_idJsp23");
        selenium.waitForPageToLoad("30000");
        selenium.open(CONTEXT_PATH + "/faces/jsp/parapheur/parapheurs.jsp");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Console d'administration");
        selenium.waitForPageToLoad("30000");
        selenium.click("_idJsp9");
        selenium.waitForPageToLoad("30000");
        assertTrue(selenium.isTextPresent("test-delete-dossier"));
        selenium.click("//span[text()=\"test-delete-dossier\"]/../..//img[@alt=\"Supprimer le dossier\"]");
        selenium.waitForPageToLoad("30000");
        selenium.click("delete-dossier:_idJsp11");
        selenium.waitForPageToLoad("30000");
        assertFalse(selenium.isTextPresent("test-delete-dossier"));
    }

    public void testFollowDossier() {
        selenium.open(CONTEXT_PATH + "/faces/jsp/parapheur/parapheurs.jsp");
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Constituer un nouveau dossier");
        selenium.waitForPageToLoad("30000");
        selenium.type("infos:name", "test-follow-dossier");
        selenium.fireEvent("infos:name", "keyup");
        selenium.click("infos:next-button-infos");
        selenium.waitForPageToLoad("30000");
        selenium.type("alfFileInput", getTempFile().getAbsolutePath());
        selenium.click("//input[@value='Valider']");
        selenium.waitForPageToLoad("30000");
        selenium.click("add-content-upload-end:next-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("ajout_circuit:select_soustypesmetier-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("ajout_circuit:next-button-circuit");
        selenium.waitForPageToLoad("30000");
        selenium.click("person-props:_idJsp23");
        selenium.waitForPageToLoad("30000");
        selenium.open(CONTEXT_PATH + "/faces/jsp/parapheur/parapheurs.jsp");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Console d'administration");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Gérer les dossiers");
        selenium.waitForPageToLoad("30000");
        assertTrue(selenium.isTextPresent("test-follow-dossier"));
        selenium.click("//span[text()=\"test-follow-dossier\"]/../..//img[@alt=\"Transférer le dossier\"]");
        selenium.waitForPageToLoad("30000");
        selenium.click("dialog:finish-button");
        selenium.waitForPageToLoad("30000");
        selenium.click("logout");
        selenium.waitForPageToLoad("30000");
        selenium.type("loginForm:user-name", "SampleUser");
        selenium.type("loginForm:user-password", "secret");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Dossiers à transmettre");
        selenium.waitForPageToLoad("30000");
        assertTrue(selenium.isTextPresent("test-follow-dossier"));
    }

    public void testConfigurationActes() {
        selenium.open("/parapheur/faces/jsp/parapheur/login.jsp");
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.open("/parapheur/wcs/parapheur/s2low/actes");
        selenium.waitForPageToLoad("30000");
        selenium.type("//input[@name='certificat']", this.getTempFile().getAbsolutePath());
        selenium.type("//input[@name='password']", "password");
        selenium.type("//input[@name='server']", "server");
        selenium.type("//input[@name='port']", "1234");
        selenium.type("//input[@name='baseUrlArchivage']", "http://server:1234/");
        selenium.click("//input[@value='Enregistrer']");
        selenium.waitForPageToLoad("30000");
        assertEquals("password", selenium.getValue("//input[@name='password']"));
        assertEquals("server", selenium.getValue("//input[@name='server']"));
        assertEquals("1234", selenium.getValue("//input[@name='port']"));
        assertEquals("http://server:1234/", selenium.getValue("//input[@name='baseUrlArchivage']"));
    }

    public void testConfigurationHelios() {
        selenium.open("/parapheur/faces/jsp/parapheur/login.jsp");
        selenium.type("loginForm:user-name", "admin");
        selenium.type("loginForm:user-password", "admin");
        selenium.click("loginForm:submit");
        selenium.waitForPageToLoad("30000");
        selenium.open("/parapheur/wcs/parapheur/s2low/helios");
        selenium.waitForPageToLoad("30000");
        selenium.type("//input[@name='certificat']", this.getTempFile().getAbsolutePath());
        selenium.type("//input[@name='password']", "password");
        selenium.type("//input[@name='server']", "server");
        selenium.type("//input[@name='port']", "1234");
        selenium.type("//input[@name='collectivite']", "54321");
        selenium.select("//select[@name='parapheur']", "ParapheurAdmin");
        selenium.type("//input[@name='pPolicyIdentifierID']", "pid");
        selenium.type("//input[@name='pPolicyIdentifierDescription']", "pdesc");
        selenium.type("//input[@name='pPolicyDigest']", "pdigest");
        selenium.type("//input[@name='pSPURI']", "spuri");
        selenium.type("//input[@name='pClaimedRole']", "role");
        selenium.type("//input[@name='pCity']", "ville");
        selenium.type("//input[@name='pPostalCode']", "6789");
        selenium.type("//input[@name='pCountryName']", "pays");
        selenium.click("//input[@value='Enregistrer']");
        selenium.waitForPageToLoad("30000");
        assertEquals("password", selenium.getValue("//input[@name='password']"));
        assertEquals("server", selenium.getValue("//input[@name='server']"));
        assertEquals("1234", selenium.getValue("//input[@name='port']"));
        assertEquals("54321", selenium.getValue("//input[@name='collectivite']"));
        assertEquals("ParapheurAdmin", selenium.getValue("//select[@name='parapheur']"));
        assertEquals("pid", selenium.getValue("//input[@name='pPolicyIdentifierID']"));
        assertEquals("pdesc", selenium.getValue("//input[@name='pPolicyIdentifierDescription']"));
        assertEquals("pdigest", selenium.getValue("//input[@name='pPolicyDigest']"));
        assertEquals("spuri", selenium.getValue("//input[@name='pSPURI']"));
        assertEquals("role", selenium.getValue("//input[@name='pClaimedRole']"));
        assertEquals("ville", selenium.getValue("//input[@name='pCity']"));
        assertEquals("6789", selenium.getValue("//input[@name='pPostalCode']"));
        assertEquals("pays", selenium.getValue("//input[@name='pCountryName']"));
    }

}
