-
Notifications
You must be signed in to change notification settings - Fork 4
/
XmlCompilerTest.hx
1216 lines (956 loc) · 48.2 KB
/
XmlCompilerTest.hx
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
package hex.compiler.parser.xml;
import haxe.Timer;
import hex.collection.HashMap;
import hex.core.IApplicationAssembler;
import hex.core.ICoreFactory;
import hex.di.Injector;
import hex.di.mapping.MappingConfiguration;
import hex.domain.ApplicationDomainDispatcher;
import hex.domain.Domain;
import hex.error.Exception;
import hex.error.NoSuchElementException;
import hex.event.Dispatcher;
import hex.event.EventProxy;
import hex.ioc.assembler.ApplicationContext;
import hex.ioc.parser.xml.ApplicationXMLParser;
import hex.ioc.parser.xml.mock.AnotherMockModuleWithServiceCallback;
import hex.ioc.parser.xml.mock.IMockAmazonService;
import hex.ioc.parser.xml.mock.IMockDividerHelper;
import hex.ioc.parser.xml.mock.IMockStubStatefulService;
import hex.ioc.parser.xml.mock.MockAmazonService;
import hex.ioc.parser.xml.mock.MockAsyncCommandWithAnnotation;
import hex.ioc.parser.xml.mock.MockBooleanVO;
import hex.ioc.parser.xml.mock.MockChatModule;
import hex.ioc.parser.xml.mock.MockCommandWithAnnotation;
import hex.ioc.parser.xml.mock.MockDocument;
import hex.ioc.parser.xml.mock.MockIntVO;
import hex.ioc.parser.xml.mock.MockMacroWithAnnotation;
import hex.ioc.parser.xml.mock.MockMessageParserModule;
import hex.ioc.parser.xml.mock.MockModuleWithAnnotationProviding;
import hex.ioc.parser.xml.mock.MockModuleWithServiceCallback;
import hex.ioc.parser.xml.mock.MockReceiverModule;
import hex.ioc.parser.xml.mock.MockSenderModule;
import hex.ioc.parser.xml.mock.MockTranslationModule;
import hex.metadata.AnnotationProvider;
import hex.metadata.IAnnotationProvider;
import hex.mock.AnotherMockClass;
import hex.mock.ClassWithConstantConstantArgument;
import hex.mock.IAnotherMockInterface;
import hex.mock.IMockInjectee;
import hex.mock.IMockInterface;
import hex.mock.MockCaller;
import hex.mock.MockChat;
import hex.mock.MockClass;
import hex.mock.MockClassWithGeneric;
import hex.mock.MockClassWithInjectedProperty;
import hex.mock.MockClassWithoutArgument;
import hex.mock.MockContextHolder;
import hex.mock.MockFruitVO;
import hex.mock.MockInjectee;
import hex.mock.MockMethodCaller;
import hex.mock.MockObjectWithRegtangleProperty;
import hex.mock.MockProxy;
import hex.mock.MockReceiver;
import hex.mock.MockRectangle;
import hex.mock.MockServiceProvider;
import hex.mock.MockWeatherListener;
import hex.mock.MockWeatherModel;
import hex.runtime.ApplicationAssembler;
import hex.structures.Point;
import hex.structures.Size;
import hex.unittest.assertion.Assert;
import hex.unittest.runner.MethodRunner;
/**
* ...
* @author Francis Bourre
*/
class XmlCompilerTest
{
var _applicationAssembler : IApplicationAssembler;
static var applicationAssembler : IApplicationAssembler;
@Before
public function setUp() : Void
{
}
@After
public function tearDown() : Void
{
ApplicationDomainDispatcher.getInstance( null ).clear();
this._applicationAssembler.release();
}
function _getCoreFactory() : ICoreFactory
{
return this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getCoreFactory();
}
function _locate( key : String ) : Dynamic
{
return this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getCoreFactory().locate( key );
}
@Test( "test context reference" )
public function testContextReference() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/contextReference.xml" );
var contextHolder : MockContextHolder = this._getCoreFactory().locate( "contextHolder" );
var context = this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext );
Assert.equals( context, contextHolder.context );
}
@Test( "test building String with assembler" )
public function testBuildingStringWithAssembler() : Void
{
var assembler = new ApplicationAssembler();
assembler.getApplicationContext( "applicationContext", ApplicationContext ).getCoreFactory().register( "s2", "bonjour" );
this._applicationAssembler = XmlCompiler.compileWithAssembler( assembler, "context/xml/primitives/string.xml" );
Assert.equals( "hello", this._locate( "s" ), "" );
Assert.equals( "bonjour", this._locate( "s2" ), "" );
Assert.equals( assembler, this._applicationAssembler, "" );
}
@Test( "test building String instances with the same assembler at compile time and runtime" )
public function testBuildingStringsMixingCompileTimeAndRuntime() : Void
{
var assembler = new ApplicationAssembler();
ApplicationXMLParser.parseString( assembler, '<root name="applicationContext"><test id="s2" value="hola"/></root>' );
this._applicationAssembler = XmlCompiler.compileWithAssembler( assembler, "context/xml/primitives/string.xml" );
Assert.equals( "hello", this._locate( "s" ), "" );
Assert.equals( "hola", this._locate( "s2" ), "" );
Assert.equals( assembler, this._applicationAssembler, "" );
}
@Test( "test building String" )
public function testBuildingString() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/primitives/string.xml" );
var s : String = this._locate( "s" );
Assert.equals( "hello", s, "" );
}
@Test( "test building String with assembler property" )
public function testBuildingStringWithAssemblerProperty() : Void
{
this._applicationAssembler = new ApplicationAssembler();
XmlCompiler.compileWithAssembler( this._applicationAssembler, "context/xml/primitives/string.xml" );
var s : String = this._locate( "s" );
Assert.equals( "hello", s, "" );
}
@Ignore( "test building String with assembler static property" )
public function testBuildingStringWithAssemblerStaticProperty() : Void
{
XmlCompilerTest.applicationAssembler = new ApplicationAssembler();
XmlCompiler.compileWithAssembler( XmlCompilerTest.applicationAssembler, "context/xml/primitives/string.xml" );
var s : String = this._locate( "s" );
Assert.equals( "hello", s, "" );
}
@Test( "test read twice the same context" )
public function testReadTwiceTheSameContext() : Void
{
var applicationAssembler = new ApplicationAssembler();
this._applicationAssembler = new ApplicationAssembler();
XmlCompiler.compileWithAssembler( applicationAssembler, "context/xml/simpleInstanceWithoutArguments.xml" );
XmlCompiler.compileWithAssembler( this._applicationAssembler, "context/xml/simpleInstanceWithoutArguments.xml" );
var localCoreFactory = applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getCoreFactory();
var instance1 = localCoreFactory.locate( "instance" );
Assert.isInstanceOf( instance1, MockClassWithoutArgument );
var instance2 = this._getCoreFactory().locate( "instance" );
Assert.isInstanceOf( instance2, MockClassWithoutArgument );
Assert.notEquals( instance1, instance2 );
}
@Test( "test overriding context name" )
public function testOverridingContextName() : Void
{
this._applicationAssembler = new ApplicationAssembler();
XmlCompiler.compileWithAssembler( this._applicationAssembler, "context/xml/simpleInstanceWithoutArguments.xml", 'name1' );
XmlCompiler.compileWithAssembler( this._applicationAssembler, "context/xml/simpleInstanceWithoutArguments.xml", 'name2' );
var factory1 = this._applicationAssembler.getApplicationContext( "name1", ApplicationContext ).getCoreFactory();
var factory2 = this._applicationAssembler.getApplicationContext( "name2", ApplicationContext ).getCoreFactory();
var instance1 = factory1.locate( "instance" );
Assert.isInstanceOf( instance1, MockClassWithoutArgument );
var instance2 = factory2.locate( "instance" );
Assert.isInstanceOf( instance2, MockClassWithoutArgument );
Assert.notEquals( instance1, instance2 );
}
@Test( "test building Int" )
public function testBuildingInt() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/primitives/int.xml" );
var i : Int = this._locate( "i" );
Assert.equals( -3, i, "" );
}
@Test( "test building Hex" )
public function testBuildingHex() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/primitives/hex.xml" );
Assert.equals( 0xFFFFFF, this._locate( "i" ) );
}
@Test( "test building Bool" )
public function testBuildingBool() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/primitives/bool.xml" );
var b : Bool = this._locate( "b" );
Assert.isTrue( b, "" );
}
@Test( "test building UInt" )
public function testBuildingUInt() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/primitives/uint.xml" );
var i : UInt = this._locate( "i" );
Assert.equals( 3, i, "" );
}
@Test( "test building null" )
public function testBuildingNull() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/primitives/null.xml" );
var result = this._locate( "value" );
Assert.isNull( result, "" );
}
@Test( "test building anonymous object" )
public function testBuildingAnonymousObject() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/anonymousObject.xml" );
var obj : Dynamic = this._locate( "obj" );
Assert.equals( "Francis", obj.name );
Assert.equals( 44, obj.age );
Assert.equals( 1.75, obj.height );
Assert.isTrue( obj.isWorking );
Assert.isFalse( obj.isSleeping );
Assert.equals( 1.75, this._locate( "obj.height" ) );
}
@Test( "test building simple instance without arguments" )
public function testBuildingSimpleInstanceWithoutArguments() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/simpleInstanceWithoutArguments.xml" );
var instance : MockClassWithoutArgument = this._locate( "instance" );
Assert.isInstanceOf( instance, MockClassWithoutArgument );
}
@Test( "test building simple instance with arguments" )
public function testBuildingSimpleInstanceWithArguments() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/simpleInstanceWithArguments.xml" );
var size : Size = this._locate( "size" );
Assert.isInstanceOf( size, Size, "" );
Assert.equals( 10, size.width, "" );
Assert.equals( 20, size.height, "" );
}
@Test( "test building multiple instances with arguments" )
public function testBuildingMultipleInstancesWithArguments() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/multipleInstancesWithArguments.xml" );
var size : Size = this._locate( "size" );
Assert.isInstanceOf( size, Size, "" );
Assert.equals( 15, size.width, "" );
Assert.equals( 25, size.height, "" );
var position : Point = this._locate( "position" );
//Assert.isInstanceOf( position, Point, "" );
Assert.equals( 35, position.x, "" );
Assert.equals( 45, position.y, "" );
}
@Test( "test building single instance with primitives references" )
public function testBuildingSingleInstanceWithPrimitivesReferences() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/singleInstanceWithPrimReferences.xml" );
var x : Int = this._locate( "x" );
Assert.equals( 1, x, "" );
var y : Int = this._locate( "y" );
Assert.equals( 2, y, "" );
var position : Point = this._locate( "position" );
//Assert.isInstanceOf( position, Point, "" );
Assert.equals( 1, position.x, "" );
Assert.equals( 2, position.y, "" );
}
@Test( "test building single instance with method references" )
public function testBuildingSingleInstanceWithMethodReferences() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/singleInstanceWithMethodReferences.xml" );
var chat : MockChat = this._getCoreFactory().locate( "chat" );
Assert.isInstanceOf( chat, MockChat );
var receiver : MockReceiver = this._getCoreFactory().locate( "receiver" );
Assert.isInstanceOf( receiver, MockReceiver );
var proxyChat : MockProxy = this._getCoreFactory().locate( "proxyChat" );
Assert.isInstanceOf( proxyChat, MockProxy );
var proxyReceiver : MockProxy = this._getCoreFactory().locate( "proxyReceiver" );
Assert.isInstanceOf( proxyReceiver, MockProxy );
Assert.equals( chat, proxyChat.scope );
Assert.equals( chat.onTranslation, proxyChat.callback );
Assert.equals( receiver, proxyReceiver.scope );
Assert.equals( receiver.onMessage, proxyReceiver.callback );
}
@Test( "test building multiple instances with references" )
public function testAssignInstancePropertyWithReference() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/instancePropertyWithReference.xml" );
var width : Int = this._locate( "width" );
Assert.equals( 10, width, "" );
var height : Int = this._locate( "height" );
Assert.equals( 20, height, "" );
var size : Point = this._locate( "size" );
//Assert.isInstanceOf( size, Point, "" );
Assert.equals( width, size.x, "" );
Assert.equals( height, size.y, "" );
var rect : MockRectangle = this._locate( "rect" );
Assert.equals( width, rect.size.x, "" );
Assert.equals( height, rect.size.y, "" );
}
@Test( "test building multiple instances with references" )
public function testBuildingMultipleInstancesWithReferences() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/multipleInstancesWithReferences.xml" );
var rectSize : Point = this._locate( "rectSize" );
//Assert.isInstanceOf( rectSize, Point, "" );
Assert.equals( 30, rectSize.x, "" );
Assert.equals( 40, rectSize.y, "" );
var rectPosition : Point = this._locate( "rectPosition" );
//Assert.isInstanceOf( rectPosition, Point, "" );
Assert.equals( 10, rectPosition.x, "" );
Assert.equals( 20, rectPosition.y, "" );
var rect : MockRectangle = this._locate( "rect" );
Assert.isInstanceOf( rect, MockRectangle, "" );
Assert.equals( 10, rect.x, "" );
Assert.equals( 20, rect.y, "" );
Assert.equals( 30, rect.size.x, "" );
Assert.equals( 40, rect.size.y, "" );
}
@Test( "test simple method call" )
public function testSimpleMethodCall() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/simpleMethodCall.xml" );
var caller : MockCaller = this._locate( "caller" );
Assert.isInstanceOf( caller, MockCaller, "" );
Assert.deepEquals( [ "hello", "world" ], MockCaller.passedArguments, "" );
}
@Test( "test method call with type params" )
public function testCallWithTypeParams() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/methodCallWithTypeParams.xml" );
var caller : MockCaller = this._locate( "caller" );
Assert.isInstanceOf( caller, MockCaller, "" );
Assert.equals( 3, MockCaller.passedArray.length, "" );
}
@Test( "test building multiple instances with method calls" )
public function testBuildingMultipleInstancesWithMethodCall() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/multipleInstancesWithMethodCall.xml" );
var rectSize : Point = this._locate( "rectSize" );
//Assert.isInstanceOf( rectSize, Point, "" );
Assert.equals( 30, rectSize.x, "" );
Assert.equals( 40, rectSize.y, "" );
var rectPosition : Point = this._locate( "rectPosition" );
//Assert.isInstanceOf( rectPosition, Point, "" );
Assert.equals( 10, rectPosition.x, "" );
Assert.equals( 20, rectPosition.y, "" );
var rect : MockRectangle = this._locate( "rect" );
Assert.isInstanceOf( rect, MockRectangle, "" );
Assert.equals( 10, rect.x, "" );
Assert.equals( 20, rect.y, "" );
Assert.equals( 30, rect.width, "" );
Assert.equals( 40, rect.height, "" );
var anotherRect : MockRectangle = this._locate( "anotherRect" );
Assert.isInstanceOf( anotherRect, MockRectangle, "" );
Assert.equals( 0, anotherRect.x, "" );
Assert.equals( 0, anotherRect.y, "" );
Assert.equals( 0, anotherRect.width, "" );
Assert.equals( 0, anotherRect.height, "" );
}
@Test( "test building instance with static method" )
public function testBuildingInstanceWithStaticMethod() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/instanceWithStaticMethod.xml" );
var service : MockServiceProvider = this._locate( "service" );
Assert.isInstanceOf( service, MockServiceProvider, "" );
Assert.equals( "http://localhost/amfphp/gateway.php", MockServiceProvider.getInstance().getGateway(), "" );
}
@Test( "test building instance with static method and arguments" )
public function testBuildingInstanceWithStaticMethodAndArguments() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/instanceWithStaticMethodAndArguments.xml" );
var rect : MockRectangle = this._locate( "rect" );
Assert.isInstanceOf( rect, MockRectangle, "" );
Assert.equals( 10, rect.x, "" );
Assert.equals( 20, rect.y, "" );
Assert.equals( 30, rect.width, "" );
Assert.equals( 40, rect.height, "" );
}
@Test( "test building instance with static method and factory method" )
public function testBuildingInstanceWithStaticMethodAndFactoryMethod() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/instanceWithStaticMethodAndFactoryMethod.xml" );
var point : Point = this._locate( "point" );
//Assert.isInstanceOf( point, Point, "" );
Assert.equals( 10, point.x, "" );
Assert.equals( 20, point.y, "" );
}
@Test( "test 'inject-into' attribute" )
public function testInjectIntoAttribute() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/injectIntoAttribute.xml" );
var instance : MockClassWithInjectedProperty = this._locate( "instance" );
Assert.isInstanceOf( instance, MockClassWithInjectedProperty, "" );
Assert.equals( "hola mundo", instance.property, "" );
Assert.isTrue( instance.postConstructWasCalled, "" );
}
@Test( "test building XML without parser class" )
public function testBuildingXMLWithoutParserClass() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/xmlWithoutParserClass.xml" );
var fruits : Xml = this._locate( "fruits" );
Assert.isNotNull( fruits );
Assert.isInstanceOf( fruits, Xml );
}
@Test( "test building XML with parser class" )
public function testBuildingXMLWithParserClass() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/xmlWithParserClass.xml" );
var fruits : Array<MockFruitVO> = this._locate( "fruits" );
Assert.equals( 3, fruits.length, "" );
var orange : MockFruitVO = fruits[0];
var apple : MockFruitVO = fruits[1];
var banana : MockFruitVO = fruits[2];
Assert.equals( "orange", orange.toString(), "" );
Assert.equals( "apple", apple.toString(), "" );
Assert.equals( "banana", banana.toString(), "" );
}
@Test( "test building Arrays" )
public function testBuildingArrays() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/arrayFilledWithReferences.xml" );
var text : Array<String> = this._locate( "text" );
Assert.equals( 2, text.length, "" );
Assert.equals( "hello", text[ 0 ], "" );
Assert.equals( "world", text[ 1 ], "" );
var empty : Array<String> = this._locate( "empty" );
Assert.equals( 0, empty.length, "" );
var fruits : Array<MockFruitVO> = this._locate( "fruits" );
Assert.equals( 3, fruits.length, "" );
var orange : MockFruitVO = fruits[0];
var apple : MockFruitVO = fruits[1];
var banana : MockFruitVO = fruits[2];
Assert.equals( "orange", orange.toString(), "" );
Assert.equals( "apple", apple.toString(), "" );
Assert.equals( "banana", banana.toString(), "" );
}
@Test( "test building Map filled with references" )
public function testBuildingMapFilledWithReferences() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/hashmapFilledWithReferences.xml" );
var fruits : HashMap<Any, MockFruitVO> = this._locate( "fruits" );
Assert.isNotNull( fruits, "" );
var stubKey : Point = this._locate( "stubKey" );
Assert.isNotNull( stubKey, "" );
var orange : MockFruitVO = fruits.get( '0' );
var apple : MockFruitVO = fruits.get( 1 );
var banana : MockFruitVO = fruits.get( stubKey );
Assert.equals( "orange", orange.toString(), "" );
Assert.equals( "apple", apple.toString(), "" );
Assert.equals( "banana", banana.toString(), "" );
}
@Test( "test building HashMap with map-type" )
public function testBuildingHashMapWithMapType() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/hashmapWithMapType.xml" );
var fruits : HashMap<Any, MockFruitVO> = this._locate( "fruits" );
Assert.isNotNull( fruits, "" );
var orange : MockFruitVO = fruits.get( '0' );
var apple : MockFruitVO = fruits.get( '1' );
Assert.equals( "orange", orange.toString(), "" );
Assert.equals( "apple", apple.toString(), "" );
var map = this._getCoreFactory().getInjector().getInstanceWithClassName( "hex.collection.HashMap<String,hex.mock.MockFruitVO>", "fruits" );
Assert.equals( fruits, map );
}
@Test( "test map-type attribute with Array" )
public function testMapTypeWithArray() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/mapTypeWithArray.xml" );
var intCollection = this._getCoreFactory().getInjector().getInstanceWithClassName( "Array<Int>", "intCollection" );
var uintCollection = this._getCoreFactory().getInjector().getInstanceWithClassName( "Array<UInt>", "intCollection" );
var stringCollection = this._getCoreFactory().getInjector().getInstanceWithClassName( "Array<String>", "stringCollection" );
Assert.isInstanceOf( intCollection, Array );
Assert.isInstanceOf( uintCollection, Array );
Assert.isInstanceOf( stringCollection, Array );
Assert.equals( intCollection, uintCollection );
Assert.notEquals( intCollection, stringCollection );
}
@Test( "test map-type attribute with instance" )
public function testMapTypeWithInstance() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/mapTypeWithInstance.xml" );
var intInstance = this._getCoreFactory().getInjector().getInstanceWithClassName( "hex.mock.IMockInterfaceWithGeneric<Int>", "intInstance" );
var uintInstance = this._getCoreFactory().getInjector().getInstanceWithClassName( "hex.mock.IMockInterfaceWithGeneric<UInt>", "intInstance" );
var stringInstance = this._getCoreFactory().getInjector().getInstanceWithClassName( "hex.mock.IMockInterfaceWithGeneric<String>", "stringInstance" );
Assert.isInstanceOf( intInstance, MockClassWithGeneric );
Assert.isInstanceOf( uintInstance, MockClassWithGeneric );
Assert.isInstanceOf( stringInstance, MockClassWithGeneric );
Assert.equals( intInstance, uintInstance );
Assert.notEquals( intInstance, stringInstance );
}
@Test( "test static-ref" )
public function testStaticRef() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/staticRef.xml" );
var messageType : String = this._getCoreFactory().locate( "constant" );
Assert.isNotNull( messageType );
Assert.equals( messageType, MockClass.MESSAGE_TYPE );
}
@Test( "test static-ref property" )
public function testStaticProperty() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/staticRefProperty.xml" );
var object : Dynamic = this._getCoreFactory().locate( "object" );
Assert.isNotNull( object );
Assert.equals( MockClass.MESSAGE_TYPE, object.property );
var object2 : Dynamic = this._getCoreFactory().locate( "object2" );
Assert.isNotNull( object2 );
Assert.equals( MockClass, object2.property );
}
@Test( "test static-ref argument" )
public function testStaticArgument() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/staticRefArgument.xml" );
var instance : ClassWithConstantConstantArgument = this._locate( "instance" );
Assert.isNotNull( instance, "" );
Assert.equals( instance.constant, MockClass.MESSAGE_TYPE );
}
@Test( "test static-ref argument on method-call" )
public function testStaticArgumentOnMethodCall() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/staticRefArgumentOnMethodCall.xml" );
var instance : MockMethodCaller = this._locate( "instance" );
Assert.isNotNull( instance, "" );
Assert.equals( MockMethodCaller.staticVar, instance.argument, "" );
}
@Test( "test map-type attribute" )
public function testMapTypeAttribute() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/mapTypeAttribute.xml" );
var instance : MockClass = this._locate( "instance" );
Assert.isNotNull( instance );
Assert.isInstanceOf( instance, MockClass );
Assert.isInstanceOf( instance, IMockInterface );
Assert.equals( instance, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstance( IMockInterface, "instance" ) );
var instance2 : MockClass = this._getCoreFactory().locate( "instance2" );
Assert.isNotNull( instance2 );
Assert.isInstanceOf( instance2, MockClass );
Assert.equals( instance2, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstanceWithClassName( "hex.mock.MockModuleWithInternalType.GetInfosInternalTypedef", "instance2" ) );
}
@Test( "test multi map-type attributes" )
public function testMultiMapTypeAttributes() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/static/multiMapTypeAttributes.xml" );
var instance = this._getCoreFactory().locate( "instance" );
var f = this._getCoreFactory().locate( "f" );
var f2 = this._getCoreFactory().locate( "f2" );
Assert.isInstanceOf( instance, MockClass );
Assert.isInstanceOf( instance, IMockInterface );
Assert.isInstanceOf( instance, IAnotherMockInterface );
Assert.equals( instance, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstance( IMockInterface, "instance" ) );
Assert.equals( instance, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstance( IAnotherMockInterface, "instance" ) );
Assert.equals( f, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstanceWithClassName( "String->String", "f" ) );
Assert.equals( f, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstanceWithClassName( "hex.mock.MockModuleWithInternalType.FunctionSignature", "f" ) );
Assert.equals( f2, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstanceWithClassName( "String->String", "f2" ) );
Assert.equals( f2, this._applicationAssembler.getApplicationContext( "applicationContext", ApplicationContext ).getInjector().getInstanceWithClassName( "hex.mock.MockModuleWithInternalType.FunctionSignature", "f2" ) );
Assert.equals( f, this._getCoreFactory().locate( "instanceWithSubType.toInject1" ) );
Assert.equals( f2, this._getCoreFactory().locate( "instanceWithSubType.toInject2" ) );
Assert.equals( f, this._getCoreFactory().locate( "instanceWithSubType.toInject1b" ) );
Assert.equals( f2, this._getCoreFactory().locate( "instanceWithSubType.toInject2b" ) );
Assert.equals( f, this._getCoreFactory().locate( "instanceWithSubType.toInject1c" ) );
Assert.equals( f2, this._getCoreFactory().locate( "instanceWithSubType.toInject2c" ) );
}
@Test( "test if attribute" )
public function testIfAttribute() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/ifAttribute.xml", null, null, [ "production" => true, "test" => false, "release" => false ] );
Assert.equals( "hello production", this._locate( "message" ), "message value should equal 'hello production'" );
}
@Test( "test include with if attribute" )
public function testIncludeWithIfAttribute() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/includeWithIfAttribute.xml", null, null, [ "production" => true, "test" => false, "release" => false ] );
Assert.equals( "hello production", this._locate( "message" ), "message value should equal 'hello production'" );
}
@Test( "test include fails with if attribute" )
public function testIncludeFailsWithIfAttribute() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/includeWithIfAttribute.xml", null, null, [ "production" => false, "test" => true, "release" => true ] );
Assert.methodCallThrows( NoSuchElementException, this._getCoreFactory(), this._locate, [ "message" ], "'NoSuchElementException' should be thrown" );
}
@Test( "test file preprocessor with Xml file" )
public function testFilePreprocessorWithXmlFile() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/preprocessor.xml", null, [ "hello" => "bonjour",
"contextName" => 'applicationContext',
"context" => 'name="${contextName}"',
"node" => '<msg id="message" value="${hello}"/>' ] );
Assert.equals( "bonjour", this._locate( "message" ), "message value should equal 'bonjour'" );
}
@Test( "test file preprocessor with Xml file and include" )
public function testFilePreprocessorWithXmlFileAndInclude() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/preprocessorWithInclude.xml", null, [ "hello" => "bonjour",
"contextName" => 'applicationContext',
"context" => 'name="${contextName}"',
"node" => '<msg id="message" value="${hello}"/>' ] );
try
{
Assert.equals( "bonjour", this._locate( "message" ), "message value should equal 'bonjour'" );
}
catch ( e : Exception )
{
Assert.fail( e.message, "Exception on this._builderFactory.getCoreFactory().locate( \"message\" ) call" );
}
}
@Test( "test simple method call from another node" )
public function testSimpleMethodCallFromAnotherNode() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/simpleMethodCallFromAnotherNode.xml" );
var caller : MockCaller = this._locate( "caller" );
Assert.isInstanceOf( caller, MockCaller, "" );
Assert.deepEquals( [ "hello", "world" ], MockCaller.passedArguments, "" );
}
@Test( "test building two modules listening each other" )
public function testBuildingTwoModulesListeningEachOther() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/twoModulesListeningEachOther.xml" );
var chat : MockChatModule = this._locate( "chat" );
Assert.isNotNull( chat, "" );
Assert.isNull( chat.translatedMessage, "" );
var translation : MockTranslationModule = this._locate( "translation" );
Assert.isNotNull( translation, "" );
chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] );
Assert.equals( "Hello", chat.translatedMessage, "" );
}
@Test( "test building two modules listening each other with adapter" )
public function testBuildingTwoModulesListeningEachOtherWithAdapter() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/twoModulesListeningEachOtherWithAdapter.xml" );
var chat : MockChatModule = this._locate( "chat" );
Assert.isNotNull( chat, "" );
Assert.isNull( chat.translatedMessage, "" );
var translation : MockTranslationModule = this._locate( "translation" );
Assert.isNotNull( translation, "" );
chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] );
Assert.equals( "Hello", chat.translatedMessage, "" );
Assert.isInstanceOf( chat.date, Date, "" );
}
@Test( "test building two modules listening each other with adapter and injection" )
public function testBuildingTwoModulesListeningEachOtherWithAdapterAndInjection() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/twoModulesListeningEachOtherWithAdapterAndInjection.xml" );
var chat : MockChatModule = this._locate( "chat" );
Assert.isNotNull( chat, "" );
var receiver : MockReceiverModule = this._locate( "receiver" );
Assert.isNotNull( receiver, "" );
var parser : MockMessageParserModule = this._locate( "parser" );
Assert.isNotNull( parser, "" );
chat.dispatchDomainEvent( MockChatModule.TEXT_INPUT, [ "Bonjour" ] );
Assert.equals( "BONJOUR", receiver.message, "" );
}
@Test( "test domain dispatch after module initialisation" )
public function testDomainDispatchAfterModuleInitialisation() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/domainDispatchAfterModuleInitialisation.xml" );
var sender : MockSenderModule = this._locate( "sender" );
Assert.isNotNull( sender, "" );
var receiver : MockReceiverModule = this._locate( "receiver" );
Assert.isNotNull( receiver, "" );
Assert.equals( "hello receiver", receiver.message, "" );
}
@Async( "test event adapter strategy macro" )
public function testEventAdapterStrategyMacro() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/eventAdapterStrategyMacro.xml" );
Assert.isNotNull( this._getCoreFactory().locate( "sender" ) );
Assert.isNotNull( this._getCoreFactory().locate( "receiver" ) );
Timer.delay( MethodRunner.asyncHandler.bind( this._onEventAdapterStrategyMacro.bind()), 350 );
}
function _onEventAdapterStrategyMacro()
{
var receiver : MockReceiverModule = this._getCoreFactory().locate( "receiver" );
Assert.equals( "HELLO RECEIVER:HTTP://GOOGLE.COM", receiver.message );
}
@Test( "test building Map with class reference" )
public function testBuildingMapWithClassReference() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/hashmapWithClassReference.xml" );
var map : HashMap<Class<IMockAmazonService>, Class<MockAmazonService>> = this._locate( "map" );
Assert.isNotNull( map, "" );
var amazonServiceClass : Class<MockAmazonService> = map.get( IMockAmazonService );
Assert.equals( IMockAmazonService, map.getKeys()[ 0 ], "" );
Assert.equals( MockAmazonService, amazonServiceClass, "" );
}
@Test( "test target sub property" )
public function testTargetSubProperty() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/targetSubProperty.xml" );
var mockObject : MockObjectWithRegtangleProperty = this._locate( "mockObject" );
Assert.isInstanceOf( mockObject, MockObjectWithRegtangleProperty );
Assert.equals( 1.5, mockObject.rectangle.x );
}
@Test( "test building class reference" )
public function testBuildingClassReference() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/classReference.xml" );
var rectangleClass : Class<MockRectangle> = this._locate( "RectangleClass" );
Assert.isInstanceOf( rectangleClass, Class, "" );
Assert.isInstanceOf( Type.createInstance( rectangleClass, [] ), MockRectangle, "" );
var classContainer = this._locate( "classContainer" );
var anotherRectangleClass : Class<MockRectangle> = classContainer.AnotherRectangleClass;
Assert.isInstanceOf( anotherRectangleClass, Class, "" );
Assert.isInstanceOf( Type.createInstance( anotherRectangleClass, [] ), MockRectangle, "" );
Assert.equals( rectangleClass, anotherRectangleClass, "" );
var anotherRectangleClassRef : Class<MockRectangle> = this._locate( "classContainer.AnotherRectangleClass" );
Assert.isInstanceOf( anotherRectangleClassRef, Class, "" );
Assert.equals( anotherRectangleClass, anotherRectangleClassRef, "" );
}
@Test( "test building mapping configuration" )
public function testBuildingMappingConfiguration() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/mappingConfiguration.xml" );
var config : MappingConfiguration = this._locate( "config" );
Assert.isInstanceOf( config, MappingConfiguration );
var injector = new Injector();
config.configure( injector, null );
Assert.isInstanceOf( injector.getInstance( IMockInterface ), MockClass );
Assert.isInstanceOf( injector.getInstance( IAnotherMockInterface ), AnotherMockClass );
Assert.equals( this._locate( "instance" ), injector.getInstance( IAnotherMockInterface ) );
}
@Test( "test building mapping configuration with map names" )
public function testBuildingMappingConfigurationWithMapNames() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/mappingConfigurationWithMapNames.xml" );
var config : MappingConfiguration = this._locate( "config" );
Assert.isInstanceOf( config, MappingConfiguration );
var injector = new Injector();
config.configure( injector, null );
Assert.isInstanceOf( injector.getInstance( IAnotherMockInterface, "name1" ), MockClass );
Assert.isInstanceOf( injector.getInstance( IAnotherMockInterface, "name2" ), AnotherMockClass );
}
@Test( "test building mapping configuration with singleton" )
public function testBuildingMappingConfigurationWithSingleton() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/mappingConfigurationWithSingleton.xml" );
var config : MappingConfiguration = this._locate( "config" );
Assert.isInstanceOf( config, MappingConfiguration );
var injector = new Injector();
config.configure( injector, null );
var instance1 = injector.getInstance( IAnotherMockInterface, "name1" );
Assert.isInstanceOf( instance1, MockClass );
var copyOfInstance1 = injector.getInstance( IAnotherMockInterface, "name1" );
Assert.isInstanceOf( copyOfInstance1, MockClass, "" );
Assert.equals( instance1, copyOfInstance1 );
var instance2 = injector.getInstance( IAnotherMockInterface, "name2" );
Assert.isInstanceOf( instance2, AnotherMockClass );
var copyOfInstance2 = injector.getInstance( IAnotherMockInterface, "name2" );
Assert.isInstanceOf( copyOfInstance2, AnotherMockClass );
Assert.notEquals( instance2, copyOfInstance2 );
}
@Test( "test building mapping configuration with inject-into" )
public function testBuildingMappingConfigurationWithInjectInto() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/xml/mappingConfigurationWithInjectInto.xml" );
var config : MappingConfiguration = this._locate( "config" );
Assert.isInstanceOf( config, MappingConfiguration );
var injector = new Injector();
var domain = Domain.getDomain( 'XmlCompilerTest.testBuildingMappingConfigurationWithInjectInto' );
injector.mapToValue( Domain, domain );
config.configure( injector, null );
var mock0 = injector.getInstance( IMockInjectee, "name1" );
Assert.isInstanceOf( mock0, MockInjectee );
Assert.equals( domain, mock0.domain );
var mock1 = injector.getInstance( IMockInjectee, "name2" );
Assert.isInstanceOf( mock1, MockInjectee );
Assert.equals( domain, mock1.domain );
}
/*@Test( "test parsing twice" )
public function testParsingTwice() : Void
{
this._applicationAssembler = XmlCompiler.readXmlFile( "context/xml/parsingOnce.xml" );
XmlCompiler.readXmlFileWithAssembler( this._applicationAssembler, "context/xml/parsingTwice.xml" );
var rect0 : MockRectangle = this._locate( "rect0" );
Assert.isInstanceOf( rect0, MockRectangle );
Assert.equals( 10, rect0.x );
Assert.equals( 20, rect0.y );
Assert.equals( 30, rect0.width );
Assert.equals( 40, rect0.height );
var rect1 : MockRectangle = this._locate( "rect1" );
Assert.isInstanceOf( rect1, MockRectangle );
Assert.equals( 50, rect1.x );
Assert.equals( 60, rect1.y );
Assert.equals( 70, rect1.width );
Assert.equals( 40, rect1.height );
}*/
@Test( "test static-ref with factory" )
public function testStaticRefWithFactory() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/staticRefFactory.xml" );
var doc : MockDocument = this._locate( "div" );
Assert.isNotNull( doc, "" );
Assert.isInstanceOf( doc, MockDocument, "" );
}
@Test( "test module listening service" )
public function testModuleListeningService() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/moduleListeningService.xml" );
var myService : IMockStubStatefulService = this._locate( "myService" );
Assert.isNotNull( myService, "" );
var myModule : MockModuleWithServiceCallback = this._locate( "myModule" );
Assert.isNotNull( myModule, "" );
var booleanVO = new MockBooleanVO( true );
myService.setBooleanVO( booleanVO );
Assert.isTrue( myModule.getBooleanValue(), "" );
}
@Test( "test module listening service with map-type" )
public function testModuleListeningServiceWithMapType() : Void
{
this._applicationAssembler = XmlCompiler.compile( "context/moduleListeningServiceWithMapType.xml" );
var myService : IMockStubStatefulService = this._locate( "myService" );