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; 017 018 import org.apache.maven.model.License; 019 import org.codehaus.mojo.license.model.ProjectLicenseInfo; 020 import org.junit.Assert; 021 import org.junit.Test; 022 import org.xml.sax.SAXException; 023 024 import javax.xml.parsers.ParserConfigurationException; 025 import javax.xml.transform.TransformerException; 026 import javax.xml.transform.TransformerFactoryConfigurationError; 027 import java.io.File; 028 import java.io.FileInputStream; 029 import java.io.IOException; 030 import java.util.ArrayList; 031 import java.util.List; 032 033 /** 034 * @since 1.0 035 */ 036 public class LicenseSummaryTest 037 { 038 039 /** 040 * Test reading the license summary xml file into ProjectLicenseInfo objects 041 */ 042 @Test 043 public void testReadLicenseSummary() 044 throws IOException, SAXException, ParserConfigurationException 045 { 046 File licenseSummaryFile = new File( "src/test/resources/license-summary-test.xml" ); 047 Assert.assertTrue( licenseSummaryFile.exists() ); 048 FileInputStream fis = new FileInputStream( licenseSummaryFile ); 049 List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary( fis ); 050 fis.close(); 051 ProjectLicenseInfo dep = list.get( 0 ); 052 Assert.assertEquals( "org.codehaus.mojo", dep.getGroupId() ); 053 Assert.assertEquals( "junk", dep.getArtifactId() ); 054 Assert.assertEquals( "1.1", dep.getVersion() ); 055 056 } 057 058 /** 059 * Test writing license information to a license.xml file and then read this file 060 * back in to make sure it's ok. 061 */ 062 @Test 063 public void testWriteReadLicenseSummary() 064 throws IOException, SAXException, ParserConfigurationException, TransformerFactoryConfigurationError, 065 TransformerException 066 { 067 List<ProjectLicenseInfo> licSummary = new ArrayList<ProjectLicenseInfo>(); 068 ProjectLicenseInfo dep1 = new ProjectLicenseInfo( "org.test", "test1", "1.0" ); 069 ProjectLicenseInfo dep2 = new ProjectLicenseInfo( "org.test", "test2", "2.0" ); 070 071 License lic = new License(); 072 lic.setName( "lgpl" ); 073 lic.setUrl( "http://www.gnu.org/licenses/lgpl-3.0.txt" ); 074 lic.setComments( "lgpl version 3.0" ); 075 dep1.addLicense( lic ); 076 dep2.addLicense( lic ); 077 078 licSummary.add( dep1 ); 079 licSummary.add( dep2 ); 080 081 File licenseSummaryFile = File.createTempFile( "licSummary", "tmp" ); 082 // File licenseSummaryFile = new File( "src/test/resources/license-summary-test-2.xml" ); 083 LicenseSummaryWriter.writeLicenseSummary( licSummary, licenseSummaryFile ); 084 085 Assert.assertTrue( licenseSummaryFile.exists() ); 086 FileInputStream fis = new FileInputStream( licenseSummaryFile ); 087 List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary( fis ); 088 fis.close(); 089 ProjectLicenseInfo dep = list.get( 0 ); 090 Assert.assertEquals( "org.test", dep.getGroupId() ); 091 Assert.assertEquals( "test1", dep.getArtifactId() ); 092 Assert.assertEquals( "1.0", dep.getVersion() ); 093 094 } 095 }