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  
20  package org.apache.myfaces.tobago.internal.taglib.component;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  import org.apache.myfaces.tobago.internal.taglib.TobagoTag;
24  import org.apache.myfaces.tobago.util.ComponentUtils;
25  import org.junit.Assert;
26  import org.junit.Before;
27  import org.junit.Test;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  import javax.faces.component.UICommand;
32  import javax.faces.component.UIComponent;
33  import javax.servlet.jsp.JspException;
34  import javax.servlet.jsp.tagext.Tag;
35  import java.util.Iterator;
36  import java.util.Map;
37  
38  public class GenericComponentTagUnitTest extends GenericTestBase {
39  
40    private static final Logger LOG = LoggerFactory.getLogger(GenericComponentTagUnitTest.class);
41  
42    @Before
43    public void setUp() throws Exception {
44      String[] tldPaths = new String[1];
45      tldPaths[0] = "META-INF/org/apache/myfaces/tobago/internal/taglib/component/tobago.tld";
46      setTldPaths(tldPaths);
47      super.setUp();
48      getRequest().setAttribute("peter", new DummyBean(true, 20, "Peter"));
49      getRequest().setAttribute("marry", new DummyBean(false, 17, "Marry"));
50    }
51  
52    @Test
53    public void testComponent()
54        throws JspException, IllegalAccessException, InstantiationException, ClassNotFoundException {
55      // TODO create new test
56      /*for (Tld tld : tlds) {
57        for (net.sf.maventaglib.checker.Tag tag : tld.getTags()) {
58          javax.servlet.jsp.tagext.Tag tagInstance = getTagInstance(tag);
59          if (tagInstance instanceof UIComponentTag
60              && (tagInstance instanceof ButtonTag || tagInstance instanceof LinkTag)) {
61            LOG.info("testing tag: " + tagInstance.getClass().getName());
62            testComponent(tagInstance);
63          }
64        }
65      }*/
66    }
67  
68    private void testComponent(Tag tag) throws JspException {
69      if (tag instanceof TobagoTag) {
70        TobagoTag tobagoTag = (TobagoTag) tag;
71        //MockViewTag root = new MockViewTag();
72        //root.setPageContext(pageContext);
73        //root.setRendered("false");
74        //root.doStartTag();
75        //tobagoTag.setParent(root);
76        //tobagoTag.setPageContext(pageContext);
77  //      tobagoTag.setRendered("true");
78        //tobagoTag.setDisabled("#{peter.male}");
79        //tobagoTag.setHeight("#{marry.size}");
80        tobagoTag.doStartTag();
81        UIComponent component = tobagoTag.getComponentInstance();
82        UICommand command = (UICommand) component;
83        Object disabled = component.getAttributes().get(Attributes.DISABLED);
84        LOG.debug("disabled = '" + disabled + "'");
85        Map attributes = component.getAttributes();
86        for (Iterator i = attributes.keySet().iterator(); i.hasNext();) {
87          Object value = i.next();
88          LOG.debug("value = " + value);
89        }
90        Object height = attributes.get(Attributes.HEIGHT);
91        LOG.debug("height = '" + height + "'");
92  
93        Assert.assertTrue(ComponentUtils.getBooleanAttribute(command, Attributes.DISABLED));
94        Assert.assertFalse(ComponentUtils.getBooleanAttribute(command, Attributes.HEIGHT));
95      }
96    }
97  }