myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1461889 - in /myfaces/core/branches/2.0.x/impl/src/test: java/org/apache/myfaces/view/facelets/impl/ resources/org/apache/myfaces/view/facelets/impl/ resources/org/apache/myfaces/view/facelets/impl/resources/ resources/org/apache/myfaces/v...
Date Wed, 27 Mar 2013 22:58:32 GMT
Author: lu4242
Date: Wed Mar 27 22:58:32 2013
New Revision: 1461889

URL: http://svn.apache.org/r1461889
Log:
MYFACES-3659 Conditional include of scripts and stylesheets (add junit test thanks to dennis
hoersch for provide this patch)

Added:
    myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/impl/ResourceMarkDeleteTest.java
  (with props)
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/
  (with props)
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/
  (with props)
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/
  (with props)
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/a.js
  (with props)
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/x.js
  (with props)
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/test_conditional_include_resources.xhtml
  (with props)

Added: myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/impl/ResourceMarkDeleteTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/impl/ResourceMarkDeleteTest.java?rev=1461889&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/impl/ResourceMarkDeleteTest.java
(added)
+++ myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/impl/ResourceMarkDeleteTest.java
Wed Mar 27 22:58:32 2013
@@ -0,0 +1,104 @@
+/*
+ * 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.myfaces.view.facelets.impl;
+
+import java.io.IOException;
+import java.util.List;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import org.apache.myfaces.view.facelets.FaceletTestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ResourceMarkDeleteTest  extends FaceletTestCase {
+
+    @Test
+    public void test_only_ajs_is_included() throws IOException
+    {
+        UIViewRoot root = facesContext.getViewRoot();
+
+        // Building the view
+        // Because 'includeResource' is not set the second resource should not be included
+        vdl.buildView(facesContext, root, "test_conditional_include_resources.xhtml");
+
+        List<UIComponent> resources = root.getComponentResources(facesContext, "head");
+
+        Assert.assertTrue("Only one script is included.", resources.size() == 1);
+        Assert.assertTrue("a.js is included.", resources.get(0).getAttributes().get("name").equals("a.js"));
+    }
+
+    @Test
+    public void test_ajs_and_xjs_are_included() throws IOException
+    {
+        facesContext.getAttributes().put("includeResource", Boolean.TRUE);
+        UIViewRoot root = facesContext.getViewRoot();
+
+        // Building the view
+        // Because 'includeResource' is now set the second resource should be included
+        vdl.buildView(facesContext, root, "test_conditional_include_resources.xhtml");
+
+        List<UIComponent> resources = root.getComponentResources(facesContext, "head");
+
+        Assert.assertTrue("Two scripts are included.", resources.size() == 2);
+    }
+
+    @Test
+    public void test_only_ajs_after_refresh_view_is_included() throws IOException
+    {
+    	UIViewRoot view = facesContext.getViewRoot();
+
+        // Building the initial view
+        // Because 'includeResource' is not set the second resource should not be included
+        vdl.buildView(facesContext, view, "test_conditional_include_resources.xhtml");
+
+        {
+            List<UIComponent> resources = view.getComponentResources(facesContext,
"head");
+
+            Assert.assertTrue("Only one script is included.", resources.size() == 1);
+        }
+
+        // reset 'isFilledView'
+        facesContext.getAttributes().remove(view);
+
+        // Building the view a second time
+        // Because 'includeResource' is now set the second resource should be included
+        facesContext.getAttributes().put("includeResource", Boolean.TRUE);
+        vdl.buildView(facesContext, view);
+
+        {
+            List<UIComponent> resources = view.getComponentResources(facesContext,
"head");
+
+            Assert.assertTrue("Two scripts are included.", resources.size() == 2);
+        }
+
+        // reset 'isFilledView'
+        facesContext.getAttributes().remove(view);
+        // Building the view a third time
+        // Because 'includeResource' is now removed the second resource should not be included
+
+        facesContext.getAttributes().remove("includeResource");
+        vdl.buildView(facesContext, view);
+
+        {
+            List<UIComponent> resources = view.getComponentResources(facesContext,
"head");
+
+            Assert.assertTrue("Only one script is included.", resources.size() == 1);
+        }
+    }
+}
\ No newline at end of file

Propchange: myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/view/facelets/impl/ResourceMarkDeleteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/a.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/a.js?rev=1461889&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/a.js
(added)
+++ myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/a.js
Wed Mar 27 22:58:32 2013
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+var a = "A";
\ No newline at end of file

Propchange: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/a.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/x.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/x.js?rev=1461889&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/x.js
(added)
+++ myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/x.js
Wed Mar 27 22:58:32 2013
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+var x = "X";
\ No newline at end of file

Propchange: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/resources/js/x.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/test_conditional_include_resources.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/test_conditional_include_resources.xhtml?rev=1461889&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/test_conditional_include_resources.xhtml
(added)
+++ myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/test_conditional_include_resources.xhtml
Wed Mar 27 22:58:32 2013
@@ -0,0 +1,36 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!--
+ Licensed 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.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:ui="http://java.sun.com/jsf/facelets"
+    xmlns:h="http://java.sun.com/jsf/html"
+    xmlns:f="http://java.sun.com/jsf/core"
+    xmlns:c="http://java.sun.com/jsp/jstl/core">
+<h:head id="head">
+</h:head>
+<h:body id="body">
+
+        <h:outputScript id="ajs" library="js" name="a.js" target="head" />
+        Some text
+        <c:if test="#{facesContext.attributes.includeResource}">
+            BLA
+            <h:outputScript id="xjs" library="js" name="x.js" target="head" />
+        </c:if>
+
+        <h:form id="form">
+            <h:inputText id="input" value="" />
+        </h:form>
+</h:body>
+</html>
\ No newline at end of file

Propchange: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/view/facelets/impl/test_conditional_include_resources.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message