001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.junit.spec;
016    
017    import org.apache.tapestry.junit.TapestryTestCase;
018    import org.apache.tapestry.spec.*;
019    import org.testng.annotations.Test;
020    
021    import java.util.Collections;
022    import java.util.HashSet;
023    import java.util.Set;
024    
025    /**
026     * Test cases for page and component specifications.
027     *
028     * @author Howard Lewis Ship
029     * @since 2.2
030     */
031    @Test
032    public class TestComponentSpecification extends TapestryTestCase
033    {
034    
035        public void test_Bean_Property() throws Exception
036        {
037            IComponentSpecification s = parseComponent("BeanProperty.jwc");
038            IBeanSpecification fred = s.getBeanSpecification("fred");
039    
040            checkList("propertyNames",
041                      new String[]{ "bruce", "nicole", "zeta" },
042                      fred.getPropertyNames());
043    
044            checkProperty(fred, "bruce", "wayne");
045            checkProperty(fred, "nicole", "kidman");
046            checkProperty(fred, "zeta", "jones");
047    
048        }
049    
050        public void test_Component_Property() throws Exception
051        {
052            IComponentSpecification s = parseComponent("ComponentProperty.jwc");
053            IContainedComponent c = s.getComponent("barney");
054    
055            checkList("propertyNames", new String[]
056              { "apple", "chocolate", "frozen" }, c.getPropertyNames());
057    
058            checkProperty(c, "apple", "pie");
059            checkProperty(c, "chocolate", "cake");
060            checkProperty(c, "frozen", "yogurt");
061    
062        }
063    
064        public void test_Asset_Property() throws Exception
065        {
066            IComponentSpecification s = parseComponent("AssetProperty.jwc");
067    
068            checkAsset(s, "private", "hugh", "grant");
069            checkAsset(s, "external", "joan", "rivers");
070            checkAsset(s, "context", "john", "cusak");
071        }
072    
073        private void checkAsset(IComponentSpecification s, String assetName, String propertyName,
074                                String expectedValue)
075        {
076            IAssetSpecification a = s.getAsset(assetName);
077    
078            assertEquals(expectedValue, a.getProperty(propertyName));
079        }
080    
081        /** @since 4.0 */
082    
083        public void testGetReservedParameterNames()
084        {
085            IComponentSpecification s = new ComponentSpecification();
086    
087            assertEquals(Collections.EMPTY_SET, s.getReservedParameterNames());
088    
089            s.addReservedParameterName("Fred");
090    
091            Set expected = new HashSet();
092    
093            expected.add("fred");
094    
095            assertEquals(expected, s.getReservedParameterNames());
096    
097            IParameterSpecification ps = new ParameterSpecification();
098    
099            ps.setAliases("wilma,barney");
100            ps.setParameterName("bambam");
101    
102            s.addParameter(ps);
103    
104            expected.add("wilma");
105            expected.add("barney");
106            expected.add("bambam");
107    
108            assertEquals(expected, s.getReservedParameterNames());
109    
110            try
111            {
112                s.getReservedParameterNames().clear();
113                unreachable();
114            }
115            catch (UnsupportedOperationException ex)
116            {
117                // expected
118            }
119    
120        }
121    }