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 package org.codehaus.mojo.license.model;
27
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 import java.io.IOException;
33 import java.net.URL;
34 import java.util.Arrays;
35 import java.util.List;
36
37
38
39
40
41
42
43 public class LicenseStoreTest
44 {
45
46 public static final List<String> DEFAULT_LICENSES =
47 Arrays.asList( "agpl_v3", "apache_v2", "cddl_v1", "fdl_v1_3", "gpl_v1", "gpl_v2", "gpl_v3", "lgpl_v2_1",
48 "lgpl_v3", "mit" );
49
50 public static final List<String> NEW_LICENSES = Arrays.asList( "license1", "license2" );
51
52 protected LicenseStore store;
53
54 @Before
55 public void setUp()
56 {
57 store = null;
58 }
59
60 @Test
61 public void testJarRepository()
62 throws IOException
63 {
64
65 store = new LicenseStore();
66 store.init();
67
68 List<LicenseRepository> repositories = store.getRepositories();
69 Assert.assertNotNull( repositories );
70 Assert.assertEquals( 1, repositories.size() );
71 LicenseRepository repository = repositories.get( 0 );
72
73 License[] licenses1 = repository.getLicenses();
74 License[] licenses = store.getLicenses();
75 Assert.assertNotNull( licenses );
76 Assert.assertNotNull( licenses1 );
77 Assert.assertEquals( DEFAULT_LICENSES.size(), licenses.length );
78 Assert.assertEquals( DEFAULT_LICENSES.size(), licenses1.length );
79
80 for ( String licenseName : DEFAULT_LICENSES )
81 {
82 License license = repository.getLicense( licenseName );
83 License license1 = store.getLicense( licenseName );
84 Assert.assertNotNull( license );
85 Assert.assertNotNull( license1 );
86 Assert.assertEquals( license, license1 );
87 }
88
89 for ( String licenseName : store.getLicenseNames() )
90 {
91 Assert.assertTrue( DEFAULT_LICENSES.contains( licenseName ) );
92 }
93 }
94
95 @Test
96 public void testOtherJarRepository()
97 throws IOException
98 {
99
100 URL baseURL = getClass().getResource( "/newRepository" );
101 LicenseRepository jarRepository = new LicenseRepository();
102 jarRepository.setBaseURL( baseURL );
103
104 store = new LicenseStore();
105 store.addRepository( jarRepository );
106 store.init();
107 List<LicenseRepository> repositories = store.getRepositories();
108 Assert.assertNotNull( repositories );
109 Assert.assertEquals( 1, repositories.size() );
110 LicenseRepository repository = repositories.get( 0 );
111
112 License[] licenses1 = repository.getLicenses();
113 License[] licenses = store.getLicenses();
114 Assert.assertNotNull( licenses );
115 Assert.assertNotNull( licenses1 );
116 Assert.assertEquals( licenses1.length, 2 );
117 Assert.assertEquals( licenses1.length, licenses.length );
118
119 for ( String licenseName : NEW_LICENSES )
120 {
121 License license = repository.getLicense( licenseName );
122 License license1 = store.getLicense( licenseName );
123 Assert.assertNotNull( license );
124 Assert.assertNotNull( license1 );
125 Assert.assertEquals( license, license1 );
126 }
127
128 for ( String licenseName : store.getLicenseNames() )
129 {
130 Assert.assertTrue( NEW_LICENSES.contains( licenseName ) );
131 }
132 }
133 }