001    // Copyright 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.annotations;
016    
017    import java.lang.reflect.Method;
018    
019    import org.apache.hivemind.Location;
020    import org.apache.hivemind.Resource;
021    import org.apache.tapestry.enhance.EnhancementOperation;
022    import org.apache.tapestry.spec.ComponentSpecification;
023    import org.apache.tapestry.spec.IAssetSpecification;
024    import org.apache.tapestry.spec.IComponentSpecification;
025    import org.testng.annotations.Test;
026    
027    /**
028     * Tests for {@link org.apache.tapestry.annotations.AssetAnnotationWorker}.
029     * 
030     */
031    @Test
032    public class TestAssetAnnotationWorker extends BaseAnnotationTestCase
033    {
034        public void test_Success()
035        {
036            Location l = newLocation();
037            Resource r = newMock(Resource.class);
038            EnhancementOperation op = newOp();
039            IComponentSpecification spec = new ComponentSpecification();
040            spec.setSpecificationLocation(r);
041    
042            replay();
043    
044            Method m = findMethod(AnnotatedPage.class, "getGlobalStylesheet");
045    
046            new AssetAnnotationWorker().performEnhancement(op, spec, m, l);
047    
048            verify();
049    
050            IAssetSpecification as = spec.getAsset("globalStylesheet");
051    
052            assertEquals("/style/global.css", as.getPath());
053            assertEquals(as.getLocation(), l);
054            assertEquals("globalStylesheet", as.getPropertyName());
055        }
056    
057        public void test_Class_Relative_Asset()
058        {
059            Location l = newLocation();
060            Resource r = newMock(Resource.class);
061            EnhancementOperation op = newOp();
062            IComponentSpecification spec = new ComponentSpecification();
063            spec.setSpecificationLocation(r);
064    
065            replay();
066    
067            Method m = findMethod(AnnotatedPage.class, "getTextAsset");
068    
069            new AssetAnnotationWorker().performEnhancement(op, spec, m, l);
070    
071            verify();
072    
073            IAssetSpecification as = spec.getAsset("textAsset");
074    
075            assertEquals("images/test-asset.txt", as.getPath());
076            assertEquals(as.getLocation(), l);
077            assertEquals("textAsset", as.getPropertyName());
078        }
079    }