001: package edu.iu.uis.eden.services.docelements;
002:
003: import java.util.Collection;
004:
005: import org.jdom.Element;
006:
007: import edu.iu.uis.eden.WorkflowServiceErrorImpl;
008: import edu.iu.uis.eden.services.IDocElement;
009: import edu.iu.uis.eden.services.ServiceErrorConstants;
010:
011: public class TestCompoundReviewerElement extends
012: IDocInterfaceTestTemplate {
013: private CompoundReviewerElement compoundReviewer;
014: private String partyType;
015:
016: public TestCompoundReviewerElement(String s) {
017: super (s);
018: }
019:
020: protected void setUp() {
021: compoundReviewer = new CompoundReviewerElement();
022: partyType = "U";
023: }
024:
025: protected void tearDown() {
026: }
027:
028: public IDocElement getIDocElement() {
029: return this .compoundReviewer;
030: }
031:
032: /**
033: * no it isn't
034: */
035: public void testIsRouteControl() {
036: assertEquals("CompoundReviewElement is not a route control",
037: false, this .compoundReviewer.isRouteControl());
038:
039: //try to set and restest
040: this .compoundReviewer.setRouteControl(true);
041: assertEquals(
042: "CompoundReviewElement is allowing route control to be set",
043: false, this .compoundReviewer.isRouteControl());
044: }
045:
046: /**
047: * check that the correct root element is there
048: */
049: public void testGetXMLContent() {
050: this .compoundReviewer.addReviewer("rkirkend", this .partyType);
051:
052: Element me = this .compoundReviewer.getXMLContent();
053: assertEquals("didn't make element with correct name", me
054: .getName(), this .compoundReviewer.getElementName());
055: }
056:
057: /**
058: * is a collection of the correct number coming back
059: */
060: public void testGetReviewerCollection() {
061: this .compoundReviewer.addReviewer("rkirkend", this .partyType);
062: this .compoundReviewer.addReviewer("andlee", this .partyType);
063:
064: Collection reviewers = this .compoundReviewer.getReviewers();
065: assertEquals("returning collection with incorrect count", 2,
066: reviewers.size());
067: }
068:
069: /**
070: * empty when has no reviewer not empty when has reviewers
071: */
072: public void testIsEmpty() {
073: assertTrue("empty obj. reporting not empty",
074: this .compoundReviewer.isEmpty());
075: }
076:
077: /**
078: * set some reviewers make xml make a compoundReviewer from that xml
079: * and see if the reviewers are there
080: */
081: public void testLoadFromXMLContent() {
082: String reviewer1 = "rkirkend";
083: String reviewer2 = "andlee";
084: String partyType = "u";
085:
086: this .compoundReviewer.addReviewer(reviewer1, partyType);
087: this .compoundReviewer.addReviewer(reviewer2, partyType);
088:
089: Element me = this .compoundReviewer.getXMLContent();
090:
091: CompoundReviewerElement aCompoundReviewer = new CompoundReviewerElement();
092:
093: try {
094: aCompoundReviewer.loadFromXMLContent(me, false);
095: } catch (Exception ex) {
096: fail("threw exception loading from self generated xml");
097: }
098:
099: ReviewerElement aReviewer1 = aCompoundReviewer.getReviewer(
100: reviewer1, partyType);
101: ReviewerElement aReviewer2 = aCompoundReviewer.getReviewer(
102: reviewer2, partyType);
103:
104: assertEquals(
105: "didn't properly load children props with self generated "
106: + "xml", reviewer1, aReviewer1.getNetworkId());
107: assertEquals(
108: "didn't properly load children props with self generated "
109: + "xml", reviewer2, aReviewer2.getNetworkId());
110: }
111:
112: /**
113: * empty is invalid empty error. All others are individual reviewer
114: * object errors and is a child_in_error error
115: */
116: public void testValidate() {
117: try {
118: WorkflowServiceErrorImpl err = this .compoundReviewer
119: .validate();
120: assertEquals(
121: "empty compoundReviewer returned incorrect err type",
122: ServiceErrorConstants.COMPOUND_REVIEWER_BLANK, err
123: .getKey());
124:
125: //give incorrect value and recheck
126: this .compoundReviewer.addReviewer("", "");
127: err = this .compoundReviewer.validate();
128: assertEquals(
129: "compoundReviewer with child in error returned incorrect "
130: + "err type",
131: ServiceErrorConstants.CHILDREN_IN_ERROR, err
132: .getKey());
133:
134: //validate an individual element that isn't there
135: assertNull(
136: "compoundReviewer returned wrong error type when "
137: + "validating a child that wasn't present",
138: this .compoundReviewer.validateReviewer(
139: "helloI'm Not there", "U"));
140:
141: /* test for a valid partyType but invalid networkId */
142: this .compoundReviewer = new CompoundReviewerElement();
143: compoundReviewer.addReviewer("I don't exist", "U");
144: err = this .compoundReviewer.validate();
145: assertNotNull(
146: "CompoundReviewerElement with incorrect username returned "
147: + "null (or correct) on validate", err);
148: assertEquals(
149: "CompoundReviewerElement in error returned wrong error "
150: + "type",
151: ServiceErrorConstants.CHILDREN_IN_ERROR, err
152: .getKey());
153: } catch (Exception ex) {
154: fail("threw exception validating");
155: }
156: }
157: }
158:
159: /*
160: * Copyright 2003 The Trustees of Indiana University. All rights reserved.
161: *
162: * This file is part of the EDEN software package.
163: * For license information, see the LICENSE file in the top level directory
164: * of the EDEN source distribution.
165: */
|