From f47e2415ad4176e25431e45992e06302276231bf Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Tue, 21 Feb 2017 21:52:18 +0100 Subject: [PATCH 1/9] Initial support for PHPUnit testing. Signed-off-by: Bartlomiej Laczkowski --- assembly/assembly-ide-war/pom.xml | 4 + .../resources/org/eclipse/che/ide/IDE.gwt.xml | 1 + assembly/assembly-wsagent-war/pom.xml | 4 + che.bat | 2 + .../testing/junit/server/JUnitTestRunner.java | 14 + .../testing/testng/server/TestNGRunner.java | 14 + .../che-plugin-testing-phpunit-ide/pom.xml | 80 ++++ .../testing/phpunit/ide/PHPUnitGinModule.java | 30 ++ .../phpunit/ide/PHPUnitTestAction.java | 53 +++ .../ide/PHPUnitTestLocalizationConstant.java | 35 ++ .../phpunit/ide/PHPUnitTestResources.java | 27 ++ .../ide/action/PHPRunContainerTestAction.java | 139 ++++++ .../ide/action/PHPRunScriptTestAction.java | 133 ++++++ .../plugin/testing/phpunit/PHPUnit.gwt.xml | 21 + ...PHPUnitTestLocalizationConstant.properties | 18 + .../plugin/testing/phpunit/ide/svg/test.svg | 18 + .../testing/phpunit/ide/svg/test_all.svg | 74 +++ .../che-plugin-testing-phpunit-server/pom.xml | 73 +++ .../phpunit/server/PHPUnitMessageParser.java | 144 ++++++ .../phpunit/server/PHPUnitTestEngine.java | 269 +++++++++++ .../server/PHPUnitTestResultsProvider.java | 176 +++++++ .../phpunit/server/PHPUnitTestRunner.java | 83 ++++ .../server/inject/PHPUnitGuiceModule.java | 32 ++ .../server/model/AbstractPHPUnitElement.java | 93 ++++ .../model/AbstractPHPUnitTestEvent.java | 69 +++ .../model/AbstractPHPUnitTestResult.java | 103 ++++ .../phpunit/server/model/PHPUnitTestCase.java | 101 ++++ .../server/model/PHPUnitTestException.java | 62 +++ .../phpunit/server/model/PHPUnitTestRoot.java | 37 ++ .../server/model/PHPUnitTestSuite.java | 123 +++++ .../server/model/PHPUnitTestWarning.java | 40 ++ .../server/model/PHPUnitTraceFrame.java | 80 ++++ .../phpunit-printer/PHPUnitLogger5x.php | 433 +++++++++++++++++ .../phpunit-printer/PHPUnitLogger6x.php | 448 ++++++++++++++++++ .../plugin-testing-phpunit/pom.xml | 39 ++ plugins/plugin-testing-php/pom.xml | 45 ++ .../che-plugin-testing-ide/pom.xml | 7 + .../che/plugin/testing/ide/TestResources.java | 20 +- .../plugin/testing/ide/TestServiceClient.java | 38 +- .../testing/ide/view/TestResultPresenter.java | 20 +- .../testing/ide/view/TestResultView.java | 11 + .../testing/ide/view/TestResultViewImpl.java | 128 +++-- .../navigation/SimpleLocationHandler.java | 149 ++++++ .../view/navigation/TestClassNavigation.java | 2 + .../factory/TestResultNodeFactory.java | 22 +- .../nodes/AbstractTestResultTreeNode.java | 105 ++++ .../navigation/nodes/TestResultClassNode.java | 1 + .../navigation/nodes/TestResultGroupNode.java | 1 + .../nodes/TestResultMethodNode.java | 1 + .../view/navigation/nodes/TestResultNode.java | 104 ++++ .../navigation/nodes/TestResultRootNode.java | 92 ++++ .../nodes/TestResultTraceFrameNode.java | 92 ++++ .../testing/ide/svg/test_result_failure.svg | 52 ++ .../testing/ide/svg/test_result_skipped.svg | 52 ++ .../testing/ide/svg/test_result_success.svg | 52 ++ .../ide/svg/test_result_trace_frame.svg | 21 + .../testing/ide/svg/test_result_warning.svg | 52 ++ .../ide/view/TestResultViewImpl.ui.xml | 38 +- plugins/pom.xml | 1 + pom.xml | 10 + wsagent/che-core-api-testing-shared/pom.xml | 9 + .../che/api/testing/shared/Failure.java | 1 + .../che/api/testing/shared/TestResult.java | 1 + .../shared/common/TestResultStatus.java | 22 + .../testing/shared/common/TestResultType.java | 22 + .../testing/shared/dto/SimpleLocationDto.java | 52 ++ .../api/testing/shared/dto/TestResultDto.java | 127 +++++ .../testing/shared/dto/TestResultRootDto.java | 111 +++++ .../shared/dto/TestResultTraceDto.java | 53 +++ .../shared/dto/TestResultTraceFrameDto.java | 52 ++ wsagent/che-core-api-testing/pom.xml | 7 + .../api/testing/server/TestingService.java | 49 +- .../testing/server/framework/TestRunner.java | 29 ++ 73 files changed, 4658 insertions(+), 65 deletions(-) create mode 100644 che.bat create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestAction.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestResources.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/PHPUnit.gwt.xml create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test.svg create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test_all.svg create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/inject/PHPUnitGuiceModule.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestWarning.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger6x.php create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml create mode 100644 plugins/plugin-testing-php/pom.xml create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_failure.svg create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_skipped.svg create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_success.svg create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_trace_frame.svg create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_warning.svg create mode 100644 wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultStatus.java create mode 100644 wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultType.java create mode 100644 wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java create mode 100644 wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java create mode 100644 wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java create mode 100644 wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceDto.java create mode 100644 wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java diff --git a/assembly/assembly-ide-war/pom.xml b/assembly/assembly-ide-war/pom.xml index bd097af5579..285699a0f81 100644 --- a/assembly/assembly-ide-war/pom.xml +++ b/assembly/assembly-ide-war/pom.xml @@ -268,6 +268,10 @@ org.eclipse.che.plugin che-plugin-testing-junit-ide + + org.eclipse.che.plugin + che-plugin-testing-phpunit-ide + org.eclipse.che.plugin che-plugin-testing-testng-ide diff --git a/assembly/assembly-ide-war/src/main/resources/org/eclipse/che/ide/IDE.gwt.xml b/assembly/assembly-ide-war/src/main/resources/org/eclipse/che/ide/IDE.gwt.xml index 4f25c968cf6..b0213edb88d 100644 --- a/assembly/assembly-ide-war/src/main/resources/org/eclipse/che/ide/IDE.gwt.xml +++ b/assembly/assembly-ide-war/src/main/resources/org/eclipse/che/ide/IDE.gwt.xml @@ -90,6 +90,7 @@ + diff --git a/assembly/assembly-wsagent-war/pom.xml b/assembly/assembly-wsagent-war/pom.xml index 39be203ec6c..c4ec005f5b4 100644 --- a/assembly/assembly-wsagent-war/pom.xml +++ b/assembly/assembly-wsagent-war/pom.xml @@ -228,6 +228,10 @@ org.eclipse.che.plugin che-plugin-testing-junit-server + + org.eclipse.che.plugin + che-plugin-testing-phpunit-server + org.eclipse.che.plugin che-plugin-testing-testng-server diff --git a/che.bat b/che.bat new file mode 100644 index 00000000000..f4e6e9d8414 --- /dev/null +++ b/che.bat @@ -0,0 +1,2 @@ +docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v //c/Users/Bartek/git/che-bart:/repo -v //c//tmp:/data eclipse/che:latest start +pause \ No newline at end of file diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-server/src/main/java/org/eclipse/che/plugin/testing/junit/server/JUnitTestRunner.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-server/src/main/java/org/eclipse/che/plugin/testing/junit/server/JUnitTestRunner.java index f76dbed8d7c..f618b1f4e78 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-server/src/main/java/org/eclipse/che/plugin/testing/junit/server/JUnitTestRunner.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-server/src/main/java/org/eclipse/che/plugin/testing/junit/server/JUnitTestRunner.java @@ -27,6 +27,8 @@ import org.eclipse.che.api.testing.server.framework.TestRunner; import org.eclipse.che.api.testing.shared.Failure; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.dto.server.DtoFactory; import org.eclipse.che.plugin.testing.classpath.server.TestClasspathProvider; import org.eclipse.che.plugin.testing.classpath.server.TestClasspathRegistry; @@ -283,4 +285,16 @@ private TestResult run3xTestClasses(Class... classes) throws Exception { dtoResult.setFailures(jUnitFailures); return dtoResult; } + + @Override + public TestResultRootDto runTests(Map testParameters) throws Exception { + // New API - Not supported yet + return null; + } + + @Override + public List getTestResults(List testResultsPath) { + // New API - Not supported yet + return null; + } } diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-server/src/main/java/org/eclipse/che/plugin/testing/testng/server/TestNGRunner.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-server/src/main/java/org/eclipse/che/plugin/testing/testng/server/TestNGRunner.java index 153cd423d98..2df9596cfea 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-server/src/main/java/org/eclipse/che/plugin/testing/testng/server/TestNGRunner.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-server/src/main/java/org/eclipse/che/plugin/testing/testng/server/TestNGRunner.java @@ -28,6 +28,8 @@ import org.eclipse.che.api.testing.server.framework.TestRunner; import org.eclipse.che.api.testing.shared.Failure; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.dto.server.DtoFactory; import org.eclipse.che.plugin.testing.classpath.server.TestClasspathProvider; import org.eclipse.che.plugin.testing.classpath.server.TestClasspathRegistry; @@ -261,4 +263,16 @@ private TestResult runTestXML(String projectAbsolutePath, String xmlPath) throws dtoResult.setFailures(testNGFailures); return dtoResult; } + + @Override + public TestResultRootDto runTests(Map testParameters) throws Exception { + // New API - Not supported yet + return null; + } + + @Override + public List getTestResults(List testResultsPath) { + // New API - Not supported yet + return null; + } } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml new file mode 100644 index 00000000000..04306d5b6cf --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml @@ -0,0 +1,80 @@ + + + + 4.0.0 + + che-plugin-testing-phpunit + org.eclipse.che.plugin + 5.3.0-SNAPSHOT + + che-plugin-testing-phpunit-ide + Che Plugin :: PHP Testing :: PHPUnit IDE + + + com.google.inject + guice + + + javax.validation + validation-api + + + org.eclipse.che.core + che-core-api-testing-shared + + + org.eclipse.che.core + che-core-commons-gwt + + + org.eclipse.che.core + che-core-ide-api + + + org.eclipse.che.core + che-core-ide-app + + + org.eclipse.che.plugin + che-plugin-testing-ide + + + org.vectomatic + lib-gwt-svg + + + com.google.gwt + gwt-user + provided + + + com.google.gwt.inject + gin + provided + + + + + + src/main/java + + **/*.java + + + + src/main/resources + + + + diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java new file mode 100644 index 00000000000..640e93266f2 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.ide; + +import org.eclipse.che.ide.api.extension.ExtensionGinModule; +import org.eclipse.che.plugin.testing.ide.TestAction; + +import com.google.gwt.inject.client.AbstractGinModule; +import com.google.gwt.inject.client.multibindings.GinMultibinder; + +/** + * PHPUnit Gin module. + * + * @author Bartlomiej Laczkowski + */ +@ExtensionGinModule +public class PHPUnitGinModule extends AbstractGinModule { + @Override + protected void configure() { + GinMultibinder.newSetBinder(binder(), TestAction.class).addBinding().to(PHPUnitTestAction.class); + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestAction.java new file mode 100644 index 00000000000..fec186cf6b3 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestAction.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.ide; + +import org.eclipse.che.ide.api.action.Action; +import org.eclipse.che.ide.api.action.ActionManager; +import org.eclipse.che.ide.api.action.DefaultActionGroup; +import org.eclipse.che.ide.api.keybinding.KeyBindingAgent; +import org.eclipse.che.plugin.testing.ide.TestAction; +import org.eclipse.che.plugin.testing.phpunit.ide.action.PHPRunContainerTestAction; +import org.eclipse.che.plugin.testing.phpunit.ide.action.PHPRunScriptTestAction; + +import com.google.inject.Inject; + +/** + * PHPUnit test action implementation. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestAction implements TestAction { + + private final Action runScriptTestAction; + private PHPRunContainerTestAction runContainerTestAction; + + @Inject + public PHPUnitTestAction(ActionManager actionManager, PHPRunScriptTestAction runScriptTestAction, + PHPRunContainerTestAction runAllTestAction, KeyBindingAgent keyBinding) { + actionManager.registerAction("PHPRunScriptTestAction", runScriptTestAction); + actionManager.registerAction("PHPRunAllTestAction", runAllTestAction); + this.runScriptTestAction = runScriptTestAction; + this.runContainerTestAction = runAllTestAction; + } + + @Override + public void addMainMenuItems(DefaultActionGroup testMainMenu) { + testMainMenu.add(runScriptTestAction); + testMainMenu.add(runContainerTestAction); + } + + @Override + public void addContextMenuItems(DefaultActionGroup testContextMenu) { + testContextMenu.add(runScriptTestAction); + testContextMenu.add(runContainerTestAction); + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java new file mode 100644 index 00000000000..d15374e69d5 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.ide; + +import com.google.gwt.i18n.client.Messages; + +/** + * Localization constants. Interface to represent the constants defined in + * resource bundle: 'PHPUnitTestLocalizationConstant.properties'. + * + * @author Bartlomiej Laczkowski + */ +public interface PHPUnitTestLocalizationConstant extends Messages { + + @Key("action.runScript.title") + String actionRunScriptTitle(); + + @Key("action.runScript.description") + String actionRunScriptDescription(); + + @Key("action.runContainer.title") + String actionRunContainerTitle(); + + @Key("action.runContainer.description") + String actionRunContainerDescription(); + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestResources.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestResources.java new file mode 100644 index 00000000000..1c73817d8b1 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestResources.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.ide; + +import org.vectomatic.dom.svg.ui.SVGResource; + +import com.google.gwt.resources.client.ClientBundle; + +/** + * PHPUnit ide part resources. + * + * @author Bartlomiej Laczkowski + */ +public interface PHPUnitTestResources extends ClientBundle { + + @Source("org/eclipse/che/plugin/testing/phpunit/ide/svg/test.svg") + SVGResource testIcon(); + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java new file mode 100644 index 00000000000..20142f1d62f --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.ide.action; + +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; +import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import javax.validation.constraints.NotNull; + +import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.api.promises.client.OperationException; +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.promises.client.PromiseError; +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; +import org.eclipse.che.ide.api.action.ActionEvent; +import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.notification.StatusNotification; +import org.eclipse.che.ide.api.resources.Container; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.selection.Selection; +import org.eclipse.che.ide.api.selection.SelectionAgent; +import org.eclipse.che.ide.resources.tree.ContainerNode; +import org.eclipse.che.plugin.testing.ide.TestServiceClient; +import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; +import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestLocalizationConstant; +import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestResources; + +import com.google.inject.Inject; + +/** + * "Run Container" PHPUnit test action. + * + * @author Bartlomiej Laczkowski + */ +public class PHPRunContainerTestAction extends AbstractPerspectiveAction { + + private final NotificationManager notificationManager; + private final TestResultPresenter presenter; + private final TestServiceClient service; + private final AppContext appContext; + private final SelectionAgent selectionAgent; + + @Inject + public PHPRunContainerTestAction(PHPUnitTestResources resources, NotificationManager notificationManager, + AppContext appContext, TestResultPresenter presenter, TestServiceClient service, + SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunContainerTitle(), + localization.actionRunScriptDescription(), null, resources.testIcon()); + this.notificationManager = notificationManager; + this.presenter = presenter; + this.service = service; + this.appContext = appContext; + this.selectionAgent = selectionAgent; + } + + @Override + public void actionPerformed(ActionEvent e) { + final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE); + notificationManager.notify(notification); + final Selection selection = selectionAgent.getSelection(); + final Object possibleNode = selection.getHeadElement(); + if (possibleNode instanceof ContainerNode) { + Container container = ((ContainerNode) possibleNode).getData(); + final Project project = appContext.getRootProject(); + Map parameters = new HashMap<>(); + parameters.put("testTarget", container.getLocation().toString()); + Promise testResultPromise = service.runTests("PHPUnit", project.getPath(), parameters); + testResultPromise.then(new Operation() { + @Override + public void apply(TestResultRootDto result) throws OperationException { + notification.setStatus(SUCCESS); + if (result.getStatus() == TestResultStatus.SUCCESS) { + notification.setTitle("Test runner executed successfully"); + notification.setContent("All tests are passed"); + } else { + notification.setTitle("Test runner executed successfully with test failures."); + notification.setContent("Some test(s) failed.\n"); + } + presenter.handleResponse(result); + } + }).catchError(new Operation() { + @Override + public void apply(PromiseError exception) throws OperationException { + final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() + : "Failed to run test cases"; + notification.setContent(errorMessage); + notification.setStatus(FAIL); + } + }); + } + } + + @Override + public void updateInPerspective(@NotNull ActionEvent e) { + if ((appContext.getRootProject() == null)) { + e.getPresentation().setVisible(true); + e.getPresentation().setEnabled(false); + return; + } + final Selection selection = selectionAgent.getSelection(); + if (selection == null || selection.isEmpty()) { + e.getPresentation().setEnabled(false); + return; + } + if (selection.isMultiSelection()) { + e.getPresentation().setEnabled(false); + return; + } + final Object possibleNode = selection.getHeadElement(); + if (possibleNode instanceof ContainerNode) { + String projectType = ((ContainerNode) possibleNode).getData().getProject().getType(); + if ("php".equalsIgnoreCase(projectType) || "composer".equalsIgnoreCase(projectType)) { + e.getPresentation().setVisible(true); + e.getPresentation().setEnabled(true); + return; + } + } + e.getPresentation().setVisible(false); + e.getPresentation().setEnabled(false); + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java new file mode 100644 index 00000000000..dd0ecd625bb --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.ide.action; + +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; +import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import javax.validation.constraints.NotNull; + +import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.api.promises.client.OperationException; +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.promises.client.PromiseError; +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; +import org.eclipse.che.ide.api.action.ActionEvent; +import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.notification.StatusNotification; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.VirtualFile; +import org.eclipse.che.ide.api.selection.Selection; +import org.eclipse.che.ide.api.selection.SelectionAgent; +import org.eclipse.che.ide.resources.tree.FileNode; +import org.eclipse.che.plugin.testing.ide.TestServiceClient; +import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; +import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestLocalizationConstant; +import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestResources; + +import com.google.inject.Inject; + +/** + * "Run Script" PHPUnit test action. + * + * @author Bartlomiej Laczkowski + */ +public class PHPRunScriptTestAction extends AbstractPerspectiveAction { + + private final NotificationManager notificationManager; + private final TestResultPresenter presenter; + private final TestServiceClient service; + private final AppContext appContext; + private final SelectionAgent selectionAgent; + + @Inject + public PHPRunScriptTestAction(PHPUnitTestResources resources, NotificationManager notificationManager, + AppContext appContext, TestResultPresenter presenter, TestServiceClient service, + SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunScriptTitle(), + localization.actionRunScriptDescription(), null, resources.testIcon()); + this.notificationManager = notificationManager; + this.presenter = presenter; + this.service = service; + this.appContext = appContext; + this.selectionAgent = selectionAgent; + } + + @Override + public void actionPerformed(ActionEvent e) { + final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE); + notificationManager.notify(notification); + final Selection selection = selectionAgent.getSelection(); + final Object possibleNode = selection.getHeadElement(); + if (possibleNode instanceof FileNode) { + VirtualFile file = ((FileNode) possibleNode).getData(); + final Project project = appContext.getRootProject(); + Map parameters = new HashMap<>(); + parameters.put("testTarget", file.getLocation().toString()); + Promise testResultPromise = service.runTests("PHPUnit", project.getPath(), parameters); + testResultPromise.then(new Operation() { + @Override + public void apply(TestResultRootDto result) throws OperationException { + notification.setStatus(SUCCESS); + if (result.getStatus() == TestResultStatus.SUCCESS) { + notification.setTitle("Test runner executed successfully"); + notification.setContent("All tests are passed"); + } else { + notification.setTitle("Test runner executed successfully with test failures."); + notification.setContent("Some test(s) failed.\n"); + } + presenter.handleResponse(result); + } + }).catchError(new Operation() { + @Override + public void apply(PromiseError exception) throws OperationException { + final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() + : "Failed to run test cases"; + notification.setContent(errorMessage); + notification.setStatus(FAIL); + } + }); + } + } + + @Override + public void updateInPerspective(@NotNull ActionEvent e) { + if ((appContext.getRootProject() == null)) { + e.getPresentation().setVisible(true); + e.getPresentation().setEnabled(false); + return; + } + final Selection selection = selectionAgent.getSelection(); + if (selection == null || selection.isEmpty()) { + e.getPresentation().setEnabled(false); + return; + } + if (selection.isMultiSelection()) { + e.getPresentation().setEnabled(false); + return; + } + final Object possibleNode = selection.getHeadElement(); + boolean enable = possibleNode instanceof FileNode + && ((FileNode) possibleNode).getData().getExtension().equals("php"); + e.getPresentation().setEnabled(enable); + e.getPresentation().setVisible(enable); + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/PHPUnit.gwt.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/PHPUnit.gwt.xml new file mode 100644 index 00000000000..f020bd77ec2 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/PHPUnit.gwt.xml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties new file mode 100644 index 00000000000..84b7c7c4757 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2012-2017 Codenvy, S.A. +# 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: +# Rogue Wave Software, Inc. - initial API and implementation +# + + + +##### Actions ##### +action.runScript.title = PHPUnit Script +action.runScript.description = Run the currently selected PHPUnit test script +action.runContainer.title = PHPUnit Container +action.runContainer.description = Run all the tests available under PHPUnit test container diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test.svg b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test.svg new file mode 100644 index 00000000000..79b385d2dd6 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test.svg @@ -0,0 +1,18 @@ + + + + + + + diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test_all.svg b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test_all.svg new file mode 100644 index 00000000000..42353ffae01 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/svg/test_all.svg @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml new file mode 100644 index 00000000000..c2bc2a19097 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml @@ -0,0 +1,73 @@ + + + + 4.0.0 + + che-plugin-testing-phpunit + org.eclipse.che.plugin + 5.3.0-SNAPSHOT + + che-plugin-testing-phpunit-server + Che Plugin :: PHP Testing :: PHPUnit Server + + + com.google.code.gson + gson + + + com.google.inject + guice + + + com.google.inject.extensions + guice-multibindings + + + commons-io + commons-io + + + javax.inject + javax.inject + + + org.eclipse.che.core + che-core-api-core + + + org.eclipse.che.core + che-core-api-dto + + + org.eclipse.che.core + che-core-api-project + + + org.eclipse.che.core + che-core-api-testing + + + org.eclipse.che.core + che-core-api-testing-shared + + + org.eclipse.che.core + che-core-commons-inject + + + org.slf4j + slf4j-api + + + diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java new file mode 100644 index 00000000000..1353b000959 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server; + +import java.util.ArrayList; +import java.util.Map; + +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestCase; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestException; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestRoot; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestSuite; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestWarning; + +/** + * PHPUnit message parser. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitMessageParser { + + public static final String CALL_DYNAMIC = "->"; + public static final String CALL_STATIC = "::"; + private static final String ELEMENT_EVENT = "event"; + private static final String ELEMENT_EXCEPTION = "exception"; + private static final String ELEMENT_TARGET_TESTSUITE = "testsuite"; + private static final String ELEMENT_TARGET_TESTCASE = "testcase"; + private static final String ELEMENT_TEST = "test"; + private static final String ELEMENT_WARNINGS = "warnings"; + public static final String PROPERTY_CLASS = "class"; + public static final String PROPERTY_CODE = "code"; + public static final String PROPERTY_COUNT = "tests"; + public static final String PROPERTY_FILE = "file"; + public static final String PROPERTY_FILTERED = "filtered"; + public static final String PROPERTY_LINE = "line"; + public static final String PROPERTY_MESSAGE = "message"; + public static final String PROPERTY_DIFF = "diff"; + public static final String PROPERTY_NAME = "name"; + public static final String PROPERTY_TIME = "time"; + public static final String PROPERTY_TARGET = "target"; + public static final String PROPERTY_TRACE = "trace"; + public static final String STATUS_ERROR = "error"; + public static final String STATUS_FAIL = "fail"; + public static final String STATUS_INCOMPLETE = "incomplete"; + public static final String STATUS_PASS = "pass"; + public static final String STATUS_SKIP = "skip"; + public static final String TAG_END = "end"; + public static final String TAG_START = "start"; + + private PHPUnitTestSuite currentGroup; + private PHPUnitTestCase currentTestCase; + + public PHPUnitMessageParser(PHPUnitTestRoot testRoot) { + this.currentGroup = testRoot; + } + + /** + * Parses provided message from PHPUnit printer. + * + * @param message + */ + public void parse(final Map message) { + if (message == null) { + return; + } + final String target = (String) message.get(PROPERTY_TARGET); + final String event = (String) message.get(ELEMENT_EVENT); + final Map mTest = (Map) message.get(ELEMENT_TEST); + if (target.equals(ELEMENT_TARGET_TESTSUITE)) { + parseGroupStart(event, mTest); + if (event.equals(TAG_END)) { + parseGroupEnd(); + } + } else if (target.equals(ELEMENT_TARGET_TESTCASE)) { + if (event.equals(TAG_START)) { + parseTestStart(event, mTest); + } else { + parseTestEnd(message, event, mTest); + } + } + } + + private void parseGroupStart(final String event, final Map mTest) { + if (event.equals(TAG_START)) { + final PHPUnitTestSuite group = new PHPUnitTestSuite(mTest, currentGroup); + currentGroup.addChild(group, false); + group.setParent(currentGroup); + currentGroup = group; + } + } + + private void parseGroupEnd() { + final PHPUnitTestSuite group = currentGroup; + currentGroup = (PHPUnitTestSuite) currentGroup.getParent(); + currentGroup.addChild(group, true); + } + + private void parseTestStart(final String event, final Map mTest) { + final PHPUnitTestCase testCase = new PHPUnitTestCase(mTest, currentGroup, event); + currentTestCase = testCase; + currentGroup.addChild(testCase, false); + } + + private void parseTestEnd(final Map message, final String event, final Map mTest) { + final PHPUnitTestCase testCase = currentTestCase; + testCase.updateStatus(event); + final Map exception = (Map) message.get(ELEMENT_EXCEPTION); + if (exception != null) + parseException(testCase, exception); + final Map warnings = (Map) message.get(ELEMENT_WARNINGS); + if (warnings != null) + parseWarnings(testCase, warnings); + final String time = (String) message.get(PROPERTY_TIME); + testCase.setTime(Double.valueOf(time)); + currentGroup.addChild(testCase, true); + } + + /** + * @param testCase + * @param exception + */ + private void parseException(final PHPUnitTestCase testCase, final Map exception) { + testCase.setException(new PHPUnitTestException(exception, testCase)); + } + + private void parseWarnings(final PHPUnitTestCase testCase, final Map warnings) { + Map mWarning; + // keep initial order + for (int i = 0; (mWarning = (Map) warnings.get(String.valueOf(i))) != null; ++i) { + if (testCase.getWarnings() == null) + testCase.setWarnings(new ArrayList(warnings.size())); + final PHPUnitTestWarning warning = new PHPUnitTestWarning(mWarning, testCase); + testCase.getWarnings().add(i, warning); + } + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java new file mode 100644 index 00000000000..263c784310c --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java @@ -0,0 +1,269 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server; + +import static org.eclipse.che.plugin.testing.phpunit.server.PHPUnitTestRunner.LOG; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +import org.apache.commons.io.FileUtils; +import org.eclipse.che.api.core.ServerException; +import org.eclipse.che.api.core.util.CommandLine; +import org.eclipse.che.api.core.util.LineConsumer; +import org.eclipse.che.api.core.util.ProcessUtil; +import org.eclipse.che.api.project.server.ProjectManager; +import org.eclipse.che.api.project.server.VirtualFileEntry; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.api.vfs.Path; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestRoot; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.internal.LinkedTreeMap; + +/** + * PHPUnit tests running engine. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestEngine { + + private final class PrinterListener implements Runnable { + + private ServerSocket serverSocket; + private Socket socket; + private Gson gson = new GsonBuilder().create(); + private ExecutorService threadExecutor; + + public PrinterListener() { + threadExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + final Thread thread = new Thread(r, "PHPUnitPrinterListener"); + thread.setDaemon(true); + return thread; + } + }); + } + + @Override + public void run() { + try { + serverSocket = new ServerSocket(PRINTER_PORT, 1); + serverSocket.setSoTimeout(10000); + serverSocket.setReuseAddress(true); + // Release engine to perform tests + latchReady.countDown(); + socket = serverSocket.accept(); + handleReport(socket); + } catch (final IOException e) { + Thread.currentThread().interrupt(); + LOG.error(e.getMessage(), e); + } finally { + shutdown(); + } + } + + void shutdown() { + try { + if (socket != null && !socket.isClosed()) + socket.close(); + } catch (final Exception e) { + } + try { + if (serverSocket != null && !serverSocket.isClosed()) + serverSocket.close(); + } catch (final IOException e) { + } + threadExecutor.shutdown(); + } + + void startup() { + threadExecutor.submit(this); + } + + @SuppressWarnings("unchecked") + private void handleReport(final Socket socket) { + try { + final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); + final PHPUnitMessageParser messageParser = new PHPUnitMessageParser(phpTestsRoot); + String line; + Map value = null; + while ((line = reader.readLine()) != null) { + try { + value = gson.fromJson(line, LinkedTreeMap.class); + messageParser.parse(value); + } catch (final Throwable e) { + value = null; + } + } + latchDone.countDown(); + shutdown(); + } catch (final IOException e) { + Thread.currentThread().interrupt(); + shutdown(); + } + } + } + + private static final String PRINTER_NAME_V5X = "PHPUnitLogger5x"; + private static final String PRINTER_NAME_V6X = "PHPUnitLogger6x"; + private static final String PRINTER_DIRECTORY = "phpunit-printer"; + private static final String PHPUNIT_GLOBAL = "phpunit"; + private static final String PHPUNIT_COMPOSER = "/vendor/bin/phpunit"; + private static final int PRINTER_PORT = 7478; + + private final ProjectManager projectManager; + private final CountDownLatch latchReady = new CountDownLatch(1); + private final CountDownLatch latchDone = new CountDownLatch(1); + + private PHPUnitTestRoot phpTestsRoot; + private PHPUnitTestResultsProvider testResultsProvider; + + public PHPUnitTestEngine(ProjectManager projectManager) { + this.projectManager = projectManager; + } + + /** + * Executes PHP unit tests with the use of provided parameters. + * + * @param testParameters + * @return + * @throws Exception + */ + public TestResultRootDto executeTests(Map testParameters) throws Exception { + String projectPath = testParameters.get("projectPath"); + String projectAbsolutePath = testParameters.get("absoluteProjectPath"); + String testTarget = testParameters.get("testTarget"); + Path testTargetAbsolutePath = Path.of(projectAbsolutePath).newPath(Path.of(testTarget).subPath(1)); + String testTargetWorkingDirectory = testTargetAbsolutePath.getParent().toString(); + String testTargetName = testTargetAbsolutePath.getName(); + // Get appropriate path to executable + String phpUnitExecutable = PHPUNIT_GLOBAL; + if (hasComposerRunner(projectPath)) { + phpUnitExecutable = projectAbsolutePath + PHPUNIT_COMPOSER; + } + // Get appropriate logger for PHP unit version + String phpPrinterName = getPrinterName(phpUnitExecutable, testTargetWorkingDirectory); + final File printerFile = getPrinterFile(phpPrinterName); + final String printerDirAbsolutePath = printerFile.getParentFile().getAbsolutePath(); + PrinterListener printerListener = new PrinterListener(); + printerListener.startup(); + // Reset provider & tests root + testResultsProvider = new PHPUnitTestResultsProvider(); + phpTestsRoot = new PHPUnitTestRoot(); + // Wait for listener thread to be started + try { + latchReady.await(); + } catch (InterruptedException e) { + LOG.error(e.getMessage(), e); + } + final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--include-path", printerDirAbsolutePath, + "--printer", phpPrinterName, testTargetName); + Process processBuildClassPath = new ProcessBuilder().redirectErrorStream(true) + .directory(new File(testTargetWorkingDirectory)).command(cmdRunTests.toShellCommand()).start(); + ProcessUtil.process(processBuildClassPath, LineConsumer.DEV_NULL); + processBuildClassPath.waitFor(); + try { + latchDone.await(); + } catch (InterruptedException e) { + LOG.error(e.getMessage(), e); + } + return testResultsProvider.getTestResultsRoot(phpTestsRoot); + } + + /** + * Returns test results for given result path. + * + * @param testResultsPath + * @return test results for given result path + */ + public List getTestResults(List testResultsPath) { + return testResultsProvider.getTestResults(testResultsPath); + } + + private String getPrinterName(String phpUnitExecutable, String testTargetWorkingDirectory) { + final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--atleast-version", "6"); + Process processBuildClassPath; + try { + processBuildClassPath = new ProcessBuilder().redirectErrorStream(true) + .directory(new File(testTargetWorkingDirectory)).command(cmdRunTests.toShellCommand()).start(); + ProcessUtil.process(processBuildClassPath, LineConsumer.DEV_NULL); + int code = processBuildClassPath.waitFor(); + if (code == 0) + return PRINTER_NAME_V6X; + } catch (Exception e) { + } + return PRINTER_NAME_V5X; + } + + private File getPrinterFile(String phpLoggerName) { + final String phpLoggerLocation = PRINTER_DIRECTORY + '/' + phpLoggerName + ".php"; + final File tmpDir = new File(System.getProperty("java.io.tmpdir")); + final File tmpPrinterFile = new File(tmpDir, phpLoggerLocation); + if (!tmpPrinterFile.exists()) { + try { + tmpPrinterFile.getParentFile().mkdir(); + tmpPrinterFile.createNewFile(); + InputStream printerFileContent = getClass().getClassLoader().getResourceAsStream(phpLoggerLocation); + FileUtils.copyInputStreamToFile(printerFileContent, tmpPrinterFile); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } finally { + if (tmpPrinterFile.exists()) { + tmpPrinterFile.getParentFile().deleteOnExit(); + tmpPrinterFile.deleteOnExit(); + } + } + } + return tmpPrinterFile; + } + + @SuppressWarnings("unchecked") + private boolean hasComposerRunner(String projectPath) { + VirtualFileEntry composerJson; + try { + composerJson = projectManager.getProjectsRoot().getChild(projectPath + "/composer.json"); + if (composerJson == null) + return false; + } catch (ServerException e) { + return false; + } + try (InputStream inputStream = composerJson.getVirtualFile().getContent(); + InputStreamReader reader = new InputStreamReader(inputStream);) { + Gson gson = new GsonBuilder().create(); + Map composerJsonMap = gson.fromJson(reader, LinkedTreeMap.class); + Map requireDev = (Map) composerJsonMap.get("require-dev"); + if (requireDev.get("phpunit/phpunit") != null) + return true; + Map require = (Map) composerJsonMap.get("require"); + if (require.get("phpunit/phpunit") != null) + return true; + } catch (Exception e) { + LOG.error(e.getMessage(), e); + } + return false; + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java new file mode 100644 index 00000000000..16b1ab91a2a --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.api.testing.shared.common.TestResultType; +import org.eclipse.che.api.testing.shared.dto.SimpleLocationDto; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceFrameDto; +import org.eclipse.che.dto.server.DtoFactory; +import org.eclipse.che.plugin.testing.phpunit.server.model.AbstractPHPUnitTestEvent; +import org.eclipse.che.plugin.testing.phpunit.server.model.AbstractPHPUnitTestResult; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestCase; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestRoot; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestSuite; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTraceFrame; + +/** + * Test results provider. + * + * @author Bartlomiej Laczkowski + */ +class PHPUnitTestResultsProvider { + + private final Map testResultsCache = new HashMap<>(); + + /** + * Builds and returns test results root. + * + * @param resultsRoot + * @return test results root + */ + public TestResultRootDto getTestResultsRoot(PHPUnitTestRoot resultsRoot) { + TestResultRootDto testResultRootDto = DtoFactory.getInstance().createDto(TestResultRootDto.class); + testResultRootDto.setTestFrameworkName(PHPUnitTestRunner.RUNNER_ID); + testResultRootDto.setStatus(getStatus(resultsRoot.getStatus())); + testResultRootDto.setResultPath(Collections.singletonList("php-tests-root")); + testResultRootDto.setName(getRootLabel(resultsRoot.getStatus())); + testResultRootDto.setInfoText(getTimeString(resultsRoot.getTime())); + // Add PHP related test result to cache + testResultsCache.put(getKey(testResultRootDto.getResultPath()), resultsRoot); + return testResultRootDto; + } + + /** + * Builds and returns test results for given path. + * + * @param testResultsPath + * @return test results for given path + */ + public List getTestResults(List testResultsPath) { + String key = getKey(testResultsPath); + AbstractPHPUnitTestResult phpTestResult = testResultsCache.get(key); + int testChildCounter = 0; + List testResults = new ArrayList<>(); + for (AbstractPHPUnitTestResult phpChildResult : phpTestResult.getChildren()) { + List childResultsPath = new ArrayList<>(testResultsPath); + childResultsPath.add(String.valueOf(testChildCounter++)); + TestResultDto testResultDto = getTestResult(phpChildResult, childResultsPath); + testResults.add(testResultDto); + } + return testResults; + } + + private TestResultDto getTestResult(AbstractPHPUnitTestResult phpTestResult, List testResultPath) { + TestResultDto testResultDto = DtoFactory.getInstance().createDto(TestResultDto.class); + testResultDto.setStatus(getStatus(phpTestResult.getStatus())); + testResultDto.setResultPath(testResultPath); + testResultDto.setName(phpTestResult.getName()); + testResultDto.setTrace(getTestTrace(phpTestResult)); + testResultDto.setInfoText(getTimeString(phpTestResult.getTime())); + testResultDto.setType( + phpTestResult instanceof PHPUnitTestSuite ? TestResultType.TEST_SUITE : TestResultType.TEST_CASE); + SimpleLocationDto simpleLocationDto = DtoFactory.getInstance().createDto(SimpleLocationDto.class); + simpleLocationDto.setResourcePath(phpTestResult.getFile()); + simpleLocationDto.setLineNumber(phpTestResult.getLine()); + testResultDto.setTestLocation(simpleLocationDto); + // Add PHP related test result to cache + testResultsCache.put(getKey(testResultDto.getResultPath()), phpTestResult); + return testResultDto; + } + + private TestResultTraceDto getTestTrace(AbstractPHPUnitTestResult phpTestResult) { + TestResultTraceDto testResultTraceDto = DtoFactory.getInstance().createDto(TestResultTraceDto.class); + if (phpTestResult instanceof PHPUnitTestCase) { + PHPUnitTestCase phpTestCase = (PHPUnitTestCase) phpTestResult; + AbstractPHPUnitTestEvent phpTestEvent = phpTestCase.getException(); + if (phpTestEvent != null) { + testResultTraceDto.setMessage(phpTestEvent.getMessage()); + List traceFrames = new ArrayList<>(); + for (PHPUnitTraceFrame phpTraceFrame : phpTestEvent.getTrace()) { + TestResultTraceFrameDto testResultTraceFrameDto = DtoFactory.getInstance() + .createDto(TestResultTraceFrameDto.class); + testResultTraceFrameDto.setTraceFrame(phpTraceFrame.toString()); + SimpleLocationDto simpleLocationDto = DtoFactory.getInstance().createDto(SimpleLocationDto.class); + simpleLocationDto.setResourcePath(phpTraceFrame.getFile()); + simpleLocationDto.setLineNumber(phpTraceFrame.getLine()); + testResultTraceFrameDto.setLocation(simpleLocationDto); + traceFrames.add(testResultTraceFrameDto); + } + testResultTraceDto.setTraceFrames(traceFrames); + return testResultTraceDto; + } + } + return null; + } + + private String getKey(List resultsPath) { + StringBuilder sb = new StringBuilder(); + Iterator resultsPathIterator = resultsPath.iterator(); + sb.append(resultsPathIterator.next()); + while (resultsPathIterator.hasNext()) { + sb.append("->" + resultsPathIterator.next()); + } + return sb.toString(); + } + + private TestResultStatus getStatus(int phpStatus) { + switch (phpStatus) { + case AbstractPHPUnitTestResult.STATUS_PASS: { + return TestResultStatus.SUCCESS; + } + case AbstractPHPUnitTestResult.STATUS_FAIL: { + return TestResultStatus.FAILURE; + } + case AbstractPHPUnitTestResult.STATUS_ERROR: { + return TestResultStatus.ERROR; + } + case AbstractPHPUnitTestResult.STATUS_SKIP: + case AbstractPHPUnitTestResult.STATUS_INCOMPLETE: { + return TestResultStatus.SKIPPED; + } + } + return null; + } + + private String getRootLabel(int phpStatus) { + switch (phpStatus) { + case AbstractPHPUnitTestResult.STATUS_PASS: { + return "Tests Passed"; + } + case AbstractPHPUnitTestResult.STATUS_FAIL: + case AbstractPHPUnitTestResult.STATUS_ERROR: { + return "Tests Failed"; + } + case AbstractPHPUnitTestResult.STATUS_SKIP: + case AbstractPHPUnitTestResult.STATUS_INCOMPLETE: { + return "Tests Skipped"; + } + } + return "Test Results"; + } + + private String getTimeString(double time) { + return "(" + (new DecimalFormat("0.000")).format(time) + " ms)"; + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java new file mode 100644 index 00000000000..5482a0cab8e --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server; + +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.che.api.project.server.ProjectManager; +import org.eclipse.che.api.testing.server.framework.TestRunner; +import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * PHPUnit implementation for the test runner service. + * + *
+ * Available Parameters for {@link PHPUnitTestRunner#runTests(Map)}
+ *
+ * projectPath : Relative path to the project directory
+ * absoluteProjectPath : Absolute path to the project directory
+ * testTarget : Path to test target (container or script).
+ * 
+ * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestRunner implements TestRunner { + + public static final Logger LOG = LoggerFactory.getLogger(PHPUnitTestRunner.class); + public static final String RUNNER_ID = "PHPUnit"; + + private final PHPUnitTestEngine testEngine; + + @Inject + public PHPUnitTestRunner(ProjectManager projectManager) { + testEngine = new PHPUnitTestEngine(projectManager); + } + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return RUNNER_ID; + } + + /** + * {@inheritDoc} + */ + @Override + public TestResultRootDto runTests(Map testParameters) throws Exception { + return testEngine.executeTests(testParameters); + } + + /** + * {@inheritDoc} + */ + @Override + public List getTestResults(List testResultsPath) { + return testEngine.getTestResults(testResultsPath); + } + + /** + * {@inheritDoc} + */ + @Override + public TestResult execute(Map testParameters) throws Exception { + return null; + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/inject/PHPUnitGuiceModule.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/inject/PHPUnitGuiceModule.java new file mode 100644 index 00000000000..6f86d5795a5 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/inject/PHPUnitGuiceModule.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.inject; + +import static com.google.inject.multibindings.Multibinder.newSetBinder; + +import org.eclipse.che.api.testing.server.framework.TestRunner; +import org.eclipse.che.inject.DynaModule; +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitTestRunner; + +import com.google.inject.AbstractModule; + +/** + * PHPUnit Guice module. + * + * @author Bartlomiej Laczkowski + */ +@DynaModule +public class PHPUnitGuiceModule extends AbstractModule { + @Override + protected void configure() { + newSetBinder(binder(), TestRunner.class).addBinding().to(PHPUnitTestRunner.class); + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java new file mode 100644 index 00000000000..8bc6bec11df --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.util.Map; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Abstract implementation for PHP unit model elements. + * + * @author Bartlomiej Laczkowski + */ +abstract public class AbstractPHPUnitElement { + + protected String file = ""; + protected boolean isFiltered = false; + protected int line = 0; + protected AbstractPHPUnitElement parent; + + public AbstractPHPUnitElement(final Map properties, final AbstractPHPUnitElement parent) { + if (properties != null) + init(properties); + if (parent != null) + setParent(parent); + } + + /** + * Sets this element parent. + * + * @param parent + */ + public void setParent(final AbstractPHPUnitElement parent) { + this.parent = parent; + } + + /** + * Returns related element file path. + * + * @return related element file path + */ + public String getFile() { + return file; + } + + /** + * Returns related element file line. + * + * @return related element file line + */ + public int getLine() { + return line; + } + + /** + * Returns element's parent. + * + * @return element's parent + */ + public AbstractPHPUnitElement getParent() { + return parent; + } + + /** + * Checks if this element is filtered. + * + * @return true if this element is filtered, false + * otherwise + */ + public boolean isFiltered() { + return isFiltered; + } + + private void init(final Map properties) { + final String pFile = (String) properties.get(PHPUnitMessageParser.PROPERTY_FILE); + if (pFile != null) { + file = (String) properties.get(PHPUnitMessageParser.PROPERTY_FILE); + line = Integer.parseInt((String) properties.get(PHPUnitMessageParser.PROPERTY_LINE)); + } + if (properties.get(PHPUnitMessageParser.PROPERTY_FILTERED) != null) { + isFiltered = true; + } + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java new file mode 100644 index 00000000000..9e8616ef862 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Abstract implementation for PHP unit test event elements. + * + * @author Bartlomiej Laczkowski + */ +public abstract class AbstractPHPUnitTestEvent extends AbstractPHPUnitElement { + + protected String message; + protected String diff; + protected List trace; + + public AbstractPHPUnitTestEvent(final Map event, final AbstractPHPUnitElement parent) { + super(event, parent); + message = (String) event.get(PHPUnitMessageParser.PROPERTY_MESSAGE); + diff = (String) event.get(PHPUnitMessageParser.PROPERTY_DIFF); + final Map mTrace = (Map) event.get(PHPUnitMessageParser.PROPERTY_TRACE); + if (mTrace == null || mTrace.isEmpty()) + return; + trace = new ArrayList(mTrace.size()); + for (int i = 0; i < mTrace.size(); ++i) { + trace.add(new PHPUnitTraceFrame((Map) mTrace.get(String.valueOf(i)), this)); + } + } + + /** + * Returns element description. + * + * @return element description + */ + public String getMessage() { + return message; + } + + /** + * Returns diff. + * + * @return diff + */ + public String getDiff() { + return diff; + } + + /** + * Returns element related trace. + * + * @return element related trace + */ + public List getTrace() { + return trace; + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java new file mode 100644 index 00000000000..709f16b4f09 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.util.Map; +import java.util.Set; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Abstract implementation for PHP unit test result elements. + * + * @author Bartlomiej Laczkowski + */ +public abstract class AbstractPHPUnitTestResult extends AbstractPHPUnitElement { + + public static final int STATUS_STARTED = 0; + public static final int STATUS_PASS = 1; + public static final int STATUS_SKIP = 2; + public static final int STATUS_INCOMPLETE = 3; + public static final int STATUS_FAIL = 4; + public static final int STATUS_ERROR = 5; + + protected String name = ""; + protected int status = 0; + protected double time = 0; + + public AbstractPHPUnitTestResult(final Map test, final PHPUnitTestSuite parent) { + super(test, parent); + if (test != null) + name = (String) test.get(PHPUnitMessageParser.PROPERTY_NAME); + } + + /** + * Implementors should return this element children. + * + * @return this element children + */ + public abstract Set getChildren(); + + /** + * Returns element name. + * + * @return element name. + */ + public String getName() { + return name; + } + + /** + * Returns number of run count. + * + * @return number of run count + */ + public int getRunCount() { + return 1; + } + + /** + * Returns element status. + * + * @return element status. + */ + public int getStatus() { + return status; + } + + /** + * Sets element status. + * + * @param status + */ + public void setStatus(final int status) { + this.status = status; + } + + /** + * Returns execution time. + * + * @return execution time + */ + public double getTime() { + return time; + } + + /** + * Sets the execution time. + * + * @param time + */ + public void setTime(double time) { + this.time = time; + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java new file mode 100644 index 00000000000..aae4926799f --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Test case model element implementation. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestCase extends AbstractPHPUnitTestResult { + + protected PHPUnitTestException exception = null; + protected List warnings = null; + + public PHPUnitTestCase(final Map test, final PHPUnitTestSuite parent) { + super(test, parent); + } + + public PHPUnitTestCase(final Map test, final PHPUnitTestSuite parent, final String sStatus) { + this(test, parent); + updateStatus(sStatus); + } + + @Override + public Set getChildren() { + return Collections.emptySet(); + } + + /** + * Updates status of this test case. + * + * @param sStatus + */ + public void updateStatus(String sStatus) { + if (sStatus.equals(PHPUnitMessageParser.STATUS_PASS)) + status = STATUS_PASS; + else if (sStatus.equals(PHPUnitMessageParser.STATUS_SKIP)) + status = STATUS_SKIP; + else if (sStatus.equals(PHPUnitMessageParser.STATUS_INCOMPLETE)) + status = STATUS_INCOMPLETE; + else if (sStatus.equals(PHPUnitMessageParser.STATUS_FAIL)) + status = STATUS_FAIL; + else if (sStatus.equals(PHPUnitMessageParser.STATUS_ERROR)) + status = STATUS_ERROR; + else if (sStatus.equals(PHPUnitMessageParser.TAG_START)) + status = STATUS_STARTED; + } + + /** + * returns related exception if there is any. + * + * @return related exception if there is any + */ + public PHPUnitTestException getException() { + return exception; + } + + /** + * Returns related warnings if there are any. + * + * @return related warnings if there are any + */ + public List getWarnings() { + return warnings; + } + + /** + * Sets test case related exception. + * + * @param exception + */ + public void setException(final PHPUnitTestException exception) { + this.exception = exception; + + } + + /** + * Sets test case related warnings. + * + * @param warnings + */ + public void setWarnings(final List warnings) { + this.warnings = warnings; + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java new file mode 100644 index 00000000000..ab7c175d095 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Test exception model element implementation. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestException extends AbstractPHPUnitTestEvent { + + private static final String TOP_CLASS = "Exception"; //$NON-NLS-1$ + private String exceptionClass = TOP_CLASS; + + public PHPUnitTestException(Map exception, PHPUnitTestCase parent) { + super(exception, parent); + exceptionClass = (String) exception.get(PHPUnitMessageParser.PROPERTY_CLASS); + } + + /** + * Returns exception class. + * + * @return exception class + */ + public String getExceptionClass() { + return exceptionClass; + } + + /** + * Sets abnormal exception if occurred. + * + * @param testCase + */ + public static void addAbnormalException(PHPUnitTestCase testCase) { + // if(ABNORMAL_EXCEPTION == null) { + Map exception = new HashMap(); + exception.put(PHPUnitMessageParser.PROPERTY_CLASS, "An unexpected termination has occurred"); + exception.put(PHPUnitMessageParser.PROPERTY_MESSAGE, "The test case was unexpectedly terminated"); + PHPUnitTestException abnormalException = new PHPUnitTestException(exception, null); + abnormalException.setParent(testCase); + testCase.setException(abnormalException); + testCase.setStatus(AbstractPHPUnitTestResult.STATUS_ERROR); + PHPUnitTestSuite parent = (PHPUnitTestSuite) testCase.getParent(); + if (parent != null) { + parent.setStatus(testCase.getStatus()); + } + testCase.setException(new PHPUnitTestException(exception, testCase)); + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java new file mode 100644 index 00000000000..e58fee01aec --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +/** + * Tests root element. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestRoot extends PHPUnitTestSuite { + + public PHPUnitTestRoot() { + super(null, null); + } + + @Override + public String getName() { + return "Test Results"; + } + + @Override + public void setStatus(final int status) { + statusCount.counts[status]++; + this.status = Math.max(this.status, status); + if (parent != null) + ((PHPUnitTestSuite) parent).setStatus(status); + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java new file mode 100644 index 00000000000..e956c992a5e --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Test suite model element implementation. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestSuite extends AbstractPHPUnitTestResult { + + protected class StatusCount { + public int[] counts = { 0, 0, 0, 0, 0, 0 }; // STATUS_STARTED, + // STATUS_PASS, + // STATUS_SKIP, + // STATUS_INCOMPLETE, + // STATUS_FAIL, + // STATUS_ERROR + } + + protected final StatusCount statusCount = new StatusCount(); + private Set children = null; + private int runCount = 0; + private int totalCount; + + public PHPUnitTestSuite(final Map test, final PHPUnitTestSuite parent) { + super(test, parent); + if (test == null) + totalCount = 0; + else + totalCount = Integer.parseInt((String) test.get(PHPUnitMessageParser.PROPERTY_COUNT)); + } + + @Override + public Set getChildren() { + return children; + } + + @Override + public int getRunCount() { + return runCount; + } + + @Override + public int getStatus() { + return status; + } + + @Override + public void setStatus(final int status) { + statusCount.counts[status]++; + this.status = Math.max(this.status, status); + if (parent != null) + ((PHPUnitTestSuite) parent).setStatus(status); + } + + /** + * Adds child element to this test suite. + * + * @param test + * @param finished + */ + public void addChild(final AbstractPHPUnitTestResult test, boolean finished) { + if (children == null) { + children = new LinkedHashSet(); + } + children.add(test); + if (test instanceof PHPUnitTestCase && finished) { + addRunCount(1); + } + time += test.getTime(); + setStatus(test.getStatus()); + } + + /** + * Returns status count. + * + * @param status + * @return status count for provided status + */ + public int getStatusCount(final int status) { + return statusCount.counts[status]; + } + + /** + * Returns total tests count. + * + * @return total tests count + */ + public int getTotalCount() { + return totalCount; + } + + /** + * Sets test suite element parent. + * + * @param group + */ + public void setParent(final PHPUnitTestSuite group) { + parent = group; + } + + private void addRunCount(final int count) { + runCount += count; + if (parent != null) + ((PHPUnitTestSuite) parent).addRunCount(count); + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestWarning.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestWarning.java new file mode 100644 index 00000000000..00d9d1fea72 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestWarning.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.util.Map; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Test warning model element implementation. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTestWarning extends AbstractPHPUnitTestEvent { + + private String code = ""; //$NON-NLS-1$ + + public PHPUnitTestWarning(final Map warning, final AbstractPHPUnitElement parent) { + super(warning, parent); + code = (String) warning.get(PHPUnitMessageParser.PROPERTY_CODE); + } + + /** + * Returns warning related code. + * + * @return warning related code + */ + public String getCode() { + return code; + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java new file mode 100644 index 00000000000..5b2a6d78822 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.server.model; + +import java.nio.file.Paths; +import java.util.Map; + +import org.eclipse.che.plugin.testing.phpunit.server.PHPUnitMessageParser; + +/** + * Trace frame model element implementation. + * + * @author Bartlomiej Laczkowski + */ +public class PHPUnitTraceFrame extends AbstractPHPUnitElement { + + private String traceFunction = ""; //$NON-NLS-1$ + private String traceClass = ""; //$NON-NLS-1$ + private String traceType = PHPUnitMessageParser.CALL_DYNAMIC; + + public PHPUnitTraceFrame(final Map frame, final AbstractPHPUnitTestEvent parent) { + super(frame, parent); + traceFunction = (String) frame.get("function"); //$NON-NLS-1$ + traceClass = (String) frame.get("class"); //$NON-NLS-1$ + traceType = (String) frame.get("type"); //$NON-NLS-1$ + } + + /** + * Returns trace frame function name. + * + * @return trace frame function name + */ + public String getFunction() { + return traceFunction; + } + + /** + * Returns trace frame class name. + * + * @return trace frame class name + */ + public String getClassName() { + return traceClass; + } + + /** + * Returns trace frame type. + * + * @return trace frame type + */ + public String getTraceType() { + return traceType; + } + + @Override + public String toString() { + final StringBuffer result = new StringBuffer(1); + if (traceClass != null) + result.append(traceClass); + if (traceType != null) + result.append(traceType); + result.append(traceFunction); + if (file != null) { + String fileName = Paths.get(file).getFileName().toString(); + result.append('(' + fileName + ':' + line + ')'); + } else { + result.append("()"); + } + return result.toString(); + } + +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php new file mode 100644 index 00000000000..ad4bc168f4d --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php @@ -0,0 +1,433 @@ +cleanTest(); + + $port = $_SERVER['ZEND_PHPUNIT_PORT']; + if (! isset($port)) { + $port = 7478; + } + $this->out = fsockopen('127.0.0.1', $port, $errno, $errstr, 5); + } + + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->writeTest($suite, 'start'); + } + + public function startTest(PHPUnit_Framework_Test $test) + { + $this->cleanTest(); + $this->writeTest($test, 'start'); + ZendPHPUnitErrorHandlerTracer::getInstance()->start(); + } + + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->status = 'error'; + $this->exception = $e; + } + + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + { + $this->status = 'fail'; + $this->exception = $e; + } + + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->status = 'incomplete'; + $this->exception = $e; + } + + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + { + $this->status = 'skip'; + $this->exception = $e; + } + + public function endTest(PHPUnit_Framework_Test $test, $time) + { + $this->warnings = ZendPHPUnitErrorHandlerTracer::getInstance()->stop(); + $this->time = $time; + $this->writeTest($test, $this->status); + } + + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + { + $this->writeTest($suite, 'end'); + } + + public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) + {} + + public function flush() + { + parent::flush(); + } + + private function cleanTest() + { + $this->status = 'pass'; + $this->exception = null; + $this->warnings = array(); + $this->time = 0; + } + + private function writeArray($array) + { + $result = $this->writeJson($this->encodeJson($array)); + return $result; + } + + private function writeTest(PHPUnit_Framework_Test $test, $event) + { + // echo out test output + if ($test instanceof PHPUnit_Framework_TestCase) { + if (! $test->hasPerformedExpectationsOnOutput() && $test->getActualOutput() != null) { + echo $test->getActualOutput(); + } + } + // write log + $result = array( + 'event' => $event + ); + if ($test instanceof PHPUnit_Framework_TestSuite) { + if (preg_match("*::*", $test->getName()) != 0) { // if it is a dataprovider test suite + // $result['target'] = 'testsuite-dataprovider'; + $result['target'] = 'testsuite'; + if ($event == 'start') + $this->dataProviderNumerator = 0; + elseif ($event == 'end') + $this->dataProviderNumerator = - 1; + } else { + $result['target'] = 'testsuite'; + $this->dataProviderNumerator = - 1; + } + try { + $class = new ReflectionClass($test->getName()); + $name = $class->getName(); + $file = $class->getFileName(); + $line = $class->getStartLine(); + $result['test'] = array( + 'name' => $name, + 'tests' => $test->count(), + 'file' => $file, + 'line' => $line + ); + } catch (ReflectionException $re) { + $name = $test->getName(); + $result['test'] = array( + 'name' => $name, + 'tests' => $test->count() + ); + } + } else { // If we're dealing with TestCase + $result['target'] = 'testcase'; + $result['time'] = $this->time; + $class = new ReflectionClass($test); + try { + $method = $class->getMethod($test->getName()); + if ($this->dataProviderNumerator < 0) { + $method_name = $method->getName(); + } else { + $method_name = $method->getName() . "[" . $this->dataProviderNumerator . "]"; + if ($event == 'start') { + $this->dataProviderNumerator ++; + } + } + $result['test'] = array( + 'name' => $method_name, + 'file' => $method->getFileName(), + 'line' => $method->getStartLine() + ); + } catch (ReflectionException $re) { + $result['test'] = array( + 'name' => $test->getName() + ); + } + } + if ($this->exception !== null) { + $message = $this->exception->getMessage(); + $diff = ""; + if ($this->exception instanceof PHPUnit_Framework_ExpectationFailedException) { + if (method_exists($this->exception, "getDescription")) { + $message = $this->exception->getDescription(); + } else + if (method_exists($this->exception, "getMessage")) { // PHPUnit 3.6.3 + $message = $this->exception->getMessage(); + } + if (method_exists($this->exception, "getComparisonFailure") && method_exists($this->exception->getComparisonFailure(), "getDiff")) { + $diff = $this->exception->getComparisonFailure()->getDiff(); + } + } + $message = trim(preg_replace('/\s+/m', ' ', $message)); + $result += array( + 'exception' => array( + 'message' => $message, + 'diff' => $diff, + 'class' => get_class($this->exception), + 'file' => $this->exception->getFile(), + 'line' => $this->exception->getLine(), + 'trace' => $this->filterTrace($this->exception->getTrace()) + ) + ); + if (! isset($result['exception']['file'])) { + $result['exception']['filtered'] = true; + } + } + if (! empty($this->warnings)) { + $result += array( + 'warnings' => $this->warnings + ); + } + if (! $this->writeArray($result)) { + die(); + } + } + + private function writeJson($buffer) + { + if ($this->out && ! @feof($this->out)) { + return @fwrite($this->out, "$buffer\n"); + } + } + + private function escapeString($string) + { + return str_replace(array( + "\\", + "\"", + '/', + "\b", + "\f", + "\n", + "\r", + "\t" + ), array( + '\\\\', + '\"', + '\/', + '\b', + '\f', + '\n', + '\r', + '\t' + ), $string); + } + + private function encodeJson($array) + { + $result = ''; + if (is_scalar($array)) + $array = array( + $array + ); + $first = true; + foreach ($array as $key => $value) { + if (! $first) + $result .= ','; + else + $first = false; + $result .= sprintf('"%s":', $this->escapeString($key)); + if (is_array($value) || is_object($value)) + $result .= sprintf('%s', $this->encodeJson($value)); + else + $result .= sprintf('"%s"', $this->escapeString($value)); + } + return '{' . $result . '}'; + } + + private function filterTrace($trace) + { + $filteredTrace = array(); + foreach ($trace as $frame) { + if (! isset($frame['file'])) + continue; + $filteredFrame = array( + 'file' => $frame['file'], + 'line' => $frame['line'], + 'function' => $frame['function'] + ); + if (isset($frame['class'])) + $filteredFrame += array( + 'class' => $frame['class'], + 'type' => $frame['type'] + ); + $filteredTrace[] = $filteredFrame; + } + return $filteredTrace; + } +} + +class ZendPHPUnitErrorHandlerTracer extends ZendPHPUnitErrorHandler +{ + + private static $ZendPHPUnitErrorHandlerTracer; + + /** + * + * @return ZendPHPUnitErrorHandlerTracer + */ + public static function getInstance() + { + if (self::$ZendPHPUnitErrorHandlerTracer === null) { + self::$ZendPHPUnitErrorHandlerTracer = new self(); + } + return self::$ZendPHPUnitErrorHandlerTracer; + } + + public static $errorCodes = array( + E_ERROR => 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parsing Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice', + E_RECOVERABLE_ERROR => 'Recoverable Error', + E_DEPRECATED => 'Deprecated', + E_USER_DEPRECATED => 'User Deprecated' + ); + + protected $warnings; + + public function handle($errno, $errstr, $errfile, $errline) + { + parent::handle($errno, $errstr, $errfile, $errline); + $warning = array( + 'code' => isset(self::$errorCodes[$errno]) ? self::$errorCodes[$errno] : $errno, + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline, + 'trace' => $this->filterTrace(debug_backtrace()), + 'time' => PHP_Timer::resourceUsage() + ); + $return = false; + switch ($errno) { // ignoring user abort + case E_USER_ERROR: + case E_RECOVERABLE_ERROR: + throw new ZendPHPUnitUserErrorException($warning['message'], $errno); + } + $this->warnings[] = $warning; + return $return; + } + + public function start() + { + $this->warnings = array(); + parent::start(); + } + + public function stop() + { + parent::stop(); + $return = $this->warnings; + $this->warnings = array(); + return $return; + } +} + +class ZendPHPUnitErrorHandler +{ + + private static $ZendPHPUnitErrorHandler; + + /** + * + * @return ZendPHPUnitErrorHandler + */ + public static function getInstance() + { + if (self::$ZendPHPUnitErrorHandler === null) { + self::$ZendPHPUnitErrorHandler = new self(); + } + return self::$ZendPHPUnitErrorHandler; + } + + public function handle($errno, $errstr, $errfile, $errline) + { + if (error_reporting() === 0) { + return false; + } + + if ($errfile === __FILE__ || (stripos($errfile, dirname(dirname(__FILE__))) === 0 && $errno !== E_USER_NOTICE)) + return true; + + // handle errors same as PHPUnit_Util_ErrorHandler + if ($errno == E_STRICT) { + if (PHPUnit_Framework_Error_Notice::$enabled !== TRUE) { + return FALSE; + } + + $exception = 'PHPUnit_Framework_Error_Notice'; + } + + else + if ($errno == E_WARNING) { + if (PHPUnit_Framework_Error_Warning::$enabled !== TRUE) { + return FALSE; + } + + $exception = 'PHPUnit_Framework_Error_Warning'; + } + + else + if ($errno == E_NOTICE) { + trigger_error($errstr, E_USER_NOTICE); + return FALSE; + } + + else { + $exception = 'PHPUnit_Framework_Error'; + } + + throw new $exception($errstr, $errno, $errfile, $errline, $trace = null); + } + + public function start() + { + set_error_handler(array( + &$this, + 'handle' + )); + } + + public function stop() + { + restore_error_handler(); + } +} + +class ZendPHPUnitUserErrorException extends Exception +{ +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger6x.php b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger6x.php new file mode 100644 index 00000000000..217af227428 --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger6x.php @@ -0,0 +1,448 @@ +cleanTest(); + + $port = $_SERVER['ZEND_PHPUNIT_PORT']; + if (! isset($port)) { + $port = 7478; + } + $this->out = fsockopen('127.0.0.1', $port, $errno, $errstr, 5); + } + + public function startTestSuite(TestSuite $suite) + { + $this->writeTest($suite, 'start'); + } + + public function startTest(Test $test) + { + $this->cleanTest(); + $this->writeTest($test, 'start'); + ZendPHPUnitErrorHandlerTracer::getInstance()->start(); + } + + public function addError(Test $test, \Exception $e, $time) + { + $this->status = 'error'; + $this->exception = $e; + } + + public function addWarning(Test $test, Warning $e, $time) { + $this->status = 'warning'; + $this->exception = $e; + } + + public function addFailure(Test $test, AssertionFailedError $e, $time) + { + $this->status = 'fail'; + $this->exception = $e; + } + + public function addIncompleteTest(Test $test, \Exception $e, $time) + { + $this->status = 'incomplete'; + $this->exception = $e; + } + + public function addSkippedTest(Test $test, \Exception $e, $time) + { + $this->status = 'skip'; + $this->exception = $e; + } + + public function endTest(Test $test, $time) + { + $this->warnings = ZendPHPUnitErrorHandlerTracer::getInstance()->stop(); + $this->time = $time; + $this->writeTest($test, $this->status); + } + + public function endTestSuite(TestSuite $suite) + { + $this->writeTest($suite, 'end'); + } + + public function addRiskyTest(Test $test, \Exception $e, $time) + {} + + public function flush() + { + parent::flush(); + } + + private function cleanTest() + { + $this->status = 'pass'; + $this->exception = null; + $this->warnings = array(); + $this->time = 0; + } + + private function writeArray($array) + { + $result = $this->writeJson($this->encodeJson($array)); + return $result; + } + + private function writeTest(Test $test, $event) + { + // echo out test output + if ($test instanceof TestCase) { + if (! $test->hasPerformedExpectationsOnOutput() && $test->getActualOutput() != null) { + echo $test->getActualOutput(); + } + } + // write log + $result = array( + 'event' => $event + ); + if ($test instanceof TestSuite) { + if (preg_match("*::*", $test->getName()) != 0) { // if it is a dataprovider test suite + // $result['target'] = 'testsuite-dataprovider'; + $result['target'] = 'testsuite'; + if ($event == 'start') + $this->dataProviderNumerator = 0; + elseif ($event == 'end') + $this->dataProviderNumerator = - 1; + } else { + $result['target'] = 'testsuite'; + $this->dataProviderNumerator = - 1; + } + try { + $class = new ReflectionClass($test->getName()); + $name = $class->getName(); + $file = $class->getFileName(); + $line = $class->getStartLine(); + $result['test'] = array( + 'name' => $name, + 'tests' => $test->count(), + 'file' => $file, + 'line' => $line + ); + } catch (ReflectionException $re) { + $name = $test->getName(); + $result['test'] = array( + 'name' => $name, + 'tests' => $test->count() + ); + } + } else { // If we're dealing with TestCase + $result['target'] = 'testcase'; + $result['time'] = $this->time; + $class = new ReflectionClass($test); + try { + $method = $class->getMethod($test->getName()); + if ($this->dataProviderNumerator < 0) { + $method_name = $method->getName(); + } else { + $method_name = $method->getName() . "[" . $this->dataProviderNumerator . "]"; + if ($event == 'start') { + $this->dataProviderNumerator ++; + } + } + $result['test'] = array( + 'name' => $method_name, + 'file' => $method->getFileName(), + 'line' => $method->getStartLine() + ); + } catch (ReflectionException $re) { + $result['test'] = array( + 'name' => $test->getName() + ); + } + } + if ($this->exception !== null) { + $message = $this->exception->getMessage(); + $diff = ""; + if ($this->exception instanceof ExpectationFailedException) { + if (method_exists($this->exception, "getDescription")) { + $message = $this->exception->getDescription(); + } else + if (method_exists($this->exception, "getMessage")) { // PHPUnit 3.6.3 + $message = $this->exception->getMessage(); + } + if (method_exists($this->exception, "getComparisonFailure") && method_exists($this->exception->getComparisonFailure(), "getDiff")) { + $diff = $this->exception->getComparisonFailure()->getDiff(); + } + } + $message = trim(preg_replace('/\s+/m', ' ', $message)); + $result += array( + 'exception' => array( + 'message' => $message, + 'diff' => $diff, + 'class' => get_class($this->exception), + 'file' => $this->exception->getFile(), + 'line' => $this->exception->getLine(), + 'trace' => $this->filterTrace($this->exception->getTrace()) + ) + ); + if (! isset($result['exception']['file'])) { + $result['exception']['filtered'] = true; + } + } + if (! empty($this->warnings)) { + $result += array( + 'warnings' => $this->warnings + ); + } + if (! $this->writeArray($result)) { + die(); + } + } + + private function writeJson($buffer) + { + if ($this->out && ! @feof($this->out)) { + return @fwrite($this->out, "$buffer\n"); + } + } + + private function escapeString($string) + { + return str_replace(array( + "\\", + "\"", + '/', + "\b", + "\f", + "\n", + "\r", + "\t" + ), array( + '\\\\', + '\"', + '\/', + '\b', + '\f', + '\n', + '\r', + '\t' + ), $string); + } + + private function encodeJson($array) + { + $result = ''; + if (is_scalar($array)) + $array = array( + $array + ); + $first = true; + foreach ($array as $key => $value) { + if (! $first) + $result .= ','; + else + $first = false; + $result .= sprintf('"%s":', $this->escapeString($key)); + if (is_array($value) || is_object($value)) + $result .= sprintf('%s', $this->encodeJson($value)); + else + $result .= sprintf('"%s"', $this->escapeString($value)); + } + return '{' . $result . '}'; + } + + private function filterTrace($trace) + { + $filteredTrace = array(); + foreach ($trace as $frame) { + if (! isset($frame['file'])) + continue; + $filteredFrame = array( + 'file' => $frame['file'], + 'line' => $frame['line'], + 'function' => $frame['function'] + ); + if (isset($frame['class'])) + $filteredFrame += array( + 'class' => $frame['class'], + 'type' => $frame['type'] + ); + $filteredTrace[] = $filteredFrame; + } + return $filteredTrace; + } +} + +class ZendPHPUnitErrorHandlerTracer extends ZendPHPUnitErrorHandler +{ + + private static $ZendPHPUnitErrorHandlerTracer; + + /** + * + * @return ZendPHPUnitErrorHandlerTracer + */ + public static function getInstance() + { + if (self::$ZendPHPUnitErrorHandlerTracer === null) { + self::$ZendPHPUnitErrorHandlerTracer = new self(); + } + return self::$ZendPHPUnitErrorHandlerTracer; + } + + public static $errorCodes = array( + E_ERROR => 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parsing Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice', + E_RECOVERABLE_ERROR => 'Recoverable Error', + E_DEPRECATED => 'Deprecated', + E_USER_DEPRECATED => 'User Deprecated' + ); + + protected $warnings; + + public function handle($errno, $errstr, $errfile, $errline) + { + parent::handle($errno, $errstr, $errfile, $errline); + $warning = array( + 'code' => isset(self::$errorCodes[$errno]) ? self::$errorCodes[$errno] : $errno, + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline, + 'trace' => $this->filterTrace(debug_backtrace()), + 'time' => PHP_Timer::resourceUsage() + ); + $return = false; + switch ($errno) { // ignoring user abort + case E_USER_ERROR: + case E_RECOVERABLE_ERROR: + throw new ZendPHPUnitUserErrorException($warning['message'], $errno); + } + $this->warnings[] = $warning; + return $return; + } + + public function start() + { + $this->warnings = array(); + parent::start(); + } + + public function stop() + { + parent::stop(); + $return = $this->warnings; + $this->warnings = array(); + return $return; + } +} + +class ZendPHPUnitErrorHandler +{ + + private static $ZendPHPUnitErrorHandler; + + /** + * + * @return ZendPHPUnitErrorHandler + */ + public static function getInstance() + { + if (self::$ZendPHPUnitErrorHandler === null) { + self::$ZendPHPUnitErrorHandler = new self(); + } + return self::$ZendPHPUnitErrorHandler; + } + + public function handle($errno, $errstr, $errfile, $errline) + { + if (error_reporting() === 0) { + return false; + } + + if ($errfile === __FILE__ || (stripos($errfile, dirname(dirname(__FILE__))) === 0 && $errno !== E_USER_NOTICE)) + return true; + + // handle errors same as PHPUnit_Util_ErrorHandler + if ($errno == E_STRICT) { + if (PHPUnit_Framework_Error_Notice::$enabled !== TRUE) { + return FALSE; + } + + $exception = 'PHPUnit_Framework_Error_Notice'; + } + + else + if ($errno == E_WARNING) { + if (PHPUnit_Framework_Error_Warning::$enabled !== TRUE) { + return FALSE; + } + + $exception = 'PHPUnit_Framework_Error_Warning'; + } + + else + if ($errno == E_NOTICE) { + trigger_error($errstr, E_USER_NOTICE); + return FALSE; + } + + else { + $exception = 'PHPUnit_Framework_Error'; + } + + throw new $exception($errstr, $errno, $errfile, $errline, $trace = null); + } + + public function start() + { + set_error_handler(array( + &$this, + 'handle' + )); + } + + public function stop() + { + restore_error_handler(); + } +} + +class ZendPHPUnitUserErrorException extends Exception +{ +} \ No newline at end of file diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml new file mode 100644 index 00000000000..c5045436e3a --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + che-plugin-testing-php-parent + org.eclipse.che.plugin + 5.3.0-SNAPSHOT + + che-plugin-testing-phpunit + pom + Che Plugin :: PHP Testing :: PHPUnit Parent + + che-plugin-testing-phpunit-ide + che-plugin-testing-phpunit-server + + + + + + org.eclipse.che.core + che-core-api-dto-maven-plugin + ${project.version} + + + + + diff --git a/plugins/plugin-testing-php/pom.xml b/plugins/plugin-testing-php/pom.xml new file mode 100644 index 00000000000..c69b06b8d71 --- /dev/null +++ b/plugins/plugin-testing-php/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + + che-plugin-parent + org.eclipse.che.plugin + 5.3.0-SNAPSHOT + + che-plugin-testing-php-parent + pom + Che Plugin :: PHP Testing :: PHP Testing Parent + + plugin-testing-phpunit + + + + + + com.mycila + license-maven-plugin + + true + + + + org.eclipse.che.core + che-core-api-dto-maven-plugin + ${project.version} + + + + + diff --git a/plugins/plugin-testing/che-plugin-testing-ide/pom.xml b/plugins/plugin-testing/che-plugin-testing-ide/pom.xml index 83c3a12f5ea..ebb1fe4ee86 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/pom.xml +++ b/plugins/plugin-testing/che-plugin-testing-ide/pom.xml @@ -117,6 +117,13 @@ + + com.mycila + license-maven-plugin + + true + + org.apache.maven.plugins maven-dependency-plugin diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestResources.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestResources.java index 7e6fd61fcbe..36065aedde9 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestResources.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestResources.java @@ -20,13 +20,31 @@ * @author Mirage Abeysekara */ public interface TestResources extends ClientBundle { - + @Source("org/eclipse/che/plugin/testing/ide/svg/test.svg") + @Deprecated SVGResource testIcon(); @Source("org/eclipse/che/plugin/testing/ide/svg/test_results_pass.svg") + @Deprecated SVGResource testResultsPass(); @Source("org/eclipse/che/plugin/testing/ide/svg/test_results_fail.svg") + @Deprecated SVGResource testResultsFail(); + + @Source("org/eclipse/che/plugin/testing/ide/svg/test_result_failure.svg") + SVGResource testResultFailureIcon(); + + @Source("org/eclipse/che/plugin/testing/ide/svg/test_result_success.svg") + SVGResource testResultSuccessIcon(); + + @Source("org/eclipse/che/plugin/testing/ide/svg/test_result_warning.svg") + SVGResource testResultWarningIcon(); + + @Source("org/eclipse/che/plugin/testing/ide/svg/test_result_skipped.svg") + SVGResource testResultSkippedIcon(); + + @Source("org/eclipse/che/plugin/testing/ide/svg/test_result_trace_frame.svg") + SVGResource testResultTraceFrameIcon(); } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestServiceClient.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestServiceClient.java index 9f8050d4940..61b8c0560fb 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestServiceClient.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestServiceClient.java @@ -10,10 +10,13 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.ide; +import java.util.List; import java.util.Map; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.ide.MimeType; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.rest.AsyncRequestFactory; @@ -37,15 +40,14 @@ public class TestServiceClient { private final DtoUnmarshallerFactory dtoUnmarshallerFactory; @Inject - public TestServiceClient(AppContext appContext, - AsyncRequestFactory asyncRequestFactory, - DtoUnmarshallerFactory dtoUnmarshallerFactory) { + public TestServiceClient(AppContext appContext, AsyncRequestFactory asyncRequestFactory, + DtoUnmarshallerFactory dtoUnmarshallerFactory) { this.appContext = appContext; this.asyncRequestFactory = asyncRequestFactory; this.dtoUnmarshallerFactory = dtoUnmarshallerFactory; - } + @Deprecated public Promise getTestResult(String projectPath, String testFramework, Map parameters) { StringBuilder sb = new StringBuilder(); if (parameters != null) { @@ -62,4 +64,32 @@ public Promise getTestResult(String projectPath, String testFramewor .send(dtoUnmarshallerFactory.newUnmarshaller(TestResult.class)); } + public Promise runTests(String testFramework, String projectPath, Map parameters) { + StringBuilder sb = new StringBuilder(); + if (parameters != null) { + for (Map.Entry e : parameters.entrySet()) { + if (sb.length() > 0) { + sb.append('&'); + } + sb.append(URL.encode(e.getKey())).append('=').append(URL.encode(e.getValue())); + } + } + String url = appContext.getDevMachine().getWsAgentBaseUrl() + "/che/testing/runtests/?testFramework=" + testFramework + + "&projectPath=" + projectPath + "&" + sb.toString(); + return asyncRequestFactory.createGetRequest(url).header(HTTPHeader.ACCEPT, MimeType.APPLICATION_JSON) + .send(dtoUnmarshallerFactory.newUnmarshaller(TestResultRootDto.class)); + } + + public Promise> getTestResults(String testFramework, List testResultsPath) { + StringBuilder params = new StringBuilder(); + for (int i = 0; i < testResultsPath.size(); i++) { + params.append("&path" + i + '='); + params.append(testResultsPath.get(i)); + } + String url = appContext.getDevMachine().getWsAgentBaseUrl() + "/che/testing/gettestresults/?testFramework=" + + testFramework + params.toString(); + return asyncRequestFactory.createGetRequest(url).header(HTTPHeader.ACCEPT, MimeType.APPLICATION_JSON) + .send(dtoUnmarshallerFactory.newListUnmarshaller(TestResultDto.class)); + } + } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java index 9f8b925aab4..9c281895ca0 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java @@ -11,6 +11,7 @@ package org.eclipse.che.plugin.testing.ide.view; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.ide.api.parts.PartStackType; import org.eclipse.che.ide.api.parts.WorkspaceAgent; import org.eclipse.che.ide.api.parts.base.BasePresenter; @@ -36,10 +37,8 @@ public class TestResultPresenter extends BasePresenter implements TestResultView private final TestResultView view; @Inject - public TestResultPresenter(WorkspaceAgent workspaceAgent, - TestLocalizationConstant localizationConstant, - TestResources resources, - TestResultView view) { + public TestResultPresenter(WorkspaceAgent workspaceAgent, TestLocalizationConstant localizationConstant, + TestResources resources, TestResultView view) { this.workspaceAgent = workspaceAgent; this.localizationConstant = localizationConstant; this.resources = resources; @@ -78,9 +77,22 @@ public void go(AcceptsOneWidget container) { * @param response * result of the test runner */ + @Deprecated public void handleResponse(TestResult response) { workspaceAgent.openPart(this, PartStackType.INFORMATION); workspaceAgent.setActivePart(this); view.showResults(response); } + + /** + * Activates test results part and shows the results. + * + * @param response + * result root of the test runner + */ + public void handleResponse(TestResultRootDto response) { + workspaceAgent.openPart(this, PartStackType.INFORMATION); + workspaceAgent.setActivePart(this); + view.showResults(response); + } } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java index 4f428f5c7ee..53c91e1f1a1 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java @@ -11,6 +11,7 @@ package org.eclipse.che.plugin.testing.ide.view; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.ide.api.mvp.View; import org.eclipse.che.ide.api.parts.base.BaseActionDelegate; @@ -20,6 +21,7 @@ * @author Mirage Abeysekara */ public interface TestResultView extends View { + /** * Sets whether this panel is visible. * @@ -34,7 +36,16 @@ public interface TestResultView extends View { * @param result * test results which comes from the server */ + @Deprecated void showResults(TestResult result); + + /** + * Activate Test results part. + * + * @param result + * test results which comes from the server + */ + void showResults(TestResultRootDto result); interface ActionDelegate extends BaseActionDelegate { } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java index 99adad5d953..70d271143f2 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java @@ -25,6 +25,9 @@ import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.api.testing.shared.Failure; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceFrameDto; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.data.tree.Node; import org.eclipse.che.ide.api.data.tree.NodeInterceptor; @@ -45,15 +48,19 @@ import org.eclipse.che.ide.util.loging.Log; import org.eclipse.che.plugin.testing.ide.view.navigation.TestClassNavigation; import org.eclipse.che.plugin.testing.ide.view.navigation.factory.TestResultNodeFactory; +import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.AbstractTestResultTreeNode; import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultClassNode; import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultGroupNode; import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultMethodNode; +import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultRootNode; +import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultTraceFrameNode; import com.google.common.base.Optional; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.resources.client.CssResource; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Timer; @@ -77,31 +84,37 @@ public class TestResultViewImpl extends BaseView interface TestResultViewImplUiBinder extends UiBinder { } + interface Styles extends CssResource { + + String traceFrameMessage(); + + } + private static final TestResultViewImplUiBinder UI_BINDER = GWT.create(TestResultViewImplUiBinder.class); private final AppContext appContext; private final EditorAgent editorAgent; private final EventBus eventBus; private final TestResultNodeFactory nodeFactory; - private TestResult lastTestResult; private Tree resultTree; + private Tree traceTree; private int lastWentLine = 0; @UiField(provided = true) SplitLayoutPanel splitLayoutPanel; @UiField - Label outputResult; + Styles style; @UiField FlowPanel navigationPanel; + @UiField + FlowPanel traceOutputPanel; + @Inject - public TestResultViewImpl(PartStackUIResources resources, - EditorAgent editorAgent, - AppContext appContext, - EventBus eventBus, - TestResultNodeFactory nodeFactory) { + public TestResultViewImpl(PartStackUIResources resources, EditorAgent editorAgent, AppContext appContext, + EventBus eventBus, TestResultNodeFactory nodeFactory) { super(resources); this.editorAgent = editorAgent; this.appContext = appContext; @@ -109,6 +122,23 @@ public TestResultViewImpl(PartStackUIResources resources, this.nodeFactory = nodeFactory; splitLayoutPanel = new SplitLayoutPanel(1); setContentWidget(UI_BINDER.createAndBindUi(this)); + resultTree = createTree(); + resultTree.getSelectionModel().addSelectionHandler(new SelectionHandler() { + @Override + public void onSelection(SelectionEvent event) { + Node selectedNode = event.getSelectedItem(); + if (selectedNode instanceof TestResultMethodNode) { + fillOutputPanel(((TestResultMethodNode) selectedNode).getStackTrace()); + } + if (selectedNode instanceof AbstractTestResultTreeNode) { + fillOutputPanel((AbstractTestResultTreeNode) selectedNode); + } + } + }); + navigationPanel.add(resultTree); + } + + private Tree createTree() { NodeUniqueKeyProvider idProvider = new NodeUniqueKeyProvider() { @NotNull @Override @@ -118,44 +148,47 @@ public String getKey(@NotNull Node item) { }; NodeStorage nodeStorage = new NodeStorage(idProvider); NodeLoader nodeLoader = new NodeLoader(Collections. emptySet()); - resultTree = new Tree(nodeStorage, nodeLoader); - resultTree.getSelectionModel().addSelectionHandler(new SelectionHandler() { - @Override - public void onSelection(SelectionEvent event) { - Node methodNode = event.getSelectedItem(); - if (methodNode instanceof TestResultMethodNode) { - outputResult.setText(((TestResultMethodNode) methodNode).getStackTrace()); - } - } - }); - resultTree.getElement().getStyle().setWidth(100, Style.Unit.PCT); - resultTree.getElement().getStyle().setHeight(100, Style.Unit.PCT); - navigationPanel.add(resultTree); + Tree tree = new Tree(nodeStorage, nodeLoader); + tree.getElement().getStyle().setWidth(100, Style.Unit.PCT); + tree.getElement().getStyle().setHeight(100, Style.Unit.PCT); + return tree; } /** * {@inheritDoc} */ @Override - protected void focusView() {} + protected void focusView() { + } /** * {@inheritDoc} */ @Override + @Deprecated public void showResults(TestResult result) { - this.lastTestResult = result; setTitle("Test Results (Framework: " + result.getTestFramework() + ")"); - buildTree(); + buildResultTree(result); focusView(); } - private void buildTree() { + /** + * {@inheritDoc} + */ + @Override + public void showResults(TestResultRootDto result) { + setTitle("Test Results (Framework: " + result.getTestFrameworkName() + ")"); + buildResultTree(result); + focusView(); + } + + @Deprecated + private void buildResultTree(TestResult result) { resultTree.getNodeStorage().clear(); - outputResult.setText(""); - TestResultGroupNode root = nodeFactory.getTestResultGroupNode(lastTestResult); - HashMap> classNodeHashMap = new HashMap<>(); - for (Failure failure : lastTestResult.getFailures()) { + // outputResult.setText(""); + TestResultGroupNode root = nodeFactory.getTestResultGroupNode(result); + Map> classNodeHashMap = new HashMap<>(); + for (Failure failure : result.getFailures()) { if (!classNodeHashMap.containsKey(failure.getFailingClass())) { List methodNodes = new ArrayList<>(); classNodeHashMap.put(failure.getFailingClass(), methodNodes); @@ -174,7 +207,46 @@ private void buildTree() { resultTree.getNodeStorage().add(root); } + private void buildResultTree(TestResultRootDto result) { + resultTree.getNodeStorage().clear(); + TestResultRootNode root = nodeFactory.createTestResultRootNode(result, result.getTestFrameworkName()); + resultTree.getNodeStorage().add(root); + } + + private void buildTraceTree(TestResultTraceDto trace) { + traceTree = createTree(); + traceTree.getNodeStorage().clear(); + List traceNodes = new ArrayList<>(); + for (TestResultTraceFrameDto traceFrame : trace.getTraceFrames()) { + TestResultTraceFrameNode traceNode = nodeFactory.createTestResultTraceFrameNode(traceFrame); + traceNodes.add(traceNode); + } + traceTree.getNodeStorage().add(traceNodes); + } + + @Deprecated + private void fillOutputPanel(String text) { + traceOutputPanel.clear(); + Label traceMessageLabel = new Label(text); + traceMessageLabel.setStyleName(style.traceFrameMessage()); + traceOutputPanel.add(traceMessageLabel); + } + + private void fillOutputPanel(AbstractTestResultTreeNode node) { + traceOutputPanel.clear(); + TestResultTraceDto testTrace = node.getTestTrace(); + if (testTrace == null) + return; + Label traceMessageLabel = new Label(testTrace.getMessage()); + traceMessageLabel.setStyleName(style.traceFrameMessage()); + traceOutputPanel.add(traceMessageLabel); + buildTraceTree(testTrace); + traceTree.getElement().getStyle().setOverflow(Style.Overflow.HIDDEN); + traceOutputPanel.add(traceTree); + } + @Override + @Deprecated public void gotoClass(String packagePath, int line) { lastWentLine = line; final Project project = appContext.getRootProject(); diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java new file mode 100644 index 00000000000..d1fe7c39837 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.ide.view.navigation; + +import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.api.promises.client.OperationException; +import org.eclipse.che.api.promises.client.PromiseError; +import org.eclipse.che.api.testing.shared.dto.SimpleLocationDto; +import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.editor.EditorAgent; +import org.eclipse.che.ide.api.editor.EditorPartPresenter; +import org.eclipse.che.ide.api.editor.document.Document; +import org.eclipse.che.ide.api.editor.text.TextPosition; +import org.eclipse.che.ide.api.editor.texteditor.TextEditor; +import org.eclipse.che.ide.api.resources.File; +import org.eclipse.che.ide.api.resources.VirtualFile; + +import com.google.common.base.Optional; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.inject.Inject; + +/** + * Simple location DTO handler. It is responsible for opening the provided + * location. + * + * @author Bartlomiej Laczkowski + */ +public class SimpleLocationHandler { + + private static final String PROJECTS_ROOT = "/projects"; + + private final EditorAgent editorAgent; + private final AppContext appContext; + + @Inject + public SimpleLocationHandler(EditorAgent editorAgent, AppContext appContext) { + this.editorAgent = editorAgent; + this.appContext = appContext; + } + + /** + * Tries to open provided location. + * + * @param location + */ + public void openFile(final SimpleLocationDto location) { + openFile(location, null); + } + + /** + * Tries to open provided location. Supports callback if there is a need. + * + * @param location + * @param callback + */ + public void openFile(final SimpleLocationDto location, final AsyncCallback callback) { + tryFindFileInWorkspace(location, new AsyncCallback() { + @Override + public void onSuccess(VirtualFile virtualFile) { + if (callback != null) + callback.onSuccess(virtualFile); + } + + @Override + public void onFailure(Throwable caught) { + if (callback != null) + callback.onFailure(caught); + } + }); + } + + private void tryFindFileInWorkspace(final SimpleLocationDto location, final AsyncCallback callback) { + String resourcePath = location.getResourcePath(); + if (resourcePath.startsWith(PROJECTS_ROOT)) + resourcePath = resourcePath.substring(PROJECTS_ROOT.length() + 1); + try { + appContext.getWorkspaceRoot().getFile(resourcePath).then(new Operation>() { + @Override + public void apply(Optional file) throws OperationException { + if (file.isPresent()) { + openFileAndScrollToLine(file.get(), location.getLineNumber(), callback); + } else { + callback.onFailure(new IllegalArgumentException(location.getResourcePath() + " not found.")); + } + } + }).catchError(new Operation() { + @Override + public void apply(PromiseError arg) throws OperationException { + callback.onFailure(new IllegalArgumentException(location.getResourcePath() + " not found.")); + } + }); + } catch (IllegalStateException ignored) { + callback.onFailure(new IllegalArgumentException(location.getResourcePath() + " not found.")); + } + } + + private void openFileAndScrollToLine(final VirtualFile virtualFile, final int scrollToLine, + final AsyncCallback callback) { + editorAgent.openEditor(virtualFile, new EditorAgent.OpenEditorCallback() { + @Override + public void onEditorOpened(EditorPartPresenter editor) { + new Timer() { + @Override + public void run() { + scrollToLine(editorAgent.getActiveEditor(), scrollToLine); + callback.onSuccess(virtualFile); + } + }.schedule(300); + } + + @Override + public void onEditorActivated(EditorPartPresenter editor) { + new Timer() { + @Override + public void run() { + scrollToLine(editorAgent.getActiveEditor(), scrollToLine); + callback.onSuccess(virtualFile); + } + }.schedule(300); + } + + @Override + public void onInitializationFailed() { + callback.onFailure( + new IllegalStateException("Initialization " + virtualFile.getName() + " in the editor failed")); + } + }); + } + + private void scrollToLine(EditorPartPresenter editor, int lineNumber) { + if (editor instanceof TextEditor) { + TextEditor textEditor = (TextEditor) editor; + Document document = textEditor.getDocument(); + if (document != null) { + TextPosition newPosition = new TextPosition(lineNumber, 0); + document.setCursorPosition(newPosition); + } + } + } +} diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/TestClassNavigation.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/TestClassNavigation.java index 235f9f04d56..16e04e50d01 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/TestClassNavigation.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/TestClassNavigation.java @@ -14,6 +14,7 @@ * Enables navigation to the failed test class. * @author Mirage Abeysekara */ +@Deprecated public interface TestClassNavigation { /** @@ -22,5 +23,6 @@ public interface TestClassNavigation { * @param packagePath * @param line */ + @Deprecated void gotoClass(String packagePath, int line); } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/factory/TestResultNodeFactory.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/factory/TestResultNodeFactory.java index 7726ba7c874..2dc245d491d 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/factory/TestResultNodeFactory.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/factory/TestResultNodeFactory.java @@ -11,10 +11,16 @@ package org.eclipse.che.plugin.testing.ide.view.navigation.factory; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceFrameDto; import org.eclipse.che.plugin.testing.ide.view.navigation.TestClassNavigation; import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultClassNode; import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultGroupNode; import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultMethodNode; +import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultNode; +import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultRootNode; +import org.eclipse.che.plugin.testing.ide.view.navigation.nodes.TestResultTraceFrameNode; import com.google.inject.assistedinject.Assisted; @@ -25,13 +31,25 @@ */ public interface TestResultNodeFactory { + TestResultRootNode createTestResultRootNode(TestResultRootDto testResultRootDto, + String frameworkName); + + TestResultNode createTestResultEntryNode(TestResultDto testResultDto, + String frameworkName); + + TestResultTraceFrameNode createTestResultTraceFrameNode(TestResultTraceFrameDto testResultTraceFrameDto); + + @Deprecated TestResultGroupNode getTestResultGroupNode(TestResult result); + @Deprecated TestResultClassNode getTestResultClassNodeNode(String className); + @Deprecated TestResultMethodNode getTestResultMethodNodeNode(@Assisted("methodName") String methodName, - @Assisted("stackTrace") String stackTrace, - @Assisted("message") String message, + @Assisted("stackTrace") String stackTrace, + @Assisted("message") String message, int lineNumber, TestClassNavigation navigationHandler); + } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java new file mode 100644 index 00000000000..af46629dff4 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.ide.view.navigation.nodes; + +import javax.validation.constraints.NotNull; + +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceDto; +import org.eclipse.che.ide.api.data.tree.AbstractTreeNode; +import org.eclipse.che.ide.ui.smartTree.presentation.HasPresentation; +import org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation; +import org.eclipse.che.plugin.testing.ide.TestResources; +import org.eclipse.che.plugin.testing.ide.TestServiceClient; +import org.eclipse.che.plugin.testing.ide.view.navigation.factory.TestResultNodeFactory; + +/** + * Abstract implementation of test result tree node. + * + * @author Bartlomiej Laczkowski + */ +public abstract class AbstractTestResultTreeNode extends AbstractTreeNode implements HasPresentation { + + protected final TestResources testResources; + protected final TestResultNodeFactory nodeFactory; + protected final TestServiceClient testServiceClient; + protected final String frameworkName; + private NodePresentation nodePresentation; + + public AbstractTestResultTreeNode(TestServiceClient testServiceClient, TestResultNodeFactory nodeFactory, + TestResources testResources, String frameworkName) { + this.testServiceClient = testServiceClient; + this.nodeFactory = nodeFactory; + this.testResources = testResources; + this.frameworkName = frameworkName; + } + + /** + * Implementors should return related test result trace if there is any. + * + * @return related test result trace + */ + public abstract TestResultTraceDto getTestTrace(); + + /** + * Implementors should return related test result info text if there is any. + * + * @return related test result info text + */ + public abstract String getTestInfoText(); + + /** + * Implementors should return related test result status. + * + * @return related test result status + */ + public abstract TestResultStatus getTestStatus(); + + @Override + public void updatePresentation(@NotNull NodePresentation presentation) { + String infoText = getTestInfoText(); + switch (getTestStatus()) { + case FAILURE: + case ERROR: { + presentation.setPresentableIcon(testResources.testResultFailureIcon()); + break; + } + case SUCCESS: { + presentation.setPresentableIcon(testResources.testResultSuccessIcon()); + break; + } + case WARNING: { + presentation.setPresentableIcon(testResources.testResultWarningIcon()); + break; + } + case SKIPPED: { + presentation.setPresentableIcon(testResources.testResultSkippedIcon()); + break; + } + } + presentation.setPresentableText(getName()); + if (infoText != null) + presentation.setInfoText(infoText); + } + + @Override + public NodePresentation getPresentation(boolean update) { + if (nodePresentation == null) { + nodePresentation = new NodePresentation(); + updatePresentation(nodePresentation); + } + if (update) { + updatePresentation(nodePresentation); + } + return nodePresentation; + } + +} diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultClassNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultClassNode.java index 13e38ee7243..babd32e07d2 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultClassNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultClassNode.java @@ -30,6 +30,7 @@ * * @author Mirage Abeysekara */ +@Deprecated public class TestResultClassNode extends AbstractTreeNode implements HasPresentation { private String className; diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultGroupNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultGroupNode.java index 2bdb6138bf8..e4485518fb7 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultGroupNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultGroupNode.java @@ -29,6 +29,7 @@ * Tree node for display the failing class. * @author Mirage Abeysekara */ +@Deprecated public class TestResultGroupNode extends AbstractTreeNode implements HasPresentation { int failureCount; diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultMethodNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultMethodNode.java index 2d59c27697b..05fdbf382be 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultMethodNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultMethodNode.java @@ -30,6 +30,7 @@ * * @author Mirage Abeysekara */ +@Deprecated public class TestResultMethodNode extends AbstractTreeNode implements HasAction, HasPresentation { private String methodName; diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java new file mode 100644 index 00000000000..54245938891 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.ide.view.navigation.nodes; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.che.api.promises.client.Function; +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.api.testing.shared.common.TestResultType; +import org.eclipse.che.api.testing.shared.dto.SimpleLocationDto; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceDto; +import org.eclipse.che.ide.api.data.tree.HasAction; +import org.eclipse.che.ide.api.data.tree.Node; +import org.eclipse.che.plugin.testing.ide.TestResources; +import org.eclipse.che.plugin.testing.ide.TestServiceClient; +import org.eclipse.che.plugin.testing.ide.view.navigation.SimpleLocationHandler; +import org.eclipse.che.plugin.testing.ide.view.navigation.factory.TestResultNodeFactory; + +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; + +/** + * Test result node (i.e. test suite, test case). + * + * @author Bartlomiej Laczkowski + */ +public class TestResultNode extends AbstractTestResultTreeNode implements HasAction { + + private final TestResultDto testResultDto; + private final SimpleLocationHandler simpleLocationHandler; + + @Inject + public TestResultNode(TestServiceClient testServiceClient, TestResultNodeFactory nodeFactory, + TestResources testResources, SimpleLocationHandler simpleLocationHandler, + @Assisted TestResultDto testResultDto, @Assisted String frameworkName) { + super(testServiceClient, nodeFactory, testResources, frameworkName); + this.testResultDto = testResultDto; + this.simpleLocationHandler = simpleLocationHandler; + } + + @Override + public String getName() { + return testResultDto.getName(); + } + + @Override + public boolean isLeaf() { + return testResultDto.getType() == TestResultType.TEST_CASE ? true : false; + } + + @Override + public String getTestInfoText() { + if (testResultDto.getInfoText() != null) + return testResultDto.getInfoText(); + return null; + } + + @Override + public TestResultStatus getTestStatus() { + return testResultDto.getStatus(); + } + + @Override + public TestResultTraceDto getTestTrace() { + return testResultDto.getTrace(); + } + + @Override + public void actionPerformed() { + SimpleLocationDto location = testResultDto.getTestLocation(); + if (location != null) { + simpleLocationHandler.openFile(location); + } + } + + @Override + protected Promise> getChildrenImpl() { + final List children = new ArrayList(); + Promise> promise = testServiceClient.getTestResults(frameworkName, + testResultDto.getResultPath()); + return promise.then(new Function, List>() { + @Override + public List apply(List arg) { + for (TestResultDto entry : arg) { + TestResultNode child = nodeFactory.createTestResultEntryNode(entry, frameworkName); + children.add(child); + } + return children; + } + }); + } + +} diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java new file mode 100644 index 00000000000..08a3f1bb264 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.ide.view.navigation.nodes; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.che.api.promises.client.Function; +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceDto; +import org.eclipse.che.ide.api.data.tree.Node; +import org.eclipse.che.plugin.testing.ide.TestResources; +import org.eclipse.che.plugin.testing.ide.TestServiceClient; +import org.eclipse.che.plugin.testing.ide.view.navigation.factory.TestResultNodeFactory; + +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; + +/** + * Test results root node. + * + * @author Bartlomiej Laczkowski + */ +public class TestResultRootNode extends AbstractTestResultTreeNode { + + private final TestResultRootDto testResultRootDto; + + @Inject + public TestResultRootNode(TestServiceClient testServiceClient, TestResultNodeFactory nodeFactory, + TestResources testResources, @Assisted TestResultRootDto testResultRootDto, + @Assisted String frameworkName) { + super(testServiceClient, nodeFactory, testResources, frameworkName); + this.testResultRootDto = testResultRootDto; + + } + + @Override + public String getName() { + return testResultRootDto.getName(); + } + + @Override + public boolean isLeaf() { + return false; + } + + @Override + public String getTestInfoText() { + if (testResultRootDto.getInfoText() != null) + return testResultRootDto.getInfoText(); + return null; + } + + @Override + public TestResultStatus getTestStatus() { + return testResultRootDto.getStatus(); + } + + @Override + public TestResultTraceDto getTestTrace() { + return testResultRootDto.getTrace(); + } + + @Override + protected Promise> getChildrenImpl() { + final List children = new ArrayList(); + Promise> promise = testServiceClient.getTestResults(frameworkName, + testResultRootDto.getResultPath()); + return promise.then(new Function, List>() { + @Override + public List apply(List arg) { + for (TestResultDto entry : arg) { + TestResultNode child = nodeFactory.createTestResultEntryNode(entry, frameworkName); + children.add(child); + } + return children; + } + }); + } + +} diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java new file mode 100644 index 00000000000..34d19e49b49 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.ide.view.navigation.nodes; + +import java.util.List; + +import javax.validation.constraints.NotNull; + +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.testing.shared.dto.SimpleLocationDto; +import org.eclipse.che.api.testing.shared.dto.TestResultTraceFrameDto; +import org.eclipse.che.ide.api.data.tree.AbstractTreeNode; +import org.eclipse.che.ide.api.data.tree.HasAction; +import org.eclipse.che.ide.api.data.tree.Node; +import org.eclipse.che.ide.ui.smartTree.presentation.HasPresentation; +import org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation; +import org.eclipse.che.plugin.testing.ide.TestResources; +import org.eclipse.che.plugin.testing.ide.view.navigation.SimpleLocationHandler; + +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; + +/** + * Test result trace frame node. + * + * @author Bartlomiej Laczkowski + */ +public class TestResultTraceFrameNode extends AbstractTreeNode implements HasPresentation, HasAction { + + private final TestResources testResources; + private final SimpleLocationHandler simpleLocationHandler; + private final TestResultTraceFrameDto testResultTraceFrameDto; + private NodePresentation nodePresentation; + + @Inject + public TestResultTraceFrameNode(TestResources testResources, SimpleLocationHandler simpleLocationHandler, + @Assisted TestResultTraceFrameDto testResultTraceFrameDto) { + this.testResources = testResources; + this.simpleLocationHandler = simpleLocationHandler; + this.testResultTraceFrameDto = testResultTraceFrameDto; + } + + @Override + public String getName() { + return testResultTraceFrameDto.getTraceFrame(); + } + + @Override + public boolean isLeaf() { + return true; + } + + @Override + public void updatePresentation(@NotNull NodePresentation presentation) { + presentation.setPresentableIcon(testResources.testResultTraceFrameIcon()); + presentation.setPresentableText(getName()); + } + + @Override + public NodePresentation getPresentation(boolean update) { + if (nodePresentation == null) { + nodePresentation = new NodePresentation(); + updatePresentation(nodePresentation); + } + if (update) { + updatePresentation(nodePresentation); + } + return nodePresentation; + } + + @Override + public void actionPerformed() { + SimpleLocationDto location = testResultTraceFrameDto.getLocation(); + if (location != null) { + simpleLocationHandler.openFile(location); + } + } + + @Override + protected Promise> getChildrenImpl() { + return null; + } + +} diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_failure.svg b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_failure.svg new file mode 100644 index 00000000000..227f0012b19 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_failure.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_skipped.svg b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_skipped.svg new file mode 100644 index 00000000000..7133aead365 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_skipped.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_success.svg b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_success.svg new file mode 100644 index 00000000000..d5162851532 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_success.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_trace_frame.svg b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_trace_frame.svg new file mode 100644 index 00000000000..6ee05a002b7 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_trace_frame.svg @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_warning.svg b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_warning.svg new file mode 100644 index 00000000000..fa5acfb9f80 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/svg/test_result_warning.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml index 4839105dd47..b34c3db3cf0 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml @@ -13,38 +13,28 @@ - - - .outputLabel { - user-select: text; - -moz-user-select: text; - -webkit-user-select: text; - -ms-user-select: text; - overflow: scroll; - margin: 2px; - white-space: pre-wrap; - } - - .outputBackground{ - background-color: #1f1f1f; - } + + .traceFrameMessage { + font-family: mainFontFamily; + font-size: fontSize; + font-weight: normal; + line-height: normal; + margin-bottom: 10px; + } - - - - - + - + - + + + - diff --git a/plugins/pom.xml b/plugins/pom.xml index 5eeef7ed636..5e5b096753e 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -56,5 +56,6 @@ plugin-zend-debugger plugin-testing plugin-testing-java + plugin-testing-php diff --git a/pom.xml b/pom.xml index d4250774fc3..e7396235377 100644 --- a/pom.xml +++ b/pom.xml @@ -854,6 +854,16 @@ che-plugin-testing-junit-server ${che.version}
+ + org.eclipse.che.plugin + che-plugin-testing-phpunit-ide + ${che.version} + + + org.eclipse.che.plugin + che-plugin-testing-phpunit-server + ${che.version} + org.eclipse.che.plugin che-plugin-testing-testng-ide diff --git a/wsagent/che-core-api-testing-shared/pom.xml b/wsagent/che-core-api-testing-shared/pom.xml index 3842f253dc7..a79c1e42056 100644 --- a/wsagent/che-core-api-testing-shared/pom.xml +++ b/wsagent/che-core-api-testing-shared/pom.xml @@ -37,5 +37,14 @@ src/main/java + + + com.mycila + license-maven-plugin + + true + + + diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/Failure.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/Failure.java index e7919e65191..f7d0adb8187 100644 --- a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/Failure.java +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/Failure.java @@ -18,6 +18,7 @@ * @author Mirage Abeysekara */ @DTO +@Deprecated public interface Failure { /** diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/TestResult.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/TestResult.java index 5d439c80844..ddd1f31222e 100644 --- a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/TestResult.java +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/TestResult.java @@ -20,6 +20,7 @@ * @author Mirage Abeysekara */ @DTO +@Deprecated public interface TestResult { /** diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultStatus.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultStatus.java new file mode 100644 index 00000000000..a130f10d3f1 --- /dev/null +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultStatus.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.shared.common; + +/** + * Test result status enum. + * + * @author Bartlomiej Laczkowski + */ +public enum TestResultStatus { + + SUCCESS, SKIPPED, WARNING, FAILURE, ERROR; + +} diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultType.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultType.java new file mode 100644 index 00000000000..d946d8ee3c3 --- /dev/null +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/common/TestResultType.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.shared.common; + +/** + * Test result type (test suite or test case). + * + * @author Bartlomiej Laczkowski + */ +public enum TestResultType { + + TEST_SUITE, TEST_CASE; + +} diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java new file mode 100644 index 00000000000..ebf649d7761 --- /dev/null +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.shared.dto; + +import org.eclipse.che.dto.shared.DTO; + +/** + * Provides info about file to be opened in the editor and line number on which + * the selection should be made. + * + * @author Bartlomiej Laczkowski + */ +@DTO +public interface SimpleLocationDto { + + /** + * Returns path to resource that should be opened in the editor. + * + * @return path to resource that should be opened in the editor + */ + String getResourcePath(); + + /** + * Sets path to resource that should be opened in the editor. + * + * @param resourcePath + */ + void setResourcePath(String resourcePath); + + /** + * Returns line number that should be selected in the editor. + * + * @return line number that should be selected in the editor. + */ + int getLineNumber(); + + /** + * Sets the line number that should be selected in the editor. + * + * @param lineNumber + */ + void setLineNumber(int lineNumber); + +} diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java new file mode 100644 index 00000000000..48f2a6edbf7 --- /dev/null +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.shared.dto; + +import java.util.List; + +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.api.testing.shared.common.TestResultType; +import org.eclipse.che.dto.shared.DTO; + +/** + * Test Result DTO. + * + * @author Bartlomiej Laczkowski + */ +@DTO +public interface TestResultDto { + + /** + * Returns test result type (i.e. test case or test suite). + * + * @return test result type (i.e. test case or test suite) + */ + TestResultType getType(); + + /** + * Sets test result type + * + * @param type + */ + void setType(TestResultType type); + + /** + * Returns test result status (success, failure, etc.) + * + * @return test result status + */ + TestResultStatus getStatus(); + + /** + * Sets test result status + * + * @param status + */ + void setStatus(TestResultStatus status); + + /** + * Returns test result name (i.e. test suite/test case name) + * + * @return test result name + */ + String getName(); + + /** + * Sets test result name + * + * @param name + */ + void setName(String name); + + /** + * Returns additional text (i.e. test execution time) that will be added as + * info text in related tree element label. + * + * @return info text + */ + String getInfoText(); + + /** + * Sets additional info text. + * + * @param infoText + */ + void setInfoText(String infoText); + + /** + * Returns test result related stack trace DTO. + * + * @return test result related stack trace DTO + */ + TestResultTraceDto getTrace(); + + /** + * Sets test result related stack trace DTO. + * + * @param traceDto + */ + void setTrace(TestResultTraceDto traceDto); + + /** + * Returns test result simple location DTO (i.e. file with related test + * case). + * + * @return test result simple location DTO + */ + SimpleLocationDto getTestLocation(); + + /** + * Sets test result simple location DTO. + * + * @param simpleLocationDto + */ + void setTestLocation(SimpleLocationDto simpleLocationDto); + + /** + * Returns path to test result. + * + * @return path to test result + */ + List getResultPath(); + + /** + * Sets path to test result. + * + * @param resultPath + */ + void setResultPath(List resultPath); + +} diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java new file mode 100644 index 00000000000..268627fc2ea --- /dev/null +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.shared.dto; + +import java.util.List; + +import org.eclipse.che.api.testing.shared.common.TestResultStatus; +import org.eclipse.che.dto.shared.DTO; + +/** + * Test result root DTO. + * + * @author Bartlomiej Laczkowski + */ +@DTO +public interface TestResultRootDto { + + /** + * Returns related test framework name. + * + * @return related test framework name + */ + String getTestFrameworkName(); + + /** + * Sets related test framework name. + * + * @param frameworkName + */ + void setTestFrameworkName(String frameworkName); + + /** + * Returns overall test result status (success/failure, etc.). + * + * @return overall test result status + */ + TestResultStatus getStatus(); + + /** + * Sets overall test result status + * + * @param status + */ + void setStatus(TestResultStatus status); + + /** + * Returns test result root name. + * + * @return test result root name + */ + String getName(); + + /** + * Sets test result root name. + * + * @param label + */ + void setName(String label); + + /** + * Returns additional text (i.e. test execution time) that will be added as + * info text in related tree element label. + * + * @return info text + */ + String getInfoText(); + + /** + * Sets additional info text. + * + * @param infoText + */ + void setInfoText(String infoText); + + /** + * Returns test result related stack trace DTO. + * + * @return test result related stack trace DTO + */ + TestResultTraceDto getTrace(); + + /** + * Sets test result related stack trace DTO. + * + * @param traceDto + */ + void setTrace(TestResultTraceDto traceDto); + + /** + * Returns path to test result root. + * + * @return path to test result root + */ + List getResultPath(); + + /** + * Sets path to test result root. + * + * @param resultPath + */ + void setResultPath(List resultPath); + +} diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceDto.java new file mode 100644 index 00000000000..f875e41f79b --- /dev/null +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceDto.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.shared.dto; + +import java.util.List; + +import org.eclipse.che.dto.shared.DTO; + +/** + * Test result trace DTO. + * + * @author Bartlomiej Laczkowski + */ +@DTO +public interface TestResultTraceDto { + + /** + * Returns related message (i.e. error/exception description). + * + * @return related message + */ + String getMessage(); + + /** + * Sets related message (i.e. error/exception description). + * + * @param message + */ + void setMessage(String message); + + /** + * Returns list of stack frames for this trace. + * + * @return list of stack frames + */ + List getTraceFrames(); + + /** + * Sets list of stack frames for this trace. + * + * @param traceFrames + */ + void setTraceFrames(List traceFrames); + +} diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java new file mode 100644 index 00000000000..3ce6859bb2f --- /dev/null +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.shared.dto; + +import org.eclipse.che.dto.shared.DTO; + +/** + * Single trace frame DTO. + * + * @author Bartlomiej Laczkowski + */ +@DTO +public interface TestResultTraceFrameDto { + + /** + * Returns trace frame description/name. + * + * @return trace frame description/name + */ + String getTraceFrame(); + + /** + * Sets trace frame description/name. + * + * @param traceFrame + */ + void setTraceFrame(String traceFrame); + + /** + * Returns trace frame simple location DTO (i.e. file with related + * method/function definition). + * + * @return trace frame simple location DTO + */ + SimpleLocationDto getLocation(); + + /** + * Sets trace frame simple location DTO. + * + * @param location + */ + void setLocation(SimpleLocationDto location); + +} diff --git a/wsagent/che-core-api-testing/pom.xml b/wsagent/che-core-api-testing/pom.xml index 8163c937ba7..e5c8975ab0a 100644 --- a/wsagent/che-core-api-testing/pom.xml +++ b/wsagent/che-core-api-testing/pom.xml @@ -111,6 +111,13 @@ + + com.mycila + license-maven-plugin + + true + + org.eclipse.che.core che-core-api-dto-maven-plugin diff --git a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestingService.java b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestingService.java index b7428ad4565..0ec76a2fd65 100644 --- a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestingService.java +++ b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestingService.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.api.testing.server; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,6 +27,8 @@ import org.eclipse.che.api.testing.server.framework.TestFrameworkRegistry; import org.eclipse.che.api.testing.server.framework.TestRunner; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.core.resources.ResourcesPlugin; import io.swagger.annotations.Api; @@ -64,7 +67,9 @@ public TestingService(TestFrameworkRegistry frameworkRegistry) { * @return the test result of test case * @throws Exception * when the test runner failed to execute test cases. + * @deprecated Use "runtests" instead */ + @Deprecated @GET @Path("run") @Produces(MediaType.APPLICATION_JSON) @@ -76,12 +81,51 @@ public TestResult run(@Context UriInfo uriInfo) throws Exception { String absoluteProjectPath = ResourcesPlugin.getPathToWorkspace() + projectPath; queryParameters.put("absoluteProjectPath", absoluteProjectPath); String testFramework = queryParameters.get("testFramework"); + getTestRunner(testFramework); + TestResult result = frameworkRegistry.getTestRunner(testFramework).execute(queryParameters); + return result; + } + + @GET + @Path("runtests") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Execute Java tests and return result root entry", notes = "The GET parameters are passed to the test framework implementation.") + @ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Server error") }) + public TestResultRootDto runTests(@Context UriInfo uriInfo) throws Exception { + Map queryParameters = getMap(uriInfo.getQueryParameters()); + String projectPath = queryParameters.get("projectPath"); + String absoluteProjectPath = ResourcesPlugin.getPathToWorkspace() + projectPath; + queryParameters.put("absoluteProjectPath", absoluteProjectPath); + String testFramework = queryParameters.get("testFramework"); + getTestRunner(testFramework); + TestResultRootDto result = frameworkRegistry.getTestRunner(testFramework).runTests(queryParameters); + return result; + } + + @GET + @Path("gettestresults") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Execute Java tests and return result root entry", notes = "The GET parameters are passed to the test framework implementation.") + @ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Server error") }) + public List getTestResults(@Context UriInfo uriInfo) throws Exception { + Map queryParameters = getMap(uriInfo.getQueryParameters()); + String testFramework = queryParameters.get("testFramework"); + int i = 0; + String item; + List testResultsPath = new ArrayList<>(); + while ((item = queryParameters.get("path" + (i++))) != null) { + testResultsPath.add(item); + } + getTestRunner(testFramework); + List result = frameworkRegistry.getTestRunner(testFramework).getTestResults(testResultsPath); + return result; + } + + private void getTestRunner(String testFramework) throws Exception { TestRunner runner = frameworkRegistry.getTestRunner(testFramework); if (runner == null) { throw new Exception("No test frameworks found: " + testFramework); } - TestResult result = frameworkRegistry.getTestRunner(testFramework).execute(queryParameters); - return result; } private Map getMap(MultivaluedMap queryParameters) { @@ -101,4 +145,5 @@ private Map getMap(MultivaluedMap queryParameter } return map; } + } diff --git a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/framework/TestRunner.java b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/framework/TestRunner.java index c13e7310ec2..575810d3ca7 100644 --- a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/framework/TestRunner.java +++ b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/framework/TestRunner.java @@ -10,9 +10,12 @@ *******************************************************************************/ package org.eclipse.che.api.testing.server.framework; +import java.util.List; import java.util.Map; import org.eclipse.che.api.testing.shared.TestResult; +import org.eclipse.che.api.testing.shared.dto.TestResultDto; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; /** * Interface for defining test frameworks for the test runner. All test @@ -36,8 +39,34 @@ public interface TestRunner { * @throws Exception * when test runner execution fails. */ + @Deprecated TestResult execute(Map testParameters) throws Exception; + /** + * Call this method to execute the test cases and return the results. The + * test runner framework will automatically call this method to execute + * tests. + * + * @param testParameters + * Map of parameters for executing the test cases. Most of the + * parameters are coming from the REST service request are passed + * as a map. + * @return the test results. + * @throws Exception + * when test runner execution fails. + */ + TestResultRootDto runTests(Map testParameters) throws Exception; + + /** + * Call this method to get child elements for test result that is stored + * under given path (i.e. test cases/test suites that are grouped by related + * test suite). + * + * @param testResultsPath + * @return child elements for test result under given path + */ + List getTestResults(List testResultsPath); + /** * The test runner framework will call this method to get the framework name * for registration. From e73700859e8bd3d4eb81617d7136591c7ab986d4 Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Tue, 28 Feb 2017 09:55:54 +0100 Subject: [PATCH 2/9] Added improvements for exceptions handling and presentation model. Signed-off-by: Bartlomiej Laczkowski --- ...tAction.java => JUnitTestActionGroup.java} | 6 +- .../junit/ide/inject/JUnitGinModule.java | 6 +- ...Action.java => TestNGTestActionGroup.java} | 6 +- .../testng/ide/inject/TestNGGinModule.java | 6 +- .../che-plugin-testing-phpunit-ide/pom.xml | 4 - .../testing/phpunit/ide/PHPUnitGinModule.java | 4 +- ...ction.java => PHPUnitTestActionGroup.java} | 6 +- .../ide/action/PHPRunContainerTestAction.java | 52 +-------- .../ide/action/PHPRunScriptTestAction.java | 54 +-------- ...PHPUnitTestLocalizationConstant.properties | 6 +- .../phpunit/server/PHPUnitTestEngine.java | 34 ++++-- .../server/PHPUnitTestResultsProvider.java | 11 +- .../{TestAction.java => TestActionGroup.java} | 2 +- .../plugin/testing/ide/TestActionRunner.java | 103 ++++++++++++++++++ .../plugin/testing/ide/TestingExtension.java | 6 +- .../testing/ide/inject/TestingGinModule.java | 6 +- .../testing/ide/view/TestResultPresenter.java | 4 + .../testing/ide/view/TestResultView.java | 5 + .../testing/ide/view/TestResultViewImpl.java | 91 ++++++++++------ .../testing/shared/dto/TestResultRootDto.java | 16 +++ wsagent/che-core-api-testing/pom.xml | 8 ++ .../{TestingService.java => TestService.java} | 19 +++- .../exceptions/TestFrameworkException.java | 31 ++++++ .../server/inject/TestGuiceModule.java | 4 +- ...gServiceTest.java => TestServiceTest.java} | 6 +- 25 files changed, 315 insertions(+), 181 deletions(-) rename plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/{JUnitTestAction.java => JUnitTestActionGroup.java} (94%) rename plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/{TestNGTestAction.java => TestNGTestActionGroup.java} (94%) rename plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/{PHPUnitTestAction.java => PHPUnitTestActionGroup.java} (89%) rename plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/{TestAction.java => TestActionGroup.java} (97%) create mode 100644 plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java rename wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/{TestingService.java => TestService.java} (90%) create mode 100644 wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/exceptions/TestFrameworkException.java rename wsagent/che-core-api-testing/src/test/java/org/eclipse/che/api/testing/server/{TestingServiceTest.java => TestServiceTest.java} (96%) diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestAction.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestActionGroup.java similarity index 94% rename from plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestAction.java rename to plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestActionGroup.java index e0fbc8e39f9..59ce0a85964 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestActionGroup.java @@ -16,7 +16,7 @@ import org.eclipse.che.ide.api.keybinding.KeyBindingAgent; import org.eclipse.che.ide.api.keybinding.KeyBuilder; import org.eclipse.che.ide.util.browser.UserAgent; -import org.eclipse.che.plugin.testing.ide.TestAction; +import org.eclipse.che.plugin.testing.ide.TestActionGroup; import org.eclipse.che.plugin.testing.junit.ide.action.RunAllTestAction; import org.eclipse.che.plugin.testing.junit.ide.action.RunClassContextTestAction; import org.eclipse.che.plugin.testing.junit.ide.action.RunClassTestAction; @@ -28,14 +28,14 @@ * * @author Mirage Abeysekara */ -public class JUnitTestAction implements TestAction { +public class JUnitTestActionGroup implements TestActionGroup { private final Action runClassTestAction; private final Action runAllTestAction; private final Action runClassContextTestAction; @Inject - public JUnitTestAction(ActionManager actionManager, + public JUnitTestActionGroup(ActionManager actionManager, RunClassTestAction runClassTestAction, RunAllTestAction runAllTestAction, RunClassContextTestAction runClassContextTestAction, diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java index a84f1dd80d5..e1a63b87111 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java @@ -11,8 +11,8 @@ package org.eclipse.che.plugin.testing.junit.ide.inject; import org.eclipse.che.ide.api.extension.ExtensionGinModule; -import org.eclipse.che.plugin.testing.ide.TestAction; -import org.eclipse.che.plugin.testing.junit.ide.JUnitTestAction; +import org.eclipse.che.plugin.testing.ide.TestActionGroup; +import org.eclipse.che.plugin.testing.junit.ide.JUnitTestActionGroup; import com.google.gwt.inject.client.AbstractGinModule; import com.google.gwt.inject.client.multibindings.GinMultibinder; @@ -25,6 +25,6 @@ public class JUnitGinModule extends AbstractGinModule { @Override protected void configure() { - GinMultibinder.newSetBinder(binder(), TestAction.class).addBinding().to(JUnitTestAction.class); + GinMultibinder.newSetBinder(binder(), TestActionGroup.class).addBinding().to(JUnitTestActionGroup.class); } } diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestAction.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestActionGroup.java similarity index 94% rename from plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestAction.java rename to plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestActionGroup.java index e0d24a44185..991eb493519 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestAction.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/TestNGTestActionGroup.java @@ -16,7 +16,7 @@ import org.eclipse.che.ide.api.keybinding.KeyBindingAgent; import org.eclipse.che.ide.api.keybinding.KeyBuilder; import org.eclipse.che.ide.util.browser.UserAgent; -import org.eclipse.che.plugin.testing.ide.TestAction; +import org.eclipse.che.plugin.testing.ide.TestActionGroup; import org.eclipse.che.plugin.testing.testng.ide.action.RunAllTestAction; import org.eclipse.che.plugin.testing.testng.ide.action.RunClassContextTestAction; import org.eclipse.che.plugin.testing.testng.ide.action.RunClassTestAction; @@ -29,7 +29,7 @@ * * @author Mirage Abeysekara */ -public class TestNGTestAction implements TestAction { +public class TestNGTestActionGroup implements TestActionGroup { private final Action runClassTestAction; private final Action runAllTestAction; @@ -37,7 +37,7 @@ public class TestNGTestAction implements TestAction { private final Action runTestXMLAction; @Inject - public TestNGTestAction(ActionManager actionManager, + public TestNGTestActionGroup(ActionManager actionManager, RunClassTestAction runClassTestAction, RunAllTestAction runAllTestAction, RunClassContextTestAction runClassContextTestAction, diff --git a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/inject/TestNGGinModule.java b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/inject/TestNGGinModule.java index fe73b6d8313..4a58e2e863a 100644 --- a/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/inject/TestNGGinModule.java +++ b/plugins/plugin-testing-java/plugin-testing-testng/che-plugin-testing-testng-ide/src/main/java/org/eclipse/che/plugin/testing/testng/ide/inject/TestNGGinModule.java @@ -11,8 +11,8 @@ package org.eclipse.che.plugin.testing.testng.ide.inject; import org.eclipse.che.ide.api.extension.ExtensionGinModule; -import org.eclipse.che.plugin.testing.ide.TestAction; -import org.eclipse.che.plugin.testing.testng.ide.TestNGTestAction; +import org.eclipse.che.plugin.testing.ide.TestActionGroup; +import org.eclipse.che.plugin.testing.testng.ide.TestNGTestActionGroup; import com.google.gwt.inject.client.AbstractGinModule; import com.google.gwt.inject.client.multibindings.GinMultibinder; @@ -25,6 +25,6 @@ public class TestNGGinModule extends AbstractGinModule { @Override protected void configure() { - GinMultibinder.newSetBinder(binder(), TestAction.class).addBinding().to(TestNGTestAction.class); + GinMultibinder.newSetBinder(binder(), TestActionGroup.class).addBinding().to(TestNGTestActionGroup.class); } } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml index 789ae2e43a6..ed13c86605b 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml @@ -29,10 +29,6 @@ javax.validation validation-api - - org.eclipse.che.core - che-core-api-testing-shared - org.eclipse.che.core che-core-commons-gwt diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java index 640e93266f2..fa9ce245555 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitGinModule.java @@ -11,7 +11,7 @@ package org.eclipse.che.plugin.testing.phpunit.ide; import org.eclipse.che.ide.api.extension.ExtensionGinModule; -import org.eclipse.che.plugin.testing.ide.TestAction; +import org.eclipse.che.plugin.testing.ide.TestActionGroup; import com.google.gwt.inject.client.AbstractGinModule; import com.google.gwt.inject.client.multibindings.GinMultibinder; @@ -25,6 +25,6 @@ public class PHPUnitGinModule extends AbstractGinModule { @Override protected void configure() { - GinMultibinder.newSetBinder(binder(), TestAction.class).addBinding().to(PHPUnitTestAction.class); + GinMultibinder.newSetBinder(binder(), TestActionGroup.class).addBinding().to(PHPUnitTestActionGroup.class); } } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java similarity index 89% rename from plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestAction.java rename to plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java index fec186cf6b3..5459ffdc535 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestAction.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java @@ -14,7 +14,7 @@ import org.eclipse.che.ide.api.action.ActionManager; import org.eclipse.che.ide.api.action.DefaultActionGroup; import org.eclipse.che.ide.api.keybinding.KeyBindingAgent; -import org.eclipse.che.plugin.testing.ide.TestAction; +import org.eclipse.che.plugin.testing.ide.TestActionGroup; import org.eclipse.che.plugin.testing.phpunit.ide.action.PHPRunContainerTestAction; import org.eclipse.che.plugin.testing.phpunit.ide.action.PHPRunScriptTestAction; @@ -25,13 +25,13 @@ * * @author Bartlomiej Laczkowski */ -public class PHPUnitTestAction implements TestAction { +public class PHPUnitTestActionGroup implements TestActionGroup { private final Action runScriptTestAction; private PHPRunContainerTestAction runContainerTestAction; @Inject - public PHPUnitTestAction(ActionManager actionManager, PHPRunScriptTestAction runScriptTestAction, + public PHPUnitTestActionGroup(ActionManager actionManager, PHPRunScriptTestAction runScriptTestAction, PHPRunContainerTestAction runAllTestAction, KeyBindingAgent keyBinding) { actionManager.registerAction("PHPRunScriptTestAction", runScriptTestAction); actionManager.registerAction("PHPRunAllTestAction", runAllTestAction); diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java index 20142f1d62f..794e2e6891a 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java @@ -10,10 +10,6 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.phpunit.ide.action; -import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; import java.util.Arrays; @@ -22,24 +18,15 @@ import javax.validation.constraints.NotNull; -import org.eclipse.che.api.promises.client.Operation; -import org.eclipse.che.api.promises.client.OperationException; -import org.eclipse.che.api.promises.client.Promise; -import org.eclipse.che.api.promises.client.PromiseError; -import org.eclipse.che.api.testing.shared.common.TestResultStatus; -import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.notification.StatusNotification; import org.eclipse.che.ide.api.resources.Container; import org.eclipse.che.ide.api.resources.Project; import org.eclipse.che.ide.api.selection.Selection; import org.eclipse.che.ide.api.selection.SelectionAgent; import org.eclipse.che.ide.resources.tree.ContainerNode; -import org.eclipse.che.plugin.testing.ide.TestServiceClient; -import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; +import org.eclipse.che.plugin.testing.ide.TestActionRunner; import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestLocalizationConstant; import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestResources; @@ -52,29 +39,22 @@ */ public class PHPRunContainerTestAction extends AbstractPerspectiveAction { - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; + private final TestActionRunner runner; private final AppContext appContext; private final SelectionAgent selectionAgent; @Inject - public PHPRunContainerTestAction(PHPUnitTestResources resources, NotificationManager notificationManager, - AppContext appContext, TestResultPresenter presenter, TestServiceClient service, + public PHPRunContainerTestAction(TestActionRunner runner, PHPUnitTestResources resources, AppContext appContext, SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunContainerTitle(), localization.actionRunScriptDescription(), null, resources.testIcon()); - this.notificationManager = notificationManager; - this.presenter = presenter; - this.service = service; + this.runner = runner; this.appContext = appContext; this.selectionAgent = selectionAgent; } @Override public void actionPerformed(ActionEvent e) { - final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE); - notificationManager.notify(notification); final Selection selection = selectionAgent.getSelection(); final Object possibleNode = selection.getHeadElement(); if (possibleNode instanceof ContainerNode) { @@ -82,29 +62,7 @@ public void actionPerformed(ActionEvent e) { final Project project = appContext.getRootProject(); Map parameters = new HashMap<>(); parameters.put("testTarget", container.getLocation().toString()); - Promise testResultPromise = service.runTests("PHPUnit", project.getPath(), parameters); - testResultPromise.then(new Operation() { - @Override - public void apply(TestResultRootDto result) throws OperationException { - notification.setStatus(SUCCESS); - if (result.getStatus() == TestResultStatus.SUCCESS) { - notification.setTitle("Test runner executed successfully"); - notification.setContent("All tests are passed"); - } else { - notification.setTitle("Test runner executed successfully with test failures."); - notification.setContent("Some test(s) failed.\n"); - } - presenter.handleResponse(result); - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError exception) throws OperationException { - final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() - : "Failed to run test cases"; - notification.setContent(errorMessage); - notification.setStatus(FAIL); - } - }); + runner.run("PHPUnit", project.getPath(), parameters); } } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java index dd0ecd625bb..db72ed589d6 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java @@ -10,10 +10,6 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.phpunit.ide.action; -import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; import java.util.Arrays; @@ -22,24 +18,15 @@ import javax.validation.constraints.NotNull; -import org.eclipse.che.api.promises.client.Operation; -import org.eclipse.che.api.promises.client.OperationException; -import org.eclipse.che.api.promises.client.Promise; -import org.eclipse.che.api.promises.client.PromiseError; -import org.eclipse.che.api.testing.shared.common.TestResultStatus; -import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; import org.eclipse.che.ide.api.action.ActionEvent; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.notification.StatusNotification; import org.eclipse.che.ide.api.resources.Project; import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.api.selection.Selection; import org.eclipse.che.ide.api.selection.SelectionAgent; import org.eclipse.che.ide.resources.tree.FileNode; -import org.eclipse.che.plugin.testing.ide.TestServiceClient; -import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; +import org.eclipse.che.plugin.testing.ide.TestActionRunner; import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestLocalizationConstant; import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestResources; @@ -52,29 +39,22 @@ */ public class PHPRunScriptTestAction extends AbstractPerspectiveAction { - private final NotificationManager notificationManager; - private final TestResultPresenter presenter; - private final TestServiceClient service; + private final TestActionRunner runner; private final AppContext appContext; private final SelectionAgent selectionAgent; @Inject - public PHPRunScriptTestAction(PHPUnitTestResources resources, NotificationManager notificationManager, - AppContext appContext, TestResultPresenter presenter, TestServiceClient service, - SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { + public PHPRunScriptTestAction(TestActionRunner runner, PHPUnitTestResources resources, AppContext appContext, SelectionAgent selectionAgent, + PHPUnitTestLocalizationConstant localization) { super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunScriptTitle(), localization.actionRunScriptDescription(), null, resources.testIcon()); - this.notificationManager = notificationManager; - this.presenter = presenter; - this.service = service; + this.runner = runner; this.appContext = appContext; this.selectionAgent = selectionAgent; } @Override public void actionPerformed(ActionEvent e) { - final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE); - notificationManager.notify(notification); final Selection selection = selectionAgent.getSelection(); final Object possibleNode = selection.getHeadElement(); if (possibleNode instanceof FileNode) { @@ -82,29 +62,7 @@ public void actionPerformed(ActionEvent e) { final Project project = appContext.getRootProject(); Map parameters = new HashMap<>(); parameters.put("testTarget", file.getLocation().toString()); - Promise testResultPromise = service.runTests("PHPUnit", project.getPath(), parameters); - testResultPromise.then(new Operation() { - @Override - public void apply(TestResultRootDto result) throws OperationException { - notification.setStatus(SUCCESS); - if (result.getStatus() == TestResultStatus.SUCCESS) { - notification.setTitle("Test runner executed successfully"); - notification.setContent("All tests are passed"); - } else { - notification.setTitle("Test runner executed successfully with test failures."); - notification.setContent("Some test(s) failed.\n"); - } - presenter.handleResponse(result); - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError exception) throws OperationException { - final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() - : "Failed to run test cases"; - notification.setContent(errorMessage); - notification.setStatus(FAIL); - } - }); + runner.run("PHPUnit", project.getPath(), parameters); } } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties index 84b7c7c4757..20348356e8b 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/resources/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.properties @@ -9,10 +9,8 @@ # Rogue Wave Software, Inc. - initial API and implementation # - - ##### Actions ##### -action.runScript.title = PHPUnit Script +action.runScript.title = PHPUnit action.runScript.description = Run the currently selected PHPUnit test script -action.runContainer.title = PHPUnit Container +action.runContainer.title = PHPUnit action.runContainer.description = Run all the tests available under PHPUnit test container diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java index 263c784310c..d0f7afbf553 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java @@ -28,11 +28,13 @@ import org.apache.commons.io.FileUtils; import org.eclipse.che.api.core.ServerException; +import org.eclipse.che.api.core.util.AbstractLineConsumer; import org.eclipse.che.api.core.util.CommandLine; import org.eclipse.che.api.core.util.LineConsumer; import org.eclipse.che.api.core.util.ProcessUtil; import org.eclipse.che.api.project.server.ProjectManager; import org.eclipse.che.api.project.server.VirtualFileEntry; +import org.eclipse.che.api.testing.server.exceptions.TestFrameworkException; import org.eclipse.che.api.testing.shared.dto.TestResultDto; import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.che.api.vfs.Path; @@ -71,7 +73,7 @@ public Thread newThread(Runnable r) { public void run() { try { serverSocket = new ServerSocket(PRINTER_PORT, 1); - serverSocket.setSoTimeout(10000); + serverSocket.setSoTimeout(3000); serverSocket.setReuseAddress(true); // Release engine to perform tests latchReady.countDown(); @@ -156,7 +158,11 @@ public TestResultRootDto executeTests(Map testParameters) throws String projectPath = testParameters.get("projectPath"); String projectAbsolutePath = testParameters.get("absoluteProjectPath"); String testTarget = testParameters.get("testTarget"); - Path testTargetAbsolutePath = Path.of(projectAbsolutePath).newPath(Path.of(testTarget).subPath(1)); + Path testTargetAbsolutePath; + if (Path.of(testTarget).length() > 1) + testTargetAbsolutePath = Path.of(projectAbsolutePath).newPath(Path.of(testTarget).subPath(1)); + else + testTargetAbsolutePath = Path.of(projectAbsolutePath); String testTargetWorkingDirectory = testTargetAbsolutePath.getParent().toString(); String testTargetName = testTargetAbsolutePath.getName(); // Get appropriate path to executable @@ -181,15 +187,27 @@ public TestResultRootDto executeTests(Map testParameters) throws } final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--include-path", printerDirAbsolutePath, "--printer", phpPrinterName, testTargetName); - Process processBuildClassPath = new ProcessBuilder().redirectErrorStream(true) - .directory(new File(testTargetWorkingDirectory)).command(cmdRunTests.toShellCommand()).start(); - ProcessUtil.process(processBuildClassPath, LineConsumer.DEV_NULL); - processBuildClassPath.waitFor(); + ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true) + .directory(new File(testTargetWorkingDirectory)).command(cmdRunTests.toShellCommand()); + pb.environment().put("ZEND_PHPUNIT_PORT", String.valueOf(PRINTER_PORT)); + Process processRunPHPUnitTests = pb.start(); + final StringBuilder stdErrOut = new StringBuilder(); + ProcessUtil.process(processRunPHPUnitTests, new AbstractLineConsumer() { + @Override + public void writeLine(String line) throws IOException { + if (!line.isEmpty()) + stdErrOut.append("\t" + line + "\n"); + } + }); + int exitValue = processRunPHPUnitTests.waitFor(); try { latchDone.await(); } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } + if (exitValue != 0 && stdErrOut.length() > 0 && phpTestsRoot.getChildren() == null) { + throw new TestFrameworkException("PHPUnit Error:\n" + stdErrOut.toString()); + } return testResultsProvider.getTestResultsRoot(phpTestsRoot); } @@ -255,10 +273,10 @@ private boolean hasComposerRunner(String projectPath) { Gson gson = new GsonBuilder().create(); Map composerJsonMap = gson.fromJson(reader, LinkedTreeMap.class); Map requireDev = (Map) composerJsonMap.get("require-dev"); - if (requireDev.get("phpunit/phpunit") != null) + if (requireDev != null && requireDev.get("phpunit/phpunit") != null) return true; Map require = (Map) composerJsonMap.get("require"); - if (require.get("phpunit/phpunit") != null) + if (require != null && require.get("phpunit/phpunit") != null) return true; } catch (Exception e) { LOG.error(e.getMessage(), e); diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java index 16b1ab91a2a..742f8ffde53 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java @@ -26,9 +26,9 @@ import org.eclipse.che.api.testing.shared.dto.TestResultTraceDto; import org.eclipse.che.api.testing.shared.dto.TestResultTraceFrameDto; import org.eclipse.che.dto.server.DtoFactory; -import org.eclipse.che.plugin.testing.phpunit.server.model.AbstractPHPUnitTestEvent; import org.eclipse.che.plugin.testing.phpunit.server.model.AbstractPHPUnitTestResult; import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestCase; +import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestException; import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestRoot; import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTestSuite; import org.eclipse.che.plugin.testing.phpunit.server.model.PHPUnitTraceFrame; @@ -55,6 +55,7 @@ public TestResultRootDto getTestResultsRoot(PHPUnitTestRoot resultsRoot) { testResultRootDto.setResultPath(Collections.singletonList("php-tests-root")); testResultRootDto.setName(getRootLabel(resultsRoot.getStatus())); testResultRootDto.setInfoText(getTimeString(resultsRoot.getTime())); + testResultRootDto.setEmpty(resultsRoot.getChildren() == null); // Add PHP related test result to cache testResultsCache.put(getKey(testResultRootDto.getResultPath()), resultsRoot); return testResultRootDto; @@ -91,7 +92,7 @@ private TestResultDto getTestResult(AbstractPHPUnitTestResult phpTestResult, Lis phpTestResult instanceof PHPUnitTestSuite ? TestResultType.TEST_SUITE : TestResultType.TEST_CASE); SimpleLocationDto simpleLocationDto = DtoFactory.getInstance().createDto(SimpleLocationDto.class); simpleLocationDto.setResourcePath(phpTestResult.getFile()); - simpleLocationDto.setLineNumber(phpTestResult.getLine()); + simpleLocationDto.setLineNumber(phpTestResult.getLine() - 1); testResultDto.setTestLocation(simpleLocationDto); // Add PHP related test result to cache testResultsCache.put(getKey(testResultDto.getResultPath()), phpTestResult); @@ -102,9 +103,9 @@ private TestResultTraceDto getTestTrace(AbstractPHPUnitTestResult phpTestResult) TestResultTraceDto testResultTraceDto = DtoFactory.getInstance().createDto(TestResultTraceDto.class); if (phpTestResult instanceof PHPUnitTestCase) { PHPUnitTestCase phpTestCase = (PHPUnitTestCase) phpTestResult; - AbstractPHPUnitTestEvent phpTestEvent = phpTestCase.getException(); + PHPUnitTestException phpTestEvent = phpTestCase.getException(); if (phpTestEvent != null) { - testResultTraceDto.setMessage(phpTestEvent.getMessage()); + testResultTraceDto.setMessage(phpTestEvent.getExceptionClass() + ": " + phpTestEvent.getMessage()); List traceFrames = new ArrayList<>(); for (PHPUnitTraceFrame phpTraceFrame : phpTestEvent.getTrace()) { TestResultTraceFrameDto testResultTraceFrameDto = DtoFactory.getInstance() @@ -112,7 +113,7 @@ private TestResultTraceDto getTestTrace(AbstractPHPUnitTestResult phpTestResult) testResultTraceFrameDto.setTraceFrame(phpTraceFrame.toString()); SimpleLocationDto simpleLocationDto = DtoFactory.getInstance().createDto(SimpleLocationDto.class); simpleLocationDto.setResourcePath(phpTraceFrame.getFile()); - simpleLocationDto.setLineNumber(phpTraceFrame.getLine()); + simpleLocationDto.setLineNumber(phpTraceFrame.getLine() - 1); testResultTraceFrameDto.setLocation(simpleLocationDto); traceFrames.add(testResultTraceFrameDto); } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestAction.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionGroup.java similarity index 97% rename from plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestAction.java rename to plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionGroup.java index a910547feaa..343314e1414 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestAction.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionGroup.java @@ -19,7 +19,7 @@ * * @author Mirage Abeysekara */ -public interface TestAction { +public interface TestActionGroup { /** * This method get called when the extension is loading and adding the menu diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java new file mode 100644 index 00000000000..ba53607a895 --- /dev/null +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.ide; + +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; + +import java.util.Map; + +import org.eclipse.che.api.promises.client.Operation; +import org.eclipse.che.api.promises.client.OperationException; +import org.eclipse.che.api.promises.client.Promise; +import org.eclipse.che.api.promises.client.PromiseError; +import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; +import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.notification.StatusNotification; +import org.eclipse.che.plugin.testing.ide.view.TestResultPresenter; + +import com.google.inject.Inject; + +/** + * Test action runner. + * + * @author Bartlomiej Laczkowski + */ +public class TestActionRunner { + + private final TestServiceClient service; + private final NotificationManager notificationManager; + private final TestResultPresenter presenter; + + @Inject + public TestActionRunner(TestServiceClient service, NotificationManager notificationManager, + TestResultPresenter presenter) { + this.service = service; + this.notificationManager = notificationManager; + this.presenter = presenter; + } + + public void run(String testFramework, String projectPath, Map parameters) { + presenter.clear(); + final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE); + notificationManager.notify(notification); + Promise testResultPromise = service.runTests(testFramework, projectPath, parameters); + testResultPromise.then(new Operation() { + @Override + public void apply(TestResultRootDto result) throws OperationException { + if (result.isEmpty()) { + notification.setStatus(FAIL); + notification.setTitle("No tests could be found"); + return; + } + notification.setStatus(SUCCESS); + switch (result.getStatus()) { + case SUCCESS: { + notification.setTitle("Test runner executed successfully"); + notification.setContent("All tests passed."); + break; + } + case FAILURE: { + notification.setTitle("Test runner executed successfully with test failures"); + notification.setContent("Some test(s) failed."); + break; + } + case ERROR: { + notification.setTitle("Test runner executed successfully with test errors"); + notification.setContent("Some test(s) failed with errors."); + break; + } + case WARNING: { + notification.setTitle("Test runner executed successfully with test warnings"); + notification.setContent("Some test(s) passed with warnings."); + break; + } + case SKIPPED: { + notification.setTitle("Test runner executed successfully with some tests skipped"); + notification.setContent("Some test(s) were skipped."); + break; + } + } + presenter.handleResponse(result); + } + }).catchError(new Operation() { + @Override + public void apply(PromiseError exception) throws OperationException { + notification.setTitle("Failed to execute test runner"); + notification.setContent("Please see dev-machine log for more details."); + notification.setStatus(FAIL); + } + }); + } + +} diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestingExtension.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestingExtension.java index 5f8e0e7e17b..ca48be0a10c 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestingExtension.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestingExtension.java @@ -34,12 +34,12 @@ public class TestingExtension { @Inject public TestingExtension(ActionManager actionManager, TestLocalizationConstant localization, - Set testActions) { + Set testActions) { DefaultActionGroup runMenu = (DefaultActionGroup) actionManager.getAction(GROUP_RUN); DefaultActionGroup testMainMenu = new DefaultActionGroup(localization.actionGroupMenuName(), true, actionManager); actionManager.registerAction("TestingMainGroup", testMainMenu); - for (TestAction testAction : testActions) { + for (TestActionGroup testAction : testActions) { testAction.addMainMenuItems(testMainMenu); testMainMenu.addSeparator(); } @@ -49,7 +49,7 @@ public TestingExtension(ActionManager actionManager, DefaultActionGroup testContextMenu = new DefaultActionGroup(localization.actionGroupMenuName(), true, actionManager); actionManager.registerAction("TestingContextGroup", testContextMenu); - for (TestAction testAction : testActions) { + for (TestActionGroup testAction : testActions) { testAction.addContextMenuItems(testContextMenu); testContextMenu.addSeparator(); } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/inject/TestingGinModule.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/inject/TestingGinModule.java index d8ee0e39460..d24a1505268 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/inject/TestingGinModule.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/inject/TestingGinModule.java @@ -10,13 +10,13 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.ide.inject; -import com.google.gwt.inject.client.AbstractGinModule; -import com.google.gwt.inject.client.assistedinject.GinFactoryModuleBuilder; - import org.eclipse.che.ide.api.extension.ExtensionGinModule; import org.eclipse.che.plugin.testing.ide.view.TestResultView; import org.eclipse.che.plugin.testing.ide.view.TestResultViewImpl; import org.eclipse.che.plugin.testing.ide.view.navigation.factory.TestResultNodeFactory; + +import com.google.gwt.inject.client.AbstractGinModule; +import com.google.gwt.inject.client.assistedinject.GinFactoryModuleBuilder; /** * Gin Module for test runner extension. * diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java index 9c281895ca0..ae32193f4aa 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultPresenter.java @@ -95,4 +95,8 @@ public void handleResponse(TestResultRootDto response) { workspaceAgent.setActivePart(this); view.showResults(response); } + + public void clear() { + view.clear(); + } } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java index 53c91e1f1a1..63f89d183f8 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultView.java @@ -46,6 +46,11 @@ public interface TestResultView extends View { * test results which comes from the server */ void showResults(TestResultRootDto result); + + /** + * Clears the result view. + */ + void clear(); interface ActionDelegate extends BaseActionDelegate { } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java index 70d271143f2..75cef09461b 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java @@ -96,8 +96,6 @@ interface Styles extends CssResource { private final EditorAgent editorAgent; private final EventBus eventBus; private final TestResultNodeFactory nodeFactory; - private Tree resultTree; - private Tree traceTree; private int lastWentLine = 0; @UiField(provided = true) @@ -122,20 +120,6 @@ public TestResultViewImpl(PartStackUIResources resources, EditorAgent editorAgen this.nodeFactory = nodeFactory; splitLayoutPanel = new SplitLayoutPanel(1); setContentWidget(UI_BINDER.createAndBindUi(this)); - resultTree = createTree(); - resultTree.getSelectionModel().addSelectionHandler(new SelectionHandler() { - @Override - public void onSelection(SelectionEvent event) { - Node selectedNode = event.getSelectedItem(); - if (selectedNode instanceof TestResultMethodNode) { - fillOutputPanel(((TestResultMethodNode) selectedNode).getStackTrace()); - } - if (selectedNode instanceof AbstractTestResultTreeNode) { - fillOutputPanel((AbstractTestResultTreeNode) selectedNode); - } - } - }); - navigationPanel.add(resultTree); } private Tree createTree() { @@ -168,7 +152,7 @@ protected void focusView() { @Deprecated public void showResults(TestResult result) { setTitle("Test Results (Framework: " + result.getTestFramework() + ")"); - buildResultTree(result); + fillNavigationPanel(result); focusView(); } @@ -178,13 +162,23 @@ public void showResults(TestResult result) { @Override public void showResults(TestResultRootDto result) { setTitle("Test Results (Framework: " + result.getTestFrameworkName() + ")"); - buildResultTree(result); + fillNavigationPanel(result); focusView(); } + /** + * {@inheritDoc} + */ + @Override + public void clear() { + setTitle(""); + navigationPanel.clear(); + traceOutputPanel.clear(); + } + @Deprecated - private void buildResultTree(TestResult result) { - resultTree.getNodeStorage().clear(); + private void fillNavigationPanel(TestResult result) { + Tree resultTree = buildResultTree(result); // outputResult.setText(""); TestResultGroupNode root = nodeFactory.getTestResultGroupNode(result); Map> classNodeHashMap = new HashMap<>(); @@ -205,23 +199,43 @@ private void buildResultTree(TestResult result) { } root.setChildren(classNodes); resultTree.getNodeStorage().add(root); + navigationPanel.add(resultTree); } - private void buildResultTree(TestResultRootDto result) { - resultTree.getNodeStorage().clear(); + private void fillNavigationPanel(TestResultRootDto result) { + Tree resultTree = buildResultTree(result); TestResultRootNode root = nodeFactory.createTestResultRootNode(result, result.getTestFrameworkName()); resultTree.getNodeStorage().add(root); + navigationPanel.add(resultTree); } - - private void buildTraceTree(TestResultTraceDto trace) { - traceTree = createTree(); - traceTree.getNodeStorage().clear(); - List traceNodes = new ArrayList<>(); - for (TestResultTraceFrameDto traceFrame : trace.getTraceFrames()) { - TestResultTraceFrameNode traceNode = nodeFactory.createTestResultTraceFrameNode(traceFrame); - traceNodes.add(traceNode); - } - traceTree.getNodeStorage().add(traceNodes); + + @Deprecated + private Tree buildResultTree(TestResult result) { + Tree resultTree = createTree(); + resultTree.getSelectionModel().addSelectionHandler(new SelectionHandler() { + @Override + public void onSelection(SelectionEvent event) { + Node selectedNode = event.getSelectedItem(); + if (selectedNode instanceof TestResultMethodNode) { + fillOutputPanel(((TestResultMethodNode) selectedNode).getStackTrace()); + } + } + }); + return resultTree; + } + + private Tree buildResultTree(TestResultRootDto result) { + Tree resultTree = createTree(); + resultTree.getSelectionModel().addSelectionHandler(new SelectionHandler() { + @Override + public void onSelection(SelectionEvent event) { + Node selectedNode = event.getSelectedItem(); + if (selectedNode instanceof AbstractTestResultTreeNode) { + fillOutputPanel((AbstractTestResultTreeNode) selectedNode); + } + } + }); + return resultTree; } @Deprecated @@ -240,11 +254,22 @@ private void fillOutputPanel(AbstractTestResultTreeNode node) { Label traceMessageLabel = new Label(testTrace.getMessage()); traceMessageLabel.setStyleName(style.traceFrameMessage()); traceOutputPanel.add(traceMessageLabel); - buildTraceTree(testTrace); + Tree traceTree = buildTraceTree(testTrace); traceTree.getElement().getStyle().setOverflow(Style.Overflow.HIDDEN); traceOutputPanel.add(traceTree); } + private Tree buildTraceTree(TestResultTraceDto trace) { + Tree traceTree = createTree(); + List traceNodes = new ArrayList<>(); + for (TestResultTraceFrameDto traceFrame : trace.getTraceFrames()) { + TestResultTraceFrameNode traceNode = nodeFactory.createTestResultTraceFrameNode(traceFrame); + traceNodes.add(traceNode); + } + traceTree.getNodeStorage().add(traceNodes); + return traceTree; + } + @Override @Deprecated public void gotoClass(String packagePath, int line) { diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java index 268627fc2ea..f4445296f11 100644 --- a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java @@ -108,4 +108,20 @@ public interface TestResultRootDto { */ void setResultPath(List resultPath); + /** + * Returns true if this result root is empty (has no test + * results at all). + * + * @return true if this result root is empty, + * false otherwise + */ + boolean isEmpty(); + + /** + * Sets whether this result root is empty (has no test results at all) + * + * @param isEmpty + */ + void setEmpty(boolean isEmpty); + } diff --git a/wsagent/che-core-api-testing/pom.xml b/wsagent/che-core-api-testing/pom.xml index fa30e452261..3486b3e7e21 100644 --- a/wsagent/che-core-api-testing/pom.xml +++ b/wsagent/che-core-api-testing/pom.xml @@ -52,6 +52,10 @@ javax.ws.rs javax.ws.rs-api + + org.eclipse.che.core + che-core-api-core + org.eclipse.che.core che-core-api-dto @@ -72,6 +76,10 @@ org.eclipse.che.plugin org.eclipse.core.resources + + org.slf4j + slf4j-api + com.jayway.restassured rest-assured diff --git a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestingService.java b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestService.java similarity index 90% rename from wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestingService.java rename to wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestService.java index 0ec76a2fd65..ff2225df887 100644 --- a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestingService.java +++ b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/TestService.java @@ -24,12 +24,15 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; +import org.eclipse.che.api.testing.server.exceptions.TestFrameworkException; import org.eclipse.che.api.testing.server.framework.TestFrameworkRegistry; import org.eclipse.che.api.testing.server.framework.TestRunner; import org.eclipse.che.api.testing.shared.TestResult; import org.eclipse.che.api.testing.shared.dto.TestResultDto; import org.eclipse.che.api.testing.shared.dto.TestResultRootDto; import org.eclipse.core.resources.ResourcesPlugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -43,12 +46,13 @@ */ @Api(value = "/che-testing") @Path("che/testing") -public class TestingService { +public class TestService { + public static final Logger LOG = LoggerFactory.getLogger(TestService.class); private final TestFrameworkRegistry frameworkRegistry; @Inject - public TestingService(TestFrameworkRegistry frameworkRegistry) { + public TestService(TestFrameworkRegistry frameworkRegistry) { this.frameworkRegistry = frameworkRegistry; } @@ -98,7 +102,16 @@ public TestResultRootDto runTests(@Context UriInfo uriInfo) throws Exception { queryParameters.put("absoluteProjectPath", absoluteProjectPath); String testFramework = queryParameters.get("testFramework"); getTestRunner(testFramework); - TestResultRootDto result = frameworkRegistry.getTestRunner(testFramework).runTests(queryParameters); + TestResultRootDto result; + try { + result = frameworkRegistry.getTestRunner(testFramework).runTests(queryParameters); + } catch (TestFrameworkException e) { + LOG.error(e.getMessage()); + throw e; + } catch (Exception e) { + LOG.error(e.getMessage(), e); + throw e; + } return result; } diff --git a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/exceptions/TestFrameworkException.java b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/exceptions/TestFrameworkException.java new file mode 100644 index 00000000000..37965565d4f --- /dev/null +++ b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/exceptions/TestFrameworkException.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.testing.server.exceptions; + +import org.eclipse.che.api.core.ServerException; + +/** + * Test framework specific exception. + * + * @author Bartlomiej Laczkowski + */ +@SuppressWarnings("serial") +public class TestFrameworkException extends ServerException { + + public TestFrameworkException(String message) { + super(message); + } + + public TestFrameworkException(String message, Throwable throwable) { + super(message, throwable); + } + +} diff --git a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/inject/TestGuiceModule.java b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/inject/TestGuiceModule.java index 98de83c541e..6046e0d0032 100644 --- a/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/inject/TestGuiceModule.java +++ b/wsagent/che-core-api-testing/src/main/java/org/eclipse/che/api/testing/server/inject/TestGuiceModule.java @@ -12,7 +12,7 @@ import static com.google.inject.multibindings.Multibinder.newSetBinder; -import org.eclipse.che.api.testing.server.TestingService; +import org.eclipse.che.api.testing.server.TestService; import org.eclipse.che.api.testing.server.framework.TestRunner; import org.eclipse.che.inject.DynaModule; @@ -26,6 +26,6 @@ public class TestGuiceModule extends AbstractModule { @Override protected void configure() { newSetBinder(binder(), TestRunner.class); - bind(TestingService.class); + bind(TestService.class); } } diff --git a/wsagent/che-core-api-testing/src/test/java/org/eclipse/che/api/testing/server/TestingServiceTest.java b/wsagent/che-core-api-testing/src/test/java/org/eclipse/che/api/testing/server/TestServiceTest.java similarity index 96% rename from wsagent/che-core-api-testing/src/test/java/org/eclipse/che/api/testing/server/TestingServiceTest.java rename to wsagent/che-core-api-testing/src/test/java/org/eclipse/che/api/testing/server/TestServiceTest.java index 4bef8f98f1d..35672fd280f 100644 --- a/wsagent/che-core-api-testing/src/test/java/org/eclipse/che/api/testing/server/TestingServiceTest.java +++ b/wsagent/che-core-api-testing/src/test/java/org/eclipse/che/api/testing/server/TestServiceTest.java @@ -40,7 +40,7 @@ * @author Mirage Abeysekara */ @Listeners(value = {EverrestJetty.class, MockitoTestNGListener.class}) -public class TestingServiceTest { +public class TestServiceTest { private final String SERVICE_PATH = "/che/testing"; private final String SERVICE_PATH_RUN_ACTION = SERVICE_PATH + "/run"; @@ -63,7 +63,7 @@ public class TestingServiceTest { private DtoFactory dto; @SuppressWarnings("unused") // not really... - private TestingService testingService; + private TestService testingService; @BeforeMethod public void setUp() throws Exception { @@ -72,7 +72,7 @@ public void setUp() throws Exception { when(projectRegistry.getProject(anyString())).thenReturn(registeredProject); when(frameworkRegistry.getTestRunner(TEST_FRAMEWORK_A)).thenReturn(testRunnerA); when(frameworkRegistry.getTestRunner(TEST_FRAMEWORK_B)).thenReturn(testRunnerB); - testingService = new TestingService(frameworkRegistry); + testingService = new TestService(frameworkRegistry); } // Asking for run a test from known framework. From 6b1046c17ba3197130660c432ffadf4f5035f542 Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Tue, 14 Mar 2017 09:35:43 +0100 Subject: [PATCH 3/9] Improved test results presentation model and tests execution rules. Signed-off-by: Bartlomiej Laczkowski --- .../phpunit/ide/PHPUnitTestActionGroup.java | 15 ++-- .../ide/action/PHPRunScriptTestAction.java | 7 +- .../action/PHPRunScriptTestEditorAction.java | 78 +++++++++++++++++++ .../phpunit/server/PHPUnitMessageParser.java | 1 + .../phpunit/server/PHPUnitTestEngine.java | 50 +++++++----- .../server/PHPUnitTestResultsProvider.java | 3 + .../model/AbstractPHPUnitTestResult.java | 5 +- .../phpunit/server/model/PHPUnitTestCase.java | 2 + .../server/model/PHPUnitTestSuite.java | 4 +- .../testing/ide/view/TestResultViewImpl.java | 35 ++++----- .../nodes/AbstractTestResultTreeNode.java | 8 +- .../ide/view/TestResultViewImpl.ui.xml | 18 ++--- 12 files changed, 166 insertions(+), 60 deletions(-) create mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java index 5459ffdc535..15e84a7ad0d 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java @@ -17,6 +17,7 @@ import org.eclipse.che.plugin.testing.ide.TestActionGroup; import org.eclipse.che.plugin.testing.phpunit.ide.action.PHPRunContainerTestAction; import org.eclipse.che.plugin.testing.phpunit.ide.action.PHPRunScriptTestAction; +import org.eclipse.che.plugin.testing.phpunit.ide.action.PHPRunScriptTestEditorAction; import com.google.inject.Inject; @@ -28,20 +29,24 @@ public class PHPUnitTestActionGroup implements TestActionGroup { private final Action runScriptTestAction; - private PHPRunContainerTestAction runContainerTestAction; + private final Action runScriptTestEditorAction; + private final Action runContainerTestAction; @Inject public PHPUnitTestActionGroup(ActionManager actionManager, PHPRunScriptTestAction runScriptTestAction, - PHPRunContainerTestAction runAllTestAction, KeyBindingAgent keyBinding) { + PHPRunScriptTestEditorAction runScriptTestEditorAction, PHPRunContainerTestAction runContainerTestAction, + KeyBindingAgent keyBinding) { actionManager.registerAction("PHPRunScriptTestAction", runScriptTestAction); - actionManager.registerAction("PHPRunAllTestAction", runAllTestAction); + actionManager.registerAction("PHPRunScriptTestEditorAction", runScriptTestEditorAction); + actionManager.registerAction("PHPRunContainerTestAction", runContainerTestAction); this.runScriptTestAction = runScriptTestAction; - this.runContainerTestAction = runAllTestAction; + this.runScriptTestEditorAction = runScriptTestEditorAction; + this.runContainerTestAction = runContainerTestAction; } @Override public void addMainMenuItems(DefaultActionGroup testMainMenu) { - testMainMenu.add(runScriptTestAction); + testMainMenu.add(runScriptTestEditorAction); testMainMenu.add(runContainerTestAction); } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java index db72ed589d6..8314e7b5125 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java @@ -44,8 +44,8 @@ public class PHPRunScriptTestAction extends AbstractPerspectiveAction { private final SelectionAgent selectionAgent; @Inject - public PHPRunScriptTestAction(TestActionRunner runner, PHPUnitTestResources resources, AppContext appContext, SelectionAgent selectionAgent, - PHPUnitTestLocalizationConstant localization) { + public PHPRunScriptTestAction(TestActionRunner runner, PHPUnitTestResources resources, AppContext appContext, + SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunScriptTitle(), localization.actionRunScriptDescription(), null, resources.testIcon()); this.runner = runner; @@ -84,7 +84,8 @@ public void updateInPerspective(@NotNull ActionEvent e) { } final Object possibleNode = selection.getHeadElement(); boolean enable = possibleNode instanceof FileNode - && ((FileNode) possibleNode).getData().getExtension().equals("php"); + && (((FileNode) possibleNode).getData().getExtension().equals("php") + || ((FileNode) possibleNode).getData().getExtension().equals("phtml")); e.getPresentation().setEnabled(enable); e.getPresentation().setVisible(enable); } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java new file mode 100644 index 00000000000..f44fb69650a --- /dev/null +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2016 Rogue Wave Software, 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: + * Rogue Wave Software, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.testing.phpunit.ide.action; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.che.ide.api.action.ActionEvent; +import org.eclipse.che.ide.api.action.ProjectAction; +import org.eclipse.che.ide.api.app.AppContext; +import org.eclipse.che.ide.api.editor.EditorAgent; +import org.eclipse.che.ide.api.editor.EditorInput; +import org.eclipse.che.ide.api.editor.EditorPartPresenter; +import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; +import org.eclipse.che.ide.api.resources.Project; +import org.eclipse.che.ide.api.resources.VirtualFile; +import org.eclipse.che.ide.api.selection.SelectionAgent; +import org.eclipse.che.plugin.testing.ide.TestActionRunner; +import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestLocalizationConstant; +import org.eclipse.che.plugin.testing.phpunit.ide.PHPUnitTestResources; + +import com.google.inject.Inject; + +/** + * "Run Script" PHPUnit test editor action. + * + * @author Bartlomiej Laczkowski + */ +public class PHPRunScriptTestEditorAction extends ProjectAction { + + private final TestActionRunner runner; + private final AppContext appContext; + private final EditorAgent editorAgent; + private final FileTypeRegistry fileTypeRegistry; + + @Inject + public PHPRunScriptTestEditorAction(TestActionRunner runner, EditorAgent editorAgent, + FileTypeRegistry fileTypeRegistry, PHPUnitTestResources resources, AppContext appContext, + SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { + super(localization.actionRunScriptTitle(), localization.actionRunScriptDescription(), resources.testIcon()); + this.runner = runner; + this.appContext = appContext; + this.editorAgent = editorAgent; + this.fileTypeRegistry = fileTypeRegistry; + } + + @Override + public void actionPerformed(ActionEvent e) { + final Project project = appContext.getRootProject(); + EditorPartPresenter editorPart = editorAgent.getActiveEditor(); + final VirtualFile file = editorPart.getEditorInput().getFile(); + Map parameters = new HashMap<>(); + parameters.put("testTarget", file.getLocation().toString()); + runner.run("PHPUnit", project.getPath(), parameters); + } + + @Override + protected void updateProjectAction(ActionEvent e) { + if (editorAgent.getActiveEditor() != null) { + EditorInput input = editorAgent.getActiveEditor().getEditorInput(); + VirtualFile file = input.getFile(); + final String fileExtension = fileTypeRegistry.getFileTypeByFile(file).getExtension(); + if ("php".equals(fileExtension) || "phtml".equals(fileExtension)) { + e.getPresentation().setEnabledAndVisible(true); + return; + } + } + e.getPresentation().setEnabledAndVisible(false); + } +} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java index 1353b000959..189f8051bc1 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java @@ -47,6 +47,7 @@ public class PHPUnitMessageParser { public static final String PROPERTY_TARGET = "target"; public static final String PROPERTY_TRACE = "trace"; public static final String STATUS_ERROR = "error"; + public static final String STATUS_WARNING = "warning"; public static final String STATUS_FAIL = "fail"; public static final String STATUS_INCOMPLETE = "incomplete"; public static final String STATUS_PASS = "pass"; diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java index d0f7afbf553..fcde4bbd550 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java @@ -27,6 +27,7 @@ import java.util.concurrent.ThreadFactory; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.util.AbstractLineConsumer; import org.eclipse.che.api.core.util.CommandLine; @@ -81,7 +82,6 @@ public void run() { handleReport(socket); } catch (final IOException e) { Thread.currentThread().interrupt(); - LOG.error(e.getMessage(), e); } finally { shutdown(); } @@ -157,14 +157,9 @@ public PHPUnitTestEngine(ProjectManager projectManager) { public TestResultRootDto executeTests(Map testParameters) throws Exception { String projectPath = testParameters.get("projectPath"); String projectAbsolutePath = testParameters.get("absoluteProjectPath"); - String testTarget = testParameters.get("testTarget"); - Path testTargetAbsolutePath; - if (Path.of(testTarget).length() > 1) - testTargetAbsolutePath = Path.of(projectAbsolutePath).newPath(Path.of(testTarget).subPath(1)); - else - testTargetAbsolutePath = Path.of(projectAbsolutePath); - String testTargetWorkingDirectory = testTargetAbsolutePath.getParent().toString(); - String testTargetName = testTargetAbsolutePath.getName(); + String testTargetRelativePath = testParameters.get("testTarget"); + File testTargetFile = getTestTargetFile(testTargetRelativePath, projectAbsolutePath); + File testTargetWorkingDirectory = testTargetFile.isDirectory() ? testTargetFile : testTargetFile.getParentFile(); // Get appropriate path to executable String phpUnitExecutable = PHPUNIT_GLOBAL; if (hasComposerRunner(projectPath)) { @@ -186,9 +181,10 @@ public TestResultRootDto executeTests(Map testParameters) throws LOG.error(e.getMessage(), e); } final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--include-path", printerDirAbsolutePath, - "--printer", phpPrinterName, testTargetName); + "--printer", phpPrinterName, getTestTarget(testTargetFile)); ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true) - .directory(new File(testTargetWorkingDirectory)).command(cmdRunTests.toShellCommand()); + .directory(testTargetWorkingDirectory) + .command(cmdRunTests.toShellCommand()); pb.environment().put("ZEND_PHPUNIT_PORT", String.valueOf(PRINTER_PORT)); Process processRunPHPUnitTests = pb.start(); final StringBuilder stdErrOut = new StringBuilder(); @@ -196,7 +192,7 @@ public TestResultRootDto executeTests(Map testParameters) throws @Override public void writeLine(String line) throws IOException { if (!line.isEmpty()) - stdErrOut.append("\t" + line + "\n"); + stdErrOut.append(line + "\n"); } }); int exitValue = processRunPHPUnitTests.waitFor(); @@ -221,14 +217,14 @@ public List getTestResults(List testResultsPath) { return testResultsProvider.getTestResults(testResultsPath); } - private String getPrinterName(String phpUnitExecutable, String testTargetWorkingDirectory) { + private String getPrinterName(String phpUnitExecutable, File testTargetWorkingDirectory) { final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--atleast-version", "6"); - Process processBuildClassPath; + Process processVersionCheck; try { - processBuildClassPath = new ProcessBuilder().redirectErrorStream(true) - .directory(new File(testTargetWorkingDirectory)).command(cmdRunTests.toShellCommand()).start(); - ProcessUtil.process(processBuildClassPath, LineConsumer.DEV_NULL); - int code = processBuildClassPath.waitFor(); + processVersionCheck = new ProcessBuilder().redirectErrorStream(true) + .directory(testTargetWorkingDirectory).command(cmdRunTests.toShellCommand()).start(); + ProcessUtil.process(processVersionCheck, LineConsumer.DEV_NULL); + int code = processVersionCheck.waitFor(); if (code == 0) return PRINTER_NAME_V6X; } catch (Exception e) { @@ -257,6 +253,22 @@ private File getPrinterFile(String phpLoggerName) { } return tmpPrinterFile; } + + private File getTestTargetFile(String testTargetRelativePath, String projectAbsolutePath) { + if (Path.of(testTargetRelativePath).length() > 1) + return new File(Path.of(projectAbsolutePath).newPath(Path.of(testTargetRelativePath).subPath(1)).toString()); + return new File(Path.of(projectAbsolutePath).toString()); + } + + private String getTestTarget(File testTargetFile) { + if (testTargetFile.isDirectory()) { + if ((new File(testTargetFile, "phpunit.xml").exists() || new File(testTargetFile, "phpunit.xml.dist").exists())) { + return ""; + } + return testTargetFile.getAbsolutePath(); + } + return FilenameUtils.removeExtension(testTargetFile.getAbsolutePath()); + } @SuppressWarnings("unchecked") private boolean hasComposerRunner(String projectPath) { @@ -283,5 +295,5 @@ private boolean hasComposerRunner(String projectPath) { } return false; } - + } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java index 742f8ffde53..3855d726f02 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java @@ -139,6 +139,9 @@ private TestResultStatus getStatus(int phpStatus) { case AbstractPHPUnitTestResult.STATUS_PASS: { return TestResultStatus.SUCCESS; } + case AbstractPHPUnitTestResult.STATUS_WARNING: { + return TestResultStatus.WARNING; + } case AbstractPHPUnitTestResult.STATUS_FAIL: { return TestResultStatus.FAILURE; } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java index 709f16b4f09..19d92350dc7 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java @@ -26,8 +26,9 @@ public abstract class AbstractPHPUnitTestResult extends AbstractPHPUnitElement { public static final int STATUS_PASS = 1; public static final int STATUS_SKIP = 2; public static final int STATUS_INCOMPLETE = 3; - public static final int STATUS_FAIL = 4; - public static final int STATUS_ERROR = 5; + public static final int STATUS_WARNING = 4; + public static final int STATUS_FAIL = 5; + public static final int STATUS_ERROR = 6; protected String name = ""; protected int status = 0; diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java index aae4926799f..30c298b5781 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java @@ -53,6 +53,8 @@ else if (sStatus.equals(PHPUnitMessageParser.STATUS_SKIP)) status = STATUS_SKIP; else if (sStatus.equals(PHPUnitMessageParser.STATUS_INCOMPLETE)) status = STATUS_INCOMPLETE; + else if (sStatus.equals(PHPUnitMessageParser.STATUS_WARNING)) + status = STATUS_WARNING; else if (sStatus.equals(PHPUnitMessageParser.STATUS_FAIL)) status = STATUS_FAIL; else if (sStatus.equals(PHPUnitMessageParser.STATUS_ERROR)) diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java index e956c992a5e..d8040850358 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java @@ -24,7 +24,7 @@ public class PHPUnitTestSuite extends AbstractPHPUnitTestResult { protected class StatusCount { - public int[] counts = { 0, 0, 0, 0, 0, 0 }; // STATUS_STARTED, + public int[] counts = { 0, 0, 0, 0, 0, 0, 0 }; // STATUS_STARTED, // STATUS_PASS, // STATUS_SKIP, // STATUS_INCOMPLETE, @@ -76,7 +76,7 @@ public void setStatus(final int status) { */ public void addChild(final AbstractPHPUnitTestResult test, boolean finished) { if (children == null) { - children = new LinkedHashSet(); + children = new LinkedHashSet<>(); } children.add(test); if (test instanceof PHPUnitTestCase && finished) { diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java index 75cef09461b..cc2f005b17f 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.ide.view; +import static org.eclipse.che.ide.ui.smartTree.SelectionModel.Mode.SINGLE; import static org.eclipse.che.plugin.maven.shared.MavenAttributes.DEFAULT_TEST_SOURCE_FOLDER; import java.util.ArrayList; @@ -57,13 +58,14 @@ import com.google.common.base.Optional; import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.gwt.resources.client.CssResource; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.ui.DockLayoutPanel; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.SplitLayoutPanel; @@ -86,7 +88,9 @@ interface TestResultViewImplUiBinder extends UiBinder emptySet()); Tree tree = new Tree(nodeStorage, nodeLoader); - tree.getElement().getStyle().setWidth(100, Style.Unit.PCT); - tree.getElement().getStyle().setHeight(100, Style.Unit.PCT); + tree.getSelectionModel().setSelectionMode(SINGLE); return tree; } - /** - * {@inheritDoc} - */ - @Override - protected void focusView() { - } - /** * {@inheritDoc} */ @@ -242,7 +238,7 @@ public void onSelection(SelectionEvent event) { private void fillOutputPanel(String text) { traceOutputPanel.clear(); Label traceMessageLabel = new Label(text); - traceMessageLabel.setStyleName(style.traceFrameMessage()); + traceMessageLabel.setStyleName(style.traceOutputMessage()); traceOutputPanel.add(traceMessageLabel); } @@ -251,12 +247,15 @@ private void fillOutputPanel(AbstractTestResultTreeNode node) { TestResultTraceDto testTrace = node.getTestTrace(); if (testTrace == null) return; - Label traceMessageLabel = new Label(testTrace.getMessage()); - traceMessageLabel.setStyleName(style.traceFrameMessage()); - traceOutputPanel.add(traceMessageLabel); + Label traceOutputMessage = new Label(testTrace.getMessage()); + traceOutputMessage.setStyleName(style.traceOutputMessage()); + traceOutputMessage.setWordWrap(true); + traceOutputPanel.add(traceOutputMessage); Tree traceTree = buildTraceTree(testTrace); - traceTree.getElement().getStyle().setOverflow(Style.Overflow.HIDDEN); - traceOutputPanel.add(traceTree); + DockLayoutPanel traceOutputStack = new DockLayoutPanel(Unit.PX); + traceOutputStack.setStyleName(style.traceOutputStack()); + traceOutputStack.add(traceTree); + traceOutputPanel.add(traceOutputStack); } private Tree buildTraceTree(TestResultTraceDto trace) { diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java index af46629dff4..813564aaf64 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.che.plugin.testing.ide.view.navigation.nodes; +import static org.eclipse.che.ide.api.theme.Style.getEditorInfoTextColor; + import javax.validation.constraints.NotNull; import org.eclipse.che.api.testing.shared.common.TestResultStatus; @@ -33,6 +35,8 @@ public abstract class AbstractTestResultTreeNode extends AbstractTreeNode implem protected final TestServiceClient testServiceClient; protected final String frameworkName; private NodePresentation nodePresentation; + + private static final String TEXT_INFO_CSS = "color: " + getEditorInfoTextColor() + "; font-size: 11px"; public AbstractTestResultTreeNode(TestServiceClient testServiceClient, TestResultNodeFactory nodeFactory, TestResources testResources, String frameworkName) { @@ -86,8 +90,10 @@ public void updatePresentation(@NotNull NodePresentation presentation) { } } presentation.setPresentableText(getName()); - if (infoText != null) + if (infoText != null) { presentation.setInfoText(infoText); + presentation.setInfoTextCss(TEXT_INFO_CSS); + } } @Override diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml index b34c3db3cf0..fcafa7cbe50 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/resources/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.ui.xml @@ -15,26 +15,24 @@ xmlns:g="urn:import:com.google.gwt.user.client.ui"> - .traceFrameMessage { + .traceOutputMessage { font-family: mainFontFamily; font-size: fontSize; font-weight: normal; line-height: normal; - margin-bottom: 10px; + padding-bottom: 5px; } + .traceOutputStack { + height: 100%; + width: 100%; + } - + - - - - - - - + From f86f26722d18a063b69d3f7959e766e71908fdde Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Tue, 18 Apr 2017 20:09:00 +0200 Subject: [PATCH 4/9] Small fixup after merge with master. Signed-off-by: Bartlomiej Laczkowski --- .../eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java index 1f05f3d6558..1a4507dfbd6 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/TestResultViewImpl.java @@ -156,6 +156,8 @@ public String getKey(@NotNull Node item) { @Override @Deprecated public void showResults(TestResult result) { + clear(); + lastTestResult = result; setTitle("Test Results (Framework: " + result.getTestFramework() + ")"); fillNavigationPanel(result); focusView(); From f2b902ab3d5fdc51fde8b2dec8ebca18b4306ac8 Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Tue, 9 May 2017 21:07:24 +0200 Subject: [PATCH 5/9] Added combined printer file that conforms different PHPUnit versions. Signed-off-by: Bartlomiej Laczkowski --- .../phpunit/server/PHPUnitTestEngine.java | 28 +- .../phpunit-printer/PHPUnitLogger5x.php | 433 --------- ...UnitLogger6x.php => ZendPHPUnitLogger.php} | 913 +++++++++--------- 3 files changed, 470 insertions(+), 904 deletions(-) delete mode 100644 plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php rename plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/{PHPUnitLogger6x.php => ZendPHPUnitLogger.php} (77%) diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java index fcde4bbd550..5a91d79cecb 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java @@ -31,7 +31,6 @@ import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.util.AbstractLineConsumer; import org.eclipse.che.api.core.util.CommandLine; -import org.eclipse.che.api.core.util.LineConsumer; import org.eclipse.che.api.core.util.ProcessUtil; import org.eclipse.che.api.project.server.ProjectManager; import org.eclipse.che.api.project.server.VirtualFileEntry; @@ -129,8 +128,7 @@ private void handleReport(final Socket socket) { } } - private static final String PRINTER_NAME_V5X = "PHPUnitLogger5x"; - private static final String PRINTER_NAME_V6X = "PHPUnitLogger6x"; + private static final String PRINTER_NAME = "ZendPHPUnitLogger"; private static final String PRINTER_DIRECTORY = "phpunit-printer"; private static final String PHPUNIT_GLOBAL = "phpunit"; private static final String PHPUNIT_COMPOSER = "/vendor/bin/phpunit"; @@ -166,8 +164,7 @@ public TestResultRootDto executeTests(Map testParameters) throws phpUnitExecutable = projectAbsolutePath + PHPUNIT_COMPOSER; } // Get appropriate logger for PHP unit version - String phpPrinterName = getPrinterName(phpUnitExecutable, testTargetWorkingDirectory); - final File printerFile = getPrinterFile(phpPrinterName); + final File printerFile = getPrinterFile(); final String printerDirAbsolutePath = printerFile.getParentFile().getAbsolutePath(); PrinterListener printerListener = new PrinterListener(); printerListener.startup(); @@ -181,7 +178,7 @@ public TestResultRootDto executeTests(Map testParameters) throws LOG.error(e.getMessage(), e); } final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--include-path", printerDirAbsolutePath, - "--printer", phpPrinterName, getTestTarget(testTargetFile)); + "--printer", PRINTER_NAME, getTestTarget(testTargetFile)); ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true) .directory(testTargetWorkingDirectory) .command(cmdRunTests.toShellCommand()); @@ -217,23 +214,8 @@ public List getTestResults(List testResultsPath) { return testResultsProvider.getTestResults(testResultsPath); } - private String getPrinterName(String phpUnitExecutable, File testTargetWorkingDirectory) { - final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--atleast-version", "6"); - Process processVersionCheck; - try { - processVersionCheck = new ProcessBuilder().redirectErrorStream(true) - .directory(testTargetWorkingDirectory).command(cmdRunTests.toShellCommand()).start(); - ProcessUtil.process(processVersionCheck, LineConsumer.DEV_NULL); - int code = processVersionCheck.waitFor(); - if (code == 0) - return PRINTER_NAME_V6X; - } catch (Exception e) { - } - return PRINTER_NAME_V5X; - } - - private File getPrinterFile(String phpLoggerName) { - final String phpLoggerLocation = PRINTER_DIRECTORY + '/' + phpLoggerName + ".php"; + private File getPrinterFile() { + final String phpLoggerLocation = PRINTER_DIRECTORY + '/' + PRINTER_NAME + ".php"; final File tmpDir = new File(System.getProperty("java.io.tmpdir")); final File tmpPrinterFile = new File(tmpDir, phpLoggerLocation); if (!tmpPrinterFile.exists()) { diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php deleted file mode 100644 index ad4bc168f4d..00000000000 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger5x.php +++ /dev/null @@ -1,433 +0,0 @@ -cleanTest(); - - $port = $_SERVER['ZEND_PHPUNIT_PORT']; - if (! isset($port)) { - $port = 7478; - } - $this->out = fsockopen('127.0.0.1', $port, $errno, $errstr, 5); - } - - public function startTestSuite(PHPUnit_Framework_TestSuite $suite) - { - $this->writeTest($suite, 'start'); - } - - public function startTest(PHPUnit_Framework_Test $test) - { - $this->cleanTest(); - $this->writeTest($test, 'start'); - ZendPHPUnitErrorHandlerTracer::getInstance()->start(); - } - - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) - { - $this->status = 'error'; - $this->exception = $e; - } - - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) - { - $this->status = 'fail'; - $this->exception = $e; - } - - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) - { - $this->status = 'incomplete'; - $this->exception = $e; - } - - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) - { - $this->status = 'skip'; - $this->exception = $e; - } - - public function endTest(PHPUnit_Framework_Test $test, $time) - { - $this->warnings = ZendPHPUnitErrorHandlerTracer::getInstance()->stop(); - $this->time = $time; - $this->writeTest($test, $this->status); - } - - public function endTestSuite(PHPUnit_Framework_TestSuite $suite) - { - $this->writeTest($suite, 'end'); - } - - public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) - {} - - public function flush() - { - parent::flush(); - } - - private function cleanTest() - { - $this->status = 'pass'; - $this->exception = null; - $this->warnings = array(); - $this->time = 0; - } - - private function writeArray($array) - { - $result = $this->writeJson($this->encodeJson($array)); - return $result; - } - - private function writeTest(PHPUnit_Framework_Test $test, $event) - { - // echo out test output - if ($test instanceof PHPUnit_Framework_TestCase) { - if (! $test->hasPerformedExpectationsOnOutput() && $test->getActualOutput() != null) { - echo $test->getActualOutput(); - } - } - // write log - $result = array( - 'event' => $event - ); - if ($test instanceof PHPUnit_Framework_TestSuite) { - if (preg_match("*::*", $test->getName()) != 0) { // if it is a dataprovider test suite - // $result['target'] = 'testsuite-dataprovider'; - $result['target'] = 'testsuite'; - if ($event == 'start') - $this->dataProviderNumerator = 0; - elseif ($event == 'end') - $this->dataProviderNumerator = - 1; - } else { - $result['target'] = 'testsuite'; - $this->dataProviderNumerator = - 1; - } - try { - $class = new ReflectionClass($test->getName()); - $name = $class->getName(); - $file = $class->getFileName(); - $line = $class->getStartLine(); - $result['test'] = array( - 'name' => $name, - 'tests' => $test->count(), - 'file' => $file, - 'line' => $line - ); - } catch (ReflectionException $re) { - $name = $test->getName(); - $result['test'] = array( - 'name' => $name, - 'tests' => $test->count() - ); - } - } else { // If we're dealing with TestCase - $result['target'] = 'testcase'; - $result['time'] = $this->time; - $class = new ReflectionClass($test); - try { - $method = $class->getMethod($test->getName()); - if ($this->dataProviderNumerator < 0) { - $method_name = $method->getName(); - } else { - $method_name = $method->getName() . "[" . $this->dataProviderNumerator . "]"; - if ($event == 'start') { - $this->dataProviderNumerator ++; - } - } - $result['test'] = array( - 'name' => $method_name, - 'file' => $method->getFileName(), - 'line' => $method->getStartLine() - ); - } catch (ReflectionException $re) { - $result['test'] = array( - 'name' => $test->getName() - ); - } - } - if ($this->exception !== null) { - $message = $this->exception->getMessage(); - $diff = ""; - if ($this->exception instanceof PHPUnit_Framework_ExpectationFailedException) { - if (method_exists($this->exception, "getDescription")) { - $message = $this->exception->getDescription(); - } else - if (method_exists($this->exception, "getMessage")) { // PHPUnit 3.6.3 - $message = $this->exception->getMessage(); - } - if (method_exists($this->exception, "getComparisonFailure") && method_exists($this->exception->getComparisonFailure(), "getDiff")) { - $diff = $this->exception->getComparisonFailure()->getDiff(); - } - } - $message = trim(preg_replace('/\s+/m', ' ', $message)); - $result += array( - 'exception' => array( - 'message' => $message, - 'diff' => $diff, - 'class' => get_class($this->exception), - 'file' => $this->exception->getFile(), - 'line' => $this->exception->getLine(), - 'trace' => $this->filterTrace($this->exception->getTrace()) - ) - ); - if (! isset($result['exception']['file'])) { - $result['exception']['filtered'] = true; - } - } - if (! empty($this->warnings)) { - $result += array( - 'warnings' => $this->warnings - ); - } - if (! $this->writeArray($result)) { - die(); - } - } - - private function writeJson($buffer) - { - if ($this->out && ! @feof($this->out)) { - return @fwrite($this->out, "$buffer\n"); - } - } - - private function escapeString($string) - { - return str_replace(array( - "\\", - "\"", - '/', - "\b", - "\f", - "\n", - "\r", - "\t" - ), array( - '\\\\', - '\"', - '\/', - '\b', - '\f', - '\n', - '\r', - '\t' - ), $string); - } - - private function encodeJson($array) - { - $result = ''; - if (is_scalar($array)) - $array = array( - $array - ); - $first = true; - foreach ($array as $key => $value) { - if (! $first) - $result .= ','; - else - $first = false; - $result .= sprintf('"%s":', $this->escapeString($key)); - if (is_array($value) || is_object($value)) - $result .= sprintf('%s', $this->encodeJson($value)); - else - $result .= sprintf('"%s"', $this->escapeString($value)); - } - return '{' . $result . '}'; - } - - private function filterTrace($trace) - { - $filteredTrace = array(); - foreach ($trace as $frame) { - if (! isset($frame['file'])) - continue; - $filteredFrame = array( - 'file' => $frame['file'], - 'line' => $frame['line'], - 'function' => $frame['function'] - ); - if (isset($frame['class'])) - $filteredFrame += array( - 'class' => $frame['class'], - 'type' => $frame['type'] - ); - $filteredTrace[] = $filteredFrame; - } - return $filteredTrace; - } -} - -class ZendPHPUnitErrorHandlerTracer extends ZendPHPUnitErrorHandler -{ - - private static $ZendPHPUnitErrorHandlerTracer; - - /** - * - * @return ZendPHPUnitErrorHandlerTracer - */ - public static function getInstance() - { - if (self::$ZendPHPUnitErrorHandlerTracer === null) { - self::$ZendPHPUnitErrorHandlerTracer = new self(); - } - return self::$ZendPHPUnitErrorHandlerTracer; - } - - public static $errorCodes = array( - E_ERROR => 'Error', - E_WARNING => 'Warning', - E_PARSE => 'Parsing Error', - E_NOTICE => 'Notice', - E_CORE_ERROR => 'Core Error', - E_CORE_WARNING => 'Core Warning', - E_COMPILE_ERROR => 'Compile Error', - E_COMPILE_WARNING => 'Compile Warning', - E_USER_ERROR => 'User Error', - E_USER_WARNING => 'User Warning', - E_USER_NOTICE => 'User Notice', - E_STRICT => 'Runtime Notice', - E_RECOVERABLE_ERROR => 'Recoverable Error', - E_DEPRECATED => 'Deprecated', - E_USER_DEPRECATED => 'User Deprecated' - ); - - protected $warnings; - - public function handle($errno, $errstr, $errfile, $errline) - { - parent::handle($errno, $errstr, $errfile, $errline); - $warning = array( - 'code' => isset(self::$errorCodes[$errno]) ? self::$errorCodes[$errno] : $errno, - 'message' => $errstr, - 'file' => $errfile, - 'line' => $errline, - 'trace' => $this->filterTrace(debug_backtrace()), - 'time' => PHP_Timer::resourceUsage() - ); - $return = false; - switch ($errno) { // ignoring user abort - case E_USER_ERROR: - case E_RECOVERABLE_ERROR: - throw new ZendPHPUnitUserErrorException($warning['message'], $errno); - } - $this->warnings[] = $warning; - return $return; - } - - public function start() - { - $this->warnings = array(); - parent::start(); - } - - public function stop() - { - parent::stop(); - $return = $this->warnings; - $this->warnings = array(); - return $return; - } -} - -class ZendPHPUnitErrorHandler -{ - - private static $ZendPHPUnitErrorHandler; - - /** - * - * @return ZendPHPUnitErrorHandler - */ - public static function getInstance() - { - if (self::$ZendPHPUnitErrorHandler === null) { - self::$ZendPHPUnitErrorHandler = new self(); - } - return self::$ZendPHPUnitErrorHandler; - } - - public function handle($errno, $errstr, $errfile, $errline) - { - if (error_reporting() === 0) { - return false; - } - - if ($errfile === __FILE__ || (stripos($errfile, dirname(dirname(__FILE__))) === 0 && $errno !== E_USER_NOTICE)) - return true; - - // handle errors same as PHPUnit_Util_ErrorHandler - if ($errno == E_STRICT) { - if (PHPUnit_Framework_Error_Notice::$enabled !== TRUE) { - return FALSE; - } - - $exception = 'PHPUnit_Framework_Error_Notice'; - } - - else - if ($errno == E_WARNING) { - if (PHPUnit_Framework_Error_Warning::$enabled !== TRUE) { - return FALSE; - } - - $exception = 'PHPUnit_Framework_Error_Warning'; - } - - else - if ($errno == E_NOTICE) { - trigger_error($errstr, E_USER_NOTICE); - return FALSE; - } - - else { - $exception = 'PHPUnit_Framework_Error'; - } - - throw new $exception($errstr, $errno, $errfile, $errline, $trace = null); - } - - public function start() - { - set_error_handler(array( - &$this, - 'handle' - )); - } - - public function stop() - { - restore_error_handler(); - } -} - -class ZendPHPUnitUserErrorException extends Exception -{ -} diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger6x.php b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/ZendPHPUnitLogger.php similarity index 77% rename from plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger6x.php rename to plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/ZendPHPUnitLogger.php index 217af227428..a116604458a 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/PHPUnitLogger6x.php +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/resources/phpunit-printer/ZendPHPUnitLogger.php @@ -1,448 +1,465 @@ -cleanTest(); - - $port = $_SERVER['ZEND_PHPUNIT_PORT']; - if (! isset($port)) { - $port = 7478; - } - $this->out = fsockopen('127.0.0.1', $port, $errno, $errstr, 5); - } - - public function startTestSuite(TestSuite $suite) - { - $this->writeTest($suite, 'start'); - } - - public function startTest(Test $test) - { - $this->cleanTest(); - $this->writeTest($test, 'start'); - ZendPHPUnitErrorHandlerTracer::getInstance()->start(); - } - - public function addError(Test $test, \Exception $e, $time) - { - $this->status = 'error'; - $this->exception = $e; - } - - public function addWarning(Test $test, Warning $e, $time) { - $this->status = 'warning'; - $this->exception = $e; - } - - public function addFailure(Test $test, AssertionFailedError $e, $time) - { - $this->status = 'fail'; - $this->exception = $e; - } - - public function addIncompleteTest(Test $test, \Exception $e, $time) - { - $this->status = 'incomplete'; - $this->exception = $e; - } - - public function addSkippedTest(Test $test, \Exception $e, $time) - { - $this->status = 'skip'; - $this->exception = $e; - } - - public function endTest(Test $test, $time) - { - $this->warnings = ZendPHPUnitErrorHandlerTracer::getInstance()->stop(); - $this->time = $time; - $this->writeTest($test, $this->status); - } - - public function endTestSuite(TestSuite $suite) - { - $this->writeTest($suite, 'end'); - } - - public function addRiskyTest(Test $test, \Exception $e, $time) - {} - - public function flush() - { - parent::flush(); - } - - private function cleanTest() - { - $this->status = 'pass'; - $this->exception = null; - $this->warnings = array(); - $this->time = 0; - } - - private function writeArray($array) - { - $result = $this->writeJson($this->encodeJson($array)); - return $result; - } - - private function writeTest(Test $test, $event) - { - // echo out test output - if ($test instanceof TestCase) { - if (! $test->hasPerformedExpectationsOnOutput() && $test->getActualOutput() != null) { - echo $test->getActualOutput(); - } - } - // write log - $result = array( - 'event' => $event - ); - if ($test instanceof TestSuite) { - if (preg_match("*::*", $test->getName()) != 0) { // if it is a dataprovider test suite - // $result['target'] = 'testsuite-dataprovider'; - $result['target'] = 'testsuite'; - if ($event == 'start') - $this->dataProviderNumerator = 0; - elseif ($event == 'end') - $this->dataProviderNumerator = - 1; - } else { - $result['target'] = 'testsuite'; - $this->dataProviderNumerator = - 1; - } - try { - $class = new ReflectionClass($test->getName()); - $name = $class->getName(); - $file = $class->getFileName(); - $line = $class->getStartLine(); - $result['test'] = array( - 'name' => $name, - 'tests' => $test->count(), - 'file' => $file, - 'line' => $line - ); - } catch (ReflectionException $re) { - $name = $test->getName(); - $result['test'] = array( - 'name' => $name, - 'tests' => $test->count() - ); - } - } else { // If we're dealing with TestCase - $result['target'] = 'testcase'; - $result['time'] = $this->time; - $class = new ReflectionClass($test); - try { - $method = $class->getMethod($test->getName()); - if ($this->dataProviderNumerator < 0) { - $method_name = $method->getName(); - } else { - $method_name = $method->getName() . "[" . $this->dataProviderNumerator . "]"; - if ($event == 'start') { - $this->dataProviderNumerator ++; - } - } - $result['test'] = array( - 'name' => $method_name, - 'file' => $method->getFileName(), - 'line' => $method->getStartLine() - ); - } catch (ReflectionException $re) { - $result['test'] = array( - 'name' => $test->getName() - ); - } - } - if ($this->exception !== null) { - $message = $this->exception->getMessage(); - $diff = ""; - if ($this->exception instanceof ExpectationFailedException) { - if (method_exists($this->exception, "getDescription")) { - $message = $this->exception->getDescription(); - } else - if (method_exists($this->exception, "getMessage")) { // PHPUnit 3.6.3 - $message = $this->exception->getMessage(); - } - if (method_exists($this->exception, "getComparisonFailure") && method_exists($this->exception->getComparisonFailure(), "getDiff")) { - $diff = $this->exception->getComparisonFailure()->getDiff(); - } - } - $message = trim(preg_replace('/\s+/m', ' ', $message)); - $result += array( - 'exception' => array( - 'message' => $message, - 'diff' => $diff, - 'class' => get_class($this->exception), - 'file' => $this->exception->getFile(), - 'line' => $this->exception->getLine(), - 'trace' => $this->filterTrace($this->exception->getTrace()) - ) - ); - if (! isset($result['exception']['file'])) { - $result['exception']['filtered'] = true; - } - } - if (! empty($this->warnings)) { - $result += array( - 'warnings' => $this->warnings - ); - } - if (! $this->writeArray($result)) { - die(); - } - } - - private function writeJson($buffer) - { - if ($this->out && ! @feof($this->out)) { - return @fwrite($this->out, "$buffer\n"); - } - } - - private function escapeString($string) - { - return str_replace(array( - "\\", - "\"", - '/', - "\b", - "\f", - "\n", - "\r", - "\t" - ), array( - '\\\\', - '\"', - '\/', - '\b', - '\f', - '\n', - '\r', - '\t' - ), $string); - } - - private function encodeJson($array) - { - $result = ''; - if (is_scalar($array)) - $array = array( - $array - ); - $first = true; - foreach ($array as $key => $value) { - if (! $first) - $result .= ','; - else - $first = false; - $result .= sprintf('"%s":', $this->escapeString($key)); - if (is_array($value) || is_object($value)) - $result .= sprintf('%s', $this->encodeJson($value)); - else - $result .= sprintf('"%s"', $this->escapeString($value)); - } - return '{' . $result . '}'; - } - - private function filterTrace($trace) - { - $filteredTrace = array(); - foreach ($trace as $frame) { - if (! isset($frame['file'])) - continue; - $filteredFrame = array( - 'file' => $frame['file'], - 'line' => $frame['line'], - 'function' => $frame['function'] - ); - if (isset($frame['class'])) - $filteredFrame += array( - 'class' => $frame['class'], - 'type' => $frame['type'] - ); - $filteredTrace[] = $filteredFrame; - } - return $filteredTrace; - } -} - -class ZendPHPUnitErrorHandlerTracer extends ZendPHPUnitErrorHandler -{ - - private static $ZendPHPUnitErrorHandlerTracer; - - /** - * - * @return ZendPHPUnitErrorHandlerTracer - */ - public static function getInstance() - { - if (self::$ZendPHPUnitErrorHandlerTracer === null) { - self::$ZendPHPUnitErrorHandlerTracer = new self(); - } - return self::$ZendPHPUnitErrorHandlerTracer; - } - - public static $errorCodes = array( - E_ERROR => 'Error', - E_WARNING => 'Warning', - E_PARSE => 'Parsing Error', - E_NOTICE => 'Notice', - E_CORE_ERROR => 'Core Error', - E_CORE_WARNING => 'Core Warning', - E_COMPILE_ERROR => 'Compile Error', - E_COMPILE_WARNING => 'Compile Warning', - E_USER_ERROR => 'User Error', - E_USER_WARNING => 'User Warning', - E_USER_NOTICE => 'User Notice', - E_STRICT => 'Runtime Notice', - E_RECOVERABLE_ERROR => 'Recoverable Error', - E_DEPRECATED => 'Deprecated', - E_USER_DEPRECATED => 'User Deprecated' - ); - - protected $warnings; - - public function handle($errno, $errstr, $errfile, $errline) - { - parent::handle($errno, $errstr, $errfile, $errline); - $warning = array( - 'code' => isset(self::$errorCodes[$errno]) ? self::$errorCodes[$errno] : $errno, - 'message' => $errstr, - 'file' => $errfile, - 'line' => $errline, - 'trace' => $this->filterTrace(debug_backtrace()), - 'time' => PHP_Timer::resourceUsage() - ); - $return = false; - switch ($errno) { // ignoring user abort - case E_USER_ERROR: - case E_RECOVERABLE_ERROR: - throw new ZendPHPUnitUserErrorException($warning['message'], $errno); - } - $this->warnings[] = $warning; - return $return; - } - - public function start() - { - $this->warnings = array(); - parent::start(); - } - - public function stop() - { - parent::stop(); - $return = $this->warnings; - $this->warnings = array(); - return $return; - } -} - -class ZendPHPUnitErrorHandler -{ - - private static $ZendPHPUnitErrorHandler; - - /** - * - * @return ZendPHPUnitErrorHandler - */ - public static function getInstance() - { - if (self::$ZendPHPUnitErrorHandler === null) { - self::$ZendPHPUnitErrorHandler = new self(); - } - return self::$ZendPHPUnitErrorHandler; - } - - public function handle($errno, $errstr, $errfile, $errline) - { - if (error_reporting() === 0) { - return false; - } - - if ($errfile === __FILE__ || (stripos($errfile, dirname(dirname(__FILE__))) === 0 && $errno !== E_USER_NOTICE)) - return true; - - // handle errors same as PHPUnit_Util_ErrorHandler - if ($errno == E_STRICT) { - if (PHPUnit_Framework_Error_Notice::$enabled !== TRUE) { - return FALSE; - } - - $exception = 'PHPUnit_Framework_Error_Notice'; - } - - else - if ($errno == E_WARNING) { - if (PHPUnit_Framework_Error_Warning::$enabled !== TRUE) { - return FALSE; - } - - $exception = 'PHPUnit_Framework_Error_Warning'; - } - - else - if ($errno == E_NOTICE) { - trigger_error($errstr, E_USER_NOTICE); - return FALSE; - } - - else { - $exception = 'PHPUnit_Framework_Error'; - } - - throw new $exception($errstr, $errno, $errfile, $errline, $trace = null); - } - - public function start() - { - set_error_handler(array( - &$this, - 'handle' - )); - } - - public function stop() - { - restore_error_handler(); - } -} - -class ZendPHPUnitUserErrorException extends Exception -{ -} \ No newline at end of file +cleanTest(); + + $port = $_SERVER['ZEND_PHPUNIT_PORT']; + if (! isset($port)) { + $port = 7478; + } + $this->out = fsockopen('127.0.0.1', $port, $errno, $errstr, 5); + } + + public function startTestSuite(TestSuite $suite) + { + $this->writeTest($suite, 'start'); + } + + public function startTest(Test $test) + { + $this->cleanTest(); + $this->writeTest($test, 'start'); + ZendPHPUnitErrorHandlerTracer::getInstance()->start(); + } + + public function addError(Test $test, \Exception $e, $time) + { + $this->status = 'error'; + $this->exception = $e; + } + + public function addWarning(Test $test, Warning $e, $time) { + $this->status = 'warning'; + $this->exception = $e; + } + + public function addFailure(Test $test, AssertionFailedError $e, $time) + { + $this->status = 'fail'; + $this->exception = $e; + } + + public function addIncompleteTest(Test $test, \Exception $e, $time) + { + $this->status = 'incomplete'; + $this->exception = $e; + } + + public function addSkippedTest(Test $test, \Exception $e, $time) + { + $this->status = 'skip'; + $this->exception = $e; + } + + public function endTest(Test $test, $time) + { + $this->warnings = ZendPHPUnitErrorHandlerTracer::getInstance()->stop(); + $this->time = $time; + $this->writeTest($test, $this->status); + } + + public function endTestSuite(TestSuite $suite) + { + $this->writeTest($suite, 'end'); + } + + public function addRiskyTest(Test $test, \Exception $e, $time) + {} + + public function flush() + { + parent::flush(); + } + + private function cleanTest() + { + $this->status = 'pass'; + $this->exception = null; + $this->warnings = array(); + $this->time = 0; + } + + private function writeArray($array) + { + $result = $this->writeJson($this->encodeJson($array)); + return $result; + } + + private function writeTest(Test $test, $event) + { + // echo out test output + if ($test instanceof TestCase) { + $hasPerformed = false; + if (method_exists($test, 'hasPerformedExpectationsOnOutput')) { + $hasPerformed = $test->hasPerformedExpectationsOnOutput(); + } else { + $hasPerformed = $test->hasExpectationOnOutput(); + } + + if (! $hasPerformed && $test->getActualOutput() != null) { + echo $test->getActualOutput(); + } + } + // write log + $result = array( + 'event' => $event + ); + if ($test instanceof TestSuite) { + if (preg_match("*::*", $test->getName()) != 0) { // if it is a dataprovider test suite + // $result['target'] = 'testsuite-dataprovider'; + $result['target'] = 'testsuite'; + if ($event == 'start') + $this->dataProviderNumerator = 0; + elseif ($event == 'end') + $this->dataProviderNumerator = - 1; + } else { + $result['target'] = 'testsuite'; + $this->dataProviderNumerator = - 1; + } + try { + $class = new ReflectionClass($test->getName()); + $name = $class->getName(); + $file = $class->getFileName(); + $line = $class->getStartLine(); + $result['test'] = array( + 'name' => $name, + 'tests' => $test->count(), + 'file' => $file, + 'line' => $line + ); + } catch (ReflectionException $re) { + $name = $test->getName(); + $result['test'] = array( + 'name' => $name, + 'tests' => $test->count() + ); + } + } else { // If we're dealing with TestCase + $result['target'] = 'testcase'; + $result['time'] = $this->time; + $class = new ReflectionClass($test); + try { + $method = $class->getMethod($test->getName()); + if ($this->dataProviderNumerator < 0) { + $method_name = $method->getName(); + } else { + $method_name = $method->getName() . "[" . $this->dataProviderNumerator . "]"; + if ($event == 'start') { + $this->dataProviderNumerator ++; + } + } + $result['test'] = array( + 'name' => $method_name, + 'file' => $method->getFileName(), + 'line' => $method->getStartLine() + ); + } catch (ReflectionException $re) { + $result['test'] = array( + 'name' => $test->getName() + ); + } + } + if ($this->exception !== null) { + $message = $this->exception->getMessage(); + $diff = ""; + if ($this->exception instanceof ExpectationFailedException) { + if (method_exists($this->exception, "getDescription")) { + $message = $this->exception->getDescription(); + } else + if (method_exists($this->exception, "getMessage")) { // PHPUnit 3.6.3 + $message = $this->exception->getMessage(); + } + if (method_exists($this->exception, "getComparisonFailure") && method_exists($this->exception->getComparisonFailure(), "getDiff")) { + $diff = $this->exception->getComparisonFailure()->getDiff(); + } + } + $message = trim(preg_replace('/\s+/m', ' ', $message)); + $result += array( + 'exception' => array( + 'message' => $message, + 'diff' => $diff, + 'class' => get_class($this->exception), + 'file' => $this->exception->getFile(), + 'line' => $this->exception->getLine(), + 'trace' => ZendPHPUnitLogger::filterTrace($this->exception->getTrace()) + ) + ); + if (! isset($result['exception']['file'])) { + $result['exception']['filtered'] = true; + } + } + if (! empty($this->warnings)) { + $result += array( + 'warnings' => $this->warnings + ); + } + if (! $this->writeArray($result)) { + die(); + } + } + + private function writeJson($buffer) + { + if ($this->out && ! @feof($this->out)) { + return @fwrite($this->out, "$buffer\n"); + } + } + + private function escapeString($string) + { + return str_replace(array( + "\\", + "\"", + '/', + "\b", + "\f", + "\n", + "\r", + "\t" + ), array( + '\\\\', + '\"', + '\/', + '\b', + '\f', + '\n', + '\r', + '\t' + ), $string); + } + + private function encodeJson($array) + { + $result = ''; + if (is_scalar($array)) + $array = array( + $array + ); + $first = true; + foreach ($array as $key => $value) { + if (! $first) + $result .= ','; + else + $first = false; + $result .= sprintf('"%s":', $this->escapeString($key)); + if (is_array($value) || is_object($value)) + $result .= sprintf('%s', $this->encodeJson($value)); + else + $result .= sprintf('"%s"', $this->escapeString($value)); + } + return '{' . $result . '}'; + } + + public static function filterTrace($trace) + { + $filteredTrace = array(); + foreach ($trace as $frame) { + if (! isset($frame['file'])) + continue; + $filteredFrame = array( + 'file' => $frame['file'], + 'line' => $frame['line'], + 'function' => $frame['function'] + ); + if (isset($frame['class'])) + $filteredFrame += array( + 'class' => $frame['class'], + 'type' => $frame['type'] + ); + $filteredTrace[] = $filteredFrame; + } + return $filteredTrace; + } +} + +class ZendPHPUnitErrorHandlerTracer extends ZendPHPUnitErrorHandler +{ + + private static $ZendPHPUnitErrorHandlerTracer; + + /** + * + * @return ZendPHPUnitErrorHandlerTracer + */ + public static function getInstance() + { + if (self::$ZendPHPUnitErrorHandlerTracer === null) { + self::$ZendPHPUnitErrorHandlerTracer = new self(); + } + return self::$ZendPHPUnitErrorHandlerTracer; + } + + public static $errorCodes = array( + E_ERROR => 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parsing Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice', + E_RECOVERABLE_ERROR => 'Recoverable Error', + E_DEPRECATED => 'Deprecated', + E_USER_DEPRECATED => 'User Deprecated' + ); + + protected $warnings; + + public function handle($errno, $errstr, $errfile, $errline) + { + parent::handle($errno, $errstr, $errfile, $errline); + $warning = array( + 'code' => isset(self::$errorCodes[$errno]) ? self::$errorCodes[$errno] : $errno, + 'message' => $errstr, + 'file' => $errfile, + 'line' => $errline, + 'trace' => ZendPHPUnitLogger::filterTrace(debug_backtrace()), + 'time' => PHP_Timer::resourceUsage() + ); + $return = false; + switch ($errno) { // ignoring user abort + case E_USER_ERROR: + case E_RECOVERABLE_ERROR: + throw new ZendPHPUnitUserErrorException($warning['message'], $errno); + } + $this->warnings[] = $warning; + return $return; + } + + public function start() + { + $this->warnings = array(); + parent::start(); + } + + public function stop() + { + parent::stop(); + $return = $this->warnings; + $this->warnings = array(); + return $return; + } +} + +class ZendPHPUnitErrorHandler +{ + + private static $ZendPHPUnitErrorHandler; + + /** + * + * @return ZendPHPUnitErrorHandler + */ + public static function getInstance() + { + if (self::$ZendPHPUnitErrorHandler === null) { + self::$ZendPHPUnitErrorHandler = new self(); + } + return self::$ZendPHPUnitErrorHandler; + } + + public function handle($errno, $errstr, $errfile, $errline) + { + if (error_reporting() === 0) { + return false; + } + + if ($errfile === __FILE__ || (stripos($errfile, dirname(dirname(__FILE__))) === 0 && $errno !== E_USER_NOTICE)) + return true; + + // handle errors same as PHPUnit_Util_ErrorHandler + if ($errno == E_STRICT) { + if (PHPUnit_Framework_Error_Notice::$enabled !== TRUE) { + return FALSE; + } + + $exception = 'PHPUnit_Framework_Error_Notice'; + } + + else + if ($errno == E_WARNING) { + if (PHPUnit_Framework_Error_Warning::$enabled !== TRUE) { + return FALSE; + } + + $exception = 'PHPUnit_Framework_Error_Warning'; + } + + else + if ($errno == E_NOTICE) { + trigger_error($errstr, E_USER_NOTICE); + return FALSE; + } + + else { + $exception = 'PHPUnit_Framework_Error'; + } + + throw new $exception($errstr, $errno, $errfile, $errline, $trace = null); + } + + public function start() + { + set_error_handler(array( + &$this, + 'handle' + )); + } + + public function stop() + { + restore_error_handler(); + } +} + +class ZendPHPUnitUserErrorException extends Exception +{ +} From af334cb7d02cb7a817f3a95c46207e2bd7d0be08 Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Tue, 9 May 2017 21:52:18 +0200 Subject: [PATCH 6/9] Fixed possible NPE issue while opening PHPUnit test case source file. Signed-off-by: Bartlomiej Laczkowski --- .../testing/ide/view/navigation/SimpleLocationHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java index d1fe7c39837..2d8b94ffd01 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java @@ -79,7 +79,13 @@ public void onFailure(Throwable caught) { } private void tryFindFileInWorkspace(final SimpleLocationDto location, final AsyncCallback callback) { + if (location == null) { + return; + } String resourcePath = location.getResourcePath(); + if (resourcePath == null || resourcePath.isEmpty()) { + return; + } if (resourcePath.startsWith(PROJECTS_ROOT)) resourcePath = resourcePath.substring(PROJECTS_ROOT.length() + 1); try { From 4e0186f264d04ae51506511bba0790357b1ef9bb Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Wed, 31 May 2017 14:26:41 +0200 Subject: [PATCH 7/9] Bump up PHPUnit plug-ins version to 5.12.0. --- .../che-plugin-testing-phpunit-ide/pom.xml | 2 +- .../che-plugin-testing-phpunit-server/pom.xml | 2 +- plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml | 2 +- plugins/plugin-testing-php/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml index e19f10bbff1..bdb245a3426 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/pom.xml @@ -16,7 +16,7 @@ che-plugin-testing-phpunit org.eclipse.che.plugin - 5.11.0-SNAPSHOT + 5.12.0-SNAPSHOT che-plugin-testing-phpunit-ide Che Plugin :: PHP Testing :: PHPUnit IDE diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml index be4f4191db1..bdf5ac2223e 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/pom.xml @@ -16,7 +16,7 @@ che-plugin-testing-phpunit org.eclipse.che.plugin - 5.11.0-SNAPSHOT + 5.12.0-SNAPSHOT che-plugin-testing-phpunit-server Che Plugin :: PHP Testing :: PHPUnit Server diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml b/plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml index 60f42bf124a..8d37d8147ea 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/pom.xml @@ -16,7 +16,7 @@ che-plugin-testing-php-parent org.eclipse.che.plugin - 5.11.0-SNAPSHOT + 5.12.0-SNAPSHOT che-plugin-testing-phpunit pom diff --git a/plugins/plugin-testing-php/pom.xml b/plugins/plugin-testing-php/pom.xml index 4e4657e4b50..787e4df7162 100644 --- a/plugins/plugin-testing-php/pom.xml +++ b/plugins/plugin-testing-php/pom.xml @@ -16,7 +16,7 @@ che-plugin-parent org.eclipse.che.plugin - 5.11.0-SNAPSHOT + 5.12.0-SNAPSHOT che-plugin-testing-php-parent pom From 47da1cd7398161dd16e2cc678d10d792c39e23a0 Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Wed, 31 May 2017 16:16:19 +0200 Subject: [PATCH 8/9] Small fixup after merge with master. Signed-off-by: Bartlomiej Laczkowski --- .../junit/ide/JUnitTestActionGroup.java | 71 ------------------- .../junit/ide/inject/JUnitGinModule.java | 4 +- 2 files changed, 2 insertions(+), 73 deletions(-) delete mode 100644 plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestActionGroup.java diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestActionGroup.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestActionGroup.java deleted file mode 100644 index 1a0a5f5fed9..00000000000 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/JUnitTestActionGroup.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.testing.junit.ide; - -import org.eclipse.che.ide.api.action.Action; -import org.eclipse.che.ide.api.action.ActionManager; -import org.eclipse.che.ide.api.action.DefaultActionGroup; -import org.eclipse.che.ide.api.keybinding.KeyBindingAgent; -import org.eclipse.che.ide.api.keybinding.KeyBuilder; -import org.eclipse.che.ide.util.browser.UserAgent; -import org.eclipse.che.plugin.testing.ide.TestAction; -import org.eclipse.che.plugin.testing.junit.ide.action.RunAllTestAction; -import org.eclipse.che.plugin.testing.junit.ide.action.RunClassContextTestAction; -import org.eclipse.che.plugin.testing.junit.ide.action.RunClassTestAction; - -import com.google.inject.Inject; - -/** - * JUnit 3.x and 4.x ide implementation. - * - * @author Mirage Abeysekara - */ -public class JUnitTestActionGroup implements TestAction { - - private final Action runClassTestAction; - private final Action runAllTestAction; - private final Action runClassContextTestAction; - - @Inject - public JUnitTestActionGroup(ActionManager actionManager, - RunClassTestAction runClassTestAction, - RunAllTestAction runAllTestAction, - RunClassContextTestAction runClassContextTestAction, - KeyBindingAgent keyBinding) { - actionManager.registerAction("TestActionRunClass", runClassTestAction); - actionManager.registerAction("TestActionRunAll", runAllTestAction); - actionManager.registerAction("TestActionRunClassContext", runClassContextTestAction); - if (UserAgent.isMac()) { - keyBinding.getGlobal().addKey(new KeyBuilder().control().alt().charCode('z').build(), "TestActionRunAll"); - keyBinding.getGlobal().addKey(new KeyBuilder().control().shift().charCode('z').build(), "TestActionRunClass"); - } else { - keyBinding.getGlobal().addKey(new KeyBuilder().action().alt().charCode('z').build(), "TestActionRunAll"); - keyBinding.getGlobal().addKey(new KeyBuilder().action().shift().charCode('z').build(), "TestActionRunClass"); - } - - this.runAllTestAction = runAllTestAction; - this.runClassContextTestAction = runClassContextTestAction; - this.runClassTestAction = runClassTestAction; - } - - - @Override - public void addMainMenuItems(DefaultActionGroup testMainMenu) { - testMainMenu.add(runClassTestAction); - testMainMenu.add(runAllTestAction); - } - - @Override - public void addContextMenuItems(DefaultActionGroup testContextMenu) { - testContextMenu.add(runClassContextTestAction); - testContextMenu.add(runAllTestAction); - } -} diff --git a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java index a016743e633..a84f1dd80d5 100644 --- a/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java +++ b/plugins/plugin-testing-java/plugin-testing-junit/che-plugin-testing-junit-ide/src/main/java/org/eclipse/che/plugin/testing/junit/ide/inject/JUnitGinModule.java @@ -12,7 +12,7 @@ import org.eclipse.che.ide.api.extension.ExtensionGinModule; import org.eclipse.che.plugin.testing.ide.TestAction; -import org.eclipse.che.plugin.testing.junit.ide.JUnitTestActionGroup; +import org.eclipse.che.plugin.testing.junit.ide.JUnitTestAction; import com.google.gwt.inject.client.AbstractGinModule; import com.google.gwt.inject.client.multibindings.GinMultibinder; @@ -25,6 +25,6 @@ public class JUnitGinModule extends AbstractGinModule { @Override protected void configure() { - GinMultibinder.newSetBinder(binder(), TestAction.class).addBinding().to(JUnitTestActionGroup.class); + GinMultibinder.newSetBinder(binder(), TestAction.class).addBinding().to(JUnitTestAction.class); } } From 8de852ab07bcfd95960aa1ecc9fc97a30c3e4341 Mon Sep 17 00:00:00 2001 From: Bartlomiej Laczkowski Date: Fri, 2 Jun 2017 16:56:03 +0200 Subject: [PATCH 9/9] Format code to be in line with Che code conventions. Signed-off-by: Bartlomiej Laczkowski --- .../phpunit/ide/PHPUnitTestActionGroup.java | 8 ++- .../ide/PHPUnitTestLocalizationConstant.java | 3 +- .../ide/action/PHPRunContainerTestAction.java | 18 ++++-- .../ide/action/PHPRunScriptTestAction.java | 22 ++++--- .../action/PHPRunScriptTestEditorAction.java | 14 +++-- .../phpunit/server/PHPUnitMessageParser.java | 58 +++++++++---------- .../phpunit/server/PHPUnitTestEngine.java | 58 ++++++++++--------- .../server/PHPUnitTestResultsProvider.java | 9 +-- .../phpunit/server/PHPUnitTestRunner.java | 4 +- .../server/model/AbstractPHPUnitElement.java | 9 ++- .../model/AbstractPHPUnitTestEvent.java | 4 +- .../model/AbstractPHPUnitTestResult.java | 18 +++--- .../phpunit/server/model/PHPUnitTestCase.java | 4 +- .../server/model/PHPUnitTestException.java | 4 +- .../phpunit/server/model/PHPUnitTestRoot.java | 6 +- .../server/model/PHPUnitTestSuite.java | 20 +++---- .../server/model/PHPUnitTraceFrame.java | 6 +- .../plugin/testing/ide/TestActionRunner.java | 7 ++- .../navigation/SimpleLocationHandler.java | 16 ++--- .../nodes/AbstractTestResultTreeNode.java | 18 +++--- .../view/navigation/nodes/TestResultNode.java | 13 +++-- .../navigation/nodes/TestResultRootNode.java | 14 +++-- .../nodes/TestResultTraceFrameNode.java | 11 ++-- .../testing/shared/dto/SimpleLocationDto.java | 3 +- .../api/testing/shared/dto/TestResultDto.java | 6 +- .../testing/shared/dto/TestResultRootDto.java | 9 +-- .../shared/dto/TestResultTraceFrameDto.java | 3 +- 27 files changed, 195 insertions(+), 170 deletions(-) diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java index a5f71b6d1e6..aa3989e0711 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestActionGroup.java @@ -33,9 +33,11 @@ public class PHPUnitTestActionGroup implements TestAction { private final Action runContainerTestAction; @Inject - public PHPUnitTestActionGroup(ActionManager actionManager, PHPRunScriptTestAction runScriptTestAction, - PHPRunScriptTestEditorAction runScriptTestEditorAction, PHPRunContainerTestAction runContainerTestAction, - KeyBindingAgent keyBinding) { + public PHPUnitTestActionGroup(ActionManager actionManager, + PHPRunScriptTestAction runScriptTestAction, + PHPRunScriptTestEditorAction runScriptTestEditorAction, + PHPRunContainerTestAction runContainerTestAction, + KeyBindingAgent keyBinding) { actionManager.registerAction("PHPRunScriptTestAction", runScriptTestAction); actionManager.registerAction("PHPRunScriptTestEditorAction", runScriptTestEditorAction); actionManager.registerAction("PHPRunContainerTestAction", runContainerTestAction); diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java index d15374e69d5..95d178c397d 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/PHPUnitTestLocalizationConstant.java @@ -13,8 +13,7 @@ import com.google.gwt.i18n.client.Messages; /** - * Localization constants. Interface to represent the constants defined in - * resource bundle: 'PHPUnitTestLocalizationConstant.properties'. + * Localization constants. Interface to represent the constants defined in resource bundle: 'PHPUnitTestLocalizationConstant.properties'. * * @author Bartlomiej Laczkowski */ diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java index 794e2e6891a..0b255aad720 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunContainerTestAction.java @@ -40,14 +40,20 @@ public class PHPRunContainerTestAction extends AbstractPerspectiveAction { private final TestActionRunner runner; - private final AppContext appContext; - private final SelectionAgent selectionAgent; + private final AppContext appContext; + private final SelectionAgent selectionAgent; @Inject - public PHPRunContainerTestAction(TestActionRunner runner, PHPUnitTestResources resources, AppContext appContext, - SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { - super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunContainerTitle(), - localization.actionRunScriptDescription(), null, resources.testIcon()); + public PHPRunContainerTestAction(TestActionRunner runner, + PHPUnitTestResources resources, + AppContext appContext, + SelectionAgent selectionAgent, + PHPUnitTestLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), + localization.actionRunContainerTitle(), + localization.actionRunScriptDescription(), + null, + resources.testIcon()); this.runner = runner; this.appContext = appContext; this.selectionAgent = selectionAgent; diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java index 8314e7b5125..35ac2bee863 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestAction.java @@ -40,14 +40,20 @@ public class PHPRunScriptTestAction extends AbstractPerspectiveAction { private final TestActionRunner runner; - private final AppContext appContext; - private final SelectionAgent selectionAgent; + private final AppContext appContext; + private final SelectionAgent selectionAgent; @Inject - public PHPRunScriptTestAction(TestActionRunner runner, PHPUnitTestResources resources, AppContext appContext, - SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { - super(Arrays.asList(PROJECT_PERSPECTIVE_ID), localization.actionRunScriptTitle(), - localization.actionRunScriptDescription(), null, resources.testIcon()); + public PHPRunScriptTestAction(TestActionRunner runner, + PHPUnitTestResources resources, + AppContext appContext, + SelectionAgent selectionAgent, + PHPUnitTestLocalizationConstant localization) { + super(Arrays.asList(PROJECT_PERSPECTIVE_ID), + localization.actionRunScriptTitle(), + localization.actionRunScriptDescription(), + null, + resources.testIcon()); this.runner = runner; this.appContext = appContext; this.selectionAgent = selectionAgent; @@ -84,8 +90,8 @@ public void updateInPerspective(@NotNull ActionEvent e) { } final Object possibleNode = selection.getHeadElement(); boolean enable = possibleNode instanceof FileNode - && (((FileNode) possibleNode).getData().getExtension().equals("php") - || ((FileNode) possibleNode).getData().getExtension().equals("phtml")); + && (((FileNode) possibleNode).getData().getExtension().equals("php") + || ((FileNode) possibleNode).getData().getExtension().equals("phtml")); e.getPresentation().setEnabled(enable); e.getPresentation().setVisible(enable); } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java index f44fb69650a..5c579faa66a 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-ide/src/main/java/org/eclipse/che/plugin/testing/phpunit/ide/action/PHPRunScriptTestEditorAction.java @@ -37,14 +37,18 @@ public class PHPRunScriptTestEditorAction extends ProjectAction { private final TestActionRunner runner; - private final AppContext appContext; - private final EditorAgent editorAgent; + private final AppContext appContext; + private final EditorAgent editorAgent; private final FileTypeRegistry fileTypeRegistry; @Inject - public PHPRunScriptTestEditorAction(TestActionRunner runner, EditorAgent editorAgent, - FileTypeRegistry fileTypeRegistry, PHPUnitTestResources resources, AppContext appContext, - SelectionAgent selectionAgent, PHPUnitTestLocalizationConstant localization) { + public PHPRunScriptTestEditorAction(TestActionRunner runner, + EditorAgent editorAgent, + FileTypeRegistry fileTypeRegistry, + PHPUnitTestResources resources, + AppContext appContext, + SelectionAgent selectionAgent, + PHPUnitTestLocalizationConstant localization) { super(localization.actionRunScriptTitle(), localization.actionRunScriptDescription(), resources.testIcon()); this.runner = runner; this.appContext = appContext; diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java index 189f8051bc1..306f66d0224 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitMessageParser.java @@ -26,37 +26,37 @@ */ public class PHPUnitMessageParser { - public static final String CALL_DYNAMIC = "->"; - public static final String CALL_STATIC = "::"; - private static final String ELEMENT_EVENT = "event"; - private static final String ELEMENT_EXCEPTION = "exception"; + public static final String CALL_DYNAMIC = "->"; + public static final String CALL_STATIC = "::"; + private static final String ELEMENT_EVENT = "event"; + private static final String ELEMENT_EXCEPTION = "exception"; private static final String ELEMENT_TARGET_TESTSUITE = "testsuite"; - private static final String ELEMENT_TARGET_TESTCASE = "testcase"; - private static final String ELEMENT_TEST = "test"; - private static final String ELEMENT_WARNINGS = "warnings"; - public static final String PROPERTY_CLASS = "class"; - public static final String PROPERTY_CODE = "code"; - public static final String PROPERTY_COUNT = "tests"; - public static final String PROPERTY_FILE = "file"; - public static final String PROPERTY_FILTERED = "filtered"; - public static final String PROPERTY_LINE = "line"; - public static final String PROPERTY_MESSAGE = "message"; - public static final String PROPERTY_DIFF = "diff"; - public static final String PROPERTY_NAME = "name"; - public static final String PROPERTY_TIME = "time"; - public static final String PROPERTY_TARGET = "target"; - public static final String PROPERTY_TRACE = "trace"; - public static final String STATUS_ERROR = "error"; - public static final String STATUS_WARNING = "warning"; - public static final String STATUS_FAIL = "fail"; - public static final String STATUS_INCOMPLETE = "incomplete"; - public static final String STATUS_PASS = "pass"; - public static final String STATUS_SKIP = "skip"; - public static final String TAG_END = "end"; - public static final String TAG_START = "start"; + private static final String ELEMENT_TARGET_TESTCASE = "testcase"; + private static final String ELEMENT_TEST = "test"; + private static final String ELEMENT_WARNINGS = "warnings"; + public static final String PROPERTY_CLASS = "class"; + public static final String PROPERTY_CODE = "code"; + public static final String PROPERTY_COUNT = "tests"; + public static final String PROPERTY_FILE = "file"; + public static final String PROPERTY_FILTERED = "filtered"; + public static final String PROPERTY_LINE = "line"; + public static final String PROPERTY_MESSAGE = "message"; + public static final String PROPERTY_DIFF = "diff"; + public static final String PROPERTY_NAME = "name"; + public static final String PROPERTY_TIME = "time"; + public static final String PROPERTY_TARGET = "target"; + public static final String PROPERTY_TRACE = "trace"; + public static final String STATUS_ERROR = "error"; + public static final String STATUS_WARNING = "warning"; + public static final String STATUS_FAIL = "fail"; + public static final String STATUS_INCOMPLETE = "incomplete"; + public static final String STATUS_PASS = "pass"; + public static final String STATUS_SKIP = "skip"; + public static final String TAG_END = "end"; + public static final String TAG_START = "start"; - private PHPUnitTestSuite currentGroup; - private PHPUnitTestCase currentTestCase; + private PHPUnitTestSuite currentGroup; + private PHPUnitTestCase currentTestCase; public PHPUnitMessageParser(PHPUnitTestRoot testRoot) { this.currentGroup = testRoot; diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java index 5a91d79cecb..45dd5332940 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestEngine.java @@ -53,9 +53,9 @@ public class PHPUnitTestEngine { private final class PrinterListener implements Runnable { - private ServerSocket serverSocket; - private Socket socket; - private Gson gson = new GsonBuilder().create(); + private ServerSocket serverSocket; + private Socket socket; + private Gson gson = new GsonBuilder().create(); private ExecutorService threadExecutor; public PrinterListener() { @@ -90,13 +90,11 @@ void shutdown() { try { if (socket != null && !socket.isClosed()) socket.close(); - } catch (final Exception e) { - } + } catch (final Exception e) {} try { if (serverSocket != null && !serverSocket.isClosed()) serverSocket.close(); - } catch (final IOException e) { - } + } catch (final IOException e) {} threadExecutor.shutdown(); } @@ -128,17 +126,17 @@ private void handleReport(final Socket socket) { } } - private static final String PRINTER_NAME = "ZendPHPUnitLogger"; - private static final String PRINTER_DIRECTORY = "phpunit-printer"; - private static final String PHPUNIT_GLOBAL = "phpunit"; - private static final String PHPUNIT_COMPOSER = "/vendor/bin/phpunit"; - private static final int PRINTER_PORT = 7478; + private static final String PRINTER_NAME = "ZendPHPUnitLogger"; + private static final String PRINTER_DIRECTORY = "phpunit-printer"; + private static final String PHPUNIT_GLOBAL = "phpunit"; + private static final String PHPUNIT_COMPOSER = "/vendor/bin/phpunit"; + private static final int PRINTER_PORT = 7478; - private final ProjectManager projectManager; - private final CountDownLatch latchReady = new CountDownLatch(1); - private final CountDownLatch latchDone = new CountDownLatch(1); + private final ProjectManager projectManager; + private final CountDownLatch latchReady = new CountDownLatch(1); + private final CountDownLatch latchDone = new CountDownLatch(1); - private PHPUnitTestRoot phpTestsRoot; + private PHPUnitTestRoot phpTestsRoot; private PHPUnitTestResultsProvider testResultsProvider; public PHPUnitTestEngine(ProjectManager projectManager) { @@ -157,7 +155,8 @@ public TestResultRootDto executeTests(Map testParameters) throws String projectAbsolutePath = testParameters.get("absoluteProjectPath"); String testTargetRelativePath = testParameters.get("testTarget"); File testTargetFile = getTestTargetFile(testTargetRelativePath, projectAbsolutePath); - File testTargetWorkingDirectory = testTargetFile.isDirectory() ? testTargetFile : testTargetFile.getParentFile(); + File testTargetWorkingDirectory = + testTargetFile.isDirectory() ? testTargetFile : testTargetFile.getParentFile(); // Get appropriate path to executable String phpUnitExecutable = PHPUNIT_GLOBAL; if (hasComposerRunner(projectPath)) { @@ -177,11 +176,15 @@ public TestResultRootDto executeTests(Map testParameters) throws } catch (InterruptedException e) { LOG.error(e.getMessage(), e); } - final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, "--include-path", printerDirAbsolutePath, - "--printer", PRINTER_NAME, getTestTarget(testTargetFile)); + final CommandLine cmdRunTests = new CommandLine(phpUnitExecutable, + "--include-path", + printerDirAbsolutePath, + "--printer", + PRINTER_NAME, + getTestTarget(testTargetFile)); ProcessBuilder pb = new ProcessBuilder().redirectErrorStream(true) - .directory(testTargetWorkingDirectory) - .command(cmdRunTests.toShellCommand()); + .directory(testTargetWorkingDirectory) + .command(cmdRunTests.toShellCommand()); pb.environment().put("ZEND_PHPUNIT_PORT", String.valueOf(PRINTER_PORT)); Process processRunPHPUnitTests = pb.start(); final StringBuilder stdErrOut = new StringBuilder(); @@ -235,16 +238,19 @@ private File getPrinterFile() { } return tmpPrinterFile; } - + private File getTestTargetFile(String testTargetRelativePath, String projectAbsolutePath) { if (Path.of(testTargetRelativePath).length() > 1) - return new File(Path.of(projectAbsolutePath).newPath(Path.of(testTargetRelativePath).subPath(1)).toString()); + return new File(Path.of(projectAbsolutePath) + .newPath(Path.of(testTargetRelativePath).subPath(1)) + .toString()); return new File(Path.of(projectAbsolutePath).toString()); } private String getTestTarget(File testTargetFile) { if (testTargetFile.isDirectory()) { - if ((new File(testTargetFile, "phpunit.xml").exists() || new File(testTargetFile, "phpunit.xml.dist").exists())) { + if ((new File(testTargetFile, "phpunit.xml").exists() + || new File(testTargetFile, "phpunit.xml.dist").exists())) { return ""; } return testTargetFile.getAbsolutePath(); @@ -263,7 +269,7 @@ private boolean hasComposerRunner(String projectPath) { return false; } try (InputStream inputStream = composerJson.getVirtualFile().getContent(); - InputStreamReader reader = new InputStreamReader(inputStream);) { + InputStreamReader reader = new InputStreamReader(inputStream);) { Gson gson = new GsonBuilder().create(); Map composerJsonMap = gson.fromJson(reader, LinkedTreeMap.class); Map requireDev = (Map) composerJsonMap.get("require-dev"); @@ -277,5 +283,5 @@ private boolean hasComposerRunner(String projectPath) { } return false; } - + } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java index 3855d726f02..d7c7f843e8e 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestResultsProvider.java @@ -88,8 +88,8 @@ private TestResultDto getTestResult(AbstractPHPUnitTestResult phpTestResult, Lis testResultDto.setName(phpTestResult.getName()); testResultDto.setTrace(getTestTrace(phpTestResult)); testResultDto.setInfoText(getTimeString(phpTestResult.getTime())); - testResultDto.setType( - phpTestResult instanceof PHPUnitTestSuite ? TestResultType.TEST_SUITE : TestResultType.TEST_CASE); + testResultDto.setType(phpTestResult instanceof PHPUnitTestSuite ? TestResultType.TEST_SUITE + : TestResultType.TEST_CASE); SimpleLocationDto simpleLocationDto = DtoFactory.getInstance().createDto(SimpleLocationDto.class); simpleLocationDto.setResourcePath(phpTestResult.getFile()); simpleLocationDto.setLineNumber(phpTestResult.getLine() - 1); @@ -108,8 +108,9 @@ private TestResultTraceDto getTestTrace(AbstractPHPUnitTestResult phpTestResult) testResultTraceDto.setMessage(phpTestEvent.getExceptionClass() + ": " + phpTestEvent.getMessage()); List traceFrames = new ArrayList<>(); for (PHPUnitTraceFrame phpTraceFrame : phpTestEvent.getTrace()) { - TestResultTraceFrameDto testResultTraceFrameDto = DtoFactory.getInstance() - .createDto(TestResultTraceFrameDto.class); + TestResultTraceFrameDto testResultTraceFrameDto = + DtoFactory.getInstance() + .createDto(TestResultTraceFrameDto.class); testResultTraceFrameDto.setTraceFrame(phpTraceFrame.toString()); SimpleLocationDto simpleLocationDto = DtoFactory.getInstance().createDto(SimpleLocationDto.class); simpleLocationDto.setResourcePath(phpTraceFrame.getFile()); diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java index 5482a0cab8e..ce033797bdf 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/PHPUnitTestRunner.java @@ -38,8 +38,8 @@ */ public class PHPUnitTestRunner implements TestRunner { - public static final Logger LOG = LoggerFactory.getLogger(PHPUnitTestRunner.class); - public static final String RUNNER_ID = "PHPUnit"; + public static final Logger LOG = LoggerFactory.getLogger(PHPUnitTestRunner.class); + public static final String RUNNER_ID = "PHPUnit"; private final PHPUnitTestEngine testEngine; diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java index 8bc6bec11df..a23050c8c5c 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitElement.java @@ -21,9 +21,9 @@ */ abstract public class AbstractPHPUnitElement { - protected String file = ""; - protected boolean isFiltered = false; - protected int line = 0; + protected String file = ""; + protected boolean isFiltered = false; + protected int line = 0; protected AbstractPHPUnitElement parent; public AbstractPHPUnitElement(final Map properties, final AbstractPHPUnitElement parent) { @@ -72,8 +72,7 @@ public AbstractPHPUnitElement getParent() { /** * Checks if this element is filtered. * - * @return true if this element is filtered, false - * otherwise + * @return true if this element is filtered, false otherwise */ public boolean isFiltered() { return isFiltered; diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java index 9e8616ef862..0ddd06579e1 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestEvent.java @@ -23,8 +23,8 @@ */ public abstract class AbstractPHPUnitTestEvent extends AbstractPHPUnitElement { - protected String message; - protected String diff; + protected String message; + protected String diff; protected List trace; public AbstractPHPUnitTestEvent(final Map event, final AbstractPHPUnitElement parent) { diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java index 19d92350dc7..845b6f1c53c 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/AbstractPHPUnitTestResult.java @@ -22,17 +22,17 @@ */ public abstract class AbstractPHPUnitTestResult extends AbstractPHPUnitElement { - public static final int STATUS_STARTED = 0; - public static final int STATUS_PASS = 1; - public static final int STATUS_SKIP = 2; + public static final int STATUS_STARTED = 0; + public static final int STATUS_PASS = 1; + public static final int STATUS_SKIP = 2; public static final int STATUS_INCOMPLETE = 3; - public static final int STATUS_WARNING = 4; - public static final int STATUS_FAIL = 5; - public static final int STATUS_ERROR = 6; + public static final int STATUS_WARNING = 4; + public static final int STATUS_FAIL = 5; + public static final int STATUS_ERROR = 6; - protected String name = ""; - protected int status = 0; - protected double time = 0; + protected String name = ""; + protected int status = 0; + protected double time = 0; public AbstractPHPUnitTestResult(final Map test, final PHPUnitTestSuite parent) { super(test, parent); diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java index 30c298b5781..dcc7af2c486 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestCase.java @@ -24,8 +24,8 @@ */ public class PHPUnitTestCase extends AbstractPHPUnitTestResult { - protected PHPUnitTestException exception = null; - protected List warnings = null; + protected PHPUnitTestException exception = null; + protected List warnings = null; public PHPUnitTestCase(final Map test, final PHPUnitTestSuite parent) { super(test, parent); diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java index ab7c175d095..3e79c044188 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestException.java @@ -22,8 +22,8 @@ */ public class PHPUnitTestException extends AbstractPHPUnitTestEvent { - private static final String TOP_CLASS = "Exception"; //$NON-NLS-1$ - private String exceptionClass = TOP_CLASS; + private static final String TOP_CLASS = "Exception"; //$NON-NLS-1$ + private String exceptionClass = TOP_CLASS; public PHPUnitTestException(Map exception, PHPUnitTestCase parent) { super(exception, parent); diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java index e58fee01aec..45c60ad3744 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestRoot.java @@ -20,12 +20,12 @@ public class PHPUnitTestRoot extends PHPUnitTestSuite { public PHPUnitTestRoot() { super(null, null); } - + @Override public String getName() { return "Test Results"; } - + @Override public void setStatus(final int status) { statusCount.counts[status]++; @@ -33,5 +33,5 @@ public void setStatus(final int status) { if (parent != null) ((PHPUnitTestSuite) parent).setStatus(status); } - + } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java index d8040850358..eb10ac47c78 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTestSuite.java @@ -25,17 +25,17 @@ public class PHPUnitTestSuite extends AbstractPHPUnitTestResult { protected class StatusCount { public int[] counts = { 0, 0, 0, 0, 0, 0, 0 }; // STATUS_STARTED, - // STATUS_PASS, - // STATUS_SKIP, - // STATUS_INCOMPLETE, - // STATUS_FAIL, - // STATUS_ERROR + // STATUS_PASS, + // STATUS_SKIP, + // STATUS_INCOMPLETE, + // STATUS_FAIL, + // STATUS_ERROR } - protected final StatusCount statusCount = new StatusCount(); - private Set children = null; - private int runCount = 0; - private int totalCount; + protected final StatusCount statusCount = new StatusCount(); + private Set children = null; + private int runCount = 0; + private int totalCount; public PHPUnitTestSuite(final Map test, final PHPUnitTestSuite parent) { super(test, parent); @@ -119,5 +119,5 @@ private void addRunCount(final int count) { if (parent != null) ((PHPUnitTestSuite) parent).addRunCount(count); } - + } diff --git a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java index 5b2a6d78822..538d71880cb 100644 --- a/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java +++ b/plugins/plugin-testing-php/plugin-testing-phpunit/che-plugin-testing-phpunit-server/src/main/java/org/eclipse/che/plugin/testing/phpunit/server/model/PHPUnitTraceFrame.java @@ -22,9 +22,9 @@ */ public class PHPUnitTraceFrame extends AbstractPHPUnitElement { - private String traceFunction = ""; //$NON-NLS-1$ - private String traceClass = ""; //$NON-NLS-1$ - private String traceType = PHPUnitMessageParser.CALL_DYNAMIC; + private String traceFunction = ""; //$NON-NLS-1$ + private String traceClass = ""; //$NON-NLS-1$ + private String traceType = PHPUnitMessageParser.CALL_DYNAMIC; public PHPUnitTraceFrame(final Map frame, final AbstractPHPUnitTestEvent parent) { super(frame, parent); diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java index ba53607a895..68f2f692eb7 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/TestActionRunner.java @@ -35,13 +35,14 @@ */ public class TestActionRunner { - private final TestServiceClient service; + private final TestServiceClient service; private final NotificationManager notificationManager; private final TestResultPresenter presenter; @Inject - public TestActionRunner(TestServiceClient service, NotificationManager notificationManager, - TestResultPresenter presenter) { + public TestActionRunner(TestServiceClient service, + NotificationManager notificationManager, + TestResultPresenter presenter) { this.service = service; this.notificationManager = notificationManager; this.presenter = presenter; diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java index 2d8b94ffd01..5446968d225 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/SimpleLocationHandler.java @@ -29,8 +29,7 @@ import com.google.inject.Inject; /** - * Simple location DTO handler. It is responsible for opening the provided - * location. + * Simple location DTO handler. It is responsible for opening the provided location. * * @author Bartlomiej Laczkowski */ @@ -38,8 +37,8 @@ public class SimpleLocationHandler { private static final String PROJECTS_ROOT = "/projects"; - private final EditorAgent editorAgent; - private final AppContext appContext; + private final EditorAgent editorAgent; + private final AppContext appContext; @Inject public SimpleLocationHandler(EditorAgent editorAgent, AppContext appContext) { @@ -109,8 +108,9 @@ public void apply(PromiseError arg) throws OperationException { } } - private void openFileAndScrollToLine(final VirtualFile virtualFile, final int scrollToLine, - final AsyncCallback callback) { + private void openFileAndScrollToLine(final VirtualFile virtualFile, + final int scrollToLine, + final AsyncCallback callback) { editorAgent.openEditor(virtualFile, new EditorAgent.OpenEditorCallback() { @Override public void onEditorOpened(EditorPartPresenter editor) { @@ -136,8 +136,8 @@ public void run() { @Override public void onInitializationFailed() { - callback.onFailure( - new IllegalStateException("Initialization " + virtualFile.getName() + " in the editor failed")); + callback.onFailure(new IllegalStateException("Initialization " + virtualFile.getName() + + " in the editor failed")); } }); } diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java index 813564aaf64..dcd0615e7fb 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/AbstractTestResultTreeNode.java @@ -30,16 +30,18 @@ */ public abstract class AbstractTestResultTreeNode extends AbstractTreeNode implements HasPresentation { - protected final TestResources testResources; + protected final TestResources testResources; protected final TestResultNodeFactory nodeFactory; - protected final TestServiceClient testServiceClient; - protected final String frameworkName; - private NodePresentation nodePresentation; - - private static final String TEXT_INFO_CSS = "color: " + getEditorInfoTextColor() + "; font-size: 11px"; + protected final TestServiceClient testServiceClient; + protected final String frameworkName; + private NodePresentation nodePresentation; - public AbstractTestResultTreeNode(TestServiceClient testServiceClient, TestResultNodeFactory nodeFactory, - TestResources testResources, String frameworkName) { + private static final String TEXT_INFO_CSS = "color: " + getEditorInfoTextColor() + "; font-size: 11px"; + + public AbstractTestResultTreeNode(TestServiceClient testServiceClient, + TestResultNodeFactory nodeFactory, + TestResources testResources, + String frameworkName) { this.testServiceClient = testServiceClient; this.nodeFactory = nodeFactory; this.testResources = testResources; diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java index 54245938891..2704e1ae402 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultNode.java @@ -37,13 +37,16 @@ */ public class TestResultNode extends AbstractTestResultTreeNode implements HasAction { - private final TestResultDto testResultDto; + private final TestResultDto testResultDto; private final SimpleLocationHandler simpleLocationHandler; @Inject - public TestResultNode(TestServiceClient testServiceClient, TestResultNodeFactory nodeFactory, - TestResources testResources, SimpleLocationHandler simpleLocationHandler, - @Assisted TestResultDto testResultDto, @Assisted String frameworkName) { + public TestResultNode(TestServiceClient testServiceClient, + TestResultNodeFactory nodeFactory, + TestResources testResources, + SimpleLocationHandler simpleLocationHandler, + @Assisted TestResultDto testResultDto, + @Assisted String frameworkName) { super(testServiceClient, nodeFactory, testResources, frameworkName); this.testResultDto = testResultDto; this.simpleLocationHandler = simpleLocationHandler; @@ -88,7 +91,7 @@ public void actionPerformed() { protected Promise> getChildrenImpl() { final List children = new ArrayList(); Promise> promise = testServiceClient.getTestResults(frameworkName, - testResultDto.getResultPath()); + testResultDto.getResultPath()); return promise.then(new Function, List>() { @Override public List apply(List arg) { diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java index 08a3f1bb264..a6773fd659b 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultRootNode.java @@ -37,12 +37,14 @@ public class TestResultRootNode extends AbstractTestResultTreeNode { private final TestResultRootDto testResultRootDto; @Inject - public TestResultRootNode(TestServiceClient testServiceClient, TestResultNodeFactory nodeFactory, - TestResources testResources, @Assisted TestResultRootDto testResultRootDto, - @Assisted String frameworkName) { + public TestResultRootNode(TestServiceClient testServiceClient, + TestResultNodeFactory nodeFactory, + TestResources testResources, + @Assisted TestResultRootDto testResultRootDto, + @Assisted String frameworkName) { super(testServiceClient, nodeFactory, testResources, frameworkName); this.testResultRootDto = testResultRootDto; - + } @Override @@ -66,7 +68,7 @@ public String getTestInfoText() { public TestResultStatus getTestStatus() { return testResultRootDto.getStatus(); } - + @Override public TestResultTraceDto getTestTrace() { return testResultRootDto.getTrace(); @@ -76,7 +78,7 @@ public TestResultTraceDto getTestTrace() { protected Promise> getChildrenImpl() { final List children = new ArrayList(); Promise> promise = testServiceClient.getTestResults(frameworkName, - testResultRootDto.getResultPath()); + testResultRootDto.getResultPath()); return promise.then(new Function, List>() { @Override public List apply(List arg) { diff --git a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java index 34d19e49b49..221e1087def 100644 --- a/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java +++ b/plugins/plugin-testing/che-plugin-testing-ide/src/main/java/org/eclipse/che/plugin/testing/ide/view/navigation/nodes/TestResultTraceFrameNode.java @@ -35,14 +35,15 @@ */ public class TestResultTraceFrameNode extends AbstractTreeNode implements HasPresentation, HasAction { - private final TestResources testResources; - private final SimpleLocationHandler simpleLocationHandler; + private final TestResources testResources; + private final SimpleLocationHandler simpleLocationHandler; private final TestResultTraceFrameDto testResultTraceFrameDto; - private NodePresentation nodePresentation; + private NodePresentation nodePresentation; @Inject - public TestResultTraceFrameNode(TestResources testResources, SimpleLocationHandler simpleLocationHandler, - @Assisted TestResultTraceFrameDto testResultTraceFrameDto) { + public TestResultTraceFrameNode(TestResources testResources, + SimpleLocationHandler simpleLocationHandler, + @Assisted TestResultTraceFrameDto testResultTraceFrameDto) { this.testResources = testResources; this.simpleLocationHandler = simpleLocationHandler; this.testResultTraceFrameDto = testResultTraceFrameDto; diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java index ebf649d7761..b3cb705740f 100644 --- a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/SimpleLocationDto.java @@ -13,8 +13,7 @@ import org.eclipse.che.dto.shared.DTO; /** - * Provides info about file to be opened in the editor and line number on which - * the selection should be made. + * Provides info about file to be opened in the editor and line number on which the selection should be made. * * @author Bartlomiej Laczkowski */ diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java index 48f2a6edbf7..3118cba96d6 100644 --- a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultDto.java @@ -67,8 +67,7 @@ public interface TestResultDto { void setName(String name); /** - * Returns additional text (i.e. test execution time) that will be added as - * info text in related tree element label. + * Returns additional text (i.e. test execution time) that will be added as info text in related tree element label. * * @return info text */ @@ -96,8 +95,7 @@ public interface TestResultDto { void setTrace(TestResultTraceDto traceDto); /** - * Returns test result simple location DTO (i.e. file with related test - * case). + * Returns test result simple location DTO (i.e. file with related test case). * * @return test result simple location DTO */ diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java index f4445296f11..3c9e74d6d63 100644 --- a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultRootDto.java @@ -66,8 +66,7 @@ public interface TestResultRootDto { void setName(String label); /** - * Returns additional text (i.e. test execution time) that will be added as - * info text in related tree element label. + * Returns additional text (i.e. test execution time) that will be added as info text in related tree element label. * * @return info text */ @@ -109,11 +108,9 @@ public interface TestResultRootDto { void setResultPath(List resultPath); /** - * Returns true if this result root is empty (has no test - * results at all). + * Returns true if this result root is empty (has no test results at all). * - * @return true if this result root is empty, - * false otherwise + * @return true if this result root is empty, false otherwise */ boolean isEmpty(); diff --git a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java index 3ce6859bb2f..56392f3f1b8 100644 --- a/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java +++ b/wsagent/che-core-api-testing-shared/src/main/java/org/eclipse/che/api/testing/shared/dto/TestResultTraceFrameDto.java @@ -35,8 +35,7 @@ public interface TestResultTraceFrameDto { void setTraceFrame(String traceFrame); /** - * Returns trace frame simple location DTO (i.e. file with related - * method/function definition). + * Returns trace frame simple location DTO (i.e. file with related method/function definition). * * @return trace frame simple location DTO */