View Javadoc

    1   /*
    2    * $Id: ClasspathConfigurationProviderTest.java 501717 2007-01-31 03:51:11Z mrdon $
    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  package org.apache.struts2.config;
    22
    23  import java.util.Map;
    24
    25  import org.apache.struts2.dispatcher.ServletDispatcherResult;
    26
    27  import com.opensymphony.xwork2.config.Configuration;
    28  import com.opensymphony.xwork2.config.entities.ActionConfig;
    29  import com.opensymphony.xwork2.config.entities.PackageConfig;
    30  import com.opensymphony.xwork2.config.entities.ResultConfig;
    31  import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
    32  import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
    33
    34  import junit.framework.TestCase;
    35
    36  public class ClasspathConfigurationProviderTest extends TestCase {
    37
    38      ClasspathConfigurationProvider provider;
    39      Configuration config;
    40
    41      public void setUp() {
    42          provider = new ClasspathConfigurationProvider(new String[]{"org.apache.struts2.config"});
    43          config = new DefaultConfiguration();
    44          PackageConfig strutsDefault = new PackageConfig("struts-default");
    45          strutsDefault.addResultTypeConfig(new ResultTypeConfig("dispatcher", ServletDispatcherResult.class.getName(), "location"));
    46          strutsDefault.setDefaultResultType("dispatcher");
    47          config.addPackageConfig("struts-default", strutsDefault);
    48          PackageConfig customPackage = new PackageConfig("custom-package");
    49          customPackage.setNamespace("/custom");
    50          config.addPackageConfig("custom-package", customPackage);
    51          provider.init(config);
    52          provider.loadPackages();
    53      }
    54
    55      public void testFoundRootPackages() {
    56          assertEquals(5, config.getPackageConfigs().size());
    57          PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config");
    58          assertNotNull(pkg);
    59          Map configs = pkg.getActionConfigs();
    60          assertNotNull(configs);
    61          // assertEquals(1, configs.size());
    62          ActionConfig actionConfig = (ActionConfig) configs.get("customParentPackage");
    63          assertNotNull(actionConfig);
    64      }
    65
    66      public void testParentPackage() {
    67          PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config");
    68          // assertEquals(2, pkg.getParents().size());
    69          Map configs = pkg.getActionConfigs();
    70          ActionConfig config = (ActionConfig) configs.get("customParentPackage");
    71          assertNotNull(config);
    72          assertEquals("/custom", pkg.getNamespace());
    73      }
    74
    75      public void testCustomNamespace() {
    76          PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.CustomNamespaceAction");
    77          Map configs = pkg.getAllActionConfigs();
    78          // assertEquals(2, configs.size());
    79          ActionConfig config = (ActionConfig) configs.get("customNamespace");
    80          assertEquals(config.getPackageName(), pkg.getName());
    81          assertEquals(1, pkg.getParents().size());
    82          assertNotNull(config);
    83          assertEquals("/mynamespace", pkg.getNamespace());
    84          ActionConfig ac = (ActionConfig) configs.get("customParentPackage");
    85          assertNotNull(ac);
    86      }
    87
    88      public void testResultAnnotations() {
    89          PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.cltest");
    90          assertEquals("/cltest", pkg.getNamespace());
    91          ActionConfig acfg = pkg.getActionConfigs().get("twoResult");
    92          assertNotNull(acfg);
    93          assertEquals(3, acfg.getResults().size());
    94      }
    95
    96      public void testActionImplementation() {
    97          PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.cltest");
    98          assertEquals("/cltest", pkg.getNamespace());
    99          ActionConfig acfg = pkg.getActionConfigs().get("actionImpl");
    100         assertNotNull(acfg);
    101     }
    102 }