Package com._1c.g5.v8.dt.testing
Class TestingWorkspace
- java.lang.Object
- 
- com._1c.g5.v8.dt.testing.TestingWorkspace
 
- 
- All Implemented Interfaces:
- org.junit.rules.TestRule
 
 public class TestingWorkspace extends Object implements org.junit.rules.TestRule Testing workspace rule allows to set up test projects for testing purposes. Provides a set of usefull methods such as project set up and workspace clean. Testing workspace cleans working workspace before and after test execution automatically. Typical test execution flow is next:- Test starts running in a clean workspace.
- Test is responsible to set up the necessary workspace state.
- After running a test, the workspace is cleaned up automatically.
 TestingWorkspacerule may provide its own testing workspace for each test or single testing workspace for all tests inside test class, based on@Ruleor@ClassRuleannotations.Example of rule usage with its own testing workspace for each test inside test class: public class TestingWorkspaceRuleExampleTest { @Rule public TestingWorkspace testingWorkspace = new TestingWorkspace(); @Test public void testSomeProjectBehavior() { IProject project = testingWorkspace.setUpProject("Main", getClass()); // we can use project for testing here, it is already built ... } @Test public void testSomeOtherProjectBehavior() { IProject project = testingWorkspace.setUpProject("Other", getClass()); // we can use project for testing here, it is already built ... } }Example of rule usage with single testing workspace for all tests inside test class: public class TestingWorkspaceRuleClassExampleTest { @ClassRule public static TestingWorkspace testingWorkspace = new TestingWorkspace(); private static IProject mainProject; private static IProject otherProject; @BeforeClass public static void setUp() throws Exception { mainProject = testingWorkspace.setUpProject("Main", TestingWorkspaceRuleClassExampleTest.class); otherProject = testingWorkspace.setUpProject("Other", TestingWorkspaceRuleClassExampleTest.class); } @Test public void testSomeProjectBehavior() { // we can use first and second project for testing here, they are already built ... } @Test public void testSomeOtherProjectBehavior() { // ... and here too } }Note, that clients need to use TestingWorkspacewith@ClassRulerule annotation carefully: tests exectution may have side effect from one test to other, because they share the same workspace.
- 
- 
Constructor SummaryConstructors Constructor Description TestingWorkspace()Creates an instance ofTestingWorkspacewith default parameters.TestingWorkspace(boolean autoBuild, boolean cleanUp)Creates an instance ofTestingWorkspace.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafter()Tears down the test execution.org.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runner.Description description)protected voidbefore()Sets up the test execution.voidbuildWorkspace()Builds the workspace and waits for build completion.voidcleanUpWorkspace()Deletes all resources in the workspace.org.eclipse.core.resources.IProjectgetProject(String name)Returns the testing workspace project.org.eclipse.core.resources.IWorkspacegetWorkspace()Returns the testing workspace.org.eclipse.core.resources.IWorkspaceRootgetWorkspaceRoot()Returns the testing workspace root.voidsetCopyProjectOnSetUp(boolean value)Sets flag of copying project content into the workspace during the setup phase.org.eclipse.core.resources.IProjectsetUpProject(String name, Class<?> sourceClass)Creates a new project in the workspace.org.eclipse.core.resources.IProjectsetUpProject(String name, String sourceName, Class<?> sourceClass)Creates a new project in the workspace.org.eclipse.core.resources.IProjectsetUpProject(String name, String sourceName, Path sourceRoot)CreatesIProject.org.eclipse.core.resources.IProjectsetUpProject(String name, Path sourceRoot)CreatesIProject.voidwaitForBuildCompletion()Waits for the workspace build completion.
 
- 
- 
- 
Constructor Detail- 
TestingWorkspacepublic TestingWorkspace() Creates an instance ofTestingWorkspacewith default parameters.
 - 
TestingWorkspacepublic TestingWorkspace(boolean autoBuild, boolean cleanUp)Creates an instance ofTestingWorkspace.- Parameters:
- autoBuild- the property "Build Automatically" value for the testing workspace
- cleanUp- whether need to clean up workspace automatically before and after each rule exetuion; may be usefull if client want to have manual workspace clean control
 
 
- 
 - 
Method Detail- 
applypublic org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)- Specified by:
- applyin interface- org.junit.rules.TestRule
 
 - 
getWorkspacepublic org.eclipse.core.resources.IWorkspace getWorkspace() Returns the testing workspace. Shortcut toResourcesPlugin.getWorkspace().- Returns:
- the testing workspace, never null
 
 - 
getWorkspaceRootpublic org.eclipse.core.resources.IWorkspaceRoot getWorkspaceRoot() Returns the testing workspace root. Shortcut togetWorkspace().getRoot().
 - 
getProjectpublic org.eclipse.core.resources.IProject getProject(String name) Returns the testing workspace project. Shortcut togetWorkspaceRoot().getProject(name).- Parameters:
- name- the name of the project to get, cannot be- null
- Returns:
- the project with the provided name, never null
 
 - 
buildWorkspacepublic void buildWorkspace() throws org.eclipse.core.runtime.CoreExceptionBuilds the workspace and waits for build completion.- Throws:
- org.eclipse.core.runtime.CoreException- if workspace build or wait error occurred
 
 - 
cleanUpWorkspacepublic void cleanUpWorkspace() throws org.eclipse.core.runtime.CoreExceptionDeletes all resources in the workspace.- Throws:
- org.eclipse.core.runtime.CoreException- if workspace clean up error occurred
 
 - 
setUpProjectpublic org.eclipse.core.resources.IProject setUpProject(String name, Class<?> sourceClass) throws org.eclipse.core.runtime.CoreException Creates a new project in the workspace. The project will be copied from the OSGi-bundle of this test case ifcopyProjectOnSetUpflag set totrue(default). The content must reside in the folder/workspace/<project-name> inside the bundle.- Parameters:
- name- the name of the creating project and source project inside bundle to set up, cannot be- null
- sourceClass- the source class to get OSGi-bundle for, e.g. test case, cannot be- null
- Returns:
- the created and opened project never null
- Throws:
- org.eclipse.core.runtime.CoreException- if project creation error occurred
- IllegalArgumentException- if the project with the provided name not found in the source OSGi-bundle
 
 - 
setUpProjectpublic org.eclipse.core.resources.IProject setUpProject(String name, String sourceName, Class<?> sourceClass) throws org.eclipse.core.runtime.CoreException Creates a new project in the workspace. The project will be copied from the OSGi-bundle of this test case ifcopyProjectOnSetUpflag set totrue(default). The content must reside in the folder/workspace/<project-name> inside the bundle.- Parameters:
- name- the name of the creating project, cannot be- null
- sourceName- the source of source project inside bundle to set up, cannot be- null
- sourceClass- the source class to get OSGi-bundle for, e.g. test case, cannot be- null
- Returns:
- the created and opened project never null
- Throws:
- org.eclipse.core.runtime.CoreException- if project creation error occurred
- IllegalArgumentException- if the project with the provided name not found in the source OSGi-bundle
 
 - 
setUpProjectpublic org.eclipse.core.resources.IProject setUpProject(String name, Path sourceRoot) throws org.eclipse.core.runtime.CoreException CreatesIProject.- Parameters:
- name- the name of the creating project and source project in the source root, cannot be- null
- sourceRoot- the location of the project parent directory, cannot be- null
- Returns:
- the new project, never null
- Throws:
- org.eclipse.core.runtime.CoreException- if project creation error occurred
- IllegalArgumentException- if project with provided name not found in the source root
 
 - 
setUpProjectpublic org.eclipse.core.resources.IProject setUpProject(String name, String sourceName, Path sourceRoot) throws org.eclipse.core.runtime.CoreException CreatesIProject.- Parameters:
- name- the name of the creating project, cannot be- null
- sourceName- the source of source project in the source root, cannot be- null
- sourceRoot- the location of the project parent directory, cannot be- null
- Returns:
- the new project, never null
- Throws:
- org.eclipse.core.runtime.CoreException- if project creation error occurred
- IllegalArgumentException- if project with provided name not found in the source root
 
 - 
waitForBuildCompletionpublic void waitForBuildCompletion() Waits for the workspace build completion.
 - 
setCopyProjectOnSetUppublic void setCopyProjectOnSetUp(boolean value) Sets flag of copying project content into the workspace during the setup phase. Set this flag before any of#setUpProject()calls.- Parameters:
- value-- trueif the project content should be copied into the workpace,- falseotherwise
 
 - 
beforeprotected void before() throws ExceptionSets up the test execution. Method is executed before the rule statement.
 
- 
 
-