View Javadoc

1   /*
2    * #%L
3    * License Maven Plugin
4    * 
5    * $Id: LicenseStoreTest.java 14664 2011-09-09 07:47:49Z tchemit $
6    * $HeadURL: http://svn.codehaus.org/mojo/tags/license-maven-plugin-1.0/src/test/java/org/codehaus/mojo/license/model/LicenseStoreTest.java $
7    * %%
8    * Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU Lesser General Public License as 
12   * published by the Free Software Foundation, either version 3 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Lesser Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Lesser Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
23   * #L%
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   * Tests {@link LicenseStore}.
39   *
40   * @author tchemit <chemit@codelutin.com>
41   * @since 1.0
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 }