01: package edu.iu.uis.eden.services.docelements;
02:
03: import junit.framework.Assert;
04: import junit.framework.TestCase;
05:
06: import org.jdom.Element;
07:
08: import edu.iu.uis.eden.exception.InvalidXmlException;
09: import edu.iu.uis.eden.services.IDocElement;
10: import edu.iu.uis.eden.services.InconsistentDocElementStateException;
11:
12: /**
13: * <p>Title: TestIDocInterface</p>
14: * <p>Description: To be extended by all classes implementing
15: * the IDocElement Interface. This will work the non-class specific
16: * implementation of the interface, insuring consistent behavior
17: * accross all classes.</p>
18: * <p>Copyright: Copyright (c) 2002</p>
19: * <p>Company: Indiana University</p>
20: * @author Ryan Kirkendall
21: * @version 1.0
22: */
23: public abstract class IDocInterfaceTestTemplate extends TestCase {
24: public IDocInterfaceTestTemplate(String s) {
25: super (s);
26: }
27:
28: protected void setUp() {
29: }
30:
31: protected void tearDown() {
32: }
33:
34: /**
35: * test the first scenario, which is the object has just been
36: * intaniated and is empty this will return null
37: */
38: public void testGetXMLContent() {
39: IDocElement docElement = getIDocElement();
40: Assert.assertNull(
41: "Newly instantiated object not returning null "
42: + "when generating XMLContent", docElement
43: .getXMLContent());
44: }
45:
46: public void testLoadFromXMLContentDefaultBehavior() {
47: IDocElement docElement = this .getIDocElement();
48:
49: //give null allow blanks
50: try {
51: docElement.loadFromXMLContent(null, true);
52: } catch (Exception ex) {
53: Assert
54: .fail("threw exception loading null element set to allow blanks");
55: }
56:
57: //give null dont allow blanks
58: try {
59: docElement.loadFromXMLContent(null, false);
60: Assert
61: .fail("didn't throw InconsistentDocElementStateException "
62: + "loaded with null element allowBlanks set to false");
63: } catch (InconsistentDocElementStateException ex) {
64: } catch (InvalidXmlException ex) {
65: Assert
66: .fail("didn't throw InconsistentDocElementStateException "
67: + "loaded with null element allowBlanks set to false");
68: }
69:
70: //give element of wrong type
71: try {
72: docElement.loadFromXMLContent(new Element("Imbad"), false);
73: Assert
74: .fail("Didn't throw InvalidXmlException when loaded with "
75: + "element of the wrong type");
76: } catch (InconsistentDocElementStateException ex) {
77: Assert
78: .fail("Didn't throw InvalidXmlException when loaded with "
79: + "element of the wrong type");
80: } catch (InvalidXmlException ex) {
81: }
82: }
83:
84: public abstract IDocElement getIDocElement();
85: }
86:
87: /*
88: * Copyright 2003 The Trustees of Indiana University. All rights reserved.
89: *
90: * This file is part of the EDEN software package.
91: * For license information, see the LICENSE file in the top level directory
92: * of the EDEN source distribution.
93: */
|