    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
    56  /***
    57   * @author koichik
    58   */
    59  public class AxisDeployerTest extends S2TestCase {
    60      private S2Container container;
    61      private int containerCount;
    62      private int componentDefCount;
    63      private List serviceComponents = new ArrayList();
    64      private List handlerComponents = new ArrayList();
    65      private List wsddFileNames = new ArrayList();
    66
    67      public AxisDeployerTest(String name) {
    68          super(name);
    69      }
    70
    71      public void setUp() {
    72          containerCount = 0;
    73          componentDefCount = 0;
    74          serviceComponents.clear();
    75          handlerComponents.clear();
    76          wsddFileNames.clear();
    77      }
    78
    79      public void testForEach0() {
    80          AxisDeployer deployer = new DeployCounter();
    81          deployer.forEach(container);
    82          assertEquals(1, containerCount);
    83          assertEquals(0, componentDefCount);
    84      }
    85
    86      public void testForEach1() {
    87          include("AxisDeployerTest.forEach1.dicon");
    88          AxisDeployer deployer = new DeployCounter();
    89          deployer.forEach(container);
    90          assertEquals(2, containerCount);
    91          assertEquals(1, componentDefCount);
    92      }
    93
    94      public void testForEach2() {
    95          include("AxisDeployerTest.forEach1.dicon");
    96          include("AxisDeployerTest.forEach2.dicon");
    97          AxisDeployer deployer = new DeployCounter();
    98          deployer.forEach(container);
    99          assertEquals(4, containerCount);
    100         assertEquals(4, componentDefCount);
    101     }
    102
    103     public void testProcessContainer0() {
    104         createTestDeployer().forEach(container);
    105         assertEquals(0, wsddFileNames.size());
    106     }
    107
    108     public void testProcessContainer1() {
    109         include("AxisDeployerTest.processContainer1.dicon");
    110         createTestDeployer().forEach(container);
    111         assertEquals(2, wsddFileNames.size());
    112         assertEquals("foo.wsdd", wsddFileNames.get(0));
    113         assertEquals("bar.wsdd", wsddFileNames.get(1));
    114     }
    115
    116     public void testProcessComponent0() {
    117         createTestDeployer().forEach(container);
    118         assertEquals(0, serviceComponents.size());
    119         assertEquals(0, handlerComponents.size());
    120     }
    121
    122     public void testProcessComponent1() {
    123         include("AxisDeployerTest.processComponent1.dicon");
    124         createTestDeployer().forEach(container);
    125         assertEquals(2, serviceComponents.size());
    126         assertEquals(1, handlerComponents.size());
    127     }
    128
    129     private class DeployCounter extends AxisDeployer {
    130         public void process(S2Container container) {
    131             ++containerCount;
    132         }
    133
    134         public void process(ComponentDef compoenentDef) {
    135             ++componentDefCount;
    136         }
    137     };
    138
    139     private AxisDeployer createTestDeployer() {
    140         AxisDeployer deployer = new AxisDeployer();
    141         deployer.serviceDeployer = new ItemDeployer() {
    142             public void deploy(ComponentDef componentDef, MetaDef metaDef) {
    143                 serviceComponents.add(componentDef);
    144             }
    145         };
    146         deployer.handlerDeployer = new ItemDeployer() {
    147             public void deploy(ComponentDef componentDef, MetaDef metaDef) {
    148                 handlerComponents.add(componentDef);
    149             }
    150         };
    151         deployer.wsddDeployer = new ItemDeployer() {
    152             public void deploy(ComponentDef componentDef, MetaDef metaDef) {
    153                 wsddFileNames.add(metaDef.getValue());
    154             }
    155         };
    156         return deployer;
    157     }
    158 }