View Javadoc

    1   package org.apache.turbine.annotation;
    2
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *   http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21
    22  import static org.junit.Assert.assertEquals;
    23  import static org.junit.Assert.assertFalse;
    24  import static org.junit.Assert.assertNotNull;
    25
    26  import java.util.List;
    27
    28  import org.apache.commons.configuration.Configuration;
    29  import org.apache.fulcrum.factory.FactoryService;
    30  import org.apache.turbine.modules.Screen;
    31  import org.apache.turbine.modules.ScreenLoader;
    32  import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
    33  import org.apache.turbine.util.TurbineConfig;
    34  import org.apache.turbine.util.TurbineException;
    35  import org.junit.AfterClass;
    36  import org.junit.BeforeClass;
    37  import org.junit.Ignore;
    38  import org.junit.Test;
    39
    40  /**
    41   * Tests the various annotations
    42   *
    43   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
    44   */
    45  public class AnnotationProcessorTest
    46  {
    47      private static TurbineConfig tc;
    48
    49      @TurbineConfiguration
    50      private Configuration completeConfiguration = null;
    51
    52      @TurbineConfiguration("serverdata.default")
    53      private Configuration serverdataDefaultConfiguration = null;
    54
    55      @TurbineConfiguration("module.cache")
    56      private boolean moduleCache = true;
    57
    58      @TurbineConfiguration("action.cache.size")
    59      private int actionCacheSize = 0;
    60
    61      @TurbineConfiguration("template.homepage")
    62      private String templateHomepage;
    63
    64      @TurbineConfiguration("module.packages")
    65      private List<String> modulePackages;
    66
    67      @TurbineConfiguration("does.not.exist")
    68      private long notModified = 1;
    69
    70      @TurbineLoader(Screen.class)
    71      private ScreenLoader screenLoader;
    72
    73      @TurbineService
    74      private AssemblerBrokerService asb;
    75
    76      @TurbineService
    77      private FactoryService factory;
    78
    79      @BeforeClass
    80      public static void init() throws Exception
    81      {
    82          tc = new TurbineConfig(".", "/conf/test/CompleteTurbineResources.properties");
    83          tc.initialize();
    84      }
    85
    86      @AfterClass
    87      public static void destroy()
    88          throws Exception
    89      {
    90          tc.dispose();
    91      }
    92
    93      @Test
    94      public void testProcess() throws TurbineException
    95      {
    96          AnnotationProcessor.process(this);
    97
    98          assertNotNull(completeConfiguration);
    99          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 }