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.out.velocity;
20  
21  import static org.apache.creadur.whisker.app.ConfigurationBuilder.*;
22  
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.Collections;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import org.apache.creadur.whisker.app.Result;
30  import org.apache.creadur.whisker.model.Descriptor;
31  import org.apache.creadur.whisker.model.License;
32  import org.apache.creadur.whisker.model.Organisation;
33  import org.apache.creadur.whisker.model.WithinDirectory;
34  
35  import junit.framework.TestCase;
36  
37  public class TestNoticeGeneration extends TestCase {
38  
39      StringResultWriterFactory writerFactory;
40      VelocityEngine subject;
41      License primaryLicense = new License(false, "This is the license text", Collections.<String> emptyList(), "example.org", "http://example.org", "Example License");
42      String primaryOrg = "example.org";
43      String primaryNotice = "The primary notice.";
44      Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
45      Map<String, License> licenses = new HashMap<String, License>();
46      Map<String, String> notices = new HashMap<String, String>();
47      Map<String, Organisation> organisations = new HashMap<String, Organisation>();
48  
49      @Override
50      protected void setUp() throws Exception {
51          super.setUp();
52          writerFactory = new StringResultWriterFactory();
53          subject = new VelocityEngine(new EmptyLog());
54          primaryLicense.storeIn(licenses);
55      }
56  
57      @Override
58      protected void tearDown() throws Exception {
59          super.tearDown();
60      }
61  
62      public void testThatWhenThereAreNoThirdPartyNoticesHeaderIsNotShown() throws Exception {
63          Descriptor work =
64                  new Descriptor(primaryLicense, primaryOrg,  primaryNotice,
65                          licenses, notices, organisations, contents);
66  
67          subject.generate(work, writerFactory, aConfiguration().build());
68  
69          assertEquals("Only one request for NOTICE writer", 1, writerFactory.requestsFor(Result.NOTICE));
70          assertEquals("When no third party notices, expect that only the primary notice is output", primaryNotice, writerFactory.firstOutputFor(Result.NOTICE).trim());
71      }
72  
73      public void testThatNoticeOutputIsSkippedWhenThereAreNoNotices() throws Exception {
74          Descriptor work =
75                  new Descriptor(primaryLicense, primaryOrg,  "",
76                          licenses, notices, organisations, contents);
77  
78          subject.generate(work, writerFactory, aConfiguration().build());
79  
80          assertEquals("No requests for NOTICE writer", 0, writerFactory.requestsFor(Result.NOTICE));
81      }
82  
83  }