1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.analysis.license;
20
21 import org.apache.commons.io.IOUtils;
22 import org.apache.rat.api.Document;
23 import org.apache.rat.document.MockLocation;
24 import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
25 import org.apache.rat.test.utils.Resources;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import java.io.BufferedReader;
30 import java.io.StringReader;
31
32 import static org.junit.Assert.assertFalse;
33 import static org.junit.Assert.assertTrue;
34
35 public class OASISLicenseTest {
36
37 private static final String LICENSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
38 "<!--\n" +
39 "\n" +
40 "\n" +
41 "OASIS takes no position regarding the validity or scope of any intellectual property or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; neither does it represent that it has made any effort to identify any such rights. Information on OASIS's procedures with respect to rights in OASIS specifications can be found at the OASIS website. Copies of claims of rights made available for publication and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementors or users of this specification, can be obtained from the OASIS Executive Director.\n" +
42 "\n" +
43 "\n" +
44 "OASIS invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights which may cover technology that may be required to implement this specification. Please address the information to the OASIS Executive Director\n." +
45 "\n" +
46 "Copyright (C) OASIS Open (2004-2005). All Rights Reserved.\n" +
47 "\n" +
48 "This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to OASIS, except as needed for the purpose of developing OASIS specifications, in which case the procedures for copyrights defined in the OASIS Intellectual Property Rights document must be followed, or as required to translate it into languages other than English.\n" +
49 "\n" +
50 "\n" +
51 "The limited permissions granted above are perpetual and will not be revoked by OASIS or its successors or assigns.\n" +
52 "\n" +
53 "\n" +
54 "This document and the information contained herein is provided on an \"AS IS\" basis and OASIS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.\n" +
55 "-->\n";
56
57 private OASISLicense license;
58
59 private MockClaimReporter reporter;
60
61 @Before
62 public void setUp() throws Exception {
63 license = new OASISLicense();
64 reporter = new MockClaimReporter();
65 }
66
67 @Test
68 public void match() throws Exception {
69 BufferedReader in = null;
70 try {
71 in = new BufferedReader(new StringReader(LICENSE));
72 String line = in.readLine();
73 boolean result = false;
74 final Document subject = new MockLocation("subject");
75 while (line != null) {
76 result = license.match(subject, line);
77 line = in.readLine();
78 }
79 assertTrue("OASIS license should be matched", result);
80 license.reset();
81 result = license.match(subject, "New line");
82 assertFalse("After reset, content should build up again", result);
83 } finally {
84 IOUtils.closeQuietly(in);
85 }
86 }
87
88 @Test
89 public void noMatch() throws Exception {
90 BufferedReader in = null;
91 try {
92 in = Resources.getBufferedResourceReader("elements/Source.java");
93 String line = in.readLine();
94 boolean result = false;
95 final Document subject = new MockLocation("subject");
96 while (line != null) {
97 result = license.match(subject, line);
98 line = in.readLine();
99 }
100 assertFalse("OASIS license should not be matched", result);
101 license.reset();
102 } finally {
103 IOUtils.closeQuietly(in);
104 }
105 }
106
107 @Test(timeout = 2000)
108 public void goodFiles() throws Exception {
109 DirectoryScanner.testFilesInDir("oasis/good", license, true);
110 }
111
112 @Test(timeout = 2000)
113 public void baddFiles() throws Exception {
114 DirectoryScanner.testFilesInDir("oasis/bad", license, false);
115 }
116
117 }