forked from dosoudil/maven-repository-builder
-
Notifications
You must be signed in to change notification settings - Fork 12
/
tests.py
executable file
·726 lines (623 loc) · 34.5 KB
/
tests.py
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
#!/usr/bin/env python2
""" tests.py: Unit tests for maven repo builder and related tools"""
import logging
import os
import tempfile
import unittest
import copy
import artifact_list_builder
import configuration
import maven_repo_util
from indy_apis import IndyApi
from artifact_list_builder import ArtifactListBuilder, ArtifactSpec, ArtifactType
from maven_repo_util import ChecksumMode
from maven_artifact import MavenArtifact
from configuration import Configuration
from filter import Filter
class Tests(unittest.TestCase):
indyUrl = 'http://dev208.mw.lab.eng.bos.redhat.com:8080/'
artifactList = {
"com.google.guava:guava": {
"1": {
"1.0.0": ArtifactSpec("http://repo1.maven.org/maven2/", [ArtifactType("pom", True, set(['']))]),
"1.0.1": ArtifactSpec("http://repo1.maven.org/maven2/", [ArtifactType("pom", True, set(['']))]),
"1.1.0": ArtifactSpec("http://repo1.maven.org/maven2/", [ArtifactType("pom", True, set(['']))])},
"2": {
"1.0.2": ArtifactSpec("http://repo2.maven.org/maven2/", [ArtifactType("pom", True, set(['']))])},
"3": {
"1.2.0": ArtifactSpec("http://repo3.maven.org/maven2/", [ArtifactType("pom", True, set(['']))]),
"1.0.0": ArtifactSpec("http://repo3.maven.org/maven2/", [ArtifactType("pom", True, set(['']))])}},
"org.jboss:jboss-foo": {
"1": {
"1.0.0": ArtifactSpec("http://repo1.maven.org/maven2/", [ArtifactType("jar", True, set(['']))]),
"1.0.1": ArtifactSpec("http://repo1.maven.org/maven2/", [ArtifactType("jar", True, set(['']))]),
"1.1.0": ArtifactSpec("http://repo1.maven.org/maven2/", [ArtifactType("jar", True, set(['']))])},
"2": {
"1.0.1": ArtifactSpec("http://repo2.maven.org/maven2/", [ArtifactType("jar", True, set(['']))]),
"1.0.2": ArtifactSpec("http://repo2.maven.org/maven2/", [ArtifactType("jar", True, set(['']))])}}}
def setUp(self):
logging.basicConfig(format="%(levelname)s (%(threadName)s): %(message)s", level=logging.DEBUG)
def test_url_download(self):
# make sure the shuffled sequence does not lose any elements
url = "http://repo1.maven.org/maven2/org/jboss/jboss-parent/10/jboss-parent-10.pom"
tempDownloadDir = tempfile.mkdtemp()
filepath = os.path.join(tempDownloadDir, "downloadfile.txt")
self.assertFalse(os.path.exists(filepath), "Download file already exists: " + filepath)
maven_repo_util.download(url, filepath, ChecksumMode.generate)
self.assertTrue(os.path.exists(filepath), "File not downloaded")
maven_repo_util.download(url, None, ChecksumMode.generate)
localfilename = "jboss-parent-10.pom"
self.assertTrue(os.path.exists(localfilename))
if os.path.exists(localfilename):
logging.debug('Removing temp local file: ' + localfilename)
os.remove(localfilename)
def test_bad_urls(self):
url = "junk://repo1.maven.org/maven2/org/jboss/jboss-parent/10/jboss-parent-10.p"
maven_repo_util.download(url, None, ChecksumMode.generate)
url = "sadjfasfjsl"
maven_repo_util.download(url, None, ChecksumMode.generate)
url = "http://1234/maven2/org/jboss/jboss-parent/10/jboss-parent-10.p"
maven_repo_util.download(url, None, ChecksumMode.generate)
def test_http_404(self):
url = "http://repo1.maven.org/maven2/somefilethatdoesnotexist"
code = maven_repo_util.download(url, None, ChecksumMode.generate)
self.assertEqual(code, 404)
def test_maven_artifact(self):
artifact1 = MavenArtifact.createFromGAV("org.jboss:jboss-parent:pom:10")
self.assertEqual(artifact1.groupId, "org.jboss")
self.assertEqual(artifact1.artifactId, "jboss-parent")
self.assertEqual(artifact1.version, "10")
self.assertEqual(artifact1.getArtifactType(), "pom")
self.assertEqual(artifact1.getClassifier(), "")
self.assertEqual(artifact1.getArtifactFilename(), "jboss-parent-10.pom")
self.assertEqual(artifact1.getArtifactFilepath(), "org/jboss/jboss-parent/10/jboss-parent-10.pom")
artifact2 = MavenArtifact.createFromGAV("org.jboss:jboss-foo:jar:1.0")
self.assertEqual(artifact2.getArtifactFilepath(), "org/jboss/jboss-foo/1.0/jboss-foo-1.0.jar")
self.assertEqual(artifact2.getPomFilepath(), "org/jboss/jboss-foo/1.0/jboss-foo-1.0.pom")
self.assertEqual(artifact2.getSourcesFilepath(), "org/jboss/jboss-foo/1.0/jboss-foo-1.0-sources.jar")
artifact3 = MavenArtifact.createFromGAV("org.jboss:jboss-test:jar:client:2.0.0.Beta1")
self.assertEqual(artifact3.getClassifier(), "client")
self.assertEqual(artifact3.getArtifactFilename(), "jboss-test-2.0.0.Beta1-client.jar")
self.assertEqual(artifact3.getArtifactFilepath(),
"org/jboss/jboss-test/2.0.0.Beta1/jboss-test-2.0.0.Beta1-client.jar")
artifact4 = MavenArtifact.createFromGAV("org.acme:jboss-bar:jar:1.0-alpha-1:compile")
self.assertEqual(artifact4.getArtifactFilepath(), "org/acme/jboss-bar/1.0-alpha-1/jboss-bar-1.0-alpha-1.jar")
artifact5 = MavenArtifact.createFromGAV("com.google.guava:guava:pom:r05")
self.assertEqual(artifact5.groupId, "com.google.guava")
self.assertEqual(artifact5.artifactId, "guava")
self.assertEqual(artifact5.version, "r05")
self.assertEqual(artifact5.getArtifactType(), "pom")
self.assertEqual(artifact5.getClassifier(), "")
self.assertEqual(artifact5.getArtifactFilename(), "guava-r05.pom")
def test_filter_excluded_GAVs(self):
config = Configuration()
alf = Filter(config)
config.excludedGAVs = ["com.google.guava:guava:1.1.0"]
al = copy.deepcopy(self.artifactList)
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
alf._filterExcludedGAVs(al)
self.assertFalse('1.1.0' in al['com.google.guava:guava']['1'])
config.excludedGAVs = ["com.google.guava:guava:1.0*"]
al = copy.deepcopy(self.artifactList)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.2' in al['com.google.guava:guava']['2'])
self.assertTrue('1.0.0' in al['com.google.guava:guava']['3'])
alf._filterExcludedGAVs(al)
self.assertFalse('1.0.0' in al['com.google.guava:guava']['1'])
self.assertFalse('1.0.1' in al['com.google.guava:guava']['1'])
self.assertFalse('2' in al['com.google.guava:guava'])
self.assertFalse('1.0.0' in al['com.google.guava:guava']['3'])
config.excludedGAVs = ["com.google.guava:*"]
al = copy.deepcopy(self.artifactList)
self.assertTrue('com.google.guava:guava' in al)
alf._filterExcludedGAVs(al)
self.assertFalse('com.google.guava:guava' in al)
def test_filter_excludedTypes(self):
config = Configuration()
alf = Filter(config)
config.excludedTypes = ["zip", "war"]
al = copy.deepcopy(self.artifactList)
al["foo:bar"] = {
"1": {
"1.0.0": ArtifactSpec("http://repo1.maven.org/maven2/",
[ArtifactType("zip", True, set([''])), ArtifactType("pom", False, set(['']))])
}
}
alf._filterExcludedTypes(al)
self.assertFalse('foo:bar' in al)
al["foo:bar"] = {
"1": {
"1.0.0": ArtifactSpec("http://repo1.maven.org/maven2/",
[ArtifactType("zip", True, set([''])), ArtifactType("pom", False, set(['']))])
}
}
config.gatcvWhitelist = ["*:zip:scm-sources:*"]
alf._filterExcludedTypes(al)
self.assertFalse('foo:bar' in al)
al["foo:bar"] = {
"1": {
"1.0.0": ArtifactSpec("http://repo1.maven.org/maven2/",
[ArtifactType("zip", True, set(['scm-sources'])),
ArtifactType("pom", False, set(['']))])
}
}
alf._filterExcludedTypes(al)
self.assertTrue('foo:bar' in al)
def test_filter_duplicates(self):
config = Configuration()
alf = Filter(config)
al = copy.deepcopy(self.artifactList)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.0' in al['com.google.guava:guava']['3'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['2'])
alf._filterDuplicates(al)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertFalse('1.0.0' in al['com.google.guava:guava']['3'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertFalse('1.0.1' in al['org.jboss:jboss-foo']['2'])
def test_ArtifactListBuilder_getPrefixes(self):
i = ["org.abc.def:qwer:1.0.1", "org.abc.def:qwer:1.2.1",
"org.abc.def:qwera:1.*", "org.abc.def:qwera:2.0",
"org.abc.ret:popo:2.0", "org.abc.ret:papa:*",
"org.abc.zir:fgh:1.2.3", "org.abc.zir:fgh:*",
"org.abc.zir:*:*", "org.abc.zar:*", "org.zui.zor*",
"r/eu\.test\.qwe:.*:.*/", "r/eu\.trest\..*/",
"r/com\.part[abc]\.poiu:mark:1\.0/",
"r/ru\.uju\.mnou:jaja:1\.[23].*/"]
o = set(["org/abc/def/qwer/1.0.1/", "org/abc/def/qwer/1.2.1/",
"org/abc/def/qwera/", "org/abc/ret/popo/2.0/",
"org/abc/ret/papa/", "org/abc/zir/",
"org/abc/zar/", "org/zui/",
"eu/test/qwe/", "eu/trest/",
"com/", "ru/uju/mnou/jaja/"])
config = Configuration()
alb = ArtifactListBuilder(config)
out = alb._getPrefixes(i)
self.assertEqual(out, o)
i = ["org.abc.def:qwer:1.0.1", "org.abc.def:qwer:1.2.1",
"r/r.\..*/"]
o = set([""])
out = alb._getPrefixes(i)
self.assertEqual(out, o)
i = ["org.abc.def:qwer:1.0.1", "org.abc.def:qwer:1.2.1",
"r/(org|com).*/"]
o = set([""])
out = alb._getPrefixes(i)
self.assertEqual(out, o)
i = []
o = set([""])
out = alb._getPrefixes(i)
self.assertEqual(out, o)
def test_filter_multiple_versions(self):
config = Configuration()
config.singleVersion = True
alf = Filter(config)
al = copy.deepcopy(self.artifactList)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertTrue('2' in al['com.google.guava:guava'])
self.assertTrue('3' in al['com.google.guava:guava'])
self.assertTrue('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('2' in al['org.jboss:jboss-foo'])
alf._filterMultipleVersions(al)
self.assertFalse('1.0.0' in al['com.google.guava:guava']['1'])
self.assertFalse('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertFalse('2' in al['com.google.guava:guava'])
self.assertFalse('3' in al['com.google.guava:guava'])
self.assertFalse('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertFalse('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertFalse('2' in al['org.jboss:jboss-foo'])
config.multiVersionGAs = ["com.google.guava:guava"]
al = copy.deepcopy(self.artifactList)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertTrue('2' in al['com.google.guava:guava'])
self.assertTrue('3' in al['com.google.guava:guava'])
self.assertTrue('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('2' in al['org.jboss:jboss-foo'])
alf._filterMultipleVersions(al)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertTrue('2' in al['com.google.guava:guava'])
self.assertTrue('3' in al['com.google.guava:guava'])
self.assertFalse('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertFalse('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertFalse('2' in al['org.jboss:jboss-foo'])
config.multiVersionGAs = ["*:jboss-foo"]
al = copy.deepcopy(self.artifactList)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertTrue('2' in al['com.google.guava:guava'])
self.assertTrue('3' in al['com.google.guava:guava'])
self.assertTrue('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('2' in al['org.jboss:jboss-foo'])
alf._filterMultipleVersions(al)
self.assertFalse('1.0.0' in al['com.google.guava:guava']['1'])
self.assertFalse('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertFalse('2' in al['com.google.guava:guava'])
self.assertFalse('3' in al['com.google.guava:guava'])
self.assertTrue('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('2' in al['org.jboss:jboss-foo'])
config.multiVersionGAs = ["r/.*:jboss-foo/"]
al = copy.deepcopy(self.artifactList)
self.assertTrue('1.0.0' in al['com.google.guava:guava']['1'])
self.assertTrue('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertTrue('2' in al['com.google.guava:guava'])
self.assertTrue('3' in al['com.google.guava:guava'])
self.assertTrue('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('2' in al['org.jboss:jboss-foo'])
alf._filterMultipleVersions(al)
self.assertFalse('1.0.0' in al['com.google.guava:guava']['1'])
self.assertFalse('1.0.1' in al['com.google.guava:guava']['1'])
self.assertTrue('1.1.0' in al['com.google.guava:guava']['1'])
self.assertFalse('2' in al['com.google.guava:guava'])
self.assertFalse('3' in al['com.google.guava:guava'])
self.assertTrue('1.0.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.0.1' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('1.1.0' in al['org.jboss:jboss-foo']['1'])
self.assertTrue('2' in al['org.jboss:jboss-foo'])
def _getExpectedArtifacts(self, repoUrl, dependencies):
artSpecDict = {}
for dep in dependencies.keys():
artifact = MavenArtifact.createFromGAV(dep)
artTypes = []
artTypes.append(ArtifactType(artifact.artifactType, artifact.artifactType != "pom", dependencies[dep]))
artSpec = ArtifactSpec(repoUrl, artTypes)
gav = artifact.getGAV()
if gav in artSpecDict.keys():
artSpecDict[gav].merge(artSpec)
else:
artSpecDict[gav] = artSpec
expectedArtifacts = {}
for (gav, artSpec) in artSpecDict.iteritems():
artifact = MavenArtifact.createFromGAV(gav)
expectedArtifacts[artifact] = artSpec
return expectedArtifacts
def test_listDependencies(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
repoUrls = ['http://repo.maven.apache.org/maven2/']
gavs = [
'com.sun.faces:jsf-api:2.0.11',
'org.apache.ant:ant:1.8.0'
]
dependencies = {
'javax.servlet:javax.servlet-api:pom:3.0.1': set(['']),
'javax.servlet:javax.servlet-api:jar:3.0.1': set(['', 'javadoc', 'sources']),
'javax.servlet.jsp.jstl:jstl-api:pom:1.2': set(['']),
'javax.servlet.jsp.jstl:jstl-api:jar:1.2': set(['', 'javadoc', 'sources']),
'xml-apis:xml-apis:pom:1.3.04': set(['']),
'xml-apis:xml-apis:jar:1.3.04': set(['', 'source', 'sources']),
'javax.servlet:servlet-api:pom:2.5': set(['']),
'javax.servlet:servlet-api:jar:2.5': set(['', 'sources']),
'javax.el:javax.el-api:pom:2.2.1': set(['']),
'javax.el:javax.el-api:jar:2.2.1': set(['', 'javadoc', 'sources']),
'junit:junit:pom:3.8.2': set(['']),
'junit:junit:jar:3.8.2': set(['', 'javadoc', 'sources']),
'xerces:xercesImpl:pom:2.9.0': set(['']),
'xerces:xercesImpl:jar:2.9.0': set(['']),
'javax.servlet.jsp:jsp-api:pom:2.1': set(['']),
'javax.servlet.jsp:jsp-api:jar:2.1': set(['', 'sources']),
'javax.servlet.jsp:javax.servlet.jsp-api:pom:2.2.1': set(['']),
'javax.servlet.jsp:javax.servlet.jsp-api:jar:2.2.1': set(['', 'javadoc', 'sources']),
'org.apache.ant:ant-launcher:pom:1.8.0': set(['']),
'org.apache.ant:ant-launcher:jar:1.8.0': set([''])
}
expectedArtifacts = self._getExpectedArtifacts(repoUrls[0], dependencies)
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listDependencies(repoUrls, gavs, False, None, False)
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_listDependencies_recursive(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
repoUrls = ['http://repo.maven.apache.org/maven2/']
gavs = [
'com.sun.faces:jsf-api:2.0.11',
'org.apache.ant:ant:1.8.0'
]
dependencies = {
'junit:junit:pom:3.8.2': set(['']),
'junit:junit:jar:3.8.2': set(['', 'sources', 'javadoc']),
'xerces:xercesImpl:pom:2.9.0': set(['']),
'xerces:xercesImpl:jar:2.9.0': set(['']),
'xml-apis:xml-apis:pom:1.3.04': set(['']),
'xml-apis:xml-apis:jar:1.3.04': set(['', 'source', 'sources']),
'javax.el:javax.el-api:pom:2.2.1': set(['']),
'javax.el:javax.el-api:jar:2.2.1': set(['', 'sources', 'javadoc']),
'xml-resolver:xml-resolver:pom:1.2': set(['']),
'xml-resolver:xml-resolver:jar:1.2': set(['', 'sources']),
'javax.servlet:servlet-api:pom:2.5': set(['']),
'javax.servlet:servlet-api:jar:2.5': set(['', 'sources']),
'javax.servlet.jsp:jsp-api:pom:2.1': set(['']),
'javax.servlet.jsp:jsp-api:jar:2.1': set(['', 'sources']),
'org.apache.ant:ant-launcher:pom:1.8.0': set(['']),
'org.apache.ant:ant-launcher:jar:1.8.0': set(['']),
'javax.servlet.jsp.jstl:jstl-api:pom:1.2': set(['']),
'javax.servlet.jsp.jstl:jstl-api:jar:1.2': set(['', 'sources', 'javadoc']),
'javax.servlet:javax.servlet-api:pom:3.0.1': set(['']),
'javax.servlet:javax.servlet-api:jar:3.0.1': set(['', 'sources', 'javadoc']),
'javax.servlet.jsp:javax.servlet.jsp-api:pom:2.2.1': set(['']),
'javax.servlet.jsp:javax.servlet.jsp-api:jar:2.2.1': set(['', 'sources', 'javadoc'])
}
expectedArtifacts = self._getExpectedArtifacts(repoUrls[0], dependencies)
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listDependencies(repoUrls, gavs, True, None, False)
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_listDependencyGraph_allclassifiers(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
sourceKey = "repository:central"
topGavs = [
'org.apache.ant:ant:1.8.0'
]
dependencies = {
'org.apache.ant:ant:pom:1.8.0': set(['']),
'org.apache.ant:ant:jar:1.8.0': set(['']),
'org.apache.ant:ant-launcher:pom:1.8.0': set(['']),
'org.apache.ant:ant-launcher:jar:1.8.0': set(['']),
'org.apache.ant:ant-parent:pom:1.8.0': set(['']),
'org.apache:apache:pom:3': set(['']),
'org.apache:apache:pom:4': set(['']),
'xerces:xercesImpl:pom:2.9.0': set(['']),
'xerces:xercesImpl:jar:2.9.0': set(['']),
'xml-apis:xml-apis:pom:1.3.04': set(['']),
'xml-apis:xml-apis:jar:1.3.04': set(['', 'source', 'sources']),
'xml-resolver:xml-resolver:pom:1.2': set(['']),
'xml-resolver:xml-resolver:jar:1.2': set(['', 'sources'])
}
expectedArtifacts = self._getExpectedArtifacts(self.indyUrl, dependencies)
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listDependencyGraph(self.indyUrl, None, sourceKey, topGavs)
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_listDependencyGraph_specified_classifiers(self):
config = configuration.Configuration()
config.addClassifiers = config._parseClassifiers("sources,dummy")
sourceKey = "repository:central"
topGavs = [
'org.apache.ant:ant:1.8.0'
]
dependencies = {
'org.apache.ant:ant:pom:1.8.0': set(['']),
#'org.apache.ant:ant:jar:1.8.0': set(['']),
'org.apache.ant:ant-launcher:pom:1.8.0': set(['']),
'org.apache.ant:ant-launcher:jar:1.8.0': set(['']),
'org.apache.ant:ant-parent:pom:1.8.0': set(['']),
'org.apache:apache:pom:3': set(['']),
'org.apache:apache:pom:4': set(['']),
'xerces:xercesImpl:pom:2.9.0': set(['']),
'xerces:xercesImpl:jar:2.9.0': set(['']),
'xml-apis:xml-apis:pom:1.3.04': set(['']),
'xml-apis:xml-apis:jar:1.3.04': set(['', 'sources']),
'xml-resolver:xml-resolver:pom:1.2': set(['']),
'xml-resolver:xml-resolver:jar:1.2': set(['', 'sources'])
}
expectedArtifacts = self._getExpectedArtifacts(self.indyUrl, dependencies)
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listDependencyGraph(self.indyUrl, None, sourceKey, topGavs)
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_listDependencyGraph(self):
config = configuration.Configuration()
config.addClassifiers = ""
sourceKey = "repository:central"
topGavs = [
'org.apache.ant:ant:1.8.0'
]
dependencies = {
'org.apache.ant:ant:pom:1.8.0': set(['']),
#'org.apache.ant:ant:jar:1.8.0': set(['']),
'org.apache.ant:ant-launcher:pom:1.8.0': set(['']),
'org.apache.ant:ant-launcher:jar:1.8.0': set(['']),
'org.apache.ant:ant-parent:pom:1.8.0': set(['']),
'org.apache:apache:pom:3': set(['']),
'org.apache:apache:pom:4': set(['']),
'xerces:xercesImpl:pom:2.9.0': set(['']),
'xerces:xercesImpl:jar:2.9.0': set(['']),
'xml-apis:xml-apis:pom:1.3.04': set(['']),
'xml-apis:xml-apis:jar:1.3.04': set(['']),
'xml-resolver:xml-resolver:pom:1.2': set(['']),
'xml-resolver:xml-resolver:jar:1.2': set([''])
}
expectedArtifacts = self._getExpectedArtifacts(self.indyUrl, dependencies)
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listDependencyGraph(self.indyUrl, None, sourceKey, topGavs)
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_indyCreateDeleteWorkspace(self):
indyApi = IndyApi(self.indyUrl)
ws = indyApi.createWorkspace()
wsid = ws["id"]
delResult = indyApi.deleteWorkspace(wsid)
self.assertTrue(delResult)
def test_listMeadTagArtifacts(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
kojiUrl = "http://brewhub.devel.redhat.com/brewhub/"
tagName = "mead-import-maven"
downloadRootUrl = "http://download.devel.redhat.com/brewroot/packages/"
gavPatts = [
'org.apache.maven:maven-core:2.0.6'
]
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listMeadTagArtifacts(kojiUrl, downloadRootUrl, tagName, gavPatts)
expectedUrl = downloadRootUrl + "org.apache.maven-maven-core/2.0.6/1/maven/"
expectedArtifacts = {
MavenArtifact.createFromGAV(gavPatts[0]): ArtifactSpec(expectedUrl, [
ArtifactType("pom", True, set([''])),
ArtifactType("jar", True, set(['', 'javadoc', 'sources']))])
}
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_listRepository_http(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
repoUrls = ['http://repo.maven.apache.org/maven2/']
gavPatts = [
'com.sun.faces:jsf-api:2.0.11',
'org.apache.ant:ant:1.8.0'
]
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listRepository(repoUrls, gavPatts, None)
expectedArtifacts = {
MavenArtifact.createFromGAV(gavPatts[0]): ArtifactSpec(repoUrls[0], [ArtifactType("pom", True, set([''])),
ArtifactType("jar", True, set(['', 'javadoc', 'sources']))]),
MavenArtifact.createFromGAV(gavPatts[1]): ArtifactSpec(repoUrls[0], [ArtifactType("pom", True, set([''])),
ArtifactType("jar", True, set(['']))])
}
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_listRepository_file(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
repoUrls = ['file://./tests/testrepo']
gavPatts = [
'bar:foo-bar:1.1',
'foo.baz:baz-core:1.0'
]
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listRepository(repoUrls, gavPatts, None)
expectedArtifacts = {
MavenArtifact.createFromGAV(gavPatts[0]): ArtifactSpec(repoUrls[0], [ArtifactType("pom", True, set(['']))]),
MavenArtifact.createFromGAV(gavPatts[1]): ArtifactSpec(repoUrls[0], [ArtifactType("pom", True, set([''])),
ArtifactType("jar", True, set(['', 'javadoc', 'sources']))])
}
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test_listRepository_file_gatcvs(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
repoUrls = ['file://./tests/testrepo']
gatcvs = [
'bar:foo-bar:pom:1.1',
'foo.baz:baz-core:jar:1.0'
]
builder = artifact_list_builder.ArtifactListBuilder(config)
actualArtifacts = builder._listRepository(repoUrls, None, gatcvs)
expectedArtifacts = {
MavenArtifact.createFromGAV(gatcvs[0]): ArtifactSpec(repoUrls[0], [ArtifactType("pom", True, set(['']))]),
MavenArtifact.createFromGAV(gatcvs[1]): ArtifactSpec(repoUrls[0], [ArtifactType("pom", True, set([''])),
ArtifactType("jar", True, set(['', 'javadoc', 'sources']))])
}
self.assertEqualArtifactList(expectedArtifacts, actualArtifacts)
def test__getExtensionsAndClassifiers_dot_in_classifier(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
artifactId = 'showcase-distribution-wars'
version = '0.3.3-redhat-8'
filenames = ['showcase-distribution-wars-0.3.3-redhat-8-jboss-as7.0.war']
builder = artifact_list_builder.ArtifactListBuilder(config)
extsAndClasss = builder._getExtensionsAndClassifiers(artifactId, version, filenames)[0]
self.assertEqual(len(extsAndClasss), 1)
self.assertTrue("war" in extsAndClasss)
self.assertEqual(extsAndClasss["war"], set(["jboss-as7.0"]))
def test__getExtensionsAndClassifiers_md5_of_dot_in_classifier(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
artifactId = 'showcase-distribution-wars'
version = '0.3.3-redhat-8'
filenames = ["showcase-distribution-wars-0.3.3-redhat-8-jboss-as7.0.war.md5"]
builder = artifact_list_builder.ArtifactListBuilder(config)
extsAndClasss = builder._getExtensionsAndClassifiers(artifactId, version, filenames)[0]
self.assertEqual(len(extsAndClasss), 0)
def test__getExtensionsAndClassifiers_dot_in_classifier_tar_gz(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
artifactId = 'showcase-distribution-wars'
version = '0.3.3-redhat-8'
filenames = ["showcase-distribution-wars-0.3.3-redhat-8-jboss-as7.0.tar.gz"]
builder = artifact_list_builder.ArtifactListBuilder(config)
extsAndClasss = builder._getExtensionsAndClassifiers(artifactId, version, filenames)[0]
self.assertEqual(len(extsAndClasss), 1)
self.assertTrue("tar.gz" in extsAndClasss)
self.assertEqual(extsAndClasss["tar.gz"], set(["jboss-as7.0"]))
def test__getExtensionsAndClassifiers_md5_of_dot_in_classifier_tar_gz(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
artifactId = 'showcase-distribution-wars'
version = '0.3.3-redhat-8'
filenames = ["showcase-distribution-wars-0.3.3-redhat-8-jboss-as7.0.tar.gz.md5"]
builder = artifact_list_builder.ArtifactListBuilder(config)
extsAndClasss = builder._getExtensionsAndClassifiers(artifactId, version, filenames)[0]
self.assertEqual(len(extsAndClasss), 0)
def test__getExtensionsAndClassifiers_no_classifier(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
artifactId = 'showcase-distribution-wars'
version = '0.3.3-redhat-8'
filenames = ["showcase-distribution-wars-0.3.3-redhat-8.pom"]
builder = artifact_list_builder.ArtifactListBuilder(config)
extsAndClasss = builder._getExtensionsAndClassifiers(artifactId, version, filenames)[0]
self.assertEqual(len(extsAndClasss), 1)
self.assertTrue("pom" in extsAndClasss)
self.assertEqual(extsAndClasss["pom"], set([""]))
def test__getExtensionsAndClassifiers_tar_gz(self):
config = configuration.Configuration()
config.addClassifiers = "__all__"
artifactId = 'showcase-distribution-wars'
version = '0.3.3-redhat-8'
filenames = ["showcase-distribution-wars-0.3.3-redhat-8.tar.gz"]
builder = artifact_list_builder.ArtifactListBuilder(config)
extsAndClasss = builder._getExtensionsAndClassifiers(artifactId, version, filenames)[0]
self.assertEqual(len(extsAndClasss), 1)
self.assertTrue("tar.gz" in extsAndClasss)
self.assertEqual(extsAndClasss["tar.gz"], set([""]))
def test_parseClassifiers(self):
config = Configuration()
classifiers = config._parseClassifiers("sources")
expectedClassifiers = [{"classifier": "sources", "type": "jar"}]
self.assertEquals(expectedClassifiers, classifiers)
classifiers = config._parseClassifiers("jar:sources")
expectedClassifiers = [{"classifier": "sources", "type": "jar"}]
self.assertEquals(expectedClassifiers, classifiers)
classifiers = config._parseClassifiers("sources,javadoc,zip:scm-sources")
expectedClassifiers = [{"classifier": "sources", "type": "jar"}, {"classifier": "javadoc", "type": "jar"},
{"classifier": "scm-sources", "type": "zip"}]
self.assertEquals(expectedClassifiers, classifiers)
def assertEqualArtifactList(self, expectedArtifacts, actualArtifacts):
strExp = self._artifactListToString(expectedArtifacts, " expected", "\n ")
strAct = self._artifactListToString(actualArtifacts, " actual", "\n ")
logging.debug("Comparing artifact lists:\n%s\n%s", strExp, strAct)
# Assert that length of expectedArtifacts is the same as of actualArtifacts
self.assertEqual(len(expectedArtifacts), len(actualArtifacts))
# Assert that artifact list contains all dependencies with correct classifiers
for expectedArtifact in expectedArtifacts:
foundArtifact = None
for actualArtifact in actualArtifacts:
if actualArtifact.getGAV() == expectedArtifact.getGAV():
foundArtifact = actualArtifact
self.assertTrue(foundArtifact is not None)
logging.debug("Checking types of %s", expectedArtifact)
self.assertEquals(expectedArtifacts[expectedArtifact].artTypes.keys(),
actualArtifacts[foundArtifact].artTypes.keys())
for artType in actualArtifacts[foundArtifact].artTypes:
foundClassifiers = actualArtifacts[foundArtifact].artTypes[artType].classifiers
expectedType = expectedArtifacts[expectedArtifact].artTypes[artType]
expectedClassifiers = expectedType.classifiers
logging.debug("Checking found classifiers (%s, expected are %s) of %s:%s:%s", foundClassifiers,
expectedClassifiers, foundArtifact.getGA(), artType, foundArtifact.version)
self.assertEquals(expectedClassifiers, foundClassifiers)
def _artifactListToString(self, artifactList, listName, separator):
strList = []
for artifact in artifactList:
strList.append(str(artifact))
strList.sort()
strList.insert(0, listName + ":")
return separator.join(strList)
if __name__ == '__main__':
unittest.main()