001 /*
002 * #%L
003 * License Maven Plugin
004 *
005 * $Id: LicenseStoreTest.java 14664 2011-09-09 07:47:49Z tchemit $
006 * $HeadURL: http://svn.codehaus.org/mojo/tags/license-maven-plugin-1.0/src/test/java/org/codehaus/mojo/license/model/LicenseStoreTest.java $
007 * %%
008 * Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
009 * %%
010 * This program is free software: you can redistribute it and/or modify
011 * it under the terms of the GNU Lesser General Public License as
012 * published by the Free Software Foundation, either version 3 of the
013 * License, or (at your option) any later version.
014 *
015 * This program is distributed in the hope that it will be useful,
016 * but WITHOUT ANY WARRANTY; without even the implied warranty of
017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018 * GNU General Lesser Public License for more details.
019 *
020 * You should have received a copy of the GNU General Lesser Public
021 * License along with this program. If not, see
022 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
023 * #L%
024 */
025
026 package org.codehaus.mojo.license.model;
027
028 import org.junit.Assert;
029 import org.junit.Before;
030 import org.junit.Test;
031
032 import java.io.IOException;
033 import java.net.URL;
034 import java.util.Arrays;
035 import java.util.List;
036
037 /**
038 * Tests {@link LicenseStore}.
039 *
040 * @author tchemit <chemit@codelutin.com>
041 * @since 1.0
042 */
043 public class LicenseStoreTest
044 {
045
046 public static final List<String> DEFAULT_LICENSES =
047 Arrays.asList( "agpl_v3", "apache_v2", "cddl_v1", "fdl_v1_3", "gpl_v1", "gpl_v2", "gpl_v3", "lgpl_v2_1",
048 "lgpl_v3", "mit" );
049
050 public static final List<String> NEW_LICENSES = Arrays.asList( "license1", "license2" );
051
052 protected LicenseStore store;
053
054 @Before
055 public void setUp()
056 {
057 store = null;
058 }
059
060 @Test
061 public void testJarRepository()
062 throws IOException
063 {
064
065 store = new LicenseStore();
066 store.init();
067
068 List<LicenseRepository> repositories = store.getRepositories();
069 Assert.assertNotNull( repositories );
070 Assert.assertEquals( 1, repositories.size() );
071 LicenseRepository repository = repositories.get( 0 );
072
073 License[] licenses1 = repository.getLicenses();
074 License[] licenses = store.getLicenses();
075 Assert.assertNotNull( licenses );
076 Assert.assertNotNull( licenses1 );
077 Assert.assertEquals( DEFAULT_LICENSES.size(), licenses.length );
078 Assert.assertEquals( DEFAULT_LICENSES.size(), licenses1.length );
079
080 for ( String licenseName : DEFAULT_LICENSES )
081 {
082 License license = repository.getLicense( licenseName );
083 License license1 = store.getLicense( licenseName );
084 Assert.assertNotNull( license );
085 Assert.assertNotNull( license1 );
086 Assert.assertEquals( license, license1 );
087 }
088
089 for ( String licenseName : store.getLicenseNames() )
090 {
091 Assert.assertTrue( DEFAULT_LICENSES.contains( licenseName ) );
092 }
093 }
094
095 @Test
096 public void testOtherJarRepository()
097 throws IOException
098 {
099
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 }