    1   /*
    2    *
    3    * The Seasar Software License, Version 1.1
    4    *
    5    * Copyright (c) 2003-2004 The Seasar Project. All rights reserved.
    6    *
    7    * Redistribution and use in source and binary forms, with or
    8    * without modification, are permitted provided that the following
    9    * conditions are met:
    10   *
    11   * 1. Redistributions of source code must retain the above
    12   *    copyright notice, this list of conditions and the following
    13   *    disclaimer.
    14   *
    15   * 2. Redistributions in binary form must reproduce the above
    16   *    copyright notice, this list of conditions and the following
    17   *    disclaimer in the documentation and/or other materials provided
    18   *    with the distribution.
    19   *
    20   * 3. The end-user documentation included with the redistribution,
    21   *    if any, must include the following acknowledgement:
    22   *    "This product includes software developed by the
    23   *    Seasar Project (http://www.seasar.org/)."
    24   *    Alternately, this acknowledgement may appear in the software
    25   *    itself, if and wherever such third-party acknowledgements
    26   *    normally appear.
    27   *
    28   * 4. Neither the name "The Seasar Project" nor the names of its
    29   *    contributors may be used to endorse or promote products derived
    30   *    from this software without specific prior written permission of
    31   *    the Seasar Project.
    32   *
    33   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR
    34   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    35   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    36   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE SEASAR PROJECT
    37   * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    38   * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    39   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    40   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    41   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    42   * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING
    43   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    44   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    45   */
    46  package org.seasar.remoting.axis.deployer;
    47
    48  import java.util.ArrayList;
    49  import java.util.List;
    50
    51  import org.seasar.extension.unit.S2TestCase;
    52  import org.seasar.framework.container.ComponentDef;
    53  import org.seasar.framework.container.MetaDef;
    54  import org.seasar.framework.container.S2Container;
    55  import org.seasar.framework.container.impl.MetaDefImpl;
    56
    57  /***
    58   * @author koichik
    59   */
    60  public class AxisDeployerTest extends S2TestCase {
    61      private S2Container container;
    62      private int containerCount;
    63      private int componentDefCount;
    64      private List serviceComponents = new ArrayList();
    65      private List handlerComponents = new ArrayList();
    66      private List wsddFileNames = new ArrayList();
    67
    68      public AxisDeployerTest(String name) {
    69          super(name);
    70      }
    71
    72      public void setUp() {
    73          containerCount = 0;
    74          componentDefCount = 0;
    75          serviceComponents.clear();
    76          handlerComponents.clear();
    77          wsddFileNames.clear();
    78      }
    79
    80      public void testForEach0() {
    81          AxisDeployer deployer = new DeployCounter();
    82          deployer.forEach(container);
    83          assertEquals(1, containerCount);
    84          assertEquals(0, componentDefCount);
    85      }
    86
    87      public void testForEach1() {
    88          include("AxisDeployerTest.forEach1.dicon");
    89          AxisDeployer deployer = new DeployCounter();
    90          deployer.forEach(container);
    91          assertEquals(2, containerCount);
    92          assertEquals(1, componentDefCount);
    93      }
    94
    95      public void testForEach2() {
    96          include("AxisDeployerTest.forEach1.dicon");
    97          include("AxisDeployerTest.forEach2.dicon");
    98          AxisDeployer deployer = new DeployCounter();
    99          deployer.forEach(container);
    100         assertEquals(4, containerCount);
    101         assertEquals(4, componentDefCount);
    102     }
    103
    104     public void testProcessContainer0() {
    105         createTestDeployer().forEach(container);
    106         assertEquals(0, wsddFileNames.size());
    107     }
    108
    109     public void testProcessContainer1() {
    110         include("AxisDeployerTest.processContainer1.dicon");
    111         createTestDeployer().forEach(container);
    112         assertEquals(2, wsddFileNames.size());
    113         assertEquals("foo.wsdd", wsddFileNames.get(0));
    114         assertEquals("bar.wsdd", wsddFileNames.get(1));
    115     }
    116
    117     public void testProcessComponent0() {
    118         createTestDeployer().forEach(container);
    119         assertEquals(0, serviceComponents.size());
    120         assertEquals(0, handlerComponents.size());
    121     }
    122
    123     public void testProcessComponent1() {
    124         include("AxisDeployerTest.processComponent1.dicon");
    125         createTestDeployer().forEach(container);
    126         assertEquals(2, serviceComponents.size());
    127         assertEquals(1, handlerComponents.size());
    128     }
    129
    130     public void testGetLocalName() {
    131         AxisDeployer deployer = new AxisDeployer();
    132         assertEquals("1", "service", deployer.getLocalName(new MetaDefImpl("axis-service")));
    133         assertEquals("2", "handler", deployer.getLocalName(new MetaDefImpl("s2-axis:handler")));
    134         assertNull("3", deployer.getLocalName(new MetaDefImpl("axis-")));
    135         assertNull("4", deployer.getLocalName(new MetaDefImpl("s2-axis:")));
    136         assertNull("5", deployer.getLocalName(new MetaDefImpl("hoge")));
    137     }
    138
    139     private class DeployCounter extends AxisDeployer {
    140         public void process(S2Container container) {
    141             ++containerCount;
    142         }
    143
    144         public void process(ComponentDef compoenentDef) {
    145             ++componentDefCount;
    146         }
    147     };
    148
    149     private AxisDeployer createTestDeployer() {
    150         AxisDeployer deployer = new AxisDeployer();
    151         deployer.serviceDeployer = new ItemDeployer() {
    152             public void deploy(ComponentDef componentDef, MetaDef metaDef) {
    153                 serviceComponents.add(componentDef);
    154             }
    155         };
    156         deployer.handlerDeployer = new ItemDeployer() {
    157             public void deploy(ComponentDef componentDef, MetaDef metaDef) {
    158                 handlerComponents.add(componentDef);
    159             }
    160         };
    161         deployer.wsddDeployer = new ItemDeployer() {
    162             public void deploy(ComponentDef componentDef, MetaDef metaDef) {
    163                 wsddFileNames.add(metaDef.getValue());
    164             }
    165         };
    166         return deployer;
    167     }
    168 }