001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Sun Seng David TAN <stan@nuxeo.com>
016 *     Antoine Taillefer
017 */
018package org.nuxeo.functionaltests.pages.forms;
019
020import java.io.IOException;
021
022import org.nuxeo.functionaltests.forms.FileWidgetElement;
023import org.nuxeo.functionaltests.forms.LayoutElement;
024import org.nuxeo.functionaltests.pages.FileDocumentBasePage;
025import org.openqa.selenium.WebDriver;
026
027/**
028 * @author Sun Seng David TAN <stan@nuxeo.com>
029 */
030public class FileCreationFormPage extends DublinCoreCreationDocumentFormPage {
031
032    public FileCreationFormPage(WebDriver driver) {
033        super(driver);
034    }
035
036    public FileDocumentBasePage createFileDocument(String title, String description, boolean uploadBlob,
037            String filePrefix, String fileSuffix, String fileContent) throws IOException {
038        titleTextInput.sendKeys(title);
039        descriptionTextInput.sendKeys(description);
040
041        if (uploadBlob) {
042            uploadBlob(filePrefix, fileSuffix, fileContent);
043        }
044
045        create();
046        return asPage(FileDocumentBasePage.class);
047    }
048
049    protected FileWidgetElement getFileWidgetElement() {
050        LayoutElement layout = new LayoutElement(driver, "document_create:nxl_file");
051        // on file document, a widget template is used => standard file
052        // widget is wrapped, hence the duplicate nxw_file id
053        return layout.getWidget("nxw_file:nxw_file_file", FileWidgetElement.class);
054    }
055
056    protected void uploadBlob(String filePrefix, String fileSuffix, String fileContent) throws IOException {
057        FileWidgetElement fileWidget = getFileWidgetElement();
058        fileWidget.uploadTestFile(filePrefix, fileSuffix, fileContent);
059    }
060
061    /**
062     * @since 7.1
063     */
064    public FileCreationFormPage createFileDocumentWithoutTitle(String filePrefix, String fileSuffix, String fileContent)
065            throws IOException {
066        uploadBlob(filePrefix, fileSuffix, fileContent);
067        create();
068        return asPage(FileCreationFormPage.class);
069    }
070
071    /**
072     * @since 7.1
073     */
074    public String getSelectedOption() {
075        FileWidgetElement fileWidget = getFileWidgetElement();
076        return fileWidget.getEditChoice();
077    }
078
079    /**
080     * @since 7.1
081     */
082    public String getSelectedFilename() {
083        FileWidgetElement fileWidget = getFileWidgetElement();
084        return fileWidget.getFilename(true);
085    }
086
087}