1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
35
36 public class LicenseSummaryTest
37 {
38
39
40
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
60
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
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 }