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 org.apache.creadur.whisker.model.Descriptor;
24  import org.apache.creadur.whisker.model.Resource;
25  
26  import junit.framework.TestCase;
27  
28  public class TestRenderingHelper extends TestCase {
29  
30      private static final String A_SOURCE_URL = "http://example.org/sample";
31  
32      RenderingHelper subject;
33  
34      Resource resourceWithSourceUrl;
35      Resource resourceNoSourceUrl;
36  
37      Descriptor work;
38  
39      @Override
40      protected void setUp() throws Exception {
41          super.setUp();
42          resourceWithSourceUrl = new Resource("a name", "an:id", A_SOURCE_URL);
43          resourceNoSourceUrl = new Resource("a name", "an:id", null);
44      }
45  
46      public void testSourceWithSourceUrlsConfiguration() {
47          subject = new RenderingHelper(work,
48                  aConfiguration().withSourceURLsInLicense().build());
49          assertEquals(subject.sourceUrl(resourceWithSourceUrl), " from " + A_SOURCE_URL);
50      }
51  
52      public void testSourceNoSourceUrlsConfiguration() {
53          subject = new RenderingHelper(work,
54                  aConfiguration().noSourceURLsInLicense().build());
55          assertEquals(subject.sourceUrl(resourceWithSourceUrl), "");
56      }
57  
58      public void testNoSourceWithSourceUrlsConfiguration() {
59          subject = new RenderingHelper(work,
60                  aConfiguration().withSourceURLsInLicense().build());
61          assertEquals(subject.sourceUrl(resourceNoSourceUrl), "");
62      }
63  
64      public void testNoSourceNoSourceUrlsConfiguration() {
65          subject = new RenderingHelper(work,
66                  aConfiguration().noSourceURLsInLicense().build());
67          assertEquals(subject.sourceUrl(resourceNoSourceUrl), "");
68      }
69  
70  }