001 /** 002 * Copyright 2010-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.codehaus.mojo.license.model; 017 018 import org.junit.Assert; 019 import org.junit.Before; 020 import org.junit.Test; 021 022 import java.io.IOException; 023 import java.net.URL; 024 import java.util.Arrays; 025 import java.util.List; 026 027 /** 028 * Tests {@link LicenseStore}. 029 * 030 * @author tchemit <chemit@codelutin.com> 031 * @since 1.0 032 */ 033 public class LicenseStoreTest 034 { 035 036 public static final List<String> DEFAULT_LICENSES = 037 Arrays.asList( "agpl_v3", "apache_v2", "cddl_v1", "fdl_v1_3", "gpl_v1", "gpl_v2", "gpl_v3", "lgpl_v2_1", 038 "lgpl_v3", "mit" ); 039 040 public static final List<String> NEW_LICENSES = Arrays.asList( "license1", "license2" ); 041 042 protected LicenseStore store; 043 044 @Before 045 public void setUp() 046 { 047 store = null; 048 } 049 050 @Test 051 public void testJarRepository() 052 throws IOException 053 { 054 055 store = new LicenseStore(); 056 store.init(); 057 058 List<LicenseRepository> repositories = store.getRepositories(); 059 Assert.assertNotNull( repositories ); 060 Assert.assertEquals( 1, repositories.size() ); 061 LicenseRepository repository = repositories.get( 0 ); 062 063 License[] licenses1 = repository.getLicenses(); 064 License[] licenses = store.getLicenses(); 065 Assert.assertNotNull( licenses ); 066 Assert.assertNotNull( licenses1 ); 067 Assert.assertEquals( DEFAULT_LICENSES.size(), licenses.length ); 068 Assert.assertEquals( DEFAULT_LICENSES.size(), licenses1.length ); 069 070 for ( String licenseName : DEFAULT_LICENSES ) 071 { 072 License license = repository.getLicense( licenseName ); 073 License license1 = store.getLicense( licenseName ); 074 Assert.assertNotNull( license ); 075 Assert.assertNotNull( license1 ); 076 Assert.assertEquals( license, license1 ); 077 } 078 079 for ( String licenseName : store.getLicenseNames() ) 080 { 081 Assert.assertTrue( DEFAULT_LICENSES.contains( licenseName ) ); 082 } 083 } 084 085 @Test 086 public void testOtherJarRepository() 087 throws IOException 088 { 089 090 URL baseURL = getClass().getResource( "/newRepository" ); 091 LicenseRepository jarRepository = new LicenseRepository(); 092 jarRepository.setBaseURL( baseURL ); 093 094 store = new LicenseStore(); 095 store.addRepository( jarRepository ); 096 store.init(); 097 List<LicenseRepository> repositories = store.getRepositories(); 098 Assert.assertNotNull( repositories ); 099 Assert.assertEquals( 1, repositories.size() ); 100 LicenseRepository repository = repositories.get( 0 ); 101 102 License[] licenses1 = repository.getLicenses(); 103 License[] licenses = store.getLicenses(); 104 Assert.assertNotNull( licenses ); 105 Assert.assertNotNull( licenses1 ); 106 Assert.assertEquals( licenses1.length, 2 ); 107 Assert.assertEquals( licenses1.length, licenses.length ); 108 109 for ( String licenseName : NEW_LICENSES ) 110 { 111 License license = repository.getLicense( licenseName ); 112 License license1 = store.getLicense( licenseName ); 113 Assert.assertNotNull( license ); 114 Assert.assertNotNull( license1 ); 115 Assert.assertEquals( license, license1 ); 116 } 117 118 for ( String licenseName : store.getLicenseNames() ) 119 { 120 Assert.assertTrue( NEW_LICENSES.contains( licenseName ) ); 121 } 122 } 123 }