001package org.apache.turbine.annotation;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.junit.Assert.assertEquals;
023import static org.junit.Assert.assertFalse;
024import static org.junit.Assert.assertNotNull;
025
026import java.util.List;
027
028import org.apache.commons.configuration.Configuration;
029import org.apache.fulcrum.factory.FactoryService;
030import org.apache.turbine.modules.Screen;
031import org.apache.turbine.modules.ScreenLoader;
032import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
033import org.apache.turbine.util.TurbineConfig;
034import org.apache.turbine.util.TurbineException;
035import org.junit.AfterClass;
036import org.junit.BeforeClass;
037import org.junit.Ignore;
038import org.junit.Test;
039
040/**
041 * Tests the various annotations
042 *
043 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
044 */
045public class AnnotationProcessorTest
046{
047    private static TurbineConfig tc;
048
049    @TurbineConfiguration
050    private Configuration completeConfiguration = null;
051
052    @TurbineConfiguration("serverdata.default")
053    private Configuration serverdataDefaultConfiguration = null;
054
055    @TurbineConfiguration("module.cache")
056    private boolean moduleCache = true;
057
058    @TurbineConfiguration("action.cache.size")
059    private int actionCacheSize = 0;
060
061    @TurbineConfiguration("template.homepage")
062    private String templateHomepage;
063
064    @TurbineConfiguration("module.packages")
065    private List<String> modulePackages;
066
067    @TurbineConfiguration("does.not.exist")
068    private long notModified = 1;
069
070    @TurbineLoader(Screen.class)
071    private ScreenLoader screenLoader;
072
073    @TurbineService
074    private AssemblerBrokerService asb;
075
076    @TurbineService
077    private FactoryService factory;
078
079    @BeforeClass
080    public static void init() throws Exception
081    {
082        tc = new TurbineConfig(".", "/conf/test/CompleteTurbineResources.properties");
083        tc.initialize();
084    }
085
086    @AfterClass
087    public static void destroy()
088        throws Exception
089    {
090        tc.dispose();
091    }
092
093    @Test
094    public void testProcess() throws TurbineException
095    {
096        AnnotationProcessor.process(this);
097
098        assertNotNull(completeConfiguration);
099        assertFalse(completeConfiguration.getBoolean("module.cache", true));
100
101        assertNotNull(serverdataDefaultConfiguration);
102        assertEquals(80, serverdataDefaultConfiguration.getInt("serverPort"));
103
104        assertFalse(moduleCache);
105        assertEquals(20, actionCacheSize);
106        assertEquals("Index.vm", templateHomepage);
107        assertNotNull(modulePackages);
108        assertEquals(3, modulePackages.size());
109        assertEquals("org.apache.turbine.services.template.modules", modulePackages.get(1));
110        assertEquals(1, notModified);
111
112        assertNotNull(screenLoader);
113        assertNotNull(asb);
114        assertNotNull(factory);
115    }
116
117    @Ignore("For performance tests only") @Test
118    public void testProcessingPerformance() throws TurbineException
119    {
120        long startTime = System.currentTimeMillis();
121
122        for (int i = 0; i < 100000; i++)
123        {
124            AnnotationProcessor.process(this);
125        }
126
127        System.out.println(System.currentTimeMillis() - startTime);
128    }
129}