-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLSLLanguageSystemTest.groovy
621 lines (544 loc) · 22.3 KB
/
LSLLanguageSystemTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/*
* LASSO - an Observatorium for the Dynamic Selection, Analysis and Comparison of Software
* Copyright (C) 2024 Marcus Kessel (University of Mannheim) and LASSO contributers
*
* This file is part of LASSO.
*
* LASSO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LASSO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LASSO. If not, see <https://www.gnu.org/licenses/>.
*/
package de.uni_mannheim.swt.lasso.service.systemtests.integration
import de.uni_mannheim.swt.lasso.engine.DataSourceNotFoundException
import de.uni_mannheim.swt.lasso.engine.LSLExecutionContext
import de.uni_mannheim.swt.lasso.engine.LSLExecutionResult
import de.uni_mannheim.swt.lasso.engine.LSLScript
import de.uni_mannheim.swt.lasso.lsl.spec.AbstractionSpec
import de.uni_mannheim.swt.lasso.service.systemtests.util.LassoTestEngine
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
/**
* Demonstrates LSL language features
*
* @author mkessel
*/
class LSLLanguageSystemTest extends AbstractGroovySystemTest {
@Autowired
@Qualifier("testLassoEngine")
LassoTestEngine lassoEngine;
/**
* <pre>
* dependsOn 'one', 'two', ...
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_dependsOn_many_actions() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select1', type: 'Select') {
abstraction('Stack') {
queryForClasses 'Stack', 'concept'
rows = 10
directly = true // without cursor functionality
}
}
/** Retrieve class implementations */
action(name: 'select2', type: 'Select') {
abstraction('List') {
queryForClasses 'List', 'concept'
rows = 10
directly = true // without cursor functionality
}
}
action(name: 'doSomething') { // plain action
dependsOn 'select1', 'select2' // depends on two former actions
includeAbstractions '*'
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'doSomething', 'Stack', 10)
verifyAbstraction(lslExecutionContext, 'doSomething', 'List', 10)
}
/**
* <pre>
* dependsOn 'executionId:one'
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_dependsOn_external_action() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content1 = '''
dataSource 'mavenCentral2020' // define data source to use
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select1', type: 'Select') {
abstraction('Stack') {
queryForClasses 'Stack', 'concept'
rows = 10
directly = true // without cursor functionality
}
}
}
'''
//
LSLScript scriptUnderTest1 = createScript(content1)
// DO EXECUTE
LSLExecutionResult lslExecutionResult1 = lassoEngine.execute(scriptUnderTest1);
LSLExecutionContext lslExecutionContext1 = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext1, 'select1', 'Stack', 10)
// second study which uses FA of first study
@Language("Groovy")
String content2 = '''
dataSource 'mavenCentral2020' // define data source to use
study(name: 'Something') {
action(name: 'doSomething') { // plain action
dependsOn 'executionId.select1'
includeAbstractions '*'
}
}
'''
// executionId:select1
content2 = content2.replace("executionId.select1", scriptUnderTest1.getExecutionId() + ":select1");
//
LSLScript scriptUnderTest2 = createScript(content2)
// DO EXECUTE
LSLExecutionResult lslExecutionResult2 = lassoEngine.execute(scriptUnderTest2);
LSLExecutionContext lslExecutionContext2 = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext2, 'doSomething', 'Stack', 10)
}
/**
* <pre>
* includeAbstractions '*'
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_includeAbstractions() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
// interface of a Stack in LQL notation
def interfaceSpec = """Stack {
push(java.lang.Object)->java.lang.Object
pop()->java.lang.Object
peek()->java.lang.Object
size()->int}"""
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select', type: 'Select') {
abstraction('Stack1') {
queryForClasses interfaceSpec // query for classes by interface specification
rows = 1
directly = true // without cursor functionality
excludeClassesByKeywords(['private', 'abstract'])
excludeTestClasses()
excludeInternalPkgs()
// optionally, we don't want it to be a collection
//excludeSuperClass("java.util.Collection", true)
// non empty classes, i.e having complexity > 1
filter 'm_static_complexity_td:[1 TO *]'
}
abstraction('Stack2') {
queryForClasses interfaceSpec // query for classes by interface specification
rows = 1
directly = true // without cursor functionality
excludeClassesByKeywords(['private', 'abstract'])
excludeTestClasses()
excludeInternalPkgs()
// optionally, we don't want it to be a collection
//excludeSuperClass("java.util.Collection", true)
// non empty classes, i.e having complexity > 1
filter 'm_static_complexity_td:[1 TO *]'
}
}
action(name: 'debug', type: 'Debug') {
dependsOn 'select'
includeAbstractions 'Stack1'
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'debug', 'Stack1', 1)
// does not contain the other FA
assert !lslExecutionContext.lassoContext.
actionContainerSpec.actions['debug'].abstractions.containsKey('Stack2')
}
/**
* <pre>
* includeImplementations {abName -> ...}
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_includeImplementations() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
// interface of a Stack in LQL notation
def interfaceSpec = """Stack {
push(java.lang.Object)->java.lang.Object
pop()->java.lang.Object
peek()->java.lang.Object
size()->int}"""
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select', type: 'Select') {
abstraction('Stack') {
queryForClasses interfaceSpec // query for classes by interface specification
rows = 10
directly = true // without cursor functionality
excludeClassesByKeywords(['private', 'abstract'])
excludeTestClasses()
excludeInternalPkgs()
// optionally, we don't want it to be a collection
//excludeSuperClass("java.util.Collection", true)
// non empty classes, i.e having complexity > 1
filter 'm_static_complexity_td:[1 TO *]'
}
}
action(name: 'debug', type: 'Debug') {
dependsOn 'select'
includeAbstractions 'Stack'
includeImplementations {abName -> // under test
// custom pick of single impl.
log("abstraction ${abName}")
log("actions ${actions.keySet()}")
abstractions[abName].implementations?.findAll { impl -> impl.id == '53ed531e-58bc-4520-8580-1e5c600cb28a'}
}
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'debug', 'Stack', 1)
// verify in-memory model of select action
AbstractionSpec abstractionSpec = lslExecutionContext.lassoContext.
actionContainerSpec.actions['debug'].abstractions['Stack']
assert abstractionSpec.implementations[0].id == '53ed531e-58bc-4520-8580-1e5c600cb28a'
}
/**
* Alternative, dynamic version to "static" configuration in the header of an action
*
* <pre>
* configure {...}
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_configure() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
// interface of a Stack in LQL notation
def interfaceSpec = """Stack {
push(java.lang.Object)->java.lang.Object
pop()->java.lang.Object
peek()->java.lang.Object
size()->int}"""
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select', type: 'Select') {
configure {
log('we do some dynamic execution block as part of configuration')
dataSource = 'mavenCentral2020'
}
abstraction('Stack') {
queryForClasses interfaceSpec // query for classes by interface specification
rows = 10
directly = true // without cursor functionality
excludeClassesByKeywords(['private', 'abstract'])
excludeTestClasses()
excludeInternalPkgs()
// optionally, we don't want it to be a collection
//excludeSuperClass("java.util.Collection", true)
// non empty classes, i.e having complexity > 1
filter 'm_static_complexity_td:[1 TO *]'
}
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'select', 'Stack', 10)
}
/**
* <pre>
* execute {...}
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_execute() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
// interface of a Stack in LQL notation
def interfaceSpec = """Stack {
push(java.lang.Object)->java.lang.Object
pop()->java.lang.Object
peek()->java.lang.Object
size()->int}"""
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select', type: 'Select') {
abstraction('Stack') {
queryForClasses interfaceSpec // query for classes by interface specification
rows = 10
directly = true // without cursor functionality
excludeClassesByKeywords(['private', 'abstract'])
excludeTestClasses()
excludeInternalPkgs()
// optionally, we don't want it to be a collection
//excludeSuperClass("java.util.Collection", true)
// non empty classes, i.e having complexity > 1
filter 'm_static_complexity_td:[1 TO *]'
}
}
action(name: 'debug', type: 'Debug') {
dependsOn 'select'
includeAbstractions 'Stack'
execute {
log('hello world')
int implsSize = abstractions['Stack'].implementations.size()
log("no of impls. ${implsSize}")
int actionSize = actions.size()
log("no of actions ${actionSize}")
}
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'debug', 'Stack', 10)
}
/**
* <pre>
* whenAbstractionsReady {...}
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_whenAbstractionsReady() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
// interface of a Stack in LQL notation
def interfaceSpec = """Stack {
push(java.lang.Object)->java.lang.Object
pop()->java.lang.Object
peek()->java.lang.Object
size()->int}"""
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select', type: 'Select') {
abstraction('Stack') {
queryForClasses interfaceSpec // query for classes by interface specification
rows = 10
directly = true // without cursor functionality
excludeClassesByKeywords(['private', 'abstract'])
excludeTestClasses()
excludeInternalPkgs()
// optionally, we don't want it to be a collection
//excludeSuperClass("java.util.Collection", true)
// non empty classes, i.e having complexity > 1
filter 'm_static_complexity_td:[1 TO *]'
}
whenAbstractionsReady {
// remove 5 implementations from the tail of the list
abstractions['Stack'].implementations = abstractions['Stack'].implementations.dropRight(5)
}
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'select', 'Stack', 5)
}
/**
* When no action type is specified, delegate to NoOp
*
* <pre>
* action(name:'myAction') {...}
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_plain_action_noop() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
// interface of a Stack in LQL notation
def interfaceSpec = """Stack {
push(java.lang.Object)->java.lang.Object
pop()->java.lang.Object
peek()->java.lang.Object
size()->int}"""
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select', type: 'Select') {
abstraction('Stack') {
queryForClasses interfaceSpec // query for classes by interface specification
rows = 10
directly = true // without cursor functionality
excludeClassesByKeywords(['private', 'abstract'])
excludeTestClasses()
excludeInternalPkgs()
// optionally, we don't want it to be a collection
//excludeSuperClass("java.util.Collection", true)
// non empty classes, i.e having complexity > 1
filter 'm_static_complexity_td:[1 TO *]'
}
}
action(name: 'myAction') { // plain action
dependsOn 'select'
includeAbstractions 'Stack'
execute {
log('hello world')
int implsSize = abstractions['Stack'].implementations.size()
log("no of impls. ${implsSize}")
int actionSize = actions.size()
log("no of actions ${actionSize}")
}
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'myAction', 'Stack', 10)
}
/**
* When no action type is specified, delegate to NoOp.
*
* Use case of merging abstractions into a new one.
*
* <pre>
* action(name:'myAction') {...}
* </pre>
*
* @throws IOException
* @throws DataSourceNotFoundException
*/
@Test
void test_plain_action_merge_new_abstraction() throws IOException, DataSourceNotFoundException {
@Language("Groovy")
String content = '''
dataSource 'mavenCentral2020' // define data source to use
/** Define a new study */
study(name: 'Select') {
/** Retrieve class implementations */
action(name: 'select1', type: 'Select') {
abstraction('Stack') {
queryForClasses 'Stack', 'concept'
rows = 10
directly = true // without cursor functionality
}
}
/** Retrieve class implementations */
action(name: 'select2', type: 'Select') {
abstraction('List') {
queryForClasses 'List', 'concept'
rows = 10
directly = true // without cursor functionality
}
}
action(name: 'merge') { // plain action
dependsOn 'select2'
includeAbstractions '*'
execute {
// merge two abstractions into new as DSL command
def merged = abstraction('Collection',
[
actions['select1'].abstractions['Stack'],
actions['select2'].abstractions['List']
]
)
log("abstraction ${merged.name} has ${merged.implementations.size()} implementations")
}
}
}
'''
//
LSLScript scriptUnderTest = createScript(content)
// DO EXECUTE
LSLExecutionResult lslExecutionResult = lassoEngine.execute(scriptUnderTest);
LSLExecutionContext lslExecutionContext = lassoEngine.getLastContext();
// assertions
verifyAbstraction(lslExecutionContext, 'merge', 'Collection', 20)
// others untouched
//verifyAbstraction(lslExecutionContext, 'merge', 'Stack', 10)
verifyAbstraction(lslExecutionContext, 'merge', 'List', 10)
}
}