From 393451f1ec26cf4900180e0c1ad983cf13060d15 Mon Sep 17 00:00:00 2001 From: Maxim Musienko Date: Thu, 28 Sep 2017 11:07:49 +0300 Subject: [PATCH] Rework and add test for checking of Test Runner plugin (#6401) * add new steps, locators and methods for the tests --- .../constant/TestMenuCommandsConstants.java | 15 +- .../che/selenium/pageobject/Consoles.java | 13 +- .../plugins/JavaTestRunnerPluginConsole.java | 84 +++++++++-- ...uginJunit4CheckRunSuitesAndScopesTest.java | 131 ++++++++++++++++++ .../testrunner/JavaTestPluginJunit4Test.java | 60 ++++---- .../testrunner/JavaTestPluginTestNgTest.java | 50 ++++--- .../pom.xml | 48 +++++++ .../java/org/eclipse/che/example/Hello.java | 25 ++++ .../org/eclipse/che/example/HelloWorld.java | 22 +++ .../eclipse/che/suite/Junit4TestSuite.java | 23 +++ .../org/eclipse/che/tests/AppAnotherTest.java | 33 +++++ .../org/eclipse/che/tests/AppOneTest.java | 39 ++++++ .../src/test/resources/suites/CheSuite.xml | 1 + 13 files changed, 477 insertions(+), 67 deletions(-) create mode 100644 selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4CheckRunSuitesAndScopesTest.java create mode 100644 selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/pom.xml create mode 100644 selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/Hello.java create mode 100644 selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/HelloWorld.java create mode 100644 selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/suite/Junit4TestSuite.java create mode 100644 selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppAnotherTest.java create mode 100644 selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppOneTest.java diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestMenuCommandsConstants.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestMenuCommandsConstants.java index 6c9b6c9c4a9..a3a264d5771 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestMenuCommandsConstants.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/core/constant/TestMenuCommandsConstants.java @@ -101,15 +101,6 @@ interface Run { String DEBUG_CONFIGURATION = "gwt-debug-topmenu/Run/Debug Configurations"; String END_DEBUG_SESSION = "gwt-debug-topmenu/Run/disconnectDebug"; String TEST = "gwt-debug-topmenu/Run/TestingMainGroup"; - - interface Test { - String TEST_NG_TEST = "topmenu/Run/Test/Run Test"; - String TEST_NG_CLASS = "gwt-debug-topmenu/Run/Test/TestNGActionRunClass"; - String TEST_NG_PROJECT = "gwt-debug-topmenu/Run/Test/TestNGActionRunAllContext"; - String TEST_NG_XML_SUITE = "gwt-debug-topmenu/Run/Test/TestNGActionRunXMLContext"; - String JUNIT_TEST = "gwt-debug-topmenu/Run/Test/RunTest"; - String JUNIT_PROJECT = "gwt-debug-topmenu/Run/Test/TestJUnitActionRunAllContext"; - } } interface Profile { @@ -198,4 +189,10 @@ interface CommandList { String ITEM_PREFFIX_ID = "gwt-debug-CommandsGroup/"; String COMMAND_LIST_XPATH = "//div[@id='gwt-debug-dropDownHeader'][2]"; } + + public static final String TEST_NG_TEST_DROP_DAWN_ITEM = "topmenu/Run/Test/Run Test"; + public static final String JUNIT_TEST_DROP_DAWN_ITEM = + "gwt-debug-topmenu/Run/Test/TestJUnitActionRun"; + + public static final String TEST_DROP_DAWN_ITEM = "gwt-debug-topmenu/Run/Test/RunTest"; } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Consoles.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Consoles.java index dba19aad84a..3219973aca1 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Consoles.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Consoles.java @@ -24,6 +24,7 @@ import org.eclipse.che.selenium.core.SeleniumWebDriver; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -59,9 +60,9 @@ public class Consoles { public static final String PREVIEW_URL = "//div[@active]//a[@href]"; public static final String COMMAND_CONSOLE_ID = "//div[@active]//div[@id='gwt-debug-commandConsoleLines']"; - protected final SeleniumWebDriver seleniumWebDriver; private final Loader loader; + private static final String CONSOLE_PANEL_DRUGGER_CSS = "div.gwt-SplitLayoutPanel-VDragger"; @Inject public Consoles(SeleniumWebDriver seleniumWebDriver, Loader loader) { @@ -73,6 +74,9 @@ public Consoles(SeleniumWebDriver seleniumWebDriver, Loader loader) { PageFactory.initElements(seleniumWebDriver, this); } + @FindBy(css = CONSOLE_PANEL_DRUGGER_CSS) + WebElement consolesPanelDrag; + @FindBy(id = PROCESSES_TAB) WebElement processesTab; @@ -300,4 +304,11 @@ public boolean processesMainAreaIsOpen() { public void clickOnMaximizePanelIcon() { redrawDriverWait.until(elementToBeClickable(By.xpath(MAXIMIZE_PANEL_ICON))).click(); } + + public void dragConsolesInDefinePosition(int verticalShiftInPixels) { + WebElement drag = redrawDriverWait.until(ExpectedConditions.visibilityOf(consolesPanelDrag)); + new Actions(seleniumWebDriver) + .dragAndDropBy(drag, verticalShiftInPixels, verticalShiftInPixels) + .perform(); + } } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/plugins/JavaTestRunnerPluginConsole.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/plugins/JavaTestRunnerPluginConsole.java index 825dcab0ae9..37ae21a4860 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/plugins/JavaTestRunnerPluginConsole.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/plugins/JavaTestRunnerPluginConsole.java @@ -16,6 +16,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import org.eclipse.che.selenium.core.SeleniumWebDriver; import org.eclipse.che.selenium.pageobject.Consoles; @@ -43,6 +44,8 @@ public class JavaTestRunnerPluginConsole extends Consoles { private static final String METHODS_MARKED_AS_IGNORED = "//div[contains(@id,'gwt-uid')]//div[@style='text-decoration: line-through; color: yellow;']"; + private static final String TEST_RESULT_NAVIGATION_TREE = "gwt-debug-test-tree-navigation-panel"; + @FindAll({@FindBy(xpath = TEST_OUTPUT_XPATH)}) private List testOutput; @@ -64,6 +67,9 @@ public class JavaTestRunnerPluginConsole extends Consoles { @FindAll({@FindBy(xpath = METHODS_MARKED_AS_IGNORED)}) private List ignoredMethods; + @FindBy(id = TEST_RESULT_NAVIGATION_TREE) + private WebElement resultTreeMainForm; + @Inject public JavaTestRunnerPluginConsole(SeleniumWebDriver seleniumWebDriver, Loader loader) { super(seleniumWebDriver, loader); @@ -86,7 +92,7 @@ public String getTestErrorMessage() { } /** - * wait single method in the result tree marked as failed (red color) + * Wait single method in the result tree marked as failed (red color). * * @param nameOfFailedMethods name of that should fail */ @@ -96,7 +102,7 @@ public void waitMethodMarkedAsFailed(String nameOfFailedMethods) { } /** - * wait single method in the result tree marked as failed (red color) + * Wait single method in the result tree marked as failed (red color). * * @param nameOfFailedMethods name of that should fail */ @@ -106,7 +112,7 @@ public void waitMethodMarkedAsIgnored(String nameOfFailedMethods) { } /** - * wait single method in the result tree marked as passed (green color) + * Wait single method in the result tree marked as passed (green color). * * @param nameOfFailedMethods name of expected method */ @@ -116,25 +122,25 @@ public void waitMethodMarkedAsPassed(String nameOfFailedMethods) { } /** - * wait the FQN of the test class in result tree class that has been launched + * Wait the FQN of the test class in result tree class that has been launched. * * @param fqn */ public void waitFqnOfTesClassInResultTree(String fqn) { new WebDriverWait(seleniumWebDriver, MINIMUM_SEC) .until( - ExpectedConditions.visibilityOfAllElementsLocatedBy( + ExpectedConditions.visibilityOfElementLocated( By.xpath(String.format(TEST_RESULT_TREE_XPATH_TEMPLATE, fqn)))); } /** - * get all name of the test methods form the test result tree marked with defined status (may be - * passed, failed or ignored) + * Get all name of the test methods form the test result tree marked with defined status (may be + * passed, failed or ignored). * * @param methodState the enumeration with defined status * @return the list with names of methods with defined status */ - public List getAllMethodsMarkedDefinedStatus(JunitMethodsState methodState) { + public List getAllNamesOfMethodsMarkedDefinedStatus(JunitMethodsState methodState) { List definedMethods = null; switch (methodState) { case PASSED: @@ -150,6 +156,28 @@ public List getAllMethodsMarkedDefinedStatus(JunitMethodsState methodSta return definedMethods; } + /** + * Get all defined methods from result tree and return as list WebElements. + * + * @param methodState the enumeration with defined status + * @return List WebElements with defined status + */ + public List getAllMethodsMarkedDefinedStatus(JunitMethodsState methodState) { + List definedMethods = null; + switch (methodState) { + case PASSED: + definedMethods = passedMethods; + break; + case FAILED: + definedMethods = failedMethods; + break; + case IGNORED: + definedMethods = ignoredMethods; + break; + } + return definedMethods; + } + private List getAllMetodsWithDefinedStatus(List definedMethod) { return new WebDriverWait(seleniumWebDriver, MINIMUM_SEC) .until(ExpectedConditions.visibilityOfAllElements(definedMethod)) @@ -157,4 +185,44 @@ private List getAllMetodsWithDefinedStatus(List definedMetho .map(WebElement::getText) .collect(Collectors.toList()); } + + /** + * Get text from the test result tree. Mote! This method represent only text from test result tree + * without styles and formatting + * + * @return text representation of results of the test result tree widget + */ + public String getTextFromResultTree() { + return new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) + .until(ExpectedConditions.visibilityOf(resultTreeMainForm)) + .getText(); + } + + /** + * Click on the item in the result tree. If will be some items with the same name - will select + * first. + * + * @param item name of the item (method or fqn of test class) in the test result tree + */ + public void selectItemInResultTree(String item) { + new WebDriverWait(seleniumWebDriver, MINIMUM_SEC) + .until(ExpectedConditions.visibilityOf(resultTreeMainForm)) + .findElement(By.xpath(String.format("//div[text()='%s']", item))) + .click(); + } + + /** + * Click on faled, passed or ignored method on the result tree. + * + * @param nameOfMethod + * @param state + */ + public void selectMethodWithDefinedStatus(JunitMethodsState state, String nameOfMethod) { + getAllMethodsMarkedDefinedStatus(state) + .stream() + .filter(webElement -> Objects.equals(webElement.getText(), nameOfMethod)) + .findFirst() + .get() + .click(); + } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4CheckRunSuitesAndScopesTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4CheckRunSuitesAndScopesTest.java new file mode 100644 index 00000000000..bf8f391d7ae --- /dev/null +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4CheckRunSuitesAndScopesTest.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.testrunner; + +import static org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole.JunitMethodsState.FAILED; +import static org.testng.Assert.assertTrue; + +import com.google.inject.Inject; +import java.nio.file.Paths; +import org.eclipse.che.api.workspace.server.DtoConverter; +import org.eclipse.che.selenium.core.client.TestCommandServiceClient; +import org.eclipse.che.selenium.core.client.TestProjectServiceClient; +import org.eclipse.che.selenium.core.constant.TestBuildConstants; +import org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants; +import org.eclipse.che.selenium.core.project.ProjectTemplates; +import org.eclipse.che.selenium.core.workspace.TestWorkspace; +import org.eclipse.che.selenium.pageobject.CodenvyEditor; +import org.eclipse.che.selenium.pageobject.Consoles; +import org.eclipse.che.selenium.pageobject.Ide; +import org.eclipse.che.selenium.pageobject.Loader; +import org.eclipse.che.selenium.pageobject.Menu; +import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel; +import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.eclipse.che.selenium.pageobject.intelligent.CommandsPalette; +import org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** @author Musienko Maxim */ +public class JavaTestPluginJunit4CheckRunSuitesAndScopesTest { + private static final String JUNIT4_PROJECT = "junit4-tests-with-separeted-suites"; + + private static final String PATH_TO_JUNIT4_TEST_CLASSES = + JUNIT4_PROJECT + "/src/test/java/org/eclipse/che/tests/AppOneTest.java"; + + private static final int VALUE_OF_SHIFTING_CONSOLES_ALONG_X_AXIS = -100; + + @Inject private JavaTestRunnerPluginConsole pluginConsole; + @Inject private ProjectExplorer projectExplorer; + @Inject private Loader loader; + @Inject private NotificationsPopupPanel notifications; + @Inject private Menu menu; + + @Inject private TestWorkspace ws; + + @Inject private Ide ide; + @Inject private Consoles consoles; + @Inject private CodenvyEditor editor; + @Inject private TestCommandServiceClient testCommandServiceClient; + @Inject private CommandsPalette commandsPalette; + @Inject private TestProjectServiceClient projectServiceClient; + + @BeforeClass + public void prepareTestProject() throws Exception { + CompileCommand compileCommand = new CompileCommand(); + testCommandServiceClient.createCommand(DtoConverter.asDto(compileCommand), ws.getId()); + projectServiceClient.importProject( + ws.getId(), + Paths.get( + getClass() + .getResource("/projects/plugins/JavaTestRunnerPlugin/" + JUNIT4_PROJECT) + .toURI()), + JUNIT4_PROJECT, + ProjectTemplates.CONSOLE_JAVA_SIMPLE); + ide.open(ws); + loader.waitOnClosed(); + projectExplorer.waitItem(JUNIT4_PROJECT); + runCompileCommandByPallete(compileCommand); + notifications.waitProgressPopupPanelClose(); + consoles.dragConsolesInDefinePosition(VALUE_OF_SHIFTING_CONSOLES_ALONG_X_AXIS); + } + + @Test + public void shouldExecuteJUnit4TestClassWithDifferentStatuses() throws InterruptedException { + // given + String expectedResultAfterFirstLaunch = + "Default Suite\n" + + "org.eclipse.che.tests.AppOneTest\n" + + "shouldBeIgnoredOfAppOne\n" + + "shouldSuccessOfAppOne\n" + + "shouldFailOfAppOne\n" + + "org.eclipse.che.suite.Junit4TestSuite\n" + + "org.eclipse.che.tests.AppAnotherTest\n" + + "shouldFailOfAppAnother\n" + + "shouldSuccessOfAppAnother\n" + + "org.eclipse.che.tests.AppAnotherTest\n" + + "shouldFailOfAppAnother\n" + + "shouldSuccessOfAppAnother\n" + + "org.eclipse.che.tests.AppAnotherTest\n" + + "shouldFailOfAppAnother\n" + + "shouldSuccessOfAppAnother"; + + String expectedExceptionForFailedTest = + "java.lang.AssertionError\n" + + " at org.junit.Assert.fail(Assert.java:86)\n" + + " at org.junit.Assert.assertTrue(Assert.java:41)"; + + projectExplorer.quickRevealToItemWithJavaScript(PATH_TO_JUNIT4_TEST_CLASSES); + projectExplorer.selectItem(JUNIT4_PROJECT); + // when + menu.runCommand( + TestMenuCommandsConstants.Run.RUN_MENU, + TestMenuCommandsConstants.Run.TEST, + TestMenuCommandsConstants.JUNIT_TEST_DROP_DAWN_ITEM); + + // then + notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); + pluginConsole.waitFqnOfTesClassInResultTree("org.eclipse.che.tests.AppAnotherTest"); + assertTrue(pluginConsole.getTextFromResultTree().equals(expectedResultAfterFirstLaunch)); + pluginConsole.waitFqnOfTesClassInResultTree("org.eclipse.che.tests.AppOneTest"); + pluginConsole.waitMethodMarkedAsPassed("shouldSuccessOfAppOne"); + pluginConsole.waitMethodMarkedAsFailed("shouldFailOfAppOne"); + pluginConsole.waitMethodMarkedAsIgnored("shouldBeIgnoredOfAppOne"); + pluginConsole.selectMethodWithDefinedStatus(FAILED, "shouldFailOfAppAnother"); + assertTrue(pluginConsole.getTestErrorMessage().startsWith(expectedExceptionForFailedTest)); + } + + private void runCompileCommandByPallete(CompileCommand compileCommand) { + commandsPalette.openCommandPalette(); + commandsPalette.startCommandByDoubleClick(compileCommand.getName()); + consoles.waitExpectedTextIntoConsole(TestBuildConstants.BUILD_SUCCESS); + } +} diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4Test.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4Test.java index 641bb300bc4..b119d584e82 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4Test.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginJunit4Test.java @@ -12,23 +12,20 @@ import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.RUN_MENU; import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.TEST; -import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.Test.JUNIT_TEST; +import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.TEST_DROP_DAWN_ITEM; import static org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole.JunitMethodsState.FAILED; import static org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole.JunitMethodsState.IGNORED; import static org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole.JunitMethodsState.PASSED; import static org.testng.Assert.assertTrue; import com.google.inject.Inject; -import java.net.URL; import java.nio.file.Paths; import org.eclipse.che.api.workspace.server.DtoConverter; import org.eclipse.che.selenium.core.client.TestCommandServiceClient; import org.eclipse.che.selenium.core.client.TestProjectServiceClient; import org.eclipse.che.selenium.core.constant.TestBuildConstants; import org.eclipse.che.selenium.core.project.ProjectTemplates; -import org.eclipse.che.selenium.core.workspace.InjectTestWorkspace; import org.eclipse.che.selenium.core.workspace.TestWorkspace; -import org.eclipse.che.selenium.core.workspace.WorkspaceTemplate; import org.eclipse.che.selenium.pageobject.CodenvyEditor; import org.eclipse.che.selenium.pageobject.Consoles; import org.eclipse.che.selenium.pageobject.Ide; @@ -48,9 +45,7 @@ public class JavaTestPluginJunit4Test { private static final String PATH_TO_JUNIT4_TEST_CLASS = JUNIT4_PROJECT + "/src/test/java/org/eclipse/che/examples/AppOneTest.java"; private static final String PATH_TO_JUNIT4_ANOTHER_TEST = - JUNIT4_PROJECT + "/src/test/java/org/eclipse/che/examples/AppAppAnotherTest.java"; - private static final String PATH_TO_JUNIT4_TEST_SUITE = - JUNIT4_PROJECT + "/src/test/java/org/eclipse/che/examples/Junit4TestSuite.java"; + JUNIT4_PROJECT + "/src/test/java/org/eclipse/che/examples/AppAnotherTest.java"; public static final String APP_TEST_ONE_FAIL_OUTPUT_TEMPLATE = "java.lang.AssertionError\n" @@ -66,38 +61,40 @@ public class JavaTestPluginJunit4Test { + " at org.junit.Assert.assertTrue(Assert.java:41)\n" + " at org.junit.Assert.assertFalse(Assert.java:64)\n" + " at org.junit.Assert.assertFalse(Assert.java:74)\n" - + " at org.eclipse.che.examples.AppAnotherTest.shouldFailOfAppAnother(AppAnotherTest.java:33)"; + + " at org.eclipse.che.examples.AppAnotherTest.shouldFailOfAppAnother(AppAnotherTest.java:34)"; + @Inject private JavaTestRunnerPluginConsole pluginConsole; @Inject private ProjectExplorer projectExplorer; @Inject private Loader loader; @Inject private NotificationsPopupPanel notifications; @Inject private Menu menu; - @InjectTestWorkspace(template = WorkspaceTemplate.CODENVY_UBUNTU_JDK8) - private TestWorkspace ws; + @Inject private TestWorkspace ws; @Inject private Ide ide; @Inject private Consoles consoles; @Inject private CodenvyEditor editor; - @Inject private TestProjectServiceClient testProjectServiceClient; @Inject private TestCommandServiceClient testCommandServiceClient; @Inject private CommandsPalette commandsPalette; + @Inject private TestProjectServiceClient projectServiceClient; @BeforeClass public void prepareTestProject() throws Exception { CompileCommand compileCommand = new CompileCommand(); testCommandServiceClient.createCommand(DtoConverter.asDto(compileCommand), ws.getId()); - - URL resource = getClass().getResource("/projects/plugins/JavaTestRunnerPlugin/junit4-tests"); - testProjectServiceClient.importProject( + projectServiceClient.importProject( ws.getId(), - Paths.get(resource.toURI()), + Paths.get( + getClass() + .getResource("/projects/plugins/JavaTestRunnerPlugin/" + JUNIT4_PROJECT) + .toURI()), JUNIT4_PROJECT, ProjectTemplates.CONSOLE_JAVA_SIMPLE); ide.open(ws); loader.waitOnClosed(); projectExplorer.waitItem(JUNIT4_PROJECT); + projectExplorer.quickExpandWithJavaScript(); runCompileCommandByPallete(compileCommand); notifications.waitProgressPopupPanelClose(); } @@ -111,11 +108,10 @@ private void runCompileCommandByPallete(CompileCommand compileCommand) { @Test public void shouldExecuteJUnit4TestClassWithDifferentStatuses() throws InterruptedException { // given - projectExplorer.quickRevealToItemWithJavaScript(PATH_TO_JUNIT4_TEST_CLASS); projectExplorer.openItemByPath(PATH_TO_JUNIT4_TEST_CLASS); // when - menu.runCommand(RUN_MENU, TEST, JUNIT_TEST); + menu.runCommand(RUN_MENU, TEST, TEST_DROP_DAWN_ITEM); // then notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); @@ -124,9 +120,9 @@ public void shouldExecuteJUnit4TestClassWithDifferentStatuses() throws Interrupt pluginConsole.waitMethodMarkedAsPassed("shouldSuccessOfAppOne"); pluginConsole.waitMethodMarkedAsFailed("shouldFailOfAppOne"); pluginConsole.waitMethodMarkedAsIgnored("shouldBeIgnoredOfAppOne"); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(PASSED).size() == 1); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(FAILED).size() == 1); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(IGNORED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(PASSED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(FAILED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(IGNORED).size() == 1); String testErrorMessage = pluginConsole.getTestErrorMessage(); assertTrue( testErrorMessage.startsWith(APP_TEST_ONE_FAIL_OUTPUT_TEMPLATE), @@ -136,37 +132,35 @@ public void shouldExecuteJUnit4TestClassWithDifferentStatuses() throws Interrupt @Test(priority = 1) public void shouldExecuteJUnit4MethodWithDifferentStatuses() throws InterruptedException { // given - projectExplorer.quickRevealToItemWithJavaScript(PATH_TO_JUNIT4_ANOTHER_TEST); projectExplorer.openItemByPath(PATH_TO_JUNIT4_ANOTHER_TEST); editor.waitActiveEditor(); - editor.setCursorToDefinedLineAndChar(28, 17); + + editor.setCursorToDefinedLineAndChar(27, 5); // when - menu.runCommand(RUN_MENU, TEST, JUNIT_TEST); + menu.runCommand(RUN_MENU, TEST, TEST_DROP_DAWN_ITEM); notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); // then pluginConsole.waitFqnOfTesClassInResultTree("org.eclipse.che.examples.AppAnotherTest"); pluginConsole.waitMethodMarkedAsPassed("shouldSuccessOfAppAnother"); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(PASSED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(PASSED).size() == 1); // then - editor.setCursorToDefinedLineAndChar(33, 17); - menu.runCommand(RUN_MENU, TEST, JUNIT_TEST); + + editor.setCursorToDefinedLineAndChar(32, 5); + menu.runCommand(RUN_MENU, TEST, TEST_DROP_DAWN_ITEM); notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); pluginConsole.waitMethodMarkedAsFailed("shouldFailOfAppAnother"); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(FAILED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(FAILED).size() == 1); String testErrorMessage = pluginConsole.getTestErrorMessage(); assertTrue( testErrorMessage.startsWith(APP_TEST_ANOTHER_FAIL_OUTPUT_TEMPLATE), "Actual message was: " + testErrorMessage); - editor.setCursorToDefinedLineAndChar(39, 17); - menu.runCommand(RUN_MENU, TEST, JUNIT_TEST); + editor.setCursorToDefinedLineAndChar(38, 5); + menu.runCommand(RUN_MENU, TEST, TEST_DROP_DAWN_ITEM); notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); pluginConsole.waitMethodMarkedAsIgnored("shouldBeIgnoredOfAppAnother"); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(IGNORED).size() == 1); - assertTrue( - testErrorMessage.startsWith(APP_TEST_ANOTHER_FAIL_OUTPUT_TEMPLATE), - "Actual message was: " + testErrorMessage); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(IGNORED).size() == 1); } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginTestNgTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginTestNgTest.java index d0c8db280e1..6d29ba29260 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginTestNgTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/testrunner/JavaTestPluginTestNgTest.java @@ -12,7 +12,7 @@ import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.RUN_MENU; import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.TEST; -import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.Test.TEST_NG_TEST; +import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.TEST_NG_TEST_DROP_DAWN_ITEM; import static org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole.JunitMethodsState.FAILED; import static org.eclipse.che.selenium.pageobject.plugins.JavaTestRunnerPluginConsole.JunitMethodsState.PASSED; import static org.testng.Assert.assertTrue; @@ -50,10 +50,6 @@ public class JavaTestPluginTestNgTest { PROJECT + "/src/test/java/org/eclipse/che/examples/AppOneTest.java"; private static final String PATH_TO_ANOTHER_TEST_CLASS = PROJECT + "/src/test/java/org/eclipse/che/examples/AppAnotherTest.java"; - private static final String PATH_TO_MAIN_CLASS = - PROJECT + "/src/main/java/org/eclipse/che/examples/HelloWorld.java"; - private static final String PATH_TO_TEST_PACKAGE = - PROJECT + "/src/test/java/org/eclipse/che/examples"; public static final String APP_TEST_ONE_FAIL_OUTPUT_TEMPLATE = "[TestNG] Running: /home/user/che/ws-agent/temp/che-testng-suite.xmlexpected [false] but found [true]\n" @@ -70,18 +66,16 @@ public class JavaTestPluginTestNgTest { + " at org.testng.Assert.fail(Assert.java:94)\n" + " at org.testng.Assert.failNotEquals(Assert.java:494)\n" + " at org.testng.Assert.assertFalse(Assert.java:63)\n" - + " at org.testng.Assert.assertFalse(Assert.java:73)\n" - + " at org.eclipse.che.examples.AppAnotherTest.shouldFailOfAppAnother(AppAnotherTest.java:31)"; + + " at org.testng.Assert.assertFalse(Assert.java:73)"; public static final String END_OF_FAILED_TEST = - "at org.testng.CheTestNGLauncher.main(CheTestNGLauncher.java:43)===============================================Default SuiteTotal tests run: 1, Failures: 1, Skips: 0==============================================="; + "===============================================Default SuiteTotal tests run: 1, Failures: 1, Skips: 0==============================================="; @InjectTestWorkspace(template = WorkspaceTemplate.CODENVY_UBUNTU_JDK8) private TestWorkspace ws; @Inject private Ide ide; @Inject private DefaultTestUser user; - @Inject private JavaTestRunnerPluginConsole pluginConsole; @Inject private ProjectExplorer projectExplorer; @Inject private Loader loader; @@ -117,14 +111,14 @@ public void shouldExecuteTestClassSuccessfully() throws InterruptedException { // when editor.waitActiveEditor(); - menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST); + menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST_DROP_DAWN_ITEM); // then notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); pluginConsole.waitMethodMarkedAsPassed("shouldSuccessOfAppOne"); pluginConsole.waitMethodMarkedAsFailed("shouldFailOfAppOne"); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(PASSED).size() == 1); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(FAILED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(PASSED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(FAILED).size() == 1); String testErrorMessage = pluginConsole.getTestErrorMessage(); assertTrue( testErrorMessage.startsWith(APP_TEST_ONE_FAIL_OUTPUT_TEMPLATE), @@ -139,14 +133,38 @@ public void shouldExecuteTestMethodsSuccessfully() throws InterruptedException { // then editor.waitActiveEditor(); editor.setCursorToDefinedLineAndChar(25, 17); - menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST); + menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST_DROP_DAWN_ITEM); + notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); + pluginConsole.waitMethodMarkedAsPassed("shouldSuccessOfAppAnother"); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(PASSED).size() == 1); + editor.setCursorToDefinedLineAndChar(30, 17); + menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST_DROP_DAWN_ITEM); + pluginConsole.waitMethodMarkedAsFailed("shouldFailOfAppAnother"); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(FAILED).size() == 1); + String testErrorMessage = pluginConsole.getTestErrorMessage(); + assertTrue( + testErrorMessage.startsWith(APP_TEST_ANOTHER_FAIL_OUTPUT_TEMPLATE), + "Actual message was: " + testErrorMessage); + assertTrue( + testErrorMessage.endsWith(END_OF_FAILED_TEST), "Actual message was: " + testErrorMessage); + } + + @Test(priority = 2) + public void shouldExecuteAlltets() throws InterruptedException { + // given + projectExplorer.openItemByPath(PATH_TO_ANOTHER_TEST_CLASS); + + // then + editor.waitActiveEditor(); + editor.setCursorToDefinedLineAndChar(25, 17); + menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST_DROP_DAWN_ITEM); notifications.waitExpectedMessageOnProgressPanelAndClosed("Test runner executed successfully."); pluginConsole.waitMethodMarkedAsPassed("shouldSuccessOfAppAnother"); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(PASSED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(PASSED).size() == 1); editor.setCursorToDefinedLineAndChar(30, 17); - menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST); + menu.runCommand(RUN_MENU, TEST, TEST_NG_TEST_DROP_DAWN_ITEM); pluginConsole.waitMethodMarkedAsFailed("shouldFailOfAppAnother"); - assertTrue(pluginConsole.getAllMethodsMarkedDefinedStatus(FAILED).size() == 1); + assertTrue(pluginConsole.getAllNamesOfMethodsMarkedDefinedStatus(FAILED).size() == 1); String testErrorMessage = pluginConsole.getTestErrorMessage(); assertTrue( testErrorMessage.startsWith(APP_TEST_ANOTHER_FAIL_OUTPUT_TEMPLATE), diff --git a/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/pom.xml b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/pom.xml new file mode 100644 index 00000000000..fb16bf52422 --- /dev/null +++ b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + org.eclipse.che.examples + console-java-simple + jar + 1.0-SNAPSHOT + hello-app + http://maven.apache.org + + + junit + junit + 4.12 + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + lib/ + org.eclipse.che.examples.HelloWorld + + + + + + + diff --git a/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/Hello.java b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/Hello.java new file mode 100644 index 00000000000..c3d7f4def9b --- /dev/null +++ b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/Hello.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.example; + +public class Hello { + + + public boolean returnTrue() { + return true; + } + + public String returnHello () { + String message = "Hello IDE"; + return message; + } + +} diff --git a/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/HelloWorld.java b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/HelloWorld.java new file mode 100644 index 00000000000..5ca80679518 --- /dev/null +++ b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/main/java/org/eclipse/che/example/HelloWorld.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.example; +public class HelloWorld { + + public static void main(String[] argvs) { + String a = "Che"; + System.out.println("Hello World " + a + "!"); + } + + public boolean returnTrue() { + return true; + } +} diff --git a/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/suite/Junit4TestSuite.java b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/suite/Junit4TestSuite.java new file mode 100644 index 00000000000..08af2bc5f89 --- /dev/null +++ b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/suite/Junit4TestSuite.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.suite; + +import org.eclipse.che.tests.AppAnotherTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +/** + * JUnit 4x Test Suite + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({AppAnotherTest.class, + AppAnotherTest.class}) +public class Junit4TestSuite { +} diff --git a/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppAnotherTest.java b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppAnotherTest.java new file mode 100644 index 00000000000..19bc0480a35 --- /dev/null +++ b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppAnotherTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.tests; + +import org.eclipse.che.example.Hello; +import org.junit.Test; +import static org.junit.Assert.assertTrue; + +/** + * Unit test for simple App. + */ +public class AppAnotherTest { + + @Test + public void shouldSuccessOfAppAnother() { + assertTrue(new Hello().returnHello().startsWith("Hello")); + } + + @Test + public void shouldFailOfAppAnother() { + assertTrue(new Hello().returnHello().endsWith("Hello")); + } + + +} diff --git a/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppOneTest.java b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppOneTest.java new file mode 100644 index 00000000000..90ca4078848 --- /dev/null +++ b/selenium/che-selenium-test/src/test/resources/projects/plugins/JavaTestRunnerPlugin/junit4-tests-with-separeted-suites/src/test/java/org/eclipse/che/tests/AppOneTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.tests; + +import org.eclipse.che.example.HelloWorld; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Unit test for simple App. + */ +public class AppOneTest { + + @Test + public void shouldSuccessOfAppOne() { + assertTrue(new HelloWorld().returnTrue()); + } + + @Test + public void shouldFailOfAppOne() { + assertFalse(new HelloWorld().returnTrue()); + } + + @Test + @Ignore + public void shouldBeIgnoredOfAppOne(){ Assert.fail();} +} diff --git a/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml b/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml index 007d4194c37..4eda815927d 100644 --- a/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml +++ b/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml @@ -543,6 +543,7 @@ +