1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.codehaus.mojo.license;
26
27 import org.apache.maven.model.License;
28 import org.codehaus.mojo.license.model.ProjectLicenseInfo;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.xml.sax.SAXException;
32
33 import javax.xml.parsers.ParserConfigurationException;
34 import javax.xml.transform.TransformerException;
35 import javax.xml.transform.TransformerFactoryConfigurationError;
36 import java.io.File;
37 import java.io.FileInputStream;
38 import java.io.IOException;
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45 public class LicenseSummaryTest
46 {
47
48
49
50
51 @Test
52 public void testReadLicenseSummary()
53 throws IOException, SAXException, ParserConfigurationException
54 {
55 File licenseSummaryFile = new File( "src/test/resources/license-summary-test.xml" );
56 Assert.assertTrue( licenseSummaryFile.exists() );
57 FileInputStream fis = new FileInputStream( licenseSummaryFile );
58 List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary( fis );
59 fis.close();
60 ProjectLicenseInfo dep = list.get( 0 );
61 Assert.assertEquals( "org.codehaus.mojo", dep.getGroupId() );
62 Assert.assertEquals( "junk", dep.getArtifactId() );
63 Assert.assertEquals( "1.1", dep.getVersion() );
64
65 }
66
67
68
69
70
71 @Test
72 public void testWriteReadLicenseSummary()
73 throws IOException, SAXException, ParserConfigurationException, TransformerFactoryConfigurationError,
74 TransformerException
75 {
76 List<ProjectLicenseInfo> licSummary = new ArrayList<ProjectLicenseInfo>();
77 ProjectLicenseInfo dep1 = new ProjectLicenseInfo( "org.test", "test1", "1.0" );
78 ProjectLicenseInfo dep2 = new ProjectLicenseInfo( "org.test", "test2", "2.0" );
79
80 License lic = new License();
81 lic.setName( "lgpl" );
82 lic.setUrl( "http://www.gnu.org/licenses/lgpl-3.0.txt" );
83 lic.setComments( "lgpl version 3.0" );
84 dep1.addLicense( lic );
85 dep2.addLicense( lic );
86
87 licSummary.add( dep1 );
88 licSummary.add( dep2 );
89
90 File licenseSummaryFile = File.createTempFile( "licSummary", "tmp" );
91
92 LicenseSummaryWriter.writeLicenseSummary( licSummary, licenseSummaryFile );
93
94 Assert.assertTrue( licenseSummaryFile.exists() );
95 FileInputStream fis = new FileInputStream( licenseSummaryFile );
96 List<ProjectLicenseInfo> list = LicenseSummaryReader.parseLicenseSummary( fis );
97 fis.close();
98 ProjectLicenseInfo dep = list.get( 0 );
99 Assert.assertEquals( "org.test", dep.getGroupId() );
100 Assert.assertEquals( "test1", dep.getArtifactId() );
101 Assert.assertEquals( "1.0", dep.getVersion() );
102
103 }
104 }