-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMolComponentFactoryTest.class.st
More file actions
1511 lines (1159 loc) · 69.3 KB
/
MolComponentFactoryTest.class.st
File metadata and controls
1511 lines (1159 loc) · 69.3 KB
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"
A MolComponentFactoryTest is a test class for testing the behavior of MolComponentFactory
"
Class {
#name : #MolComponentFactoryTest,
#superclass : #TestCase,
#category : #'Molecule-Tests-Cases'
}
{ #category : #running }
MolComponentFactoryTest >> cleanGeneratedClassesAndTraits [
| edited |
edited := false.
self class environment at: self generatedComponentClassSymbolName ifPresent: [ :c | c removeFromSystem. edited := true].
self class environment at: self generatedComponentClass2SymbolName ifPresent: [ :c | c removeFromSystem. edited := true].
self class environment at: self generatedComponentTypeSymbolName ifPresent: [ :c | c removeFromSystem. edited := true].
self class environment at: self generatedComponentServicesSymbolName ifPresent: [ :c | c removeFromSystem. edited := true].
self class environment at: self generatedComponentParametersSymbolName ifPresent: [ :c | c removeFromSystem. edited := true].
self class environment at: self generatedComponentEventsSymbolName ifPresent: [ :c | c removeFromSystem. edited := true].
(MolCompleteComponent usedComponentServices includes: MolUsedServices) ifFalse:[
MolComponentFactory addUsedServices: MolUsedServices in: MolCompleteComponent.
edited := true.
].
edited ifTrue:[(Delay forMilliseconds: 100) wait].
]
{ #category : #running }
MolComponentFactoryTest >> cleanGeneratedMethods [
"Restore methods added by tests"
MolCompleteSubComponentOverloadImpl class removeSelector: #usedComponentServices.
MolCompleteSubComponentOverloadImpl class removeSelector: #providedComponentServices
]
{ #category : #utilities }
MolComponentFactoryTest >> createInstanceMethod: aSelector in: aClassOrTrait protocol: aProtocolString withCode: aSourceCodeString [
"Create an instance method in a Class or Trait with source code implementation"
| sourceCode |
sourceCode := WriteStream on: String new.
sourceCode nextPutAll: aSelector.
aSourceCodeString ifNotNil:[
sourceCode crtab: 1.
sourceCode nextPutAll: aSourceCodeString
].
"Compile"
aClassOrTrait compile: sourceCode contents classified: aProtocolString.
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentClass [
^self class environment at: self generatedComponentClassSymbolName
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentClass2 [
^self class environment at: self generatedComponentClass2SymbolName
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentClass2SymbolName [
^ #MolTestGeneratedComponentImpl
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentClassSymbolName [
^ #MolCompleteComponentTestImpl
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentEventsSymbolName [
^ #MolTestGeneratedComponentEvents
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentEventsTrait [
^self class environment at: self generatedComponentEventsSymbolName
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentParametersSymbolName [
^ #MolTestGeneratedComponentParameters
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentParametersTrait [
^self class environment at: self generatedComponentParametersSymbolName
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentServicesSymbolName [
^ #MolTestGeneratedComponentServices
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentServicesTrait [
^self class environment at: self generatedComponentServicesSymbolName
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentTypeSymbolName [
^ #MolTestGeneratedComponentType
]
{ #category : #accessing }
MolComponentFactoryTest >> generatedComponentTypeTrait [
^self class environment at: self generatedComponentTypeSymbolName
]
{ #category : #accessing }
MolComponentFactoryTest >> generationTag [
^'Molecule-Tests-Resources - Generated'
]
{ #category : #utilities }
MolComponentFactoryTest >> resetSourceCode [
<script:'self new resetSourceCode'>
MolComponentFactory default deactivateDynamicContractUpdate: false.
self cleanGeneratedClassesAndTraits.
self restoreRemovedThings.
self cleanGeneratedMethods.
MolComponentFactory default activateDynamicContractUpdate: false.
"Issue #230: Define the component manually after source code modification without dynamic update"
MolCompleteComponentOverloadImpl defineComponent.
]
{ #category : #running }
MolComponentFactoryTest >> restoreRemovedThings [
"Restore things removed in tests"
"Simulate an overridden contract by the user VV"
self createInstanceMethod: 'usedComponentServices' in: (MolCompleteComponentOverloadImpl class) protocol: 'accessing - services' withCode: '"Warning: dont edit this method, it is generated in MolComponentFactoryTest>>restoreRemovedThings"
<componentContract>
^ {
MolUsedServices.
MolUsedServices2 }'.
self createInstanceMethod: 'providedComponentServices' in: (MolCompleteComponentOverloadImpl class) protocol: 'accessing - services' withCode: '"Warning: dont edit this method, it is generated in MolComponentFactoryTest>>restoreRemovedThings"
<componentContract>
^ {
MolUsedServices.
MolUsedServices2 }'.
self createInstanceMethod: 'usedComponentParameters' in: (MolCompleteComponentOverloadImpl class) protocol: 'accessing - parameters' withCode: '"Warning: dont edit this method, it is generated in MolComponentFactoryTest>>restoreRemovedThings"
<componentContract>
^ {
MolUsedParameters.
MolUsedParameters2 }'.
self createInstanceMethod: 'providedComponentParameters' in: (MolCompleteComponentOverloadImpl class) protocol: 'accessing - parameters' withCode: '"Warning: dont edit this method, it is generated in MolComponentFactoryTest>>restoreRemovedThings"
<componentContract>
^ {
MolUsedParameters.
MolUsedParameters2 }'.
self createInstanceMethod: 'consumedComponentEvents' in: (MolCompleteComponentOverloadImpl class) protocol: 'accessing - events' withCode: '"Warning: dont edit this method, it is generated in MolComponentFactoryTest>>restoreRemovedThings"
<componentContract>
^ {
MolUsedEvents.
MolUsedEvents2 }'.
self createInstanceMethod: 'producedComponentEvents' in: (MolCompleteComponentOverloadImpl class) protocol: 'accessing - events' withCode: '"Warning: dont edit this method, it is generated in MolComponentFactoryTest>>restoreRemovedThings"
<componentContract>
^ {
MolUsedEvents.
MolUsedEvents2 }'.
]
{ #category : #running }
MolComponentFactoryTest >> setUp [
super setUp.
self timeLimit: 30 seconds.
MolComponentManager cleanUp.
self resetSourceCode
]
{ #category : #running }
MolComponentFactoryTest >> tearDown [
self resetSourceCode.
MolComponentManager cleanUp.
super tearDown.
]
{ #category : #tests }
MolComponentFactoryTest >> testCollectComponentConnectionTraits [
| traits |
traits := MolComponentFactory default collectComponentConnectionTraits: nil.
self assert: traits isEmpty.
traits := MolComponentFactory default collectComponentConnectionTraits: MolTestComponentImplA.
self assert: traits isEmpty.
traits := MolComponentFactory default collectComponentConnectionTraits: MolTestComponentImplA new.
self assert: traits isEmpty.
traits := MolComponentFactory default collectComponentConnectionTraits: MolCompleteComponentImpl.
self assert: traits size equals: 3.
self assert: (traits includes: MolUsedServices).
self assert: (traits includes: MolUsedEvents).
self assert: (traits includes: MolUsedParameters).
traits := MolComponentFactory default collectComponentConnectionTraits: MolCompleteComponentImpl new.
self assert: traits size equals: 3.
self assert: (traits includes: MolUsedServices).
self assert: (traits includes: MolUsedEvents).
self assert: (traits includes: MolUsedParameters).
]
{ #category : #tests }
MolComponentFactoryTest >> testCollectComponentConnectionTraitsOrder [
"This test check the order of the traits collect: events, services and parameters. This is necessary to control the order to not change generated code in existing components"
| traits |
"Test with an abstract component subclass"
traits := MolComponentFactory default collectComponentConnectionTraits: MolCompleteComponentImpl.
self assert: traits size equals: 3.
self assert: (traits first) equals: MolUsedEvents.
self assert: (traits at: 2) equals: MolUsedServices.
self assert: (traits at: 3) equals: MolUsedParameters.
"Test with an augmented class as a component"
traits := MolComponentFactory default collectComponentConnectionTraits: MolAugmentedClassToAComponent.
self assert: traits size equals: 3.
self assert: (traits first) equals: MolUsedEvents.
self assert: (traits at: 2) equals: MolUsedServices.
self assert: (traits at: 3) equals: MolUsedParameters.
100 milliSeconds wait. "See issue #230, try to wait for removing previous test things"
"Test with an overloaded component class"
traits := MolComponentFactory default collectComponentConnectionTraits: MolCompleteComponentOverloadImpl.
self assert: traits size equals: 6.
self assert: (traits first) equals: MolUsedEvents.
self assert: (traits at: 2) equals: MolUsedEvents2.
self assert: (traits at: 3) equals: MolUsedServices.
self assert: (traits at: 4) equals: MolUsedServices2.
self assert: (traits at: 5) equals: MolUsedParameters.
self assert: (traits at: 6) equals: MolUsedParameters2.
]
{ #category : #tests }
MolComponentFactoryTest >> testComponentChangedOnComponentCreationWithoutType [
"Create a class, edit this class from different ways and check if the factory define the component or not"
| isDynamicContractUpdateActivated |
self assert: MolComponentFactory default dirtyComponents isEmpty.
"For testing deactive the dynamic contract update, store the previous setting for restore it at the end of the test"
isDynamicContractUpdateActivated := MolComponentFactory default isDynamicContractUpdateActivated.
MolComponentFactory default deactivateDynamicContractUpdate: false.
"remove the testing class, and create a new component without Type, when the type is added check if the component in on the dirty components list"
MolComponentFactory createComponentNamed: self generatedComponentClassSymbolName in: self generationTag.
"Waiting for event callback"
self assert: (MolComponentFactory default dirtyComponents includes: (self generatedComponentClass)).
MolComponentFactory default dirtyComponents removeAll.
"add the type manually to the created component"
self generatedComponentClass setTraitComposition: MolCompleteComponent.
"Waiting for event callback"
self assert: (MolComponentFactory default dirtyComponents includes: (self generatedComponentClass)).
MolComponentFactory default dirtyComponents removeAll.
"remove the testing class, and create a new component with Type, check if the component in on the dirty components list"
(self class environment at: self generatedComponentClassSymbolName) removeFromSystem.
MolComponentFactory createComponentForType: MolCompleteComponent named: self generatedComponentClassSymbolName in: self generationTag.
"Waiting for event callback"
self assert: (MolComponentFactory default dirtyComponents includes: (self generatedComponentClass)).
MolComponentFactory default dirtyComponents removeAll.
isDynamicContractUpdateActivated
ifTrue:[MolComponentFactory default activateDynamicContractUpdate: false]
ifFalse:[MolComponentFactory default deactivateDynamicContractUpdate: false].
]
{ #category : #tests }
MolComponentFactoryTest >> testComponentContractChanged [
"Create a class, edit this class from different ways and check if the factory define the component or not"
| isDynamicContractUpdateActivated methodName source |
self assert: MolComponentFactory default dirtyComponentTypes isEmpty.
"For testing deactive the dynamic contract update, store the previous setting for restore it at the end of the test"
isDynamicContractUpdateActivated := MolComponentFactory default isDynamicContractUpdateActivated.
MolComponentFactory default deactivateDynamicContractUpdate: false.
"Add manually a new used services in the MolCompleteComponent Type"
methodName := 'usedComponentServices'.
source := String streamContents: [ :s |
s nextPutAll: methodName.
s nextPut: Character cr.
s nextPutAll: '<componentContract>'.
s nextPut: Character cr.
s nextPutAll: '^{ }'.
].
MolCompleteComponent class compile: source.
self assert: (MolComponentFactory default dirtyComponentTypes includes: MolCompleteComponent).
MolComponentFactory default dirtyComponentTypes removeAll.
isDynamicContractUpdateActivated
ifTrue:[MolComponentFactory default activateDynamicContractUpdate: false]
ifFalse:[MolComponentFactory default deactivateDynamicContractUpdate: false].
]
{ #category : #'test - overload' }
MolComponentFactoryTest >> testComponentContractImplGeneration [
| toFind |
MolCompleteComponentOverloadImpl defineComponent.
toFind := { #getMolUsedEventsNotifier. #getMolUsedParametersProvider.
#getMolUsedServicesProvider. #getMolUsedEventsSubscriber.
#getMolUsedEventsSubscriber. #getMolUsedEvents2Notifier.
#getMolUsedParameters2Provider.
#getMolUsedServices2Provider }.
toFind := toFind reject: [ :e |
MolCompleteComponentOverloadImpl allSelectors includes: e ].
self assert: toFind isEmpty
]
{ #category : #tests }
MolComponentFactoryTest >> testComponentFactoryDefaultClass [
MolComponentFactory cleanUp.
self assert: MolComponentFactory default class equals: MolComponentFactory.
self assert: MolComponentFactory default isDynamicContractUpdateActivated.
self assert: MolComponentFactory default dirtyComponentTypes isEmpty.
self assert: MolComponentFactory default dirtyComponents isEmpty.
MolComponentFactory cleanUp.
]
{ #category : #'test - component subclasses' }
MolComponentFactoryTest >> testComponentSubclassesTraitsUses [
"Test if the traits declaration are correctly injected into a component class hierarchy
We have 3 components : A, B and C which inherits one another.
- Set a ComponentType (with an empty contract) to the ComponentA
- Adding Services, Events and Parameters in the Type and check if ComponentTraits are not propagated to B and C by the dynamic contract processing.
- Add a TraitA in the Component A, check if it only on A
- Add a TraitB in the Component B, check if it only on B
- Add a TraitC in the Component C, check if it only on C
"
| type |
self assert: MolComponentFactory default isDynamicContractUpdateActivated.
MolTestComponentImplA setTraitComposition: #().
MolTestComponentImplB setTraitComposition: #().
MolTestComponentImplC setTraitComposition: #().
self testCreateComponentType.
type := self generatedComponentTypeTrait.
MolTestComponentImplA setTraitComposition: type.
self testCreateComponentServices.
self testCreateComponentParameters.
self testCreateComponentEvents.
MolComponentFactory addProvidedServices: self generatedComponentServicesTrait in: type.
MolComponentFactory addUsedServices: self generatedComponentServicesTrait in: type.
MolComponentFactory addProvidedParameters: self generatedComponentParametersTrait in: type.
MolComponentFactory addUsedParameters: self generatedComponentParametersTrait in: type.
MolComponentFactory addProducedEvents: self generatedComponentEventsTrait in: type.
MolComponentFactory addConsumedEvents: self generatedComponentEventsTrait in: type.
"Check Trait composition of A, B and C"
self assert: MolTestComponentImplA traitComposition traits size equals: 4.
self assert: MolTestComponentImplB traitComposition isEmpty.
self assert: MolTestComponentImplC traitComposition isEmpty.
"Adding traits"
MolTestComponentImplA addToComposition: MolTestNoComponentTraitA.
MolTestComponentImplB setTraitComposition: MolTestNoComponentTraitB.
MolTestComponentImplC setTraitComposition: MolTestNoComponentTraitC.
"Check Trait composition of A, B and C"
self assert: MolTestComponentImplA traitComposition traits size equals: 5.
self assert: MolTestComponentImplB traitComposition traits size equals: 1.
self assert: MolTestComponentImplC traitComposition traits size equals: 1.
"Remove the type and check if the each no components traits are already here"
MolTestComponentImplA removeFromComposition: type.
"Check Trait composition of A, B and C"
self assert: MolTestComponentImplA traitComposition traits size equals: 1.
self assert: MolTestComponentImplB traitComposition traits size equals: 1.
self assert: MolTestComponentImplC traitComposition traits size equals: 1.
MolTestComponentImplA setTraitComposition: #().
MolTestComponentImplB setTraitComposition: #().
MolTestComponentImplC setTraitComposition: #().
]
{ #category : #'test - component subclasses' }
MolComponentFactoryTest >> testComponentSubclassesTraitsUses2 [
| type |
MolTestComponentImplA setTraitComposition: #().
self testCreateComponentType.
type := self generatedComponentTypeTrait.
MolTestComponentImplA setTraitComposition: type.
self testCreateComponentServices.
self testCreateComponentParameters.
self testCreateComponentEvents.
MolComponentFactory addProvidedServices: self generatedComponentServicesTrait in: type.
self assert: MolTestComponentImplA traitComposition traits size equals: 2.
]
{ #category : #'tests - component creation' }
MolComponentFactoryTest >> testCreateComponentClassWithType [
"Create a Component from scratch with a Type"
| class |
"delete generated class if presents"
self class environment at: self generatedComponentClassSymbolName ifPresent: [
(self class environment at: self generatedComponentClassSymbolName) removeFromSystem
].
MolComponentFactory createComponentForType: MolCompleteComponent named: self generatedComponentClassSymbolName in: self generationTag.
class := self class environment at: self generatedComponentClassSymbolName.
self assert: class notNil.
self assert: class isComponentClass.
self assert: class haveComponentType.
class comment: 'I am added and removed by test: ', self printString.
]
{ #category : #'tests - component creation' }
MolComponentFactoryTest >> testCreateComponentClassWithoutType [
"Create a Component from scratch without Type"
| class |
"delete generated class if presents"
self class environment at: self generatedComponentClassSymbolName ifPresent: [
(self class environment at: self generatedComponentClassSymbolName) removeFromSystem.
].
MolComponentFactory createComponentNamed: self generatedComponentClassSymbolName in: self generationTag.
class := self class environment at: self generatedComponentClassSymbolName.
self assert: class notNil.
self assert: class isComponentClass.
self assert: class haveComponentType equals: false.
class comment: 'I am added and removed by test: ', self printString.
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateComponentCompleteContract [
"Create a Component Type from scratch with services, events and parameters"
self testCreateComponentType.
self testCreateComponentServices.
self testCreateComponentParameters.
self testCreateComponentEvents.
"Initial Local Check"
self assert: (self generatedComponentTypeTrait providedComponentServices includes: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait usedComponentServices includes: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait providedComponentParameters includes: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait usedComponentParameters includes: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait producedComponentEvents includes: self generatedComponentEventsTrait) equals: false.
self assert: (self generatedComponentTypeTrait consumedComponentEvents includes: self generatedComponentEventsTrait) equals: false.
"Initial Global Check (inheritance)"
self assert: (self generatedComponentTypeTrait isProvideServices: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait isUseServices: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait isProvideParameters: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait isUseParameters: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait isProduceEvents: self generatedComponentEventsTrait) equals: false.
self assert: (self generatedComponentTypeTrait isConsumeEvents: self generatedComponentEventsTrait) equals: false.
"Declare provide services"
self assert: (self generatedComponentTypeTrait allProvidedServices includes: self generatedComponentServicesTrait) equals: false.
MolComponentFactory addProvidedServices: self generatedComponentServicesTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait providedComponentServices includes: self generatedComponentServicesTrait) equals: true.
"Declare use services"
self assert: (self generatedComponentTypeTrait allUsedServices includes: self generatedComponentServicesTrait) equals: false.
MolComponentFactory addUsedServices: self generatedComponentServicesTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait usedComponentServices includes: self generatedComponentServicesTrait) equals: true.
"Declare provide parameters"
self assert: (self generatedComponentTypeTrait allProvidedParameters includes: self generatedComponentParametersTrait) equals: false.
MolComponentFactory addProvidedParameters: self generatedComponentParametersTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait providedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
"Declare use parameters"
self assert: (self generatedComponentTypeTrait allUsedParameters includes: self generatedComponentParametersTrait) equals: false.
MolComponentFactory addUsedParameters: self generatedComponentParametersTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait usedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
"Declare produce events"
self assert: (self generatedComponentTypeTrait allProducedEvents includes: self generatedComponentEventsTrait) equals: false.
MolComponentFactory addProducedEvents: self generatedComponentEventsTrait in: self generatedComponentTypeTrait.
self assert: (self generatedComponentTypeTrait producedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
"Declare consume events"
self assert: (self generatedComponentTypeTrait allConsumedEvents includes: self generatedComponentEventsTrait) equals: false.
MolComponentFactory addConsumedEvents: self generatedComponentEventsTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait consumedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
"Final Local Check"
self assert: (self generatedComponentTypeTrait providedComponentServices includes: self generatedComponentServicesTrait) equals: true.
self assert: (self generatedComponentTypeTrait usedComponentServices includes: self generatedComponentServicesTrait) equals: true.
self assert: (self generatedComponentTypeTrait providedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
self assert: (self generatedComponentTypeTrait usedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
self assert: (self generatedComponentTypeTrait producedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
self assert: (self generatedComponentTypeTrait consumedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
"Final Global Check (inheritance)"
self assert: (self generatedComponentTypeTrait isProvideServices: self generatedComponentServicesTrait).
self assert: (self generatedComponentTypeTrait isUseServices: self generatedComponentServicesTrait).
self assert: (self generatedComponentTypeTrait isProvideParameters: self generatedComponentParametersTrait).
self assert: (self generatedComponentTypeTrait isUseParameters: self generatedComponentParametersTrait).
self assert: (self generatedComponentTypeTrait isProduceEvents: self generatedComponentEventsTrait).
self assert: (self generatedComponentTypeTrait isConsumeEvents: self generatedComponentEventsTrait).
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateComponentCompleteContractWithoutAPI [
"Create a Component Type from scratch with services, events and parameters but without API"
self testCreateComponentType.
self testCreateEmptyComponentServices.
self testCreateEmptyComponentParameters.
self testCreateEmptyComponentEvents.
"Initial Local Check"
self assert: (self generatedComponentTypeTrait providedComponentServices includes: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait usedComponentServices includes: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait providedComponentParameters includes: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait usedComponentParameters includes: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait producedComponentEvents includes: self generatedComponentEventsTrait) equals: false.
self assert: (self generatedComponentTypeTrait consumedComponentEvents includes: self generatedComponentEventsTrait) equals: false.
"Initial Global Check (inheritance)"
self assert: (self generatedComponentTypeTrait isProvideServices: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait isUseServices: self generatedComponentServicesTrait) equals: false.
self assert: (self generatedComponentTypeTrait isProvideParameters: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait isUseParameters: self generatedComponentParametersTrait) equals: false.
self assert: (self generatedComponentTypeTrait isProduceEvents: self generatedComponentEventsTrait) equals: false.
self assert: (self generatedComponentTypeTrait isConsumeEvents: self generatedComponentEventsTrait) equals: false.
"Declare provide services"
self assert: (self generatedComponentTypeTrait allProvidedServices includes: self generatedComponentServicesTrait) equals: false.
MolComponentFactory addProvidedServices: self generatedComponentServicesTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait providedComponentServices includes: self generatedComponentServicesTrait) equals: true.
"Declare use services"
self assert: (self generatedComponentTypeTrait allUsedServices includes: self generatedComponentServicesTrait) equals: false.
MolComponentFactory addUsedServices: self generatedComponentServicesTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait usedComponentServices includes: self generatedComponentServicesTrait) equals: true.
"Declare provide parameters"
self assert: (self generatedComponentTypeTrait allProvidedParameters includes: self generatedComponentParametersTrait) equals: false.
MolComponentFactory addProvidedParameters: self generatedComponentParametersTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait providedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
"Declare use parameters"
self assert: (self generatedComponentTypeTrait allUsedParameters includes: self generatedComponentParametersTrait) equals: false.
MolComponentFactory addUsedParameters: self generatedComponentParametersTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait usedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
"Declare produce events"
self assert: (self generatedComponentTypeTrait allProducedEvents includes: self generatedComponentEventsTrait) equals: false.
MolComponentFactory addProducedEvents: self generatedComponentEventsTrait in: self generatedComponentTypeTrait.
self assert: (self generatedComponentTypeTrait producedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
"Declare consume events"
self assert: (self generatedComponentTypeTrait allConsumedEvents includes: self generatedComponentEventsTrait) equals: false.
MolComponentFactory addConsumedEvents: self generatedComponentEventsTrait in: self generatedComponentTypeTrait.
"Local check"
self assert: (self generatedComponentTypeTrait consumedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
"Final Local Check"
self assert: (self generatedComponentTypeTrait providedComponentServices includes: self generatedComponentServicesTrait) equals: true.
self assert: (self generatedComponentTypeTrait usedComponentServices includes: self generatedComponentServicesTrait) equals: true.
self assert: (self generatedComponentTypeTrait providedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
self assert: (self generatedComponentTypeTrait usedComponentParameters includes: self generatedComponentParametersTrait) equals: true.
self assert: (self generatedComponentTypeTrait producedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
self assert: (self generatedComponentTypeTrait consumedComponentEvents includes: self generatedComponentEventsTrait) equals: true.
"Final Global Check (inheritance)"
self assert: (self generatedComponentTypeTrait isProvideServices: self generatedComponentServicesTrait).
self assert: (self generatedComponentTypeTrait isUseServices: self generatedComponentServicesTrait).
self assert: (self generatedComponentTypeTrait isProvideParameters: self generatedComponentParametersTrait).
self assert: (self generatedComponentTypeTrait isUseParameters: self generatedComponentParametersTrait).
self assert: (self generatedComponentTypeTrait isProduceEvents: self generatedComponentEventsTrait).
self assert: (self generatedComponentTypeTrait isConsumeEvents: self generatedComponentEventsTrait).
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateComponentEvents [
"Create a Component Events from scratch"
self testCreateEmptyComponentEvents.
self createInstanceMethod: 'testGeneratedEventA' in: self generatedComponentEventsTrait protocol: 'events' withCode: nil.
self createInstanceMethod: 'testGeneratedEventB' in: self generatedComponentEventsTrait protocol: 'events' withCode: nil.
]
{ #category : #'tests - component creation' }
MolComponentFactoryTest >> testCreateComponentForTypeNamedIn [
"Test errors cases"
| error |
error := false.
[MolComponentFactory createComponentForType: nil named: nil in: nil] on: Error do:[ error := true ].
self assert: error equals: true.
error := false.
[MolComponentFactory createComponentForType: String named: #ClassName in: #packageName] on: NotAComponentTypeError do:[ error := true ].
self assert: error equals: true.
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateComponentParameters [
"Create a Component Parameters from scratch"
self testCreateEmptyComponentParameters.
self createInstanceMethod: 'testGeneratedParameterA' in: self generatedComponentParametersTrait protocol: 'parameters' withCode: nil.
self createInstanceMethod: 'testGeneratedParameterB' in: self generatedComponentParametersTrait protocol: 'parameters' withCode: nil.
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateComponentServices [
"Create a Component Services from scratch"
self testCreateEmptyComponentServices.
self createInstanceMethod: 'testGeneratedServiceA' in: self generatedComponentServicesTrait protocol: 'services' withCode: nil.
self createInstanceMethod: 'testGeneratedServiceB' in: self generatedComponentServicesTrait protocol: 'services' withCode: nil.
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateComponentType [
"Create a Component Type from scratch"
"Delete Generated Component Type if presents"
| trait |
self class environment at: self generatedComponentTypeSymbolName ifPresent: [
(self class environment at: self generatedComponentTypeSymbolName) removeFromSystem.
].
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
trait := self class environment at: self generatedComponentTypeSymbolName.
self assert: trait notNil.
self assert: trait isTrait.
self assert: trait isComponentType.
self assert: trait isComponentServices equals: false.
self assert: trait isComponentEvents equals: false.
self assert: trait isComponentParameters equals: false.
trait comment: 'I am added and removed by test: ', self printString.
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateEmptyComponentEvents [
"Create a Component Events from scratch"
"Delete Generated Component Events if presents"
| trait |
self class environment at: self generatedComponentEventsSymbolName ifPresent: [
(self class environment at: self generatedComponentEventsSymbolName) removeFromSystem.
].
MolComponentFactory createComponentEvents: self generatedComponentEventsSymbolName in: self generationTag.
trait := self class environment at: self generatedComponentEventsSymbolName.
self assert: trait notNil.
self assert: trait isTrait.
self assert: trait isComponentType equals: false.
self assert: trait isComponentServices equals: false.
self assert: trait isComponentEvents.
self assert: trait isComponentParameters equals: false.
trait comment: 'I am added and removed by test: ', self printString.
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateEmptyComponentParameters [
"Create a Component Parameters from scratch"
"Delete Generated Component Parameters if presents"
| trait |
self class environment at: self generatedComponentParametersSymbolName ifPresent: [
(self class environment at: self generatedComponentParametersSymbolName) removeFromSystem.
].
MolComponentFactory createComponentParameters: self generatedComponentParametersSymbolName in: self generationTag.
trait := self class environment at: self generatedComponentParametersSymbolName.
self assert: trait notNil.
self assert: trait isTrait.
self assert: trait isComponentType equals: false.
self assert: trait isComponentServices equals: false.
self assert: trait isComponentEvents equals: false.
self assert: trait isComponentParameters.
trait comment: 'I am added and removed by test: ', self printString.
]
{ #category : #'tests - contract creation' }
MolComponentFactoryTest >> testCreateEmptyComponentServices [
"Create a Component Services from scratch"
"Delete Generated Component Services if presents"
| trait |
self class environment at: self generatedComponentServicesSymbolName ifPresent: [
(self class environment at: self generatedComponentServicesSymbolName) removeFromSystem.
].
MolComponentFactory createComponentServices: self generatedComponentServicesSymbolName in: self generationTag.
trait := self class environment at: self generatedComponentServicesSymbolName.
self assert: trait notNil.
self assert: trait isTrait.
self assert: trait isComponentType equals: false.
self assert: trait isComponentServices.
self assert: trait isComponentEvents equals: false.
self assert: trait isComponentParameters equals: false.
trait comment: 'I am added and removed by test: ', self printString.
]
{ #category : #tests }
MolComponentFactoryTest >> testCreateSourceCodeContractSelector [
| interfaces sourceCode toBeGenerated |
self testCreateComponentType.
interfaces := self generatedComponentTypeTrait consumedComponentEvents asOrderedCollection.
interfaces add: #MolTestGeneratedComponentEvents.
sourceCode := MolComponentFactory
createSourceCodeContractSelector: 'consumedComponentEvents'
protocol: MolComponentFactory protocolForComponentEvents
interfaces: interfaces
type: self generatedComponentTypeTrait.
toBeGenerated := 'consumedComponentEvents
<componentContract>
^ { #MolTestGeneratedComponentEvents }'.
self assert: sourceCode contents equals: toBeGenerated.
]
{ #category : #tests }
MolComponentFactoryTest >> testCreateSourceCodeContractSelector2 [
"Test with multiple interfaces"
| interfaces sourceCode toBeGenerated |
self testCreateComponentType.
interfaces := self generatedComponentTypeTrait consumedComponentEvents asOrderedCollection.
interfaces add: #MolTestGeneratedComponentEvents.
interfaces add: #MolUsedEvents.
interfaces add: #MolUsedChildEvents.
sourceCode := MolComponentFactory
createSourceCodeContractSelector: 'consumedComponentEvents'
protocol: MolComponentFactory protocolForComponentEvents
interfaces: interfaces
type: self generatedComponentTypeTrait.
toBeGenerated := 'consumedComponentEvents
<componentContract>
^ { #MolTestGeneratedComponentEvents . #MolUsedEvents . #MolUsedChildEvents }'.
self assert: sourceCode contents equals: toBeGenerated.
]
{ #category : #tests }
MolComponentFactoryTest >> testCreateSourceCodeContractSelector3 [
"Test without interfaces"
| interfaces sourceCode toBeGenerated |
self testCreateComponentType.
interfaces := {}.
sourceCode := MolComponentFactory
createSourceCodeContractSelector: 'consumedComponentEvents'
protocol: MolComponentFactory protocolForComponentEvents
interfaces: interfaces
type: self generatedComponentTypeTrait.
toBeGenerated := 'consumedComponentEvents
<componentContract>
^ {}'.
self assert: sourceCode contents equals: toBeGenerated.
]
{ #category : #tests }
MolComponentFactoryTest >> testDefineAllComponents [
MolComponentFactory defineAllComponents.
]
{ #category : #tests }
MolComponentFactoryTest >> testDefineComponent [
"The Factory can define only Component Classes"
MolComponentFactory defineComponent: nil.
MolComponentFactory defineComponent: Boolean.
MolComponentFactory defineComponent: MolCompleteComponentImpl new.
MolComponentFactory defineComponent: MolCompleteComponentImpl.
MolComponentFactory defineComponent: MolCompleteComponent.
]
{ #category : #tests }
MolComponentFactoryTest >> testDefineComponentTypeImplementors [
MolComponentFactory default defineComponentTypeImplementors: nil.
MolComponentFactory default defineComponentTypeImplementors: Boolean.
MolComponentFactory default defineComponentTypeImplementors: MolCompleteComponentImpl new.
MolComponentFactory default defineComponentTypeImplementors: MolCompleteComponentImpl.
MolComponentFactory default defineComponentTypeImplementors: MolCompleteComponent.
]
{ #category : #tests }
MolComponentFactoryTest >> testDefineDirtyComponents [
self assert: MolComponentFactory default dirtyComponentTypes isEmpty.
"Add a dirty component type manually"
MolComponentFactory default dirtyComponentTypes add: MolMyClientComponent.
MolComponentFactory default dirtyComponents add: MolMyClientComponentImpl.
self assert: MolComponentFactory default dirtyComponentTypes notEmpty.
self assert: MolComponentFactory default dirtyComponents notEmpty.
MolComponentFactory defineDirtyComponents.
self assert: MolComponentFactory default dirtyComponentTypes isEmpty.
self assert: MolComponentFactory default dirtyComponents isEmpty.
]
{ #category : #tests }
MolComponentFactoryTest >> testDynamicContractUpdateActivation [
self assert: MolComponentFactory default isDynamicContractUpdateActivated equals: true.
MolComponentFactory default isDynamicContractUpdateActivated: false.
self assert: MolComponentFactory default isDynamicContractUpdateActivated equals: false.
MolComponentFactory default isDynamicContractUpdateActivated: true.
self assert: MolComponentFactory default isDynamicContractUpdateActivated equals: true.
]
{ #category : #tests }
MolComponentFactoryTest >> testDynamicContractUpdateActivation2 [
self assert: MolComponentFactory default isDynamicContractUpdateActivated equals: true.
MolComponentFactory default deactivateDynamicContractUpdate: false.
self assert: MolComponentFactory default isDynamicContractUpdateActivated equals: false.
MolComponentFactory default activateDynamicContractUpdate: false.
self assert: MolComponentFactory default isDynamicContractUpdateActivated equals: true.
]
{ #category : #'tests - code generation' }
MolComponentFactoryTest >> testGenerateConsumedEventComponentAccessorsFor [
MolCompleteComponentImpl removeSelector: #getMolUsedEventsSubscriber.
MolComponentFactory default removeOldConsumedEventsComponentAccessorsFor: MolCompleteComponentImpl.
MolComponentFactory default generateConsumedEventsComponentAccessorsFor: MolCompleteComponentImpl.
self assert: (MolCompleteComponentImpl selectors includes: #getMolUsedEventsSubscriber).
]
{ #category : #'tests - code generation' }
MolComponentFactoryTest >> testGenerateProducedEventComponentAccessorsFor [
MolCompleteComponentImpl removeSelector: #getMolUsedEventsNotifier.
MolComponentFactory default removeOldProducedEventsComponentAccessorsFor: MolCompleteComponentImpl.
MolComponentFactory default generateProducedEventsComponentAccessorsFor: MolCompleteComponentImpl.
self assert: (MolCompleteComponentImpl selectors includes: #getMolUsedEventsNotifier).
]
{ #category : #'tests - code generation' }
MolComponentFactoryTest >> testGenerateUsedParametersComponentAccessorsFor [
MolCompleteComponentImpl removeSelector: #getMolUsedParametersProvider.
MolComponentFactory default removeOldUsedParametersAndServicesComponentAccessorsFor: MolCompleteComponentImpl.
MolComponentFactory default generateUsedParametersComponentAccessorsFor: MolCompleteComponentImpl.
self assert: (MolCompleteComponentImpl selectors includes: #getMolUsedParametersProvider).
]
{ #category : #'tests - code generation' }
MolComponentFactoryTest >> testGenerateUsedServicesComponentAccessorsFor [
MolCompleteComponentImpl removeSelector: #getMolUsedServicesProvider.
MolComponentFactory default removeOldUsedParametersAndServicesComponentAccessorsFor: MolCompleteComponentImpl.
MolComponentFactory default generateUsedServicesComponentAccessorsFor: MolCompleteComponentImpl.
self assert: (MolCompleteComponentImpl selectors includes: #getMolUsedServicesProvider).
]
{ #category : #'tests - component creation' }
MolComponentFactoryTest >> testMakeAComponentAndAddATrait [
"Create a Component, adding a trait and adding a component type
- Create a component Class
- Add a Trait
- Declare Component Type
"
| class componentClassNameSymbol |
self assert: MolComponentFactory default isDynamicContractUpdateActivated.
componentClassNameSymbol := self generatedComponentClass2SymbolName.
class := MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationTag.
class := self class environment at: componentClassNameSymbol.
class comment: 'I am added and removed by test: ', self printString.
"Set an existing Trait, outside Component system"
class setTraitComposition: MolTestNoComponentTraitA.
self assert: (class canPerform: #methodOfNoComponentTrait).
"Set the component type and check if the existing Trait is already functionnal"
MolComponentFactory createComponentType: self generatedComponentTypeSymbolName in: self generationTag.
class addToComposition: self generatedComponentTypeTrait.
self assert: (class canPerform: #methodOfNoComponentTrait).
]
{ #category : #'tests - component creation' }
MolComponentFactoryTest >> testMakeAComponentAndAddATraitWithCompleteContract [
"Create a Component from scratch and adding a trait
- Create a component Class
- Create a Component Type
- Declare Component Type
- Make Component Contract
- Add a Trait"
| componentClassNameSymbol componentClass |
self assert: MolComponentFactory default isDynamicContractUpdateActivated.
componentClassNameSymbol := self generatedComponentClass2SymbolName.
MolComponentFactory createComponentNamed: componentClassNameSymbol in: self generationTag.
componentClass := self class environment at: componentClassNameSymbol.