Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f5a079f427aff37a1292cf39a0a3a1eccc73b39e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * Copyright (c) 2010, 2018 Red Hat Inc. and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.linuxtools.changelog.ui.tests.utils;

import static org.junit.Assert.assertNotNull;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.changelog.ui.tests.swtbot.PrepareChangelogSWTBotTest;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;

/**
 * Subversion project abstraction for SWTBot tests. See
 * {@link PrepareChangelogSWTBotTest#setUp()} for a usage example.
 *
 */
public class SVNProject {

    private SWTWorkbenchBot bot;
    private String repoURL;
    private String projectName;
    private IProject project; // available after checkout

    public SVNProject(SWTWorkbenchBot bot) {
        this.bot = bot;
    }

    /**
     * @return the repoURL
     */
    public String getRepoURL() {
        return repoURL;
    }

    /**
     * @param repoURL the repoURL to set
     */
    public SVNProject setRepoURL(String repoURL) {
        this.repoURL = repoURL;
        return this;
    }

    /**
     * @return the projectName
     */
    public String getProjectName() {
        return projectName;
    }

    /**
     * @param projectName the projectName to set
     */
    public SVNProject setProjectName(String projectName) {
        this.projectName = projectName;
        return this;
    }

    /**
     * @return the project
     */
    public IProject getProject() {
        return project;
    }

    /**
     * @param project the project to set
     */
    public SVNProject setProject(IProject project) {
        this.project = project;
        return this;
    }

    /**
     * Use File => Import => SVN to create a svn-backed project.
     */
    public IProject checkoutProject() throws IllegalStateException {
        if (repoURL == null || projectName == null) {
            // need to have url and project set
            throw new IllegalStateException();
        }
        bot.menu("File").menu("Import...").click();

        SWTBotShell shell = bot.shell("Import");
        shell.activate();
        bot.tree().expandNode("SVN").select("Checkout Projects from SVN");
        bot.button("Next >").click();

        // create new repo
        shell = bot.shell("Checkout from SVN");
        shell.activate();
        bot.button("Next >").click();

        shell = bot.shell("Checkout from SVN");
        shell.activate();
        // Enter url
        bot.comboBoxWithLabelInGroup("Url:", "Location").setText(repoURL);
        bot.button("Next >").click();

        // the next few operation can take quite a while, adjust
        // timout accordingly.
        long oldTimeout = SWTBotPreferences.TIMEOUT;
        SWTBotPreferences.TIMEOUT = 3 * 5000;

        shell = bot.shell("Progress Information").activate();
        bot.waitUntil(Conditions.shellCloses(shell));
        shell = bot.shell("Checkout from SVN").activate();
        bot.waitUntil(new TreeItemAppearsCondition(repoURL, projectName));
        SWTBotTreeItem projectTree = bot.tree().expandNode(repoURL);
        projectTree.expandNode(projectName).select();
        bot.button("Finish").click();
        // Wait for import operation to finish
        bot.waitUntil(Conditions.shellCloses(shell));
        SWTBotShell svnCheckoutPopup = bot.shell("SVN Checkout").activate();
        bot.waitUntil(Conditions.shellCloses(svnCheckoutPopup));
        // need a little delay
        bot.waitUntil(new SVNProjectCreatedCondition(projectName));

        // Set timout back what it was.
        SWTBotPreferences.TIMEOUT = oldTimeout;

        // A quick sanity check
        IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
        IProject changelogTestsProject = (IProject)wsRoot.findMember(new Path(projectName));
        assertNotNull(changelogTestsProject);
        try {
            changelogTestsProject.refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        IResource manifest = changelogTestsProject.findMember(new Path("/META-INF/MANIFEST.MF"));
        assertNotNull(manifest);
        return changelogTestsProject;
    }

    /**
     *  Discard the automatically created SVN repo URL from the list.
     */
    public void discardRepositoryLocation() throws Exception {
        if (repoURL == null) { // need to have repoURL set
            throw new IllegalStateException();
        }
        new SVNReporsitoriesView(bot).open().discardRepository(repoURL);
    }
}

Back to the top