001: package edu.iu.uis.eden.services;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006:
007: import junit.framework.TestCase;
008: import edu.iu.uis.eden.WorkflowServiceError;
009: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
010:
011: public class TestDocElementError extends TestCase {
012: private WorkflowServiceError busError;
013:
014: public TestDocElementError(String s) {
015: super (s);
016: }
017:
018: protected void setUp() {
019: busError = new WorkflowServiceErrorImpl("message", "0");
020: }
021:
022: protected void tearDown() {
023: }
024:
025: /**
026: * test that what goes in constructor comes out
027: */
028: public void testConstructor() {
029: String message = "message";
030: String type = "1";
031: WorkflowServiceError busError = new WorkflowServiceErrorImpl(
032: message, type);
033: assertEquals(
034: "Message was altered during construction or getting",
035: message, busError.getMessage());
036: assertEquals("type was altered during construction or getting",
037: type, busError.getKey());
038: }
039:
040: /**
041: * test that when we add a list of children they are added. Use
042: * default DocElementError made in setup.
043: */
044: public void testAddChildren() {
045: //make a list of kiddie DocElementErrors
046: ArrayList kiddies = new ArrayList();
047: kiddies.add(new WorkflowServiceErrorImpl("a message", "1"));
048: kiddies.add(new WorkflowServiceErrorImpl("a message", "2"));
049:
050: //add the kiddies
051: busError.addChildren(kiddies);
052: assertEquals("Wrong number of children DocElementErrors", 2,
053: busError.getChildren().size());
054: }
055:
056: /**
057: * test that if I add a child it's in the list
058: */
059: public void testAddChild() {
060: WorkflowServiceError errorChild = new WorkflowServiceErrorImpl(
061: "childMessage", "3");
062: busError.addChild(errorChild);
063:
064: ArrayList kiddies = (ArrayList) busError.getChildren();
065:
066: //Iterate the list the one DocElementError in there should be errorChild
067: Iterator iter = kiddies.iterator();
068:
069: while (iter.hasNext()) {
070: Object item = (WorkflowServiceErrorImpl) iter.next();
071: assertEquals(
072: "Child placed in DocElementError was not retrieved",
073: errorChild, item);
074: }
075: }
076:
077: /**
078: * test that a tree is properly flatenned
079: */
080: public void testGetFlatChildrenList() {
081: WorkflowServiceErrorImpl error = new WorkflowServiceErrorImpl(
082: "parent", ServiceErrorConstants.CHILDREN_IN_ERROR);
083:
084: WorkflowServiceErrorImpl errorChild1 = new WorkflowServiceErrorImpl(
085: "child1", ServiceErrorConstants.ACTIVE_INDICATOR_NAN);
086: WorkflowServiceErrorImpl errorChild11 = new WorkflowServiceErrorImpl(
087: "child11", ServiceErrorConstants.ACTION_REQUESTED_BLANK);
088:
089: errorChild1.addChild(errorChild11);
090: error.addChild(new WorkflowServiceErrorImpl("child2",
091: ServiceErrorConstants.DATE_BEFORE_NOW));
092: error.addChild(errorChild1);
093:
094: Collection flatList = error.getFlatChildrenList();
095: Iterator iter = flatList.iterator();
096: int i = 0;
097:
098: while (iter.hasNext()) {
099: i++;
100:
101: WorkflowServiceErrorImpl daError = (WorkflowServiceErrorImpl) iter
102: .next();
103: System.out.println(daError.getMessage() + " " + i);
104: }
105:
106: assertEquals("didn't flatten error tree correctly", 3, error
107: .getFlatChildrenList().size());
108: }
109: }
110:
111: /*
112: * Copyright 2003 The Trustees of Indiana University. All rights reserved.
113: *
114: * This file is part of the EDEN software package.
115: * For license information, see the LICENSE file in the top level directory
116: * of the EDEN source distribution.
117: */
|