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.axis.server.deployment;
47  
48  import java.util.ArrayList;
49  import java.util.List;
50  
51  import javax.xml.namespace.QName;
52  
53  import org.apache.axis.providers.java.JavaProvider;
54  import org.seasar.axis.server.DeployFailedException;
55  import org.seasar.extension.unit.S2TestCase;
56  import org.seasar.framework.container.ComponentDef;
57  import org.seasar.framework.container.MetaDef;
58  import org.seasar.framework.container.S2Container;
59  import org.w3c.dom.Element;
60  
61  /***
62   * @author koichik
63   */
64  public class DeployerTest extends S2TestCase {
65      private S2Container container;
66      private int containerCount;
67      private int componentDefCount;
68      private List wsddFileNames = new ArrayList();
69  
70      public DeployerTest(String name) {
71          super(name);
72      }
73  
74      public void setUp() {
75          containerCount = 0;
76          componentDefCount = 0;
77          wsddFileNames.clear();
78      }
79  
80      public void testForEach0() {
81          Deployer deployer = new DeployCounter();
82          deployer.forEach(container);
83          assertEquals(1, containerCount);
84          assertEquals(0, componentDefCount);
85      }
86  
87      public void testForEach1() {
88          include("DeployerTest.forEach1.dicon");
89          Deployer deployer = new DeployCounter();
90          deployer.forEach(container);
91          assertEquals(2, containerCount);
92          assertEquals(1, componentDefCount);
93      }
94  
95      public void testForEach2() {
96          include("DeployerTest.forEach1.dicon");
97          include("DeployerTest.forEach2.dicon");
98          Deployer deployer = new DeployCounter();
99          deployer.forEach(container);
100         assertEquals(4, containerCount);
101         assertEquals(4, componentDefCount);
102     }
103 
104     public void testProcessContainer0() {
105         Deployer deployer = new Deployer() {
106             public void deployWSDD(String wsddFileName) {
107                 wsddFileNames.add(wsddFileName);
108             }
109         };
110         deployer.forEach(container);
111         assertEquals(0, wsddFileNames.size());
112     }
113 
114     public void testProcessContainer1() {
115         include("DeployerTest.processContainer1.dicon");
116         Deployer deployer = new Deployer() {
117             public void deployWSDD(String wsddFileName) {
118                 wsddFileNames.add(wsddFileName);
119             }
120         };
121         deployer.forEach(container);
122         assertEquals(2, wsddFileNames.size());
123         assertEquals("foo.wsdd", wsddFileNames.get(0));
124         assertEquals("bar.wsdd", wsddFileNames.get(1));
125     }
126 
127     public void testProcessContainer2() {
128         include("DeployerTest.processContainer2.dicon");
129         Deployer deployer = new Deployer() {
130             public void deployWSDD(String wsddFileName) {
131                 wsddFileNames.add(wsddFileName);
132             }
133         };
134         try {
135             deployer.forEach(container);
136             fail();
137         }
138         catch (DeployFailedException expected) {
139         }
140     }
141 
142     public void testGetServiceElement() {
143         Deployer deployer = new Deployer();
144 
145         Element e1 = deployer
146                 .getServiceElement("org/seasar/axis/server/deployment/DeployerTest.getServiceElement1.wsdd");
147         assertNotNull(e1);
148         assertEquals("service", e1.getNodeName());
149         assertEquals("one", e1.getAttribute("name"));
150 
151         try {
152             deployer
153                     .getServiceElement("org/seasar/axis/server/deployment/DeployerTest.getServiceElement0.wsdd");
154             fail();
155         }
156         catch (DeployFailedException expected) {
157         }
158 
159         try {
160             deployer
161                     .getServiceElement("org/seasar/axis/server/deployment/DeployerTest.getServiceElement2.wsdd");
162             fail();
163         }
164         catch (DeployFailedException expected) {
165         }
166     }
167 
168     public void testCreateWSDDS2Service() {
169         include("DeployerTest.createWSDDS2Service.dicon");
170         Deployer deployer = new Deployer();
171 
172         ComponentDef def1 = getComponentDef("null");
173         MetaDef meta1 = def1.getMetaDef("s2axis:service");
174         WSDDS2Service service1 = deployer.createWSDDS2Service(def1, meta1);
175         assertNotNull(service1);
176         assertEquals(new QName("null"), service1.getQName());
177 
178         ComponentDef def2 = getComponentDef("serviceDef");
179         MetaDef meta2 = def2.getMetaDef("s2axis:service");
180         WSDDS2Service service2 = deployer.createWSDDS2Service(def2, meta2);
181         assertNotNull(service2);
182         assertEquals(new QName("serviceDef"), service2.getQName());
183         assertEquals("java.lang.Boolean", service2.getParameter(JavaProvider.OPTION_CLASSNAME));
184 
185         ComponentDef def3 = getComponentDef("wsdd");
186         MetaDef meta3 = def3.getMetaDef("s2axis:service");
187         WSDDS2Service service3 = deployer.createWSDDS2Service(def3, meta3);
188         assertNotNull(service3);
189         assertEquals(new QName("FromWSDD"), service3.getQName());
190         assertEquals("java.lang.Double", service3.getParameter(JavaProvider.OPTION_CLASSNAME));
191 
192         try {
193             ComponentDef def4 = getComponentDef("int");
194             MetaDef meta4 = def4.getMetaDef("s2axis:service");
195             deployer.createWSDDS2Service(def4, meta4);
196             fail();
197         }
198         catch (DeployFailedException expected) {
199         }
200     }
201 
202     private class DeployCounter extends Deployer {
203         public void process(S2Container container) {
204             ++containerCount;
205         }
206 
207         public void process(ComponentDef compoenentDef) {
208             ++componentDefCount;
209         }
210     };
211 }