4
4
import static org .assertj .core .api .Assertions .assertThat ;
5
5
6
6
import java .io .File ;
7
+ import java .nio .file .Files ;
7
8
import java .nio .file .Path ;
9
+ import java .nio .file .Paths ;
8
10
9
11
import org .apache .commons .io .FileUtils ;
10
12
import org .eclipse .core .resources .IFile ;
17
19
import org .eclipse .swtbot .eclipse .finder .widgets .SWTBotView ;
18
20
import org .eclipse .swtbot .swt .finder .widgets .SWTBotTreeItem ;
19
21
import org .junit .BeforeClass ;
22
+ import org .junit .Ignore ;
20
23
import org .junit .Rule ;
21
24
import org .junit .Test ;
22
25
import org .junit .rules .TemporaryFolder ;
23
26
27
+ import com .devonfw .cobigen .eclipse .common .constants .external .ResourceConstants ;
24
28
import com .devonfw .cobigen .eclipse .test .common .SystemTest ;
25
29
import com .devonfw .cobigen .eclipse .test .common .swtbot .AllJobsAreFinished ;
26
30
import com .devonfw .cobigen .eclipse .test .common .utils .EclipseCobiGenUtils ;
@@ -58,7 +62,7 @@ public static void setupClass() throws Exception {
58
62
*
59
63
* @throws Exception test fails
60
64
*/
61
- public void testBasicOpenAPIGenerationWithAdaptTemplates () throws Exception {
65
+ public void testBasicOpenAPIGenerationWithAdaptTemplateSets () throws Exception {
62
66
63
67
// copy sample project to external location and import it into the workspace
64
68
String testProjName = "ExtTestProj" ;
@@ -94,12 +98,123 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
94
98
}
95
99
96
100
/**
101
+ * Test for external projects (not in workspace) taken as input
102
+ *
103
+ * @throws Exception test fails
104
+ */
105
+ public void testAdaptTemplatesAndImportIntoEclipse () throws Exception {
106
+
107
+ // copy sample project to external location and import it into the workspace
108
+ String testProjName = "ExtTestProj" ;
109
+ IJavaProject project = this .tmpMavenProjectRule .createProject (testProjName );
110
+ FileUtils .copyFile (new File (resourcesRootPath + "input/adapt-templates.yml" ),
111
+ project .getUnderlyingResource ().getLocation ().append ("adapt-templates.yml" ).toFile ());
112
+ project .getProject ().refreshLocal (IResource .DEPTH_INFINITE , new NullProgressMonitor ());
113
+ this .tmpMavenProjectRule .updateProject ();
114
+
115
+ EclipseCobiGenUtils .runAndCaptureAdaptTemplatesSets (bot );
116
+
117
+ EclipseUtils .openErrorsTreeInProblemsView (bot );
118
+
119
+ // expand the new file in the package explorer
120
+ SWTBotView view = bot .viewById (JavaUI .ID_PACKAGES );
121
+ SWTBotTreeItem javaClassItem = view .bot ().tree ().expandNode (testProjName , "adapt-templates.yml" );
122
+ javaClassItem .select ();
123
+
124
+ IProject generatorProjOfTempltesSets = ResourcesPlugin .getWorkspace ().getRoot ()
125
+ .getProject (ResourceConstants .TEMPLATE_SETS_CONFIG_PROJECT_NAME );
126
+ bot .waitUntil (new AllJobsAreFinished (), 10000000 );
127
+ IProject proj = ResourcesPlugin .getWorkspace ().getRoot ().getProject (testProjName );
128
+
129
+ Path adaptedFolder = Paths .get (generatorProjOfTempltesSets .getLocationURI ())
130
+ .resolve (ResourceConstants .TEMPLATE_SETS_ADAPTED );
131
+
132
+ assertThat (generatorProjOfTempltesSets .exists ()).isTrue ();
133
+ assertThat (Files .exists (adaptedFolder )).isTrue ();
134
+
135
+ }
136
+
137
+ /**
138
+ * Test for external projects (not in workspace) taken as input for generation
139
+ *
140
+ * @throws Exception test fails
141
+ */
142
+ public void testBasicOpenAPIGenerationWithAdaptMonolithicTemplates () throws Exception {
143
+
144
+ // copy sample project to external location and import it into the workspace
145
+ String testProjName = "ExtTestProj" ;
146
+ IJavaProject project = this .tmpMavenProjectRule .createProject (testProjName );
147
+ FileUtils .copyFile (new File (resourcesRootPath + "input/adapt-templates.yml" ),
148
+ project .getUnderlyingResource ().getLocation ().append ("adapt-templates.yml" ).toFile ());
149
+ project .getProject ().refreshLocal (IResource .DEPTH_INFINITE , new NullProgressMonitor ());
150
+ this .tmpMavenProjectRule .updateProject ();
151
+
152
+ EclipseCobiGenUtils .runAndCaptureUpdateTemplates (bot );
153
+ EclipseCobiGenUtils .runAndCaptureAdaptTemplates (bot );
154
+ EclipseUtils .updateMavenProject (bot , ResourceConstants .CONFIG_PROJECT_NAME );
155
+
156
+ EclipseUtils .openErrorsTreeInProblemsView (bot );
157
+
158
+ // expand the new file in the package explorer
159
+ SWTBotView view = bot .viewById (JavaUI .ID_PACKAGES );
160
+ SWTBotTreeItem javaClassItem = view .bot ().tree ().expandNode (testProjName , "adapt-templates.yml" );
161
+ javaClassItem .select ();
162
+
163
+ // execute CobiGen
164
+ EclipseCobiGenUtils .processCobiGen (bot , javaClassItem , 25000 , "CRUD devon4j Server>CRUD REST services" );
165
+ bot .waitUntil (new AllJobsAreFinished (), 10000 );
166
+ // increase timeout as the openAPI parser is slow on initialization
167
+ EclipseCobiGenUtils .confirmSuccessfullGeneration (bot , 40000 );
168
+
169
+ bot .waitUntil (new AllJobsAreFinished (), 10000 );
170
+ IProject proj = ResourcesPlugin .getWorkspace ().getRoot ().getProject (testProjName );
171
+ IFile generationResult = proj .getFile (
172
+ "src/main/java/com/devonfw/test/sampledatamanagement/service/impl/rest/SampledatamanagementRestServiceImpl.java" );
173
+
174
+ assertThat (generationResult .exists ()).isTrue ();
175
+ }
176
+
177
+ /*
178
+ *
97
179
* Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable
98
180
*
181
+ */
182
+ @ Test
183
+ public void testAdaptMonolithicTemplatesAndGenerate () throws Exception {
184
+
185
+ File tmpProject = this .tempFolder .newFolder ("playground" , "project" );
186
+ withEnvironmentVariable ("COBIGEN_HOME" , tmpProject .toPath ().toString ())
187
+ .execute (() -> testBasicOpenAPIGenerationWithAdaptMonolithicTemplates ());
188
+ }
189
+
190
+ /**
191
+ * TODO Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom template-sets after adapt the jar files
192
+ *
99
193
* @throws Exception test fails
100
194
*/
101
195
@ Test
102
- public void testAdaptTemplatesAndGenerate () throws Exception {
196
+ @ Ignore
197
+ public void testAdaptTemplateSetsAndGenerate () throws Exception {
198
+
199
+ Path devTemplatesPath = new File (
200
+ AdaptTemplatesTest .class .getProtectionDomain ().getCodeSource ().getLocation ().toURI ()).getParentFile ()
201
+ .getParentFile ().toPath ().resolve ("cobigen-templates" ).resolve ("crud-openapi-java-server-app" )
202
+ .resolve ("target" ).resolve ("crud-openapi-java-server-app-2021.12.007-SNAPSHOT.jar" );
203
+
204
+ File tmpProject = this .tempFolder .newFolder ("playground" , "project" );
205
+ File downloaded = this .tempFolder .newFolder ("playground" , "project" , "template-sets" , "downloaded" );
206
+ FileUtils .copyFileToDirectory (devTemplatesPath .toFile (), downloaded );
207
+ withEnvironmentVariable ("COBIGEN_HOME" , tmpProject .toPath ().toString ())
208
+ .execute (() -> testBasicOpenAPIGenerationWithAdaptTemplateSets ());
209
+ }
210
+
211
+ /*
212
+ *
213
+ * Test adaption of template-sets/downloaded/.jar files and importing the project into Eclipse
214
+ *
215
+ */
216
+ @ Test
217
+ public void testAdaptTemplateSetsAndImport () throws Exception {
103
218
104
219
Path devTemplatesPath = new File (
105
220
AdaptTemplatesTest .class .getProtectionDomain ().getCodeSource ().getLocation ().toURI ()).getParentFile ()
@@ -110,6 +225,7 @@ public void testAdaptTemplatesAndGenerate() throws Exception {
110
225
File downloaded = this .tempFolder .newFolder ("playground" , "project" , "template-sets" , "downloaded" );
111
226
FileUtils .copyFileToDirectory (devTemplatesPath .toFile (), downloaded );
112
227
withEnvironmentVariable ("COBIGEN_HOME" , tmpProject .toPath ().toString ())
113
- .execute (() -> testBasicOpenAPIGenerationWithAdaptTemplates ());
228
+ .execute (() -> testAdaptTemplatesAndImportIntoEclipse ());
229
+
114
230
}
115
231
}
0 commit comments