while (it.hasNext()) {
System.out.println((String) it.next());
}
}
WSIFPort port = service.getPort();
WSIFOperation operation;
WSIFMessage inputMessage;
WSIFMessage outputMessage;
WSIFMessage faultMessage;
String customerNumber;
String tempString;
Address address;
ShoppingCart_Java shoppingCart;
Item item;
CreditCardInfo creditCardInfo;
AirMilesContainer airMilesContainer;
Integer currentTotal = null;
Long orderConfirmationNumber;
Integer itemQuantity;
Object part;
boolean operationSucceeded;
// -----------------------------------------------------------------------------------------------------
operation = port.createOperation("createOperation");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
debug("\n---> Invocation: public ShoppingCart_Java(String firstName, String lastName, Address address, String customerNumber)");
tempString = "Albert";
inputMessage.setObjectPart("firstName", tempString);
tempString = "Einstein";
inputMessage.setObjectPart("lastName", tempString);
address = new Address("Berlin", "Unter den Linden");
inputMessage.setObjectPart("address", address);
customerNumber = "AE001";
inputMessage.setObjectPart("customerNumber", customerNumber);
operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
assertTrue("Failed to create a ShoppingCart", operationSucceeded);
// -----------------------------------------------------------------------------------------------------
operation = port.createOperation("addItemOperation");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
tempString = "100123";
inputMessage.setObjectPart("itemNumber", tempString);
item = new Item();
//inputMessage.setObjectPart("item", item);
tempString = "Pocket calculator";
inputMessage.setObjectPart("itemName", tempString);
itemQuantity = new Integer(1);
inputMessage.setObjectPart("itemQuantity", itemQuantity);
operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
assertTrue("addItem test failed", operationSucceeded);
if (operationSucceeded) {
assertTrue("Part is not an Item!!!",
outputMessage.getObjectPart("item") instanceof Item);
debug(outputMessage.getObjectPart("item"));
} else {
// Cannot get here since test would have already failed!
}
// -----------------------------------------------------------------------------------------------------
operation = port.createOperation("addItemOperation");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
tempString = "234123";
inputMessage.setObjectPart("itemNumber", tempString);
item = new Item();
inputMessage.setObjectPart("item", item);
tempString = "Pencil";
inputMessage.setObjectPart("itemName", tempString);
itemQuantity = new Integer(12);
inputMessage.setObjectPart("itemQuantity", itemQuantity);
operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
assertTrue(
"addItem succeeded when it should have thrown a outOfStockException",
!operationSucceeded);
if (operationSucceeded) {
debug(outputMessage.getObjectPart("item"));
} else {
assertNotNull(
"outputMessage should have contained outOfStockException",
faultMessage.getObjectPart("outOfStockException"));
// Extra steps useful for debugging
/* part = faultMessage.getObjectPart("invalidItemException");
if (part != null) {
debug(faultMessage.getName() + ":\n" + part);
} else {
part = faultMessage.getObjectPart("outOfStockException");
if (part != null) {
debug(faultMessage.getName() + ":\n" + part);
} else {
debug("ERROR: Unknown fault message!");
}
}
*/
}
// -----------------------------------------------------------------------------------------------------
operation = port.createOperation("addItemOperation");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
debug("\n---> Invocation: public int addItem(String itemNumber, Item item, String itemName, int itemQuantity)");
inputMessage.setObjectPart("itemNumber", "234123");
item = new Item();
inputMessage.setObjectPart("item", item);
inputMessage.setObjectPart("itemName", "Pencil");
inputMessage.setIntPart("itemQuantity", 8);
operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
assertTrue("addItem failed when it should have succeeded", operationSucceeded);
//Extra steps useful for debugging
/* part = faultMessage.getObjectPart("invalidItemException");
if (operationSucceeded) {
debug(outputMessage.getObjectPart("item"));
} else {
part = faultMessage.getObjectPart("invalidItemException");
if (part != null) {
debug(faultMessage.getName() + ":\n" + part);
} else {
part = faultMessage.getObjectPart("outOfStockException");
if (part != null) {
debug(faultMessage.getName() + ":\n" + part);
} else {
debug("ERROR: Unknown fault message!");
}
}
}*/
// -----------------------------------------------------------------------------------------------------
operation = port.createOperation("submitOrderOperation");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
debug("\n---> Invocation: public long submitOrder(CreditCardInfo creditCardInfo, AirMilesContainer airMilesContainer)");
creditCardInfo = new CreditCardInfo();
inputMessage.setObjectPart("creditCardInfo", creditCardInfo);
airMilesContainer = new AirMilesContainer();
inputMessage.setObjectPart("airMilesContainer", airMilesContainer);
inputMessage.setLongPart("orderConfirmationNumber", 0);
operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
assertTrue(
"submitOrderOperation failed when it should have succeeded.",
operationSucceeded);
debug(
"order confirmation no. = "
+ outputMessage.getObjectPart("orderConfirmationNumber"));
debug(airMilesContainer);
// -----------------------------------------------------------------------------------------------------
operation = port.createOperation("queryOrdersOperation");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
debug("\n---> Invocation: public static Orders queryOrders(String customerNumber)");