View Javadoc
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.creadur.whisker.model;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.Collections;
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import junit.framework.TestCase;
28  
29  public class TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices extends TestCase {
30  
31      License primaryLicense = new License(false, "This is the license text", Collections.<String> emptyList(), "example.org", "http://example.org", "Example License");
32      String primaryOrg = "example.org";
33      String primaryNotice = "The primary notice.";
34      Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
35      Map<String, License> licenses = new HashMap<String, License>();
36      Map<String, String> notices = new HashMap<String, String>();
37      Map<String, Organisation> organisations = new HashMap<String, Organisation>();
38      
39      Descriptor subject;
40      
41      protected void setUp() throws Exception {
42          super.setUp();
43          primaryLicense.storeIn(licenses);
44          String noticeId = "notice:id";
45          notices.put(noticeId, "Some notice text");
46          Collection<WithLicense> withLicenses = new ArrayList<WithLicense>();
47          License license = primaryLicense;
48          Collection<ByOrganisation> orgs = new ArrayList<ByOrganisation>();
49          Collection<Resource> resources = new ArrayList<Resource>();
50          String source = "";
51          String name = "resource";
52          resources.add(new Resource(name , noticeId, source));
53          String orgUrl = "org:url";
54          String orgId = "org:id";
55          String orgName = "example.org";
56          Organisation org = new Organisation(orgId, orgName, orgUrl);
57          orgs.add(new ByOrganisation(org, resources));
58          String copyright = "Copyright Blah";
59          Map<String, String> params = Collections.emptyMap();
60          withLicenses.add(new WithLicense(license, copyright, params, orgs));
61          Collection<ByOrganisation> publicDomain = Collections.emptyList();
62          contents.add(new WithinDirectory(".", withLicenses, publicDomain));
63      }
64  
65      protected void tearDown() throws Exception {
66          super.tearDown();
67      }
68  
69      public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception {
70          subject = 
71                  new Descriptor(primaryLicense, primaryOrg,  primaryNotice, 
72                          licenses, notices, organisations, contents);
73          assertTrue("When primary notices exists and third party notices needed then display is required", 
74                  subject.isNoticeRequired());        
75      }
76  
77      public void testNoticeRequiredWhenPrimaryNoticeIsNullAndThirdPartyNotices() throws Exception {
78          subject = 
79                  new Descriptor(primaryLicense, primaryOrg,  null, 
80                          licenses, notices, organisations, contents);
81          assertTrue("When no other notices exist and third party notices needed then display is required", 
82                  subject.isNoticeRequired());        
83      }
84  
85      public void testNoticeRequiredWhenPrimaryNoticeIsEmptyAndThirdPartyNotices() throws Exception {
86          subject = 
87                  new Descriptor(primaryLicense, primaryOrg,  "", 
88                          licenses, notices, organisations, contents);
89          assertTrue("When no other notices exist and third party notices needed then display is required", 
90                  subject.isNoticeRequired());        
91      }
92  
93      public void testNoticeRequiredWhenPrimaryNoticeIsWhitespaceAndThirdPartyNotices() throws Exception {
94          subject = 
95                  new Descriptor(primaryLicense, primaryOrg,  "   ", 
96                          licenses, notices, organisations, contents);
97          assertTrue("When no other notices exist and third party notices needed then display is required", 
98                  subject.isNoticeRequired());        
99      }
100 }