| 1 |
/* |
| 2 |
* Copyright 2001-2004 The Apache Software Foundation. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package test.functional; |
| 18 |
|
| 19 |
import junit.framework.TestCase; |
| 20 |
import org.apache.axis.AxisFault; |
| 21 |
import org.apache.axis.client.AdminClient; |
| 22 |
import org.apache.axis.components.logger.LogFactory; |
| 23 |
import org.apache.commons.logging.Log; |
| 24 |
import samples.stock.GetQuote; |
| 25 |
import samples.stock.GetQuote2; |
| 26 |
|
| 27 |
|
| 28 |
/** Test the stock sample code. |
| 29 |
*/ |
| 30 |
public class TestStockSample extends TestCase { |
| 31 |
static Log log = |
| 32 |
LogFactory.getLog(TestStockSample.class.getName()); |
| 33 |
|
| 34 |
public TestStockSample(String name) { |
| 35 |
super(name); |
| 36 |
} |
| 37 |
|
| 38 |
public void doTestStockJWS () throws Exception { |
| 39 |
String[] args = { "-uuser1", "-wpass1", "XXX", "-sjws/StockQuoteService.jws" }; |
| 40 |
float val = new GetQuote().getQuote(args); |
| 41 |
assertEquals("TestStockSample.doTestStockJWS(): stock price should be 66.25", val, 66.25, 0.01); |
| 42 |
|
| 43 |
// This should FAIL |
| 44 |
args[3] = "-sjws/AltStockQuoteService.jws"; |
| 45 |
try { |
| 46 |
val = new GetQuote().getQuote(args); |
| 47 |
} catch (AxisFault e) { |
| 48 |
// Don't print stack trace unless there is an error |
| 49 |
// e.printStackTrace(); |
| 50 |
return; |
| 51 |
} |
| 52 |
assertNull("-sjws/AltStockQuoteService.jws did not fail as expected."); |
| 53 |
} |
| 54 |
|
| 55 |
public void doTestDeploy () throws Exception { |
| 56 |
String[] args = { "samples/stock/deploy.wsdd" }; |
| 57 |
AdminClient.main(args); |
| 58 |
} |
| 59 |
|
| 60 |
public void doTestStockJava() throws Exception { |
| 61 |
String[] args = { "XXX" }; |
| 62 |
float val = new GetQuote2().getQuote(args); |
| 63 |
assertEquals("Stock price is not the expected 55.25 +/- 0.01", val, 55.25, 0.01); |
| 64 |
} |
| 65 |
|
| 66 |
public void doTestStock () throws Exception { |
| 67 |
String[] args = { "-uuser1", "-wpass1", "XXX" }; |
| 68 |
float val = new GetQuote().getQuote(args); |
| 69 |
assertEquals("Stock price is not the expected 55.25 +/- 0.01", val, 55.25, 0.01); |
| 70 |
} |
| 71 |
|
| 72 |
public void doTestStockNoAction () throws Exception { |
| 73 |
String[] args = { "-uuser1", "-wpass1", "XXX_noaction" }; |
| 74 |
float val = new GetQuote().getQuote(args); |
| 75 |
assertEquals("Stock price is not the expected 55.25 +/- 0.01", val, 55.25, 0.01); |
| 76 |
} |
| 77 |
|
| 78 |
public void doTestUndeploy () throws Exception { |
| 79 |
String[] args = { "samples/stock/undeploy.wsdd" }; |
| 80 |
AdminClient.main(args); |
| 81 |
} |
| 82 |
|
| 83 |
public static void main(String args[]) throws Exception { |
| 84 |
TestStockSample tester = new TestStockSample("tester"); |
| 85 |
tester.testStockService(); |
| 86 |
} |
| 87 |
|
| 88 |
public void testStockService () throws Exception { |
| 89 |
try { |
| 90 |
log.info("Testing stock sample."); |
| 91 |
log.info("Testing JWS..."); |
| 92 |
doTestStockJWS(); |
| 93 |
log.info("Testing Java Binding..."); |
| 94 |
doTestStockJava(); |
| 95 |
log.info("Testing deployment..."); |
| 96 |
doTestDeploy(); |
| 97 |
log.info("Testing service..."); |
| 98 |
doTestStock(); |
| 99 |
log.info("Testing service with SOAPAction: \"\"..."); |
| 100 |
doTestStockNoAction(); |
| 101 |
log.info("Testing undeployment..."); |
| 102 |
doTestUndeploy(); |
| 103 |
log.info("Test complete."); |
| 104 |
} |
| 105 |
catch( Exception e ) { |
| 106 |
e.printStackTrace(); |
| 107 |
throw new Exception("Fault returned from test: "+e); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
|