File: InheritanceTestCase.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (176 lines) | stat: -rw-r--r-- 7,588 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package test.wsdl.inheritance;

import org.apache.axis.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.wsdl.Definition;
import javax.wsdl.Operation;
import javax.wsdl.PortType;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.rpc.ServiceException;
import java.io.File;
import java.util.Iterator;
import java.util.List;

/**
 * This class contains the methods necessary for testing that the use inherited methods
 * function in the Java2WSDL tool works as specified.
 * 
 * When using the Java2WSDL tool with the use inherited methods switch on, the tool
 * should generate the appropriate classes to include all of the inherited methods
 * of the specified interface (in addition to the actual methods in the interface).  
 *
 * @version   1.00  21 Jan 2002
 * @author    Brent Ulbricht
 */
public class InheritanceTestCase extends junit.framework.TestCase {

    /**
     *  Constructor used in all tests utilizing the Junit Framework.
     */
    public InheritanceTestCase(String name) {
        super(name);
    } // Constructor

    /**
     *  This method insures that two methods (getLastTradePrice and getRealtimeLastTradePrice)
     *  can be called, and they return the expected stock values.  The main goal is to verify
     *  that the getLastTradePrice method does not cause any compile errors and returns the
     *  expected stock value.  
     *
     *  The getLastTradePrice method originates from the test/wsdl/inheritance/StockQuoteProvider
     *  interface.  The InheritancePortType interface extends the StockQuoteProvider interface.
     *
     *  When the WSDL is generated for the InheritancePortType interface and the use inherited
     *  methods switch is used, all methods from the StockQuoteProvider and InheritancePortType
     *  interfaces should be available for service.
     */
    public void testInheritanceTest() {
        test.wsdl.inheritance.InheritancePortType binding;
        try {
            binding = new InheritancePortTypeServiceLocator().getInheritanceTest();
        } catch (ServiceException jre) {
            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
        }
        assertTrue("binding is null", binding != null);

        // The getLastTradePrice method should return a value of 20.25 when sent the tickerSymbol
        // "SOAP".
        try {
            float expected = 20.25F;
            float actual = binding.getLastTradePrice(new java.lang.String("SOAP"));
            float delta = 0.0F;
            assertEquals("The actual and expected values did not match.", expected, actual, delta);
        } catch (java.rmi.RemoteException re) {
            throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re);
        }

        // The getRealtimeLastTradePrice method should return a value of 21.75 when sent the 
        // tickerSymbol "AXIS".
        try {
            float expected = 21.75F;
            float actual = binding.getRealtimeLastTradePrice(new java.lang.String("AXIS"));
            float delta = 0.0F;
            assertEquals("The actual and expected values did not match.", expected, actual, delta);
        } catch (java.rmi.RemoteException re) {
            throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re);
        }

    } // testInheritanceTest

    /**
     * This test validates the WSDL generated by Java2WSDL 
     */
    public void testStopClasses() {
        String path = "build" + File.separator + "work" + File.separator +
                "test" + File.separator + "wsdl" + File.separator +
                "inheritance" + File.separator + "StopExclude.wsdl";
        Document doc = null;
        Definition def = null;
        try {
            doc = XMLUtils.newDocument(path);
            assertNotNull("Unable to locate WSDL file: " + path, doc);
            WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
            //reader.setFeature("javax.wsdl.verbose", true);
            def = reader.readWSDL(path, doc);
            assertNotNull("unable to generate WSDL definition from document: " + path, def);
        } catch (Exception e) {
            throw new junit.framework.AssertionFailedError("Exception caught: " + e);
        }
        
        // Now check parts of the definition
        
        // types
        // The complex types Baby_bean and Child_bean should exist
        // The type Parent_bean should NOT exist
        NodeList typeList = doc.getElementsByTagName("wsdl:types");
        Node typeNode = typeList.item(0);
        assertNotNull("types section of the WSDL document", typeNode);
        Element typeElem = (Element) typeNode;

        boolean babyFound = false;
        boolean childFound = false;
        NodeList nodeList = typeElem.getElementsByTagName("complexType");
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node n = nodeList.item(i);
            String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
            if (name.equals("Baby_bean"))
                babyFound = true;
            else if (name.equals("Child_bean"))
                childFound = true;
            else if (name.equals("Parent_bean"))
                assertTrue("Parent_bean found in WSDL types section", false);
            else
                assertTrue("Unknown node found in types section: " + name, false);
        }
        assertTrue("Baby_bean not found in WSDL types section", babyFound);
        assertTrue("Child_bean not found in WSDL types section", childFound);
            
        // operations
        // The only ones we shold find are baby_method and child_method
        boolean babyOpFound = false;
        boolean childOpFound = false;
        
        // we iterate the portTypes, but we check to make sure there is only one
        Iterator ip = def.getPortTypes().values().iterator();
        PortType portType = (PortType) ip.next();
        List operationList = portType.getOperations();
        for (int i = 0; i < operationList.size(); ++i) {
            String opName = ((Operation) operationList.get(i)).getName();
            if (opName.equals("baby_method"))
                babyOpFound = true;
            else if (opName.equals("child_method"))
                childOpFound = true;
            else if (opName.equals("parent_method"))
                assertTrue("parent_method operation found in WSDL", false);
            else
                assertTrue("Invalid operation found in WSDL: " + opName, false);
        }
        assertTrue("WSDL has more than one portType", !ip.hasNext());
        assertTrue("baby_method operation not found in WSDL", babyOpFound);
        assertTrue("child_method operation not found in WSDL ", childOpFound);

    } // testStopClasses

} // InheritanceTestCase