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.aConfiguration;
22  import junit.framework.TestCase;
23  
24  import org.apache.commons.lang3.StringUtils;
25  import org.apache.creadur.whisker.app.Result;
26  import org.apache.creadur.whisker.model.Descriptor;
27  
28  public class TestLicenseGenerationSourceURLs extends TestCase {
29  
30      StringResultWriterFactory writerFactory;
31      VelocityEngine subject;
32      DescriptorBuilderForTesting builder;
33      Descriptor work;
34  
35      @Override
36      protected void setUp() throws Exception {
37          super.setUp();
38          writerFactory = new StringResultWriterFactory();
39          subject = new VelocityEngine(new EmptyLog());
40          builder = new DescriptorBuilderForTesting().withSourceURL();
41          work = builder.withPrimaryLicenseAndThirdPartyOrgInDirectory(".").build();
42      }
43  
44      @Override
45      protected void tearDown() throws Exception {
46          super.tearDown();
47      }
48  
49      public void testNoSourceUrlsConfiguration() throws Exception {
50          subject.generate(work, writerFactory, aConfiguration().noSourceURLsInLicense().build());
51          assertFalse(failureMessage(), outputContainsSourceUrl());
52  
53      }
54  
55      private boolean outputContainsSourceUrl() {
56          return StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE),
57                  builder.sourceUrl);
58      }
59  
60      private String failureMessage() {
61          return "Expect information when third party contents present: " + writerFactory.firstOutputFor(Result.LICENSE);
62      }
63  
64      public void testWithSourceUrlsConfiguration() throws Exception {
65          subject.generate(work, writerFactory, aConfiguration().withSourceURLsInLicense().build());
66  
67          assertTrue(failureMessage(), outputContainsSourceUrl());
68  
69      }
70  }