This repository was archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObjectSerializationTests.cs
executable file
·1313 lines (1171 loc) · 50.7 KB
/
ObjectSerializationTests.cs
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
/*
* ====================
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of the Common Development
* and Distribution License("CDDL") (the "License"). You may not use this file
* except in compliance with the License.
*
* You can obtain a copy of the License at
* http://opensource.org/licenses/cddl1.php
* See the License for the specific language governing permissions and limitations
* under the License.
*
* When distributing the Covered Code, include this CDDL Header Notice in each file
* and include the License file at http://opensource.org/licenses/cddl1.php.
* If applicable, add the following below this CDDL Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
* ====================
* Portions Copyrighted 2012-2015 ForgeRock AS.
*/
using System;
using System.IO;
using System.Text;
using NUnit.Framework;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml;
using Org.IdentityConnectors.Common;
using Org.IdentityConnectors.Common.Pooling;
using Org.IdentityConnectors.Common.Security;
using Org.IdentityConnectors.Framework.Api;
using Org.IdentityConnectors.Framework.Api.Operations;
using Org.IdentityConnectors.Framework.Common;
using Org.IdentityConnectors.Framework.Common.Exceptions;
using Org.IdentityConnectors.Framework.Common.Objects;
using Org.IdentityConnectors.Framework.Common.Objects.Filters;
using Org.IdentityConnectors.Framework.Common.Serializer;
using Org.IdentityConnectors.Framework.Impl.Api;
using Org.IdentityConnectors.Framework.Impl.Api.Remote;
using Org.IdentityConnectors.Framework.Impl.Api.Remote.Messages;
namespace FrameworkTests
{
[TestFixture]
public class ObjectSerializationTests
{
[Test]
public void TestBoolean()
{
bool v1 = true;
bool v2 = (bool)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = false;
v2 = (bool)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestCharacter()
{
char v1 = 'h';
char v2 = (char)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestInteger()
{
int v1 = 12345;
int v2 = (int)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Int32.MinValue;
v2 = (int)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Int32.MaxValue;
v2 = (int)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = -1;
v2 = (int)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestLong()
{
long v1 = 12345;
long v2 = (long)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Int64.MinValue;
v2 = (long)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Int64.MaxValue;
v2 = (long)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = -1;
v2 = (long)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestFloat()
{
float v1 = 1.1F;
float v2 = (float)CloneObject(v1);
Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
Assert.AreEqual(v1, v2);
v1 = Single.Epsilon;
v2 = (float)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Single.NaN;
v2 = (float)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Single.NegativeInfinity;
v2 = (float)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Single.PositiveInfinity;
v2 = (float)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Single.MinValue;
v2 = (float)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Single.MaxValue;
v2 = (float)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestDouble()
{
double v1 = 1.1;
double v2 = (double)CloneObject(v1);
Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
Assert.AreEqual(v1, v2);
v1 = Double.Epsilon;
v2 = (double)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Double.NaN;
v2 = (double)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Double.NegativeInfinity;
v2 = (double)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Double.PositiveInfinity;
v2 = (double)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Double.MaxValue;
v2 = (double)CloneObject(v1);
Assert.AreEqual(v1, v2);
v1 = Double.MinValue;
v2 = (double)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestString()
{
string v1 = "abcd";
string v2 = (string)CloneObject(v1);
Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
Assert.AreEqual(v1, v2);
}
[Test]
public void TestURI()
{
Uri v1 = new Uri("mailto:[email protected]");
Uri v2 = (Uri)CloneObject(v1);
Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
Assert.AreEqual(v1, v2);
}
[Test]
public void TestFile()
{
FileName v1 = new FileName("c:/foo.txt");
FileName v2 = (FileName)CloneObject(v1);
Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
Assert.AreEqual(v1, v2);
}
[Test]
public void TestBigInteger()
{
BigInteger v1 = new BigInteger("983423442347324324324");
BigInteger v2 = (BigInteger)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestBigDecimal()
{
BigDecimal v1 = new BigDecimal(new BigInteger("9847324324324"), 45);
BigDecimal v2 = (BigDecimal)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestByteArray()
{
byte[] v1 = { 1, 2, 3 };
byte[] v2 = (byte[])CloneObject(v1);
Assert.AreEqual(3, v2.Length);
Assert.AreEqual(1, v2[0]);
Assert.AreEqual(2, v2[1]);
Assert.AreEqual(3, v2[2]);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestByte()
{
byte v1 = 51;
byte v2 = (byte)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestClasses()
{
Assert.AreEqual(typeof(bool),
CloneObject(typeof(bool)));
Assert.AreEqual(typeof(bool?),
CloneObject(typeof(bool?)));
Assert.AreEqual(typeof(bool[][]),
CloneObject(typeof(bool[][])));
Assert.AreEqual(typeof(bool?[][]),
CloneObject(typeof(bool?[][])));
Assert.AreEqual(typeof(char),
CloneObject(typeof(char)));
Assert.AreEqual(typeof(char?),
CloneObject(typeof(char?)));
//if this fails, we have added a new type and we need to add
//a serializer for it
Assert.IsTrue(
CollectionUtil.SetsEqual(
CollectionUtil.NewSet<Type, object>(FrameworkUtil.GetAllSupportedConfigTypes()),
(ICollection<object>)CloneObject(FrameworkUtil.GetAllSupportedConfigTypes())));
//if this fails, we have added a new type and we need to add
//a serializer for it
Assert.IsTrue(
CollectionUtil.SetsEqual(
CollectionUtil.NewSet<Type, object>(FrameworkUtil.GetAllSupportedAttributeTypes()),
(ICollection<object>)CloneObject(FrameworkUtil.GetAllSupportedAttributeTypes())));
ICollection<Type> apiOperations =
new HashSet<Type>();
foreach (SafeType<APIOperation> op in FrameworkUtil.AllAPIOperations())
{
apiOperations.Add(op.RawType);
}
//if this fails, need to add to the OperationMappings class
Assert.IsTrue(
CollectionUtil.SetsEqual(
CollectionUtil.NewSet<Type, object>(apiOperations),
(ICollection<object>)CloneObject(apiOperations)));
}
[Test]
public void TestArrays()
{
int[] v1 = { 1, 2, 3 };
int[] v2 = (int[])CloneObject(v1);
Assert.AreEqual(3, v2.Length);
Assert.AreEqual(1, v2[0]);
Assert.AreEqual(2, v2[1]);
Assert.AreEqual(3, v2[2]);
}
[Test]
public void TestObjectArrays()
{
object[] v1 = { "1", "2", "3" };
object[] v2 = (object[])CloneObject(v1);
Assert.AreEqual(3, v2.Length);
Assert.AreEqual("1", v2[0]);
Assert.AreEqual("2", v2[1]);
Assert.AreEqual("3", v2[2]);
}
[Test]
public void TestDictionary()
{
IDictionary<object, object> map = new Dictionary<object, object>();
map["key1"] = "val1";
map["key2"] = "val2";
IDictionary<object, object> map2 = (IDictionary<object, object>)CloneObject(map);
Assert.AreEqual("val1", map["key1"]);
Assert.AreEqual("val2", map["key2"]);
IDictionary<string, string> map3 = new Dictionary<string, string>();
map3["key1"] = "val1";
map3["key2"] = "val2";
IDictionary<object, object> map4 = (IDictionary<object, object>)CloneObject(map3);
Assert.AreEqual("val1", map4["key1"]);
Assert.AreEqual("val2", map4["key2"]);
}
[Test]
public void TestCaseInsensitiveMap()
{
HashSet<ConnectorAttribute> set = new HashSet<ConnectorAttribute>();
set.Add(ConnectorAttributeBuilder.Build("foo1"));
set.Add(ConnectorAttributeBuilder.Build("foo2"));
IDictionary<String, ConnectorAttribute> map = ConnectorAttributeUtil.ToMap(set);
Assert.IsTrue(map.ContainsKey("Foo1"));
Assert.IsTrue(map.ContainsKey("Foo2"));
IDictionary<String, object> map2 = (IDictionary<String, object>)CloneObject(map);
Assert.IsTrue(map2.ContainsKey("Foo1"));
Assert.IsTrue(map2.ContainsKey("Foo2"));
}
[Test]
public void TestList()
{
IList<Object> v1 = new List<Object>();
v1.Add("val1");
v1.Add("val2");
IList<Object> v2 = (IList<Object>)CloneObject(v1);
Assert.AreEqual(2, v2.Count);
Assert.AreEqual("val1", v2[0]);
Assert.AreEqual("val2", v2[1]);
IList<string> v3 = new List<string>();
v3.Add("val1");
v3.Add("val2");
IList<object> v4 = (IList<Object>)CloneObject(v3);
Assert.AreEqual(2, v4.Count);
Assert.AreEqual("val1", v4[0]);
Assert.AreEqual("val2", v4[1]);
}
[Test]
public void TestSet()
{
//underneath the covers, this creates an
//ICollection - we need to test that ICollection
//becomes a Set
ICollection<Object> v1 =
CollectionUtil.NewReadOnlySet<object>("val1", "val2");
HashSet<Object> v2 = (HashSet<Object>)CloneObject(v1);
Assert.AreEqual(2, v2.Count);
Assert.IsTrue(v2.Contains("val1"));
Assert.IsTrue(v2.Contains("val2"));
HashSet<string> v3 = new HashSet<string>();
v3.Add("val1");
v3.Add("val2");
HashSet<object> v4 = (HashSet<Object>)CloneObject(v3);
Assert.AreEqual(2, v4.Count);
Assert.IsTrue(v4.Contains("val1"));
Assert.IsTrue(v4.Contains("val2"));
}
[Test]
public void TestCaseInsensitiveSet()
{
ICollection<String> v1 = CollectionUtil.NewCaseInsensitiveSet();
v1.Add("foo");
v1.Add("foo2");
ICollection<String> v2 = (ICollection<String>)CloneObject(v1);
Assert.IsTrue(v2.Contains("Foo"));
Assert.IsTrue(v2.Contains("Foo2"));
}
[Test]
public void TestCultureInfo()
{
//use this one since it uses all 3 fields of locale
CultureInfo v1 = new CultureInfo("nn-NO");
CultureInfo v2 = (CultureInfo)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestObjectPoolConfiguration()
{
ObjectPoolConfiguration v1 = new ObjectPoolConfiguration();
v1.MaxObjects = 1;
v1.MaxIdle = 2;
v1.MaxWait = 3;
v1.MinEvictableIdleTimeMillis = 4;
v1.MinIdle = 5;
ObjectPoolConfiguration v2 =
(ObjectPoolConfiguration)CloneObject(v1);
Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
Assert.AreEqual(v1, v2);
Assert.AreEqual(1, v2.MaxObjects);
Assert.AreEqual(2, v2.MaxIdle);
Assert.AreEqual(3, v2.MaxWait);
Assert.AreEqual(4, v2.MinEvictableIdleTimeMillis);
Assert.AreEqual(5, v2.MinIdle);
}
[Test]
public void TestConfigurationProperty()
{
ConfigurationPropertyImpl v1 = new ConfigurationPropertyImpl();
v1.Order = (1);
v1.IsConfidential = (true);
v1.IsRequired = true;
v1.Name = ("foo");
v1.HelpMessageKey = ("help key");
v1.DisplayMessageKey = ("display key");
v1.GroupMessageKey = ("group key");
v1.Value = ("bar");
v1.ValueType = (typeof(string));
v1.Operations = FrameworkUtil.AllAPIOperations();
ConfigurationPropertyImpl v2 = (ConfigurationPropertyImpl)
CloneObject(v1);
Assert.AreEqual(1, v2.Order);
Assert.IsTrue(v2.IsConfidential);
Assert.IsTrue(v2.IsRequired);
Assert.AreEqual("foo", v2.Name);
Assert.AreEqual("help key", v2.HelpMessageKey);
Assert.AreEqual("display key", v2.DisplayMessageKey);
Assert.AreEqual("group key", v2.GroupMessageKey);
Assert.AreEqual("bar", v2.Value);
Assert.AreEqual(typeof(string), v2.ValueType);
Assert.IsTrue(CollectionUtil.Equals(
FrameworkUtil.AllAPIOperations(), v2.Operations));
}
[Test]
public void TestConfigurationProperties()
{
ConfigurationPropertyImpl prop1 = new ConfigurationPropertyImpl();
prop1.Order = (1);
prop1.IsConfidential = (true);
prop1.Name = ("foo");
prop1.HelpMessageKey = ("help key");
prop1.DisplayMessageKey = ("display key");
prop1.GroupMessageKey = ("group key");
prop1.Value = ("bar");
prop1.ValueType = (typeof(string));
prop1.Operations = null;
ConfigurationPropertiesImpl v1 = new ConfigurationPropertiesImpl();
v1.Properties = (CollectionUtil.NewReadOnlyList<ConfigurationPropertyImpl>(prop1));
v1.SetPropertyValue("foo", "bar");
ConfigurationPropertiesImpl v2 = (ConfigurationPropertiesImpl)
CloneObject(v1);
Assert.AreEqual("bar", v2.GetProperty("foo").Value);
}
[Test]
public void TestAPIConfiguration()
{
ConfigurationPropertyImpl prop1 = new ConfigurationPropertyImpl();
prop1.Order = (1);
prop1.IsConfidential = (true);
prop1.Name = ("foo");
prop1.HelpMessageKey = ("help key");
prop1.DisplayMessageKey = ("display key");
prop1.GroupMessageKey = ("group key");
prop1.Value = ("bar");
prop1.ValueType = (typeof(string));
prop1.Operations = null;
ConfigurationPropertiesImpl props1 = new ConfigurationPropertiesImpl();
props1.Properties = (CollectionUtil.NewReadOnlyList<ConfigurationPropertyImpl>(prop1));
APIConfigurationImpl v1 = new APIConfigurationImpl();
v1.ConnectorPoolConfiguration = (new ObjectPoolConfiguration());
v1.ConfigurationProperties = (props1);
v1.IsConnectorPoolingSupported = (true);
v1.ProducerBufferSize = (200);
v1.SupportedOperations = (FrameworkUtil.AllAPIOperations());
IDictionary<SafeType<APIOperation>, int> map =
CollectionUtil.NewDictionary<SafeType<APIOperation>, int>(SafeType<APIOperation>.Get<CreateApiOp>(), 6);
v1.TimeoutMap = (map);
APIConfigurationImpl v2 = (APIConfigurationImpl)
CloneObject(v1);
Assert.IsTrue(!Object.ReferenceEquals(v1, v2));
Assert.IsNotNull(v2.ConnectorPoolConfiguration);
Assert.IsNotNull(v2.ConfigurationProperties);
Assert.AreEqual(v1.ConnectorPoolConfiguration, v2.ConnectorPoolConfiguration);
Assert.AreEqual(v1.ConfigurationProperties, v2.ConfigurationProperties);
Assert.IsTrue(v2.IsConnectorPoolingSupported);
Assert.AreEqual(200, v2.ProducerBufferSize);
Assert.IsTrue(CollectionUtil.SetsEqual(
FrameworkUtil.AllAPIOperations(),
v2.SupportedOperations));
Assert.AreEqual(map, v2.TimeoutMap);
}
[Test]
public void TestConnectorMessages()
{
ConnectorMessagesImpl v1 = new ConnectorMessagesImpl();
IDictionary<String, String> defaultMap = new Dictionary<String, String>();
defaultMap["key1"] = "val1";
IDictionary<CultureInfo, IDictionary<String, String>> messages =
new Dictionary<CultureInfo, IDictionary<String, String>>();
messages[new CultureInfo("en")] = defaultMap;
messages[new CultureInfo("")] = defaultMap;
v1.Catalogs = (messages);
ConnectorMessagesImpl v2 = (ConnectorMessagesImpl)
CloneObject(v1);
Assert.IsTrue(
CollectionUtil.SetsEqual(messages[new CultureInfo("")],
v2.Catalogs[new CultureInfo("")]));
Assert.IsTrue(
CollectionUtil.SetsEqual(messages[new CultureInfo("en")],
v2.Catalogs[new CultureInfo("en")]));
}
[Test]
public void TestRemoteConnectorInfo()
{
RemoteConnectorInfoImpl v1 = new RemoteConnectorInfoImpl();
v1.Messages = (new ConnectorMessagesImpl());
v1.ConnectorKey = (new ConnectorKey("my bundle",
"my version",
"my connector"));
ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();
configProperties.Properties = (new List<ConfigurationPropertyImpl>());
APIConfigurationImpl apiImpl = new APIConfigurationImpl();
apiImpl.ConfigurationProperties = (configProperties);
v1.DefaultAPIConfiguration = (apiImpl);
v1.ConnectorDisplayNameKey = ("mykey");
v1.ConnectorCategoryKey = ("LDAP");
RemoteConnectorInfoImpl v2 = (RemoteConnectorInfoImpl)
CloneObject(v1);
Assert.IsNotNull(v2.Messages);
Assert.AreEqual("my bundle", v2.ConnectorKey.BundleName);
Assert.AreEqual("my version", v2.ConnectorKey.BundleVersion);
Assert.AreEqual("my connector", v2.ConnectorKey.ConnectorName);
Assert.AreEqual("mykey", v2.ConnectorDisplayNameKey);
Assert.AreEqual("LDAP", v2.ConnectorCategoryKey);
Assert.IsNotNull(v2.DefaultAPIConfiguration);
}
[Test]
public void TestAttribute()
{
ConnectorAttribute v1 = ConnectorAttributeBuilder.Build("foo", "val1", "val2");
ConnectorAttribute v2 = (ConnectorAttribute)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestAttributeInfo()
{
ConnectorAttributeInfoBuilder builder = new ConnectorAttributeInfoBuilder();
builder.Name = ("foo");
builder.ValueType = (typeof(String));
builder.Required = (true);
builder.Readable = (true);
builder.Creatable = (true);
builder.Updateable = (true);
builder.MultiValued = (true);
builder.ReturnedByDefault = false;
ConnectorAttributeInfo v1 = builder.Build();
ConnectorAttributeInfo v2 = (ConnectorAttributeInfo)CloneObject(v1);
Assert.AreEqual(v1, v2);
Assert.AreEqual("foo", v2.Name);
Assert.AreEqual(typeof(String), v2.ValueType);
Assert.IsTrue(v2.IsMultiValued);
Assert.IsTrue(v2.IsReadable);
Assert.IsTrue(v2.IsRequired);
Assert.IsTrue(v2.IsUpdateable);
Assert.IsTrue(v2.IsCreatable);
Assert.IsFalse(v2.IsReturnedByDefault);
builder.InfoFlags = AllFlags();
v1 = builder.Build();
v2 = (ConnectorAttributeInfo)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
private ConnectorAttributeInfo.Flags AllFlags()
{
ConnectorAttributeInfo.Flags flags =
ConnectorAttributeInfo.Flags.NONE;
foreach (Enum e in Enum.GetValues(typeof(ConnectorAttributeInfo.Flags)))
{
ConnectorAttributeInfo.Flags f =
(ConnectorAttributeInfo.Flags)e;
flags |= f;
}
return flags;
}
[Test]
public void TestConnectorObject()
{
ConnectorObjectBuilder bld = new ConnectorObjectBuilder();
bld.SetUid("foo");
bld.SetName("fooToo");
ConnectorObject v1 = bld.Build();
ConnectorObject v2 = (ConnectorObject)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestName()
{
Name v1 = new Name("Test");
Name v2 = (Name)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestObjectClass()
{
ObjectClass v1 = new ObjectClass("test");
ObjectClass v2 = (ObjectClass)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestObjectClassInfo()
{
ConnectorAttributeInfoBuilder builder = new ConnectorAttributeInfoBuilder();
builder.Name = ("foo");
builder.ValueType = (typeof(String));
builder.Required = (true);
builder.Readable = (true);
builder.Updateable = (true);
builder.MultiValued = (true);
ObjectClassInfoBuilder obld = new ObjectClassInfoBuilder();
obld.ObjectType = ObjectClass.ACCOUNT_NAME;
obld.IsContainer = true;
obld.AddAttributeInfo(builder.Build());
ObjectClassInfo v1 = obld.Build();
ObjectClassInfo v2 = (ObjectClassInfo)CloneObject(v1);
Assert.AreEqual(v1, v2);
Assert.IsTrue(v2.IsContainer);
}
[Test]
public void TestUid()
{
Uid v1 = new Uid("test");
Uid v2 = (Uid)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void testOperationOptionInfo()
{
OperationOptionInfo v1 =
new OperationOptionInfo("name", typeof(int?));
OperationOptionInfo v2 =
(OperationOptionInfo)CloneObject(v1);
Assert.AreEqual(v1, v2);
}
[Test]
public void TestSchema()
{
OperationOptionInfo opInfo =
new OperationOptionInfo("name", typeof(int?));
ObjectClassInfoBuilder bld = new ObjectClassInfoBuilder();
bld.ObjectType = ObjectClass.ACCOUNT_NAME;
ObjectClassInfo info = bld.Build();
ICollection<ObjectClassInfo> temp = CollectionUtil.NewSet(info);
IDictionary<SafeType<APIOperation>, ICollection<ObjectClassInfo>> map =
new Dictionary<SafeType<APIOperation>, ICollection<ObjectClassInfo>>();
map[SafeType<APIOperation>.Get<CreateApiOp>()] = temp;
ICollection<OperationOptionInfo> temp2 = CollectionUtil.NewSet(opInfo);
IDictionary<SafeType<APIOperation>, ICollection<OperationOptionInfo>> map2 =
new Dictionary<SafeType<APIOperation>, ICollection<OperationOptionInfo>>();
map2[SafeType<APIOperation>.Get<CreateApiOp>()] = temp2;
Schema v1 = new Schema(CollectionUtil.NewSet(info),
CollectionUtil.NewSet(opInfo),
map,
map2);
Schema v2 = (Schema)CloneObject(v1);
Assert.AreEqual(v1, v2);
Assert.AreEqual(info, v2.ObjectClassInfo.First());
Assert.AreEqual(1, v2.SupportedObjectClassesByOperation.Count);
Assert.AreEqual(1, v2.SupportedOptionsByOperation.Count);
Assert.AreEqual(1, v2.OperationOptionInfo.Count);
}
[Test]
public void TestContainsFilter()
{
ContainsFilter v1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
ContainsFilter v2 = (ContainsFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestAndFilter()
{
ContainsFilter left1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
ContainsFilter right1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo2", "bar2"));
AndFilter v1 = new AndFilter(left1, right1);
AndFilter v2 = (AndFilter)CloneObject(v1);
ContainsFilter left2 = (ContainsFilter)v2.Left;
ContainsFilter right2 = (ContainsFilter)v2.Right;
Assert.AreEqual(left1.GetAttribute(), left2.GetAttribute());
Assert.AreEqual(right1.GetAttribute(), right2.GetAttribute());
}
[Test]
public void TestEndsWithFilter()
{
EndsWithFilter v1 = new EndsWithFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
EndsWithFilter v2 = (EndsWithFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestEqualsFilter()
{
EqualsFilter v1 = new EqualsFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
EqualsFilter v2 = (EqualsFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestGreaterThanFilter()
{
GreaterThanFilter v1 = new GreaterThanFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
GreaterThanFilter v2 = (GreaterThanFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestGreaterThanOrEqualFilter()
{
GreaterThanOrEqualFilter v1 = new GreaterThanOrEqualFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
GreaterThanOrEqualFilter v2 = (GreaterThanOrEqualFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestLessThanFilter()
{
LessThanFilter v1 = new LessThanFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
LessThanFilter v2 = (LessThanFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestLessThanOrEqualFilter()
{
LessThanOrEqualFilter v1 = new LessThanOrEqualFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
LessThanOrEqualFilter v2 = (LessThanOrEqualFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestNotFilter()
{
ContainsFilter left1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
NotFilter v1 = new NotFilter(left1);
NotFilter v2 = (NotFilter)CloneObject(v1);
ContainsFilter left2 = (ContainsFilter)v2.Filter;
Assert.AreEqual(left1.GetAttribute(), left2.GetAttribute());
}
[Test]
public void TestOrFilter()
{
ContainsFilter left1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
ContainsFilter right1 = new ContainsFilter(ConnectorAttributeBuilder.Build("foo2", "bar2"));
OrFilter v1 = new OrFilter(left1, right1);
OrFilter v2 = (OrFilter)CloneObject(v1);
ContainsFilter left2 = (ContainsFilter)v2.Left;
ContainsFilter right2 = (ContainsFilter)v2.Right;
Assert.AreEqual(left1.GetAttribute(), left2.GetAttribute());
Assert.AreEqual(right1.GetAttribute(), right2.GetAttribute());
}
[Test]
public void TestStartsWithFilter()
{
StartsWithFilter v1 = new StartsWithFilter(ConnectorAttributeBuilder.Build("foo", "bar"));
StartsWithFilter v2 = (StartsWithFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestContainsAllValuesFilter()
{
ContainsAllValuesFilter v1 = new ContainsAllValuesFilter(ConnectorAttributeBuilder.Build("foo", "bar", "foo"));
ContainsAllValuesFilter v2 = (ContainsAllValuesFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
}
[Test]
public void TestPresenceFilter()
{
PresenceFilter v1 = new PresenceFilter("foo");
PresenceFilter v2 = (PresenceFilter)CloneObject(v1);
Assert.AreEqual(v1.Name, v2.Name);
}
[Test]
public void TestExtendedMatchFilter()
{
ExtendedMatchFilter v1 = new ExtendedMatchFilter("bar", ConnectorAttributeBuilder.Build("foo", "a", "b"));
ExtendedMatchFilter v2 = (ExtendedMatchFilter)CloneObject(v1);
Assert.AreEqual(v1.GetAttribute(), v2.GetAttribute());
Assert.AreEqual(v1.Operator, v2.Operator);
}
[Test]
public void TestExceptions()
{
{
AlreadyExistsException v1 = new AlreadyExistsException("ex");
AlreadyExistsException v2 = (AlreadyExistsException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
ConfigurationException v1 = new ConfigurationException("ex");
ConfigurationException v2 = (ConfigurationException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
ConnectionBrokenException v1 = new ConnectionBrokenException("ex");
ConnectionBrokenException v2 = (ConnectionBrokenException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
ConnectionFailedException v1 = new ConnectionFailedException("ex");
ConnectionFailedException v2 = (ConnectionFailedException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
ConnectorException v1 = new ConnectorException("ex");
ConnectorException v2 = (ConnectorException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
ConnectorIOException v1 = new ConnectorIOException("ex");
ConnectorIOException v2 = (ConnectorIOException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
ConnectorSecurityException v1 = new ConnectorSecurityException("ex");
ConnectorSecurityException v2 = (ConnectorSecurityException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
InvalidCredentialException v1 = new InvalidCredentialException("ex");
InvalidCredentialException v2 = (InvalidCredentialException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
InvalidPasswordException v1 = new InvalidPasswordException("ex");
InvalidPasswordException v2 = (InvalidPasswordException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
PasswordExpiredException v1 = new PasswordExpiredException("ex");
v1.Uid = (new Uid("myuid"));
PasswordExpiredException v2 = (PasswordExpiredException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
Assert.AreEqual("myuid", v2.Uid.GetUidValue());
}
{
OperationTimeoutException v1 = new OperationTimeoutException("ex");
OperationTimeoutException v2 = (OperationTimeoutException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
PermissionDeniedException v1 = new PermissionDeniedException("ex");
PermissionDeniedException v2 = (PermissionDeniedException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
UnknownUidException v1 = new UnknownUidException("ex");
UnknownUidException v2 = (UnknownUidException)CloneObject(v1);
Assert.AreEqual("ex", v2.Message);
}
{
ArgumentException v1 = new ArgumentException("my msg");
ArgumentException v2 = (ArgumentException)CloneObject(v1);
Assert.AreEqual("my msg", v2.Message);
}
{
ArgumentNullException v1 = new ArgumentNullException(null, "my msg 1");
ArgumentException v2 = (ArgumentException)CloneObject(v1);
Assert.AreEqual("my msg 1", v2.Message);
}
{
Exception v1 = new Exception("my msg2");
Exception v2 = (Exception)CloneObject(v1);
Assert.AreEqual("my msg2", v2.Message);
}
}
[Test]
public void TestHelloRequest()
{
HelloRequest v1 = new HelloRequest(HelloRequest.CONNECTOR_INFO);
HelloRequest v2 = (HelloRequest)CloneObject(v1);
Assert.IsNotNull(v2);
Assert.AreEqual(HelloRequest.CONNECTOR_INFO, v2.GetInfoLevel());
}
[Test]
public void TestHelloResponse()
{
Exception ex = new Exception("foo");
IDictionary<string, object> serverInfo = new Dictionary<string, object>(1);
serverInfo.Add(HelloResponse.SERVER_START_TIME, DateTimeUtil.GetCurrentUtcTimeMillis());
ConnectorKey key = new ConnectorKey("my bundle", "my version", "my connector");
RemoteConnectorInfoImpl info = new RemoteConnectorInfoImpl();
info.Messages = (new ConnectorMessagesImpl());
info.ConnectorKey = (key);
ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();
configProperties.Properties = (new List<ConfigurationPropertyImpl>());
APIConfigurationImpl apiImpl = new APIConfigurationImpl();
apiImpl.ConfigurationProperties = (configProperties);
info.DefaultAPIConfiguration = (apiImpl);
info.ConnectorDisplayNameKey = ("mykey");
info.ConnectorCategoryKey = ("");
HelloResponse v1 = new HelloResponse(ex, serverInfo, CollectionUtil.NewReadOnlyList<ConnectorKey>(key), CollectionUtil.NewReadOnlyList<RemoteConnectorInfoImpl>(info));
HelloResponse v2 = (HelloResponse)CloneObject(v1);
Assert.IsNotNull(v2.Exception);
Assert.IsNotNull(v2.ServerInfo[HelloResponse.SERVER_START_TIME]);
Assert.IsNotNull(v2.ConnectorKeys.First());
Assert.IsNotNull(v2.ConnectorInfos.First());
}
[Test]
public void TestOperationRequest()
{
ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();
configProperties.Properties = (new List<ConfigurationPropertyImpl>());
APIConfigurationImpl apiImpl = new APIConfigurationImpl();
apiImpl.ConfigurationProperties = (configProperties);
IList<object> args = new List<object>();
args.Add("my arg");
OperationRequest v1 = new
OperationRequest(new ConnectorKey("my bundle",
"my version",
"my connector"),
SerializerUtil.SerializeBase64Object(apiImpl),
SafeType<APIOperation>.Get<CreateApiOp>(),
"mymethodName",
args);
OperationRequest v2 = (OperationRequest)CloneObject(v1);
Assert.AreEqual("my bundle", v2.ConnectorKey.BundleName);
Assert.AreEqual("my version", v2.ConnectorKey.BundleVersion);
Assert.AreEqual("my connector", v2.ConnectorKey.ConnectorName);
Assert.IsNotNull(v2.ConnectorFacadeKey);
Assert.AreEqual(SafeType<APIOperation>.Get<CreateApiOp>(), v2.Operation);
Assert.AreEqual("mymethodName", v2.OperationMethodName);
Assert.IsTrue(
CollectionUtil.Equals(