|
31 | 31 | */
|
32 | 32 | public class AdaptTemplatesTest extends SystemTest {
|
33 | 33 |
|
34 |
| - /** Temporary files rule to create temporary folders or files */ |
35 |
| - @Rule |
36 |
| - public TemporaryFolder tempFolder = new TemporaryFolder(); |
37 |
| - |
38 |
| - /** Root path of the Test Resources */ |
39 |
| - private static final String resourcesRootPath = "src/main/resources/OpenAPITest/"; |
40 |
| - |
41 |
| - /** Line separator, e.g. for windows '\r\n' */ |
42 |
| - public static final String LINE_SEPARATOR = java.lang.System.getProperty("line.separator"); |
43 |
| - |
44 |
| - /** |
45 |
| - * Setup workbench appropriately for tests |
46 |
| - * |
47 |
| - * @throws Exception test fails |
48 |
| - */ |
49 |
| - @BeforeClass |
50 |
| - public static void setupClass() throws Exception { |
51 |
| - |
52 |
| - EclipseUtils.cleanWorkspace(bot, true); |
53 |
| - |
54 |
| - } |
55 |
| - |
56 |
| - /** |
57 |
| - * Test generation with OpenAPI input after adapting templates |
58 |
| - * |
59 |
| - * @throws Exception test fails |
60 |
| - */ |
61 |
| - public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception { |
62 |
| - |
63 |
| - // copy sample project to external location and import it into the workspace |
64 |
| - String testProjName = "ExtTestProj"; |
65 |
| - IJavaProject project = this.tmpMavenProjectRule.createProject(testProjName); |
66 |
| - FileUtils.copyFile(new File(resourcesRootPath + "input/adapt-templates.yml"), |
67 |
| - project.getUnderlyingResource().getLocation().append("adapt-templates.yml").toFile()); |
68 |
| - project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); |
69 |
| - this.tmpMavenProjectRule.updateProject(); |
70 |
| - |
71 |
| - EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot); |
72 |
| - EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot); |
73 |
| - EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); |
74 |
| - |
75 |
| - EclipseUtils.openErrorsTreeInProblemsView(bot); |
76 |
| - |
77 |
| - // expand the new file in the package explorer |
78 |
| - SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); |
79 |
| - SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjName, "adapt-templates.yml"); |
80 |
| - javaClassItem.select(); |
81 |
| - |
82 |
| - IProject adaptedTemplatesProj = ResourcesPlugin.getWorkspace().getRoot() |
83 |
| - .getProject(ConfigurationConstants.COBIGEN_TEMPLATES); |
84 |
| - |
85 |
| - assertThat(adaptedTemplatesProj.exists()).isTrue(); |
86 |
| - } |
87 |
| - |
88 |
| - /** |
89 |
| - * Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME |
90 |
| - * environment variable |
91 |
| - * |
92 |
| - * @throws Exception test fails |
93 |
| - */ |
94 |
| - @Test |
95 |
| - public void testAdaptTemplates() throws Exception { |
96 |
| - |
97 |
| - File tmpProject = this.tempFolder.newFolder("playground", "project", "templates"); |
98 |
| - withEnvironmentVariable(ConfigurationConstants.CONFIG_ENV_HOME, tmpProject.getParentFile().getAbsolutePath()) |
99 |
| - .execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates()); |
100 |
| - } |
| 34 | + /** Temporary files rule to create temporary folders or files */ |
| 35 | + @Rule |
| 36 | + public TemporaryFolder tempFolder = new TemporaryFolder(); |
| 37 | + |
| 38 | + /** Root path of the Test Resources */ |
| 39 | + private static final String resourcesRootPath = "src/main/resources/OpenAPITest/"; |
| 40 | + |
| 41 | + /** Line separator, e.g. for windows '\r\n' */ |
| 42 | + public static final String LINE_SEPARATOR = java.lang.System.getProperty("line.separator"); |
| 43 | + |
| 44 | + /** |
| 45 | + * Setup workbench appropriately for tests |
| 46 | + * |
| 47 | + * @throws Exception test fails |
| 48 | + */ |
| 49 | + @BeforeClass |
| 50 | + public static void setupClass() throws Exception { |
| 51 | + |
| 52 | + EclipseUtils.cleanWorkspace(bot, true); |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Test generation with OpenAPI input after adapting templates |
| 58 | + * |
| 59 | + * @throws Exception test fails |
| 60 | + */ |
| 61 | + public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception { |
| 62 | + |
| 63 | + // copy sample project to external location and import it into the workspace |
| 64 | + String testProjName = "ExtTestProj"; |
| 65 | + IJavaProject project = this.tmpMavenProjectRule.createProject(testProjName); |
| 66 | + FileUtils.copyFile(new File(resourcesRootPath + "input/adapt-templates.yml"), |
| 67 | + project.getUnderlyingResource().getLocation().append("adapt-templates.yml").toFile()); |
| 68 | + project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); |
| 69 | + this.tmpMavenProjectRule.updateProject(); |
| 70 | + |
| 71 | + EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot); |
| 72 | + EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot); |
| 73 | + EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); |
| 74 | + |
| 75 | + EclipseUtils.openErrorsTreeInProblemsView(bot); |
| 76 | + |
| 77 | + // expand the new file in the package explorer |
| 78 | + SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); |
| 79 | + SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjName, "adapt-templates.yml"); |
| 80 | + javaClassItem.select(); |
| 81 | + |
| 82 | + IProject adaptedTemplatesProj = ResourcesPlugin.getWorkspace().getRoot() |
| 83 | + .getProject(ConfigurationConstants.COBIGEN_TEMPLATES); |
| 84 | + |
| 85 | + assertThat(adaptedTemplatesProj.exists()).isTrue(); |
| 86 | + |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable |
| 91 | + * |
| 92 | + * @throws Exception test fails |
| 93 | + */ |
| 94 | + @Test |
| 95 | + public void testAdaptTemplates() throws Exception { |
| 96 | + |
| 97 | + File tmpProject = this.tempFolder.newFolder("playground", "project", "templates"); |
| 98 | + withEnvironmentVariable(ConfigurationConstants.CONFIG_ENV_HOME, tmpProject.getParentFile().getAbsolutePath()) |
| 99 | + .execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates()); |
| 100 | + } |
101 | 101 | }
|
0 commit comments