1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */ 
19  package org.apache.rat.policy;
20  
21  import junit.framework.TestCase;
22  
23  import org.apache.rat.api.Document;
24  import org.apache.rat.api.MetaData;
25  import org.apache.rat.document.MockLocation;
26  import org.apache.rat.report.claim.impl.xml.MockClaimReporter;
27  
28  
29  public class DefaultPolicyTest extends TestCase {
30  
31      MockClaimReporter reporter;
32      DefaultPolicy policy;
33      private Document subject;
34      
35      protected void setUp() throws Exception {
36          super.setUp();
37          reporter = new MockClaimReporter();
38          policy = new DefaultPolicy();
39          subject = new MockLocation("subject");
40      }
41  
42      protected void tearDown() throws Exception {
43          super.tearDown();
44      }
45  
46      public void testASLFamily() throws Exception {
47          subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0);
48          policy.analyse(subject);
49          assertApproval(true);
50      }
51  
52      private void assertApproval(boolean pApproved) {
53          assertEquals(pApproved, MetaData.RAT_APPROVED_LICENSE_VALUE_TRUE.equals(subject.getMetaData().value(MetaData.RAT_URL_APPROVED_LICENSE)));
54      }
55  
56      public void testOASISFamily() throws Exception {
57          subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_OASIS_OPEN_LICENSE);
58          policy.analyse(subject);
59          assertApproval(true);
60      }
61      
62      public void testW3CFamily() throws Exception {
63          subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_W3C_SOFTWARE_COPYRIGHT);
64          policy.analyse(subject);
65          assertApproval(true);
66      }
67      
68      public void testW3CDocFamily() throws Exception {
69          subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_W3C_DOCUMENT_COPYRIGHT);
70          policy.analyse(subject);
71          assertApproval(true);
72      }
73      
74      public void testUnknownFamily() throws Exception {
75          subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_UNKNOWN);
76          policy.analyse(subject);
77          assertApproval(false);
78      }
79  }