creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r1361575 - in /creadur/whisker/trunk: apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/ apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/ apache-whisker-velocity/src/main/resources/org/apache/creadur/wh...
Date Sat, 14 Jul 2012 19:05:17 GMT
Author: rdonkin
Date: Sat Jul 14 19:05:16 2012
New Revision: 1361575

URL: http://svn.apache.org/viewvc?rev=1361575&view=rev
Log:
Stop NOTICE template execution when no notice required.

Added:
    creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/
    creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java
  (with props)
    creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java
  (with props)
    creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java
  (with props)
Modified:
    creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
    creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/notice.vm
    creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java

Modified: creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java?rev=1361575&r1=1361574&r2=1361575&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
(original)
+++ creadur/whisker/trunk/apache-whisker-model/src/main/java/org/apache/creadur/whisker/model/Descriptor.java
Sat Jul 14 19:05:16 2012
@@ -190,4 +190,30 @@ public class Descriptor {
         }
     }
 
+    /**
+     * Is a NOTICE document required?
+     * @return true when a NOTICE is required, false otherwise
+     */
+    public boolean isNoticeRequired() {
+       return primaryNoticeExists() || resourceNoticesExist(); 
+    }
+
+    /**
+     * Does any resource have a required notice?
+     * @return true when at least one required third party notice
+     * exists, false otherwise
+     */
+    public boolean resourceNoticesExist() {
+        return !getResourceNotices().isEmpty();
+    }
+
+    /**
+     * Does the work described have a primary notice?
+     * @return true unless the primary notice is null 
+     * or whitespace
+     */
+    public boolean primaryNoticeExists() {
+        return (this.primaryNotice != null) &&
+                   !"".equals(this.primaryNotice.trim());
+    }
 }

Added: creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java?rev=1361575&view=auto
==============================================================================
--- creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java
(added)
+++ creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java
Sat Jul 14 19:05:16 2012
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.creadur.whisker.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class TestDescriptorRequiredNoticesNoThirdPartyNotices extends TestCase {
+
+    License primaryLicense = new License(false, "This is the license text", Collections.<String>
emptyList(), "example.org", "http://example.org", "Example License");
+    String primaryOrg = "example.org";
+    String primaryNotice = "The primary notice.";
+    Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
+    Map<String, License> licenses = new HashMap<String, License>();
+    Map<String, String> notices = new HashMap<String, String>();
+    Map<String, Organisation> organisations = new HashMap<String, Organisation>();
+    
+    Descriptor subject;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        primaryLicense.storeIn(licenses);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception {
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  primaryNotice, 
+                        licenses, notices, organisations, contents);
+        assertTrue("When primary notices exists, even if there are not other notices display
is required", subject.isNoticeRequired());        
+    }
+
+    public void testNoticeNotRequiredWhenPrimaryNoticeIsNullAndNoNotices() throws Exception
{
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  null, 
+                        licenses, notices, organisations, contents);
+        assertFalse("When no other notices exist and no primary notice, display is not required",

+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeNotRequiredWhenPrimaryNoticeIsEmptyAndNoNotices() throws Exception
{
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  "", 
+                        licenses, notices, organisations, contents);
+        assertFalse("When no other notices exist and no primary notice, display is not required",

+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeNotRequiredWhenPrimaryNoticeIsWhitespaceAndNoNotices() throws Exception
{
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  "   ", 
+                        licenses, notices, organisations, contents);
+        assertFalse("When no other notices exist and no primary notice, display is not required",

+                subject.isNoticeRequired());        
+    }
+}

Propchange: creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesNoThirdPartyNotices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java?rev=1361575&view=auto
==============================================================================
--- creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java
(added)
+++ creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java
Sat Jul 14 19:05:16 2012
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.creadur.whisker.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices extends TestCase
{
+
+    License primaryLicense = new License(false, "This is the license text", Collections.<String>
emptyList(), "example.org", "http://example.org", "Example License");
+    String primaryOrg = "example.org";
+    String primaryNotice = "The primary notice.";
+    Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
+    Map<String, License> licenses = new HashMap<String, License>();
+    Map<String, String> notices = new HashMap<String, String>();
+    Map<String, Organisation> organisations = new HashMap<String, Organisation>();
+    
+    Descriptor subject;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        primaryLicense.storeIn(licenses);
+        String noticeId = "notice:id";
+        notices.put(noticeId, "Some notice text");
+        Collection<WithLicense> withLicenses = new ArrayList<WithLicense>();
+        License license = primaryLicense;
+        Collection<ByOrganisation> orgs = new ArrayList<ByOrganisation>();
+        Collection<Resource> resources = new ArrayList<Resource>();
+        String source = "";
+        String name = "resource";
+        resources.add(new Resource(name , noticeId, source));
+        String orgUrl = "org:url";
+        String orgId = "org:id";
+        String orgName = "example.org";
+        Organisation org = new Organisation(orgId, orgName, orgUrl);
+        orgs.add(new ByOrganisation(org, resources));
+        String copyright = "Copyright Blah";
+        Map<String, String> params = Collections.emptyMap();
+        withLicenses.add(new WithLicense(license, copyright, params, orgs));
+        Collection<ByOrganisation> publicDomain = Collections.emptyList();
+        contents.add(new WithinDirectory(".", withLicenses, publicDomain));
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception {
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  primaryNotice, 
+                        licenses, notices, organisations, contents);
+        assertTrue("When primary notices exists and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeRequiredWhenPrimaryNoticeIsNullAndThirdPartyNotices() throws Exception
{
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  null, 
+                        licenses, notices, organisations, contents);
+        assertTrue("When no other notices exist and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeRequiredWhenPrimaryNoticeIsEmptyAndThirdPartyNotices() throws Exception
{
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  "", 
+                        licenses, notices, organisations, contents);
+        assertTrue("When no other notices exist and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeRequiredWhenPrimaryNoticeIsWhitespaceAndThirdPartyNotices() throws
Exception {
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  "   ", 
+                        licenses, notices, organisations, contents);
+        assertTrue("When no other notices exist and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+}

Propchange: creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java?rev=1361575&view=auto
==============================================================================
--- creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java
(added)
+++ creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java
Sat Jul 14 19:05:16 2012
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.creadur.whisker.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed extends TestCase
{
+
+    License primaryLicense = new License(false, "This is the license text", Collections.<String>
emptyList(), "example.org", "http://example.org", "Example License");
+    String primaryOrg = "example.org";
+    String primaryNotice = "The primary notice.";
+    Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
+    Map<String, License> licenses = new HashMap<String, License>();
+    Map<String, String> notices = new HashMap<String, String>();
+    Map<String, Organisation> organisations = new HashMap<String, Organisation>();
+    
+    Descriptor subject;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        primaryLicense.storeIn(licenses);
+        notices.put("bogus", "some notice chaff");
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception {
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  primaryNotice, 
+                        licenses, notices, organisations, contents);
+        assertTrue("When primary notices exists and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeNotRequiredWhenPrimaryNoticeIsNullAndAllThirdPartyNoticesUnused()
throws Exception {
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  null, 
+                        licenses, notices, organisations, contents);
+        assertFalse("When no other notices exist and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeNotRequiredWhenPrimaryNoticeIsEmptyAndAllThirdPartyNoticesUnused()
throws Exception {
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  "", 
+                        licenses, notices, organisations, contents);
+        assertFalse("When no other notices exist and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+
+    public void testNoticeNotRequiredWhenPrimaryNoticeIsWhitespaceAndAllThirdPartyNoticesUnused()
throws Exception {
+        subject = 
+                new Descriptor(primaryLicense, primaryOrg,  "   ", 
+                        licenses, notices, organisations, contents);
+        assertFalse("When no other notices exist and third party notices needed then display
is required", 
+                subject.isNoticeRequired());        
+    }
+}

Propchange: creadur/whisker/trunk/apache-whisker-model/src/test/java/org/apache/creadur/whisker/model/TestDescriptorRequiredNoticesWithThirdPartyNoticesButNoneUsed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/notice.vm
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/notice.vm?rev=1361575&r1=1361574&r2=1361575&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/notice.vm
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/notice.vm
Sat Jul 14 19:05:16 2012
@@ -18,7 +18,9 @@
 ##  under the License.    
 ## 
 #################################################################################
-
+#if ( ! $work.isNoticeRequired() )
+#stop
+#end
 $indent.indent(2, $work.PrimaryNotice)
 
 

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java?rev=1361575&r1=1361574&r2=1361575&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestNoticeGeneration.java
Sat Jul 14 19:05:16 2012
@@ -28,7 +28,6 @@ import org.apache.creadur.whisker.app.Re
 import org.apache.creadur.whisker.model.Descriptor;
 import org.apache.creadur.whisker.model.License;
 import org.apache.creadur.whisker.model.Organisation;
-import org.apache.creadur.whisker.model.Resource;
 import org.apache.creadur.whisker.model.WithinDirectory;
 
 import junit.framework.TestCase;
@@ -37,12 +36,20 @@ public class TestNoticeGeneration extend
     
     StringResultWriterFactory writerFactory;
     VelocityEngine subject;
+    License primaryLicense = new License(false, "This is the license text", Collections.<String>
emptyList(), "example.org", "http://example.org", "Example License");
+    String primaryOrg = "example.org";
+    String primaryNotice = "The primary notice.";
+    Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
+    Map<String, License> licenses = new HashMap<String, License>();
+    Map<String, String> notices = new HashMap<String, String>();
+    Map<String, Organisation> organisations = new HashMap<String, Organisation>();
     
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         writerFactory = new StringResultWriterFactory();
         subject = new VelocityEngine(new EmptyLog());
+        primaryLicense.storeIn(licenses);
     }
 
     @Override
@@ -51,20 +58,25 @@ public class TestNoticeGeneration extend
     }
     
     public void testThatWhenThereAreNoThirdPartyNoticesHeaderIsNotShown() throws Exception
{
-        License primaryLicense = new License(false, "This is the license text", Collections.<String>
emptyList(), "example.org", "http://example.org", "Example License");
-        String primaryOrg = "example.org";
-        String primaryNotice = "The primary notice.";
-        Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
-        Map<String, License> licenses = new HashMap<String, License>();
-        primaryLicense.storeIn(licenses);
-        Map<String, String> notices = new HashMap<String, String>();
-        Map<String, Organisation> organisations = new HashMap<String, Organisation>();
         Descriptor work = 
                 new Descriptor(primaryLicense, primaryOrg,  primaryNotice, 
                         licenses, notices, organisations, contents);
+        
         subject.generate(work, writerFactory);
         
         assertEquals("Only one request for NOTICE writer", 1, writerFactory.requestsFor(Result.NOTICE));
         assertEquals("When no third party notices, expect that only the primary notice is
output", primaryNotice, writerFactory.firstOutputFor(Result.NOTICE).trim());
     }
+    
+    public void testThatOutputIsEmptyWhenThereAreNoNotices() throws Exception {
+        Descriptor work = 
+                new Descriptor(primaryLicense, primaryOrg,  "", 
+                        licenses, notices, organisations, contents);
+        
+        subject.generate(work, writerFactory);
+        
+        assertEquals("Only one request for NOTICE writer", 1, writerFactory.requestsFor(Result.NOTICE));
+        assertEquals("When no notices, expect that output is empty", "", writerFactory.firstOutputFor(Result.NOTICE));
+    }
+
 }



Mime
View raw message