Changeset 39034


Ignore:
Timestamp:
2024-05-19T20:03:07+12:00 (3 weeks ago)
Author:
anupama
Message:

Working on the 2nd tutorial

Location:
gs3-extensions/testing/trunk/src
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/testing/trunk/src/src/gstests/tutorials/RunGLITest.java

    r39033 r39034  
    6464import org.greenstone.gsdl3.testing.GSTestingUtil;
    6565import org.greenstone.gsdl3.testing.GSGUITestingUtil;
     66import org.greenstone.gsdl3.testing.GSBasicTestingUtil;
    6667
    6768// Java imports
    6869import javax.swing.*;
    6970import java.util.Properties;
    70 import java.io.InputStream;
     71import java.io.*;
     72import java.awt.event.InputEvent;
     73//import java.io.InputStream;
    7174//import java.io.IOException;
    7275
     
    99102    // to prevent system.exit from causing issues
    100103    //org.assertj.swing.security.NoExitSecurityManagerInstaller.installNoExitSecurityManager();
     104
     105    if(System.getenv("GSDL3SRCHOME") == null) {
     106        System.err.println("@@@ GS3 environment not set. Terminating tests.");
     107        System.exit(-1);
     108    }
    101109
    102110    props = new Properties();
     
    214222   
    215223    // First tutorial
    216     simpleHTML();
     224    //simpleHTML();
     225
     226    backdrop();
    217227   
    218228    }
     
    237247    switchToPane(GATHER_PANE);
    238248    changeUserMode("expert");
    239     //openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString());
     249    //openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.treepath").toString());
    240250
    241251    /*
     
    245255    openCollectionPath("b17mie/b17mie.htm", CLICK);
    246256    PAUSE(3);
    247     openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()); 
     257    openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.treepath").toString()); 
    248258    */
    249259
     
    259269
    260270   
    261     String dragNodePath = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString()+"simple_html/html_files", SELECT);
     271    String dragNodePath = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.treepath").toString()+"simple_html/html_files", SELECT);
    262272
    263273    String collPath = dragNDrop(dragNodePath, "");
     
    265275   
    266276    openCollectionPath("html_files", DOUBLE_CLICK);
    267     PAUSE(2);   
    268    
    269    
     277    PAUSE(2);
    270278   
    271279    //changeUserMode("librarian");
     
    288296   
    289297
    290     String path = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.path").toString(), RIGHT_CLICK);
     298    String path = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.treepath").toString(), RIGHT_CLICK);
    291299    //workspaceRightClickOption(dragNodePath, );
    292300    PAUSE(2);
     
    300308
    301309
     310    public void backdrop() {
     311    System.err.println("@@@ Tutorial 1: simple HTML"); 
     312    stealAnyCollectionLock(1);
     313    switchToPane(GATHER_PANE);
     314    /*
     315    changeUserMode("librarian");
     316
     317    String image_e_coll = props.get("samplefiles.path")+File.separator+"images"+File.separator+"image-e";
     318    File newFolder = GSBasicTestingUtil.copyIntoCollect(image_e_coll);
     319    System.err.println("Trying to create the folder " + newFolder);
     320    Assert.assertTrue(newFolder.exists());
     321    PAUSE(2);
     322    System.err.println("Successfully created folder " + newFolder);
     323   
     324    // Start a new collection within the Librarian Interface:
     325    createCollection("backdrop",
     326             "A simple image collection",
     327             "Simple image collection");
     328   
     329    loadCollection("backdrop");
     330    PAUSE(3);
     331    */
     332    //String startDragNodePath = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.treepath").toString()+"images/Bear.jpg", SELECT);
     333    //https://joel-costigliola.github.io/assertj/swing/api/index.html?org/assertj/swing/core/Robot.html
     334    final String wksFolder = openWorkspacePath(WKS_TOP_FOLDER_LOCAL, props.get("samplefiles.treepath").toString()+"images", EXPAND);
     335    robot().pressModifiersWhileRunning(InputEvent.SHIFT_MASK, new Runnable() {
     336        //https://joel-costigliola.github.io/assertj/swing/api/index.html?org/assertj/swing/core/Robot.html
     337        public void run() {
     338            String startFile = openInExpandedWorkspace(wksFolder + "/Bear.jpg", CLICK);
     339            String endFile = openInExpandedWorkspace(wksFolder + "/Tiger.jpg", CLICK);
     340        }
     341        });
     342    robot().pressModifiersWhileRunning(InputEvent.CTRL_MASK, new Runnable() {
     343        //https://joel-costigliola.github.io/assertj/swing/api/index.html?org/assertj/swing/core/Robot.html
     344        public void run() {
     345            String skipFile = openInExpandedWorkspace(wksFolder + "/README.txt", CLICK);
     346        }
     347        });
     348   
     349    PAUSE(2);
     350    //String collPath = dragNDrop(dragNodePath, "");
     351    //dragNDrop(wksFolder + "/Cat.jpg", "");
     352    //dropSelectionIntoCollection("");
     353    robot().pressModifiersWhileRunning(
     354       InputEvent.SHIFT_MASK|InputEvent.CTRL_MASK, new Runnable() {     
     355        public void run() {
     356            dragNDrop(wksFolder + "/Cat.jpg", "");
     357        }
     358        });
     359    PAUSE(2);
     360    }
     361   
    302362    public static void loadProperties() {
    303363    //System.err.println("@@@ Classpath: " + System.getProperty("java.class.path"));
     
    319379        System.exit(-1);
    320380    }
     381
     382    String sampleFilesTreePath = (String)props.get("samplefiles.path");
     383    // JTreeFixtures denote paths with /
     384    sampleFilesTreePath = sampleFilesTreePath.replace('\\', '/');
     385    props.put("samplefiles.treepath", sampleFilesTreePath);
    321386    }
    322387}
  • gs3-extensions/testing/trunk/src/src/org/greenstone/gsdl3/testing/GSGUITestingUtil.java

    r39033 r39034  
    9090    public static final boolean OPTIONAL = true;
    9191    public static final boolean COMPULSORY = true;
     92
     93    public static final int WORKSPACE_VIEW = 1;
     94    public static final int COLLECTION_VIEW = 2;
    9295   
    9396    public static Robot robot = null;
     
    588591    // in current open collection
    589592    public static void createCollectionSubfolder() {}
    590    
     593
     594    public static void dropSelectionIntoCollection(String collPath) {
     595    JTreeFixture collTree = window.tree("EnrichPane.collection_tree"); 
     596    if(collPath == null || collPath.equals("")) {
     597        collTree.drop(); // empty tree, call ancestor method AbstractComponentFixture.drop()
     598    } else {
     599        collTree.drop(collPath); // call a JTreeFixture.drop() method
     600    }
     601    }
    591602    public static String dragNDrop(String workspacePath, String collPath) {
    592603    JTreeFixture workspaceTree = window.tree("GatherPane.workspace_tree");
     
    626637    }
    627638    /*if(workspacePath.endsWith("/")) {
    628         workspacePath = workspacePath.substring(0, workspacePath.length()-1);
    629         }*/
     639      workspacePath = workspacePath.substring(0, workspacePath.length()-1);
     640      }*/
    630641   
    631642    //JTabbedPaneFixture gatherPane = switchToPane(GATHER_PANE);
     
    644655    String treePath = topGLIFolder + "/" + workspacePath;
    645656    //workspaceTree.clickPath(treePath);   
    646 
     657   
     658    JTreeFixture wks_ptr = workspaceTree.expandPath(topGLIFolder);
     659   
    647660    //PAUSE(2);
    648661   
    649 
    650662    // I think GLI works out what the child nodes are as the workspace tree is expanded,
    651663    // so childnodes don't exist when a toplevel node is closed/collapsed: so we can't
    652664    // pass the entire path in here, but have to mimic expanding one node at a time like
    653665    // a user: expand parent, then childnode, where each node is denoted by its Fullpath
    654     // from root ancestor
    655     JTreeFixture wks_ptr = workspaceTree.expandPath(topGLIFolder);
     666    // from root ancestor   
    656667    String[] nodes = workspacePath.split("/");
    657668    for(int i = 0; i < nodes.length; i++) {
     
    688699        }
    689700    }
     701    return treePath;
     702    }
     703    public static String openWorkspacePath(String workspacePath, int mouseAction) {
     704    // I think GLI works out what the child nodes are as the workspace tree is expanded,
     705    // so childnodes don't exist when a toplevel node is closed/collapsed: so we can't
     706    // pass the entire path in here, but have to mimic expanding one node at a time like
     707    // a user: expand parent, then childnode, where each node is denoted by its Fullpath
     708    // from root ancestor
     709    JTreeFixture workspaceTree = window.tree("GatherPane.workspace_tree");
     710   
     711    String[] nodes = workspacePath.split("/");
     712    JTreeFixture wks_ptr = workspaceTree.expandPath(nodes[0]);
     713    for(int i = 1; i < nodes.length; i++) {
     714        String prevNode = nodes[i-1];
     715        nodes[i] = prevNode + "/" + nodes[i];       
     716        System.err.println("\t" + nodes[i]);
     717        if(i < (nodes.length-1)) {
     718        wks_ptr = workspaceTree.expandPath(nodes[i]);
     719        System.err.println("\tExpanded node: " + nodes[i]);
     720        } else { // final node
     721        System.err.println("\tFinal node: " + nodes[i]);       
     722        wks_ptr = handleLeafNode(workspaceTree, nodes[i], mouseAction);
     723        }
     724    }
    690725   
    691726    //PAUSE(5);
     
    693728    // If wks_ptr stores the expanded workspace treeview, it's useful for dragging and dropping,
    694729    //return wks_ptr;
    695     return treePath;
    696    
    697     }
    698 
     730    return workspacePath;   
     731    }
     732    public static String openInExpandedWorkspace(String nodePath, int mouseAction) {
     733    JTreeFixture workspaceTree = window.tree("GatherPane.workspace_tree");
     734    JTreeFixture wks_ptr = handleLeafNode(workspaceTree, nodePath, mouseAction);   
     735    return nodePath;
     736    }
     737    public static JTreeFixture selectPaths(int view, String folderPath, String[] nodes)
     738    {
     739    //https://joel-costigliola.github.io/assertj/swing/api/index.html?org/assertj/swing/core/Robot.html
     740
     741   
     742    final String startFolder = (view == WORKSPACE_VIEW) ? openInExpandedWorkspace(folderPath, EXPAND) : openCollectionPath(folderPath, EXPAND);
     743   
     744
     745    JTreeFixture tree = (view == WORKSPACE_VIEW) ? window.tree("GatherPane.workspace_tree") : window.tree("EnrichPane.collection_tree");
     746
     747    for(i = 0; i < nodes.length; i++) {
     748        nodes[i] = startFolder + "/" + nodes[i];
     749    }
     750    // String... param: varargs
     751    // https://stackoverflow.com/questions/2367398/what-is-the-ellipsis-for-in-this-method-signature
     752    //"Note that the arguments may also be passed as an array of param type (this makes varargs backward compatible)."
     753    // "Also note that passing 0 varargs (nothing) is legal."
     754    tree = tree.selectPaths(nodes);
     755
     756    return tree;
     757    }
     758   
    699759    public static JTreeFixture handleLeafNode(JTreeFixture tree, String node, int mouseAction){
    700760    JTreeFixture tree_ptr = tree;
Note: See TracChangeset for help on using the changeset viewer.