gui-tests-framework: run test for different IDE with the different classpath

This commit is contained in:
Sergey Karashevich
2016-10-09 17:59:25 +03:00
parent 8a504cad23
commit e6941b799b
9 changed files with 208 additions and 407 deletions
@@ -26,7 +26,6 @@ import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiTask;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -80,7 +79,6 @@ public class FrameworksTreeFixture {
return this;
}
}
Assert.fail();
return this;
}
@@ -49,18 +49,11 @@ public class GuiTestRunner extends BlockJUnit4ClassRunner {
private final List<GarbageCollectorMXBean> myGarbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
private final MemoryMXBean myMemoryMXBean = ManagementFactory.getMemoryMXBean();
private Class<? extends IdeTestApplication> myIdeTestApplicationClass;
@Nullable private final ScreenshotTaker myScreenshotTaker;
public GuiTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
Class<?> guiTestCaseClass = testClass.getSuperclass();
//check test extends GuiTestBase
guiTestCaseClass.isInstance(GuiTestBase.class);
myIdeTestApplicationClass = guiTestCaseClass.getAnnotation(TestWithIde.class).value();
myScreenshotTaker = canRunGuiTests() ? new ScreenshotTaker() : null;
}
@@ -144,8 +137,7 @@ public class GuiTestRunner extends BlockJUnit4ClassRunner {
}
private void loadClassesWithIdeClassLoader() throws Exception {
IdeTestApplication ideTestApplication = (IdeTestApplication) myIdeTestApplicationClass.getMethod("getInstance").invoke(null);
ClassLoader ideClassLoader = ideTestApplication.getIdeClassLoader();
ClassLoader ideClassLoader = IdeTestApplication.getInstance().getIdeClassLoader();
Thread.currentThread().setContextClassLoader(ideClassLoader);
Class<?> testClass = getTestClass().getJavaClass();
@@ -313,7 +313,7 @@ public final class GuiTestUtil {
}
}).withTimeout(LONG_TIMEOUT.duration()).using(robot);
//TODO: clarify here what the hell is going on?
//TODO: clarify why we are skipping event here?
// We know the IDE event queue was pushed in front of the AWT queue. Some JDKs will leave a dummy event in the AWT queue, which
// we attempt to clear here. All other events, including those posted by the Robot, will go through the IDE event queue.
//try {
@@ -15,21 +15,47 @@
*/
package com.intellij.testGuiFramework.framework;
import com.intellij.ide.BootstrapClassLoaderUtil;
import com.intellij.ide.IdeEventQueue;
import com.intellij.ide.WindowsCommandLineProcessor;
import com.intellij.ide.startup.StartupActionScriptManager;
import com.intellij.idea.Main;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.impl.ApplicationImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.SystemProperties;
import com.intellij.util.lang.UrlClassLoader;
import com.intellij.util.text.StringTokenizer;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.regex.Pattern;
import static com.intellij.openapi.util.io.FileUtil.ensureExists;
import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName;
import static com.intellij.openapi.application.PathManager.PROPERTY_CONFIG_PATH;
import static com.intellij.openapi.util.io.FileUtil.*;
import static com.intellij.openapi.util.text.StringUtil.isNotEmpty;
import static com.intellij.testGuiFramework.framework.GuiTestUtil.getProjectCreationDirPath;
import static com.intellij.util.ArrayUtil.EMPTY_STRING_ARRAY;
import static com.intellij.util.ui.UIUtil.initDefaultLAF;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.reflect.core.Reflection.method;
import static org.junit.Assert.assertNotNull;
/**
* @author Sergey Karashevich
*/
public abstract class IdeTestApplication {
public class IdeTestApplication {
private static final Logger LOG = Logger.getInstance(IdeTestApplication.class);
private static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath";
private static final String PROPERTY_ALLOW_BOOTSTRAP_RESOURCES = "idea.allow.bootstrap.resources";
private static final String PROPERTY_ADDITIONAL_CLASSPATH = "idea.additional.classpath";
private static IdeTestApplication ourInstance;
protected ClassLoader myIdeClassLoader;
@@ -62,4 +88,176 @@ public abstract class IdeTestApplication {
}
@NotNull
public static synchronized IdeTestApplication getInstance() throws Exception {
File configDirPath = getConfigDirPath();
System.setProperty(PROPERTY_CONFIG_PATH, configDirPath.getPath());
//Force Swing FileChooser on Mac (instead of native one) to be able to use FEST to drive it.
System.setProperty("native.mac.file.chooser.enabled", "false");
//We are using this property to skip testProjectLeak in _LastSuiteTests
System.setProperty("idea.test.guimode", "true");
if (!isLoaded()) {
ourInstance = new IdeTestApplication();
recreateDirectory(configDirPath);
File newProjectsRootDirPath = getProjectCreationDirPath();
recreateDirectory(newProjectsRootDirPath);
ClassLoader ideClassLoader = ourInstance.getIdeClassLoader();
Class<?> clazz = ideClassLoader.loadClass(GuiTestUtil.class.getCanonicalName());
method("waitForIdeToStart").in(clazz).invoke();
method("setUpDefaultGeneralSettings").in(clazz).invoke();
}
return ourInstance;
}
@NotNull
private static File getConfigDirPath() throws IOException {
File dirPath = new File(getGuiTestRootDirPath(), "config");
ensureExists(dirPath);
return dirPath;
}
private static void recreateDirectory(@NotNull File path) throws IOException {
delete(path);
ensureExists(path);
}
private IdeTestApplication() throws Exception {
String[] args = EMPTY_STRING_ARRAY;
LOG.assertTrue(ourInstance == null, "Only one instance allowed.");
ourInstance = this;
pluginManagerStart(args);
mainMain();
myIdeClassLoader = createClassLoader();
WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, myIdeClassLoader);
Class<?> classUtilCoreClass = Class.forName("com.intellij.ide.ClassUtilCore", true, myIdeClassLoader);
method("clearJarURLCache").in(classUtilCoreClass).invoke();
Class<?> pluginManagerClass = Class.forName("com.intellij.ide.plugins.PluginManager", true, myIdeClassLoader);
method("start").withParameterTypes(String.class, String.class, String[].class)
.in(pluginManagerClass)
.invoke("com.intellij.idea.MainImpl", "start", args);
}
// This method replaces BootstrapClassLoaderUtil.initClassLoader. The reason behind it is that when running UI tests the ClassLoader
// containing the URLs for the plugin jars is loaded by a different ClassLoader and it gets ignored. The result is test failing because
// classes like AndroidPlugin cannot be found.
@NotNull
private static ClassLoader createClassLoader() throws MalformedURLException, URISyntaxException {
Collection<URL> classpath = new LinkedHashSet<>();
addIdeaLibraries(classpath);
addAdditionalClassPath(classpath);
UrlClassLoader.Builder builder = UrlClassLoader.build()
.urls(filterClassPath(new ArrayList<>(classpath)))
.parent(IdeTestApplication.class.getClassLoader())
.allowLock(false)
.usePersistentClasspathIndexForLocalClassDirectories();
if (SystemProperties.getBooleanProperty(PROPERTY_ALLOW_BOOTSTRAP_RESOURCES, true)) {
builder.allowBootstrapResources();
}
UrlClassLoader newClassLoader = builder.get();
// prepare plugins
try {
StartupActionScriptManager.executeActionScript();
}
catch (IOException e) {
Main.showMessage("Plugin Installation Error", e);
}
Thread.currentThread().setContextClassLoader(newClassLoader);
return newClassLoader;
}
private static void addIdeaLibraries(@NotNull Collection<URL> classpath) throws MalformedURLException {
Class<BootstrapClassLoaderUtil> aClass = BootstrapClassLoaderUtil.class;
String selfRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class");
assertNotNull(selfRoot);
URL selfRootUrl = new File(selfRoot).getAbsoluteFile().toURI().toURL();
classpath.add(selfRootUrl);
File libFolder = new File(PathManager.getLibPath());
addLibraries(classpath, libFolder, selfRootUrl);
addLibraries(classpath, new File(libFolder, "ext"), selfRootUrl);
addLibraries(classpath, new File(libFolder, "ant/lib"), selfRootUrl);
}
private static void addLibraries(@NotNull Collection<URL> classPath, @NotNull File fromDir, @NotNull URL selfRootUrl)
throws MalformedURLException {
for (File file : notNullize(fromDir.listFiles())) {
if (isJarOrZip(file)) {
URL url = file.toURI().toURL();
if (!selfRootUrl.equals(url)) {
classPath.add(url);
}
}
}
}
private static void addAdditionalClassPath(@NotNull Collection<URL> classpath) throws MalformedURLException {
StringTokenizer tokenizer = new StringTokenizer(System.getProperty(PROPERTY_ADDITIONAL_CLASSPATH, ""), File.pathSeparator, false);
while (tokenizer.hasMoreTokens()) {
String pathItem = tokenizer.nextToken();
classpath.add(new File(pathItem).toURI().toURL());
}
}
private static List<URL> filterClassPath(@NotNull List<URL> classpath) {
String ignoreProperty = System.getProperty(PROPERTY_IGNORE_CLASSPATH);
if (ignoreProperty != null) {
Pattern pattern = Pattern.compile(ignoreProperty);
for (Iterator<URL> i = classpath.iterator(); i.hasNext(); ) {
String url = i.next().toExternalForm();
if (pattern.matcher(url).matches()) {
i.remove();
}
}
}
return classpath;
}
private static void pluginManagerStart(@NotNull String[] args) {
// Duplicates what PluginManager#start does.
Main.setFlags(args);
initDefaultLAF();
}
private static void mainMain() {
// Duplicates what Main#main does.
method("installPatch").in(Main.class).invoke();
}
public void dispose() {
disposeInstance();
}
public static synchronized void disposeInstance() {
if (!isLoaded()) {
return;
}
IdeEventQueue.getInstance().flushQueue();
final Application application = ApplicationManager.getApplication();
((ApplicationImpl)application).exit(true, true, false, false);
ourInstance = null;
}
public static synchronized boolean isLoaded() {
return ourInstance != null;
}
}
@@ -1,32 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
*
* 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 com.intellij.testGuiFramework.framework;
import java.lang.annotation.*;
/**
* @author Sergey Karashevich
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface TestWithIde {
/**
* @return a IdeTestApplication class (must have a getInstance() method that runs apropriate IDE)
*/
Class<? extends IdeTestApplication> value();
}
@@ -17,7 +17,6 @@ package com.intellij.testGuiFramework.impl;
import com.intellij.testFramework.vcs.ExecutableHelper;
import com.intellij.testGuiFramework.framework.GuiTestBase;
import com.intellij.testGuiFramework.framework.TestWithIde;
import com.intellij.util.net.HttpConfigurable;
import git4idea.config.GitVcsApplicationSettings;
import org.fest.swing.core.FastRobot;
@@ -28,7 +27,6 @@ import static com.intellij.testGuiFramework.framework.GuiTestUtil.setUpSdks;
/**
* @author Sergey Karashevich
*/
@TestWithIde(IdeaGuiTestApp.class)
public class GuiTestCase extends GuiTestBase {
public GuiTestCase() {
@@ -1,243 +0,0 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
*
* 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 com.intellij.testGuiFramework.impl;
import com.intellij.ide.BootstrapClassLoaderUtil;
import com.intellij.ide.IdeEventQueue;
import com.intellij.ide.WindowsCommandLineProcessor;
import com.intellij.ide.startup.StartupActionScriptManager;
import com.intellij.idea.Main;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.impl.ApplicationImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.testGuiFramework.framework.GuiTestUtil;
import com.intellij.testGuiFramework.framework.IdeTestApplication;
import com.intellij.util.SystemProperties;
import com.intellij.util.lang.UrlClassLoader;
import com.intellij.util.text.StringTokenizer;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.regex.Pattern;
import static com.intellij.openapi.application.PathManager.PROPERTY_CONFIG_PATH;
import static com.intellij.openapi.util.io.FileUtil.*;
import static com.intellij.testGuiFramework.framework.GuiTestUtil.getProjectCreationDirPath;
import static com.intellij.util.ArrayUtil.EMPTY_STRING_ARRAY;
import static com.intellij.util.ui.UIUtil.initDefaultLAF;
import static org.fest.reflect.core.Reflection.method;
import static org.junit.Assert.assertNotNull;
public class IdeaGuiTestApp extends IdeTestApplication implements Disposable {
private static final Logger LOG = Logger.getInstance(IdeTestApplication.class);
private static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath";
private static final String PROPERTY_ALLOW_BOOTSTRAP_RESOURCES = "idea.allow.bootstrap.resources";
private static final String PROPERTY_ADDITIONAL_CLASSPATH = "idea.additional.classpath";
private static IdeTestApplication ourInstance;
@NotNull
public static synchronized IdeTestApplication getInstance() throws Exception {
File configDirPath = getConfigDirPath();
System.setProperty(PROPERTY_CONFIG_PATH, configDirPath.getPath());
//Force Swing FileChooser on Mac (instead of native one) to be able to use FEST to drive it.
System.setProperty("native.mac.file.chooser.enabled", "false");
//We are using this property to skip testProjectLeak in _LastSuiteTests
System.setProperty("idea.test.guimode", "true");
if (!isLoaded()) {
ourInstance = new IdeaGuiTestApp();
recreateDirectory(configDirPath);
File newProjectsRootDirPath = getProjectCreationDirPath();
recreateDirectory(newProjectsRootDirPath);
ClassLoader ideClassLoader = ourInstance.getIdeClassLoader();
Class<?> clazz = ideClassLoader.loadClass(GuiTestUtil.class.getCanonicalName());
method("waitForIdeToStart").in(clazz).invoke();
method("setUpDefaultGeneralSettings").in(clazz).invoke();
}
return ourInstance;
}
@NotNull
private static File getConfigDirPath() throws IOException {
File dirPath = new File(getGuiTestRootDirPath(), "config");
ensureExists(dirPath);
return dirPath;
}
private static void recreateDirectory(@NotNull File path) throws IOException {
delete(path);
ensureExists(path);
}
private IdeaGuiTestApp() throws Exception {
String[] args = EMPTY_STRING_ARRAY;
LOG.assertTrue(ourInstance == null, "Only one instance allowed.");
ourInstance = this;
pluginManagerStart(args);
mainMain();
myIdeClassLoader = createClassLoader();
//myIdeClassLoader = BootstrapClassLoaderUtil.initClassLoader(false);
WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, myIdeClassLoader);
// We turn on "GUI Testing Mode" right away, even before loading the IDE.
//Class<?> androidPluginClass = Class.forName("org.jetbrains.android.AndroidPlugin", true, myIdeClassLoader);
//method("setGuiTestingMode").withParameterTypes(boolean.class).in(androidPluginClass).invoke(true);
Class<?> classUtilCoreClass = Class.forName("com.intellij.ide.ClassUtilCore", true, myIdeClassLoader);
method("clearJarURLCache").in(classUtilCoreClass).invoke();
Class<?> pluginManagerClass = Class.forName("com.intellij.ide.plugins.PluginManager", true, myIdeClassLoader);
method("start").withParameterTypes(String.class, String.class, String[].class)
.in(pluginManagerClass)
.invoke("com.intellij.idea.MainImpl", "start", args);
}
// This method replaces BootstrapClassLoaderUtil.initClassLoader. The reason behind it is that when running UI tests the ClassLoader
// containing the URLs for the plugin jars is loaded by a different ClassLoader and it gets ignored. The result is test failing because
// classes like AndroidPlugin cannot be found.
@NotNull
private static ClassLoader createClassLoader() throws MalformedURLException, URISyntaxException {
Collection<URL> classpath = new LinkedHashSet<>();
addIdeaLibraries(classpath);
addAdditionalClassPath(classpath);
UrlClassLoader.Builder builder = UrlClassLoader.build()
.urls(filterClassPath(new ArrayList<>(classpath)))
.parent(IdeTestApplication.class.getClassLoader())
.allowLock(false)
.usePersistentClasspathIndexForLocalClassDirectories();
if (SystemProperties.getBooleanProperty(PROPERTY_ALLOW_BOOTSTRAP_RESOURCES, true)) {
builder.allowBootstrapResources();
}
UrlClassLoader newClassLoader = builder.get();
// prepare plugins
try {
StartupActionScriptManager.executeActionScript();
}
catch (IOException e) {
Main.showMessage("Plugin Installation Error", e);
}
Thread.currentThread().setContextClassLoader(newClassLoader);
return newClassLoader;
}
private static void addIdeaLibraries(@NotNull Collection<URL> classpath) throws MalformedURLException {
Class<BootstrapClassLoaderUtil> aClass = BootstrapClassLoaderUtil.class;
String selfRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class");
assertNotNull(selfRoot);
URL selfRootUrl = new File(selfRoot).getAbsoluteFile().toURI().toURL();
classpath.add(selfRootUrl);
File libFolder = new File(PathManager.getLibPath());
addLibraries(classpath, libFolder, selfRootUrl);
addLibraries(classpath, new File(libFolder, "ext"), selfRootUrl);
addLibraries(classpath, new File(libFolder, "ant/lib"), selfRootUrl);
}
private static void addLibraries(@NotNull Collection<URL> classPath, @NotNull File fromDir, @NotNull URL selfRootUrl)
throws MalformedURLException {
for (File file : notNullize(fromDir.listFiles())) {
if (isJarOrZip(file)) {
URL url = file.toURI().toURL();
if (!selfRootUrl.equals(url)) {
classPath.add(url);
}
}
}
}
private static void addAdditionalClassPath(@NotNull Collection<URL> classpath) throws MalformedURLException {
StringTokenizer tokenizer = new StringTokenizer(System.getProperty(PROPERTY_ADDITIONAL_CLASSPATH, ""), File.pathSeparator, false);
while (tokenizer.hasMoreTokens()) {
String pathItem = tokenizer.nextToken();
classpath.add(new File(pathItem).toURI().toURL());
}
}
private static List<URL> filterClassPath(@NotNull List<URL> classpath) {
String ignoreProperty = System.getProperty(PROPERTY_IGNORE_CLASSPATH);
if (ignoreProperty != null) {
Pattern pattern = Pattern.compile(ignoreProperty);
for (Iterator<URL> i = classpath.iterator(); i.hasNext(); ) {
String url = i.next().toExternalForm();
if (pattern.matcher(url).matches()) {
i.remove();
}
}
}
return classpath;
}
private static void pluginManagerStart(@NotNull String[] args) {
// Duplicates what PluginManager#start does.
Main.setFlags(args);
initDefaultLAF();
}
private static void mainMain() {
// Duplicates what Main#main does.
method("installPatch").in(Main.class).invoke();
}
@NotNull
public ClassLoader getIdeClassLoader() {
return myIdeClassLoader;
}
@Override
public void dispose() {
disposeInstance();
}
public static synchronized void disposeInstance() {
if (!isLoaded()) {
return;
}
IdeEventQueue.getInstance().flushQueue();
final Application application = ApplicationManager.getApplication();
((ApplicationImpl)application).exit(true, true, false, false);
ourInstance = null;
}
public static synchronized boolean isLoaded() {
return ourInstance != null;
}
}
@@ -9,7 +9,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="library" name="fest" level="project" />
<orderEntry type="library" exported="" name="fest" level="project" />
<orderEntry type="library" name="JUnit4" level="project" />
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="java-impl" />
@@ -20,7 +20,6 @@
<orderEntry type="module" module-name="xdebugger-impl" />
<orderEntry type="module" module-name="external-system-rt" />
<orderEntry type="module" module-name="external-system-impl" />
<orderEntry type="module" module-name="main_idea_tests" scope="TEST" />
<orderEntry type="module-library">
<library>
<CLASSES>
@@ -34,5 +33,6 @@
</orderEntry>
<orderEntry type="module" module-name="git4idea" />
<orderEntry type="module" module-name="vcs-tests" />
<orderEntry type="module" module-name="platform-main" />
</component>
</module>
@@ -1,110 +0,0 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
*
* 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 com.intellij.testGuiFramework.tests;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.testGuiFramework.fixtures.ProjectViewFixture;
import com.intellij.testGuiFramework.fixtures.ToolWindowFixture;
import com.intellij.testGuiFramework.fixtures.WelcomeFrameFixture;
import com.intellij.testGuiFramework.fixtures.newProjectWizard.NewProjectWizardFixture;
import com.intellij.testGuiFramework.framework.GuiTestUtil;
import com.intellij.testGuiFramework.impl.GuiTestCase;
import org.junit.Test;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import static com.intellij.testGuiFramework.framework.GuiTestUtil.getSystemJdk;
/**
* @author Sergey Karashevich
*/
public class JavaEEProjectTest extends GuiTestCase {
@Test
public void testJavaEEProject() throws IOException, InterruptedException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
Date date = new Date();
String projectName = "smoke-test-project-" + dateFormat.format(date);
WelcomeFrameFixture welcomeFrame = findWelcomeFrame();
welcomeFrame.createNewProject();
NewProjectWizardFixture newProjectWizard = findNewProjectWizard();
setupJdk(newProjectWizard);
//select project type and framework
newProjectWizard.
selectProjectType("Java").
selectFramework("JavaEE Persistence");
newProjectWizard.clickNext();
newProjectWizard.setProjectName(projectName);
final File locationInFileSystem = newProjectWizard.getLocationInFileSystem();
newProjectWizard.clickFinish();
myProjectFrame = findIdeFrame(projectName, locationInFileSystem);
myProjectFrame.waitForBackgroundTasksToFinish();
final ProjectViewFixture projectView = myProjectFrame.getProjectView();
final ProjectViewFixture.PaneFixture paneFixture = projectView.selectProjectPane();
paneFixture.selectByPath(projectName, "src", "META-INF", "persistence.xml");
ToolWindowFixture.showToolwindowStripes(myRobot);
//prevent from ProjectLeak (if the project is closed during the indexing
DumbService.getInstance(myProjectFrame.getProject()).waitForSmartMode();
//final JToggleButtonFixture persistence = (new JToggleButtonFinder("Persistence")).withTimeout(THIRTY_SEC_TIMEOUT.duration()).using(myRobot);
//persistence.click();
//ToolWindowFixture.clickToolwindowButton("Persistence", myRobot);
//ToolWindowFixture.clickToolwindowButton("Java Enterprise", myRobot);
}
private void setupJdk(NewProjectWizardFixture newProjectWizard) {
if (newProjectWizard.isJdkEmpty()) {
JButton newButton = GuiTestUtil.findButton(newProjectWizard,
GuiTestUtil.adduction(ApplicationBundle.message("button.new")),
myRobot);
myRobot.click(newButton);
File javaSdkPath = new File(getSystemJdk());
String sdkType = GuiTestUtil.adduction(ProjectBundle.message("sdk.java.name"));
GuiTestUtil.clickPopupMenuItem(sdkType, newButton, myRobot);
newProjectWizard.selectSdkPath(javaSdkPath, sdkType);
}
}
private void setupJdk(NewProjectWizardFixture newProjectWizard, String customPath){
if (newProjectWizard.isJdkEmpty()) {
JButton newButton = GuiTestUtil.findButton(newProjectWizard,
GuiTestUtil.adduction(ApplicationBundle.message("button.new")),
myRobot);
myRobot.click(newButton);
File javaSdkPath = new File(customPath);
String sdkType = GuiTestUtil.adduction(ProjectBundle.message("sdk.java.name"));
GuiTestUtil.clickPopupMenuItem(sdkType, newButton, myRobot);
newProjectWizard.selectSdkPath(javaSdkPath, sdkType);
}
}
}