View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.mojo.license;
17  
18  import org.apache.maven.model.License;
19  import org.codehaus.mojo.license.model.ProjectLicenseInfo;
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.xml.sax.SAXException;
23  
24  import javax.xml.parsers.ParserConfigurationException;
25  import javax.xml.transform.TransformerException;
26  import javax.xml.transform.TransformerFactoryConfigurationError;
27  import java.io.File;
28  import java.io.FileInputStream;
29  import java.io.IOException;
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * @since 1.0
35   */
36  public class LicenseSummaryTest
37  {
38  
39      /**
40       * Test reading the license summary xml file into ProjectLicenseInfo objects
41       */
42      @Test
43      public void testReadLicenseSummary()
44          throws IOException, SAXException, ParserConfigurationException
45      {
46          File licenseSummaryFile = new File( "src/test/resources/license-summary-test.xml" );
47          Assert.assertTrue( licenseSummaryFile.exists() );
48          FileInputStream fis = new FileInputStream( licenseSummaryFile );
49          List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary( fis );
50          fis.close();
51          ProjectLicenseInfo dep = list.get( 0 );
52          Assert.assertEquals( "org.codehaus.mojo", dep.getGroupId() );
53          Assert.assertEquals( "junk", dep.getArtifactId() );
54          Assert.assertEquals( "1.1", dep.getVersion() );
55  
56      }
57  
58      /**
59       * Test writing license information to a license.xml file and then read this file
60       * back in to make sure it's ok.
61       */
62      @Test
63      public void testWriteReadLicenseSummary()
64          throws IOException, SAXException, ParserConfigurationException, TransformerFactoryConfigurationError,
65          TransformerException
66      {
67          List<ProjectLicenseInfo> licSummary = new ArrayList<ProjectLicenseInfo>();
68          ProjectLicenseInfo dep1 = new ProjectLicenseInfo( "org.test", "test1", "1.0" );
69          ProjectLicenseInfo dep2 = new ProjectLicenseInfo( "org.test", "test2", "2.0" );
70  
71          License lic = new License();
72          lic.setName( "lgpl" );
73          lic.setUrl( "http://www.gnu.org/licenses/lgpl-3.0.txt" );
74          lic.setComments( "lgpl version 3.0" );
75          dep1.addLicense( lic );
76          dep2.addLicense( lic );
77  
78          licSummary.add( dep1 );
79          licSummary.add( dep2 );
80  
81          File licenseSummaryFile = File.createTempFile( "licSummary", "tmp" );
82          // File licenseSummaryFile = new File( "src/test/resources/license-summary-test-2.xml" );
83          LicenseSummaryWriter.writeLicenseSummary( licSummary, licenseSummaryFile );
84  
85          Assert.assertTrue( licenseSummaryFile.exists() );
86          FileInputStream fis = new FileInputStream( licenseSummaryFile );
87          List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary( fis );
88          fis.close();
89          ProjectLicenseInfo dep = list.get( 0 );
90          Assert.assertEquals( "org.test", dep.getGroupId() );
91          Assert.assertEquals( "test1", dep.getArtifactId() );
92          Assert.assertEquals( "1.0", dep.getVersion() );
93  
94      }
95  }