<commit_before>/**
 * Copyright 2005-2014 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.rice.krad.labs.maintenance;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
import org.openqa.selenium.By;

/**
 * @author <NAME> (<EMAIL>)
 */
public class LabsMaintenanceBOAttachmentAft extends LabsMaintenanceBase {

    /**
     * /kr-krad/kradsampleapp?viewId=KradMaintenanceSample-PageR4C2
     */
    public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=KradMaintenanceSample-PageR4C2";
    
    // values set by default for repeatable testing; left as configurable for load tests
    protected List<File> fileUploadList;

    @Override
    protected String getBookmarkUrl() {
        return BOOKMARK_URL;
    }

    @Override
    public String getUserName() {
        return "admin"; // must have blanket approve rights
    }

    @Override
    protected void navigate() throws Exception {
    	navigateToMaintenance("Maintenance Sample - BO Attachment");
    }

    protected void testMaintenanceBOAttachment() throws Exception {
    	waitAndClickByLinkText("Sample BO Attachment");
    	waitAndTypeByName("document.documentHeader.documentDescription","Test fo BO Attachment");
    	String random = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits();
    	waitAndTypeByName("document.newMaintainableObject.dataObject.id",random);
    	waitAndTypeByName("document.newMaintainableObject.dataObject.travelAttachmentGroupNumber","123");
    	fileUploadSetUp();
    	fileIngester();
    	waitAndClickSubmitByText();
		waitAndClickConfirmationOk();
    	waitForElementPresentByXpath("//button[contains(text(),'download attachment')]");
    }
    
    protected void testMaintenanceBOAttachmentCollection() throws Exception {
    	waitAndClickByLinkText("Sample BO Attachment Collection");
    	waitAndTypeByName("document.documentHeader.documentDescription","Test fo BO Attachment");
    	fileUploadSetUp();
        if(fileUploadList!=null && fileUploadList.size()>0) {
            for (File file : fileUploadList) {
                String random = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits();
                waitAndTypeByXpath("//div[@data-label='ID']/input",random);
                String path = file.getAbsolutePath().toString();
                driver.findElement(By.xpath("//div[@data-label='Attached File']/fieldset/div/div/input[@type='file']")).sendKeys(path);
                System.out.println("In for " + path);
                waitAndClickButtonByExactText("Add");
                waitForTextPresent("Adding Line...");
            }
        }
        waitForElementPresentByXpath("//button[contains(text(),'download attachment')]");
    	waitAndClickBlanketApprove();
        waitAndClickConfirmationOk();
    }
    
    private void fileUploadSetUp() throws Exception {
    	setUpResourceDir("general");
    }

    @Test
    public void testMaintenanceBOAttachmentBookmark() throws Exception {
    	testMaintenanceBOAttachment();
        passed();
    }

    @Test
    public void testMaintenanceBOAttachmentNav() throws Exception {
    	testMaintenanceBOAttachment();
        passed();
    }
    
    @Test
    public void testMaintenanceBOAttachmentCollectionBookmark() throws Exception {
    	testMaintenanceBOAttachmentCollection();
        passed();
    }

    @Test
    public void testMaintenanceBOAttachmentCollectionNav() throws Exception {
    	testMaintenanceBOAttachmentCollection();
        passed();
    }
    
    protected void setUpResourceDir(String resourceDir) {
        try {
            setUpFiles("rice-framework/krad-sampleapp/web/src/test/resources/" + resourceDir);
            System.out.println("Try for setUpResourceDir");
        } catch (Exception e) {
            System.out.println("Problem loading files from filesystem ( " + e.getMessage() + "). If running from Intellij make sure working directory is rice-framework/krad-sampleapp/web attempt to load as resource.");
            try {
                setUpResourceFiles(resourceDir);
            } catch (Exception e1) {
                e1.printStackTrace();
                jiraAwareFail("Problems loading files as resources " + e1.getMessage());<commit_msg>KULRICE-9795 - Convert the PersistableAttachment framework for KRAD<commit_after>/**
 * Copyright 2005-2014 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.rice.krad.labs.maintenance;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
import org.openqa.selenium.By;

/**
 * @author K<NAME> (<EMAIL>)
 */
public class LabsMaintenanceBOAttachmentAft extends LabsMaintenanceBase {

    /**
     * /kr-krad/kradsampleapp?viewId=KradMaintenanceSample-PageR4C2
     */
    public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=KradMaintenanceSample-PageR4C2";
    
    // values set by default for repeatable testing; left as configurable for load tests
    protected List<File> fileUploadList;

    @Override
    protected String getBookmarkUrl() {
        return BOOKMARK_URL;
    }

    @Override
    public String getUserName() {
        return "admin"; // must have blanket approve rights
    }

    @Override
    protected void navigate() throws Exception {
    	navigateToMaintenance("Maintenance Sample - BO Attachment");
    }

    protected void testMaintenanceBOAttachment() throws Exception {
    	waitAndClickByLinkText("Sample BO Attachment");
    	waitAndTypeByName("document.documentHeader.documentDescription","Test fo BO Attachment");
    	String random = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits();
    	waitAndTypeByName("document.newMaintainableObject.dataObject.id",random);
    	waitAndTypeByName("document.newMaintainableObject.dataObject.travelAttachmentGroupNumber","123");
    	fileUploadSetUp();
    	fileIngester();
    	waitAndClickSubmitByText();
		waitAndClickConfirmationOk();
    	waitForElementPresentByXpath("//button[contains(text(),'download attachment')]");
    }
    
    protected void testMaintenanceBOAttachmentCollection() throws Exception {
    	waitAndClickByLinkText("Sample BO Attachment Collection");
    	waitAndTypeByName("document.documentHeader.documentDescription","Test fo BO Attachment");
    	fileUploadSetUp();
        if(fileUploadList!=null && fileUploadList.size()>0) {
            for (File file : fileUploadList) {
                String random = AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomCharsNot9Digits();
                waitAndTypeByXpath("//div[@data-label='ID']/input",random);
                String path = file.getAbsolutePath().toString();
                driver.findElement(By.xpath("//div[@data-label='Attached File']/fieldset/div/div/input[@type='file']")).sendKeys(path);
                System.out.println("In for " + path);
                waitAndClickButtonByExactText("Add");
                waitForTextPresent("Adding Line...");
            }
        }
        waitForElementPresentByXpath("//button[contains(text(),'download attachment')]");
        waitAndClickSubmitByText();
        waitAndClickConfirmationOk();

        waitAndClickButtonByText("Reload");
        waitForProgressLoading();
        waitForTextPresent("Document was successfully reloaded.");
        assertTextPresent("FINAL");

        waitAndClickButtonByExactText("download attachment");
    }
    
    private void fileUploadSetUp() throws Exception {
    	setUpResourceDir("general");
    }

    @Test
    public void testMaintenanceBOAttachmentBookmark() throws Exception {
    	testMaintenanceBOAttachment();
        passed();
    }

    @Test
    public void testMaintenanceBOAttachmentNav() throws Exception {
    	testMaintenanceBOAttachment();
        passed();
    }
    
    @Test
    public void testMaintenanceBOAttachmentCollectionBookmark() throws Exception {
    	testMaintenanceBOAttachmentCollection();
        passed();
    }

    @Test
    public void testMaintenanceBOAttachmentCollectionNav() throws Exception {
    	testMaintenanceBOAttachmentCollection();
        passed();
    }
    
    protected void setUpResourceDir(String resourceDir) {
        try {
            setUpFiles("src/test/resources/" + resourceDir);
            System.out.println("Try for setUpResourceDir");
        } catch (Exception e) {
            System.out.println("Problem loading files from filesystem ( " + e.getMessage() + "). If running from Intellij make sure working directory is rice-framework/krad-sampleapp/web attempt to load as resource.");
            try {
                setUpResourceFiles(resourceDir);
            } catch (Exception e1) {
                e1.printStackTrace();
                jiraAwareFail("Problems loading files as resources " + e1.getMessage());
{'fraction_non_alphanumeric': 0.09858109987943986, 'fraction_numerical': 0.0048224056385050545, 'mean_word_length': 3.5196982397317687, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3409396', 'n_tokens_mistral': 2956, 'n_tokens_neox': 2901, 'n_words': 668}