001: package edu.iu.uis.eden.services.docelements;
002:
003: import junit.framework.TestCase;
004:
005: import org.jdom.Element;
006:
007: import edu.iu.uis.eden.exception.InvalidXmlException;
008: import edu.iu.uis.eden.services.InconsistentDocElementStateException;
009:
010: public class TestNetworkIdElement extends TestCase {
011: private NetworkIdElement networkId;
012:
013: public TestNetworkIdElement(String s) {
014: super (s);
015: }
016:
017: protected void setUp() {
018: networkId = new NetworkIdElement();
019: networkId.setNetworkId("rkirkend");
020: }
021:
022: protected void tearDown() {
023: }
024:
025: /**
026: * if networkId is set null should be returned.
027: *
028: * if networkId is null or empty DocElementError should be returned.
029: */
030: public void testValidate() {
031: try {
032: //start with the default a known good guy
033: assertNull("Correctly Loaded failed validation", networkId
034: .validate());
035:
036: //make a new trouble maker
037: networkId = new NetworkIdElement();
038:
039: networkId.validate();
040:
041: assertNotNull(
042: "Validate on incorrect NetworkIdElement returned null",
043: networkId.validate());
044:
045: //set networkId blank and verify an error
046: networkId.setNetworkId("");
047: assertNotNull(
048: "Validate on incorrect NetworkIdElement returned null",
049: networkId.validate());
050: } catch (Exception ex) {
051: fail("threw exception validating");
052: }
053: }
054:
055: /**
056: * load the guy from valid element and check that props are set
057: *
058: * load the guy w/ null element but allowBlanks and make sure
059: * exception isn't thrown
060: *
061: * load the guy w/ null don't allowBlanks and make sure
062: * exception is thrown
063: *
064: * load with element of wrong type and check that invalidXMLException is thrown
065: */
066: public void testLoadFromXMLContent() {
067: NetworkIdElement networkId = new NetworkIdElement();
068: String daId = "rkirkend";
069:
070: Element networkEl = new Element(networkId.getElementName());
071: networkEl.setAttribute("value", daId);
072:
073: try {
074: networkId.loadFromXMLContent(networkEl, false);
075: assertEquals("Did not properly load props from element",
076: daId, networkId.getNetworkId());
077: } catch (Exception ex) {
078: fail("threw exception loading from valid element");
079: }
080:
081: // give null element allow blanks
082: try {
083: networkId.loadFromXMLContent(null, true);
084: } catch (Exception ex) {
085: fail("threw exception loading from null element with allowBlanks "
086: + "set true");
087: }
088:
089: //give null element don't allow blanks
090: try {
091: networkId.loadFromXMLContent(null, false);
092: fail("didn't throw InconsistentDocElementStateException loaded "
093: + "with null element and allowBlanks set false");
094: } catch (InconsistentDocElementStateException ex) {
095: } catch (InvalidXmlException ex) {
096: fail("didn't throw InconsistentDocElementStateException loaded "
097: + "with null element and allowBlanks set false");
098: }
099:
100: //give wrong type of element
101: try {
102: networkId.loadFromXMLContent(new Element("imbad"), true);
103: fail("didn't throw InvalidXmlException loaded with wrong type "
104: + "of element");
105: } catch (InvalidXmlException ex) {
106: } catch (InconsistentDocElementStateException ex) {
107: fail("didn't throw InvalidXmlException loaded with wrong type "
108: + "of element");
109: }
110: }
111:
112: /**
113: * test that this sucker gives the correct XML. This is dependent upon the
114: * object made in setUp();
115: */
116: public void testGetXMLContent() {
117: assertNotNull("Returned null when loaded", networkId
118: .getXMLContent());
119: }
120:
121: /**
122: * should not be a routeControl according to the current rules
123: */
124: public void testIsRouteControl() {
125: assertEquals(
126: "This should not be a routeControl according to the "
127: + "current business rules", false, networkId
128: .isRouteControl());
129: }
130:
131: /**
132: * can the object load from the same xml in generates and arrive at the same
133: * property value
134: */
135: public void testFeedFromOwnXML() {
136: Element xmlContent = networkId.getXMLContent();
137:
138: NetworkIdElement aNetworkIdEl = new NetworkIdElement();
139:
140: try {
141: aNetworkIdEl.loadFromXMLContent(xmlContent, false);
142: } catch (InvalidXmlException ex) {
143: fail("XML generated invalid could not be loaded "
144: + "by itself");
145: } catch (Exception ex) {
146: fail("XML generated invalid could not be loaded "
147: + "by itself");
148: }
149:
150: assertEquals("Could not find value from XML it generated",
151: "rkirkend", aNetworkIdEl.getNetworkId());
152: }
153: }
154:
155: /*
156: * Copyright 2003 The Trustees of Indiana University. All rights reserved.
157: *
158: * This file is part of the EDEN software package.
159: * For license information, see the LICENSE file in the top level directory
160: * of the EDEN source distribution.
161: */
|