001: /*
002: * Copyright 2002 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: ViewCreationTest.java,v 1.3 2003/10/18 22:05:17 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.test.views;
012:
013: import com.triactive.jdo.test.*;
014: import javax.jdo.JDOFatalUserException;
015:
016: /**
017: * Tests the creation of views when auto-create tables is on.
018: *
019: * @author <a href="mailto:pierreg0@users.sourceforge.net">Kelly Grizzle</a>
020: * @version $Revision: 1.3 $
021: */
022:
023: public class ViewCreationTest extends PersistenceTestCase {
024:
025: /**
026: * Used by the JUnit framework to construct tests. Normally, programmers
027: * would never explicitly use this constructor.
028: *
029: * @param name Name of the <tt>TestCase</tt>.
030: */
031:
032: public ViewCreationTest(String name) {
033: super (name);
034: }
035:
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: schemaMgr.dropTablesFor(new Class[] { DependentView.class,
040: ReliedOnView.class });
041:
042: addClassesToSchema(new Class[] { Widget.class });
043: }
044:
045: /**
046: * Test creating views with the dependent view created first.
047: */
048: public void testCreatingDependentFirst() throws Exception {
049: addClassesToSchema(new Class[] { DependentView.class,
050: ReliedOnView.class });
051: }
052:
053: /**
054: * Test creating views with the relied on view created first.
055: */
056: public void testCreatingReliedOnFirst() throws Exception {
057: addClassesToSchema(new Class[] { ReliedOnView.class,
058: DependentView.class });
059: }
060:
061: /**
062: * Test that creating views with circular dependencies fails.
063: */
064: public void testCircularViewDependencies() {
065: /*
066: * Try creating with one view. Others should be pulled in through reference.
067: */
068: try {
069: addClassesToSchema(new Class[] { CircularReferenceView1.class });
070: fail("Creating a view with a circular dependency should have thrown exception.");
071: } catch (JDOFatalUserException e) { /* Ignore */
072: }
073:
074: try {
075: addClassesToSchema(new Class[] { CircularReferenceView2.class });
076: fail("Creating a view with a circular dependency should have thrown exception.");
077: } catch (JDOFatalUserException e) { /* Ignore */
078: }
079:
080: try {
081: addClassesToSchema(new Class[] { CircularReferenceView3.class });
082: fail("Creating a view with a circular dependency should have thrown exception.");
083: } catch (JDOFatalUserException e) { /* Ignore */
084: }
085:
086: /*
087: * Try creating with two views. Other should be pulled in through reference.
088: */
089: try {
090: addClassesToSchema(new Class[] {
091: CircularReferenceView1.class,
092: CircularReferenceView2.class });
093: fail("Creating a view with a circular dependency should have thrown exception.");
094: } catch (JDOFatalUserException e) { /* Ignore */
095: }
096: try {
097: addClassesToSchema(new Class[] {
098: CircularReferenceView2.class,
099: CircularReferenceView1.class });
100: fail("Creating a view with a circular dependency should have thrown exception.");
101: } catch (JDOFatalUserException e) { /* Ignore */
102: }
103:
104: try {
105: addClassesToSchema(new Class[] {
106: CircularReferenceView1.class,
107: CircularReferenceView3.class });
108: fail("Creating a view with a circular dependency should have thrown exception.");
109: } catch (JDOFatalUserException e) { /* Ignore */
110: }
111: try {
112: addClassesToSchema(new Class[] {
113: CircularReferenceView3.class,
114: CircularReferenceView1.class });
115: fail("Creating a view with a circular dependency should have thrown exception.");
116: } catch (JDOFatalUserException e) { /* Ignore */
117: }
118:
119: try {
120: addClassesToSchema(new Class[] {
121: CircularReferenceView2.class,
122: CircularReferenceView3.class });
123: fail("Creating a view with a circular dependency should have thrown exception.");
124: } catch (JDOFatalUserException e) { /* Ignore */
125: }
126: try {
127: addClassesToSchema(new Class[] {
128: CircularReferenceView3.class,
129: CircularReferenceView2.class });
130: fail("Creating a view with a circular dependency should have thrown exception.");
131: } catch (JDOFatalUserException e) { /* Ignore */
132: }
133:
134: /*
135: * Try creating with three views.
136: */
137: try {
138: addClassesToSchema(new Class[] {
139: CircularReferenceView1.class,
140: CircularReferenceView2.class,
141: CircularReferenceView3.class });
142: fail("Creating a view with a circular dependency should have thrown exception.");
143: } catch (JDOFatalUserException e) { /* Ignore */
144: }
145:
146: try {
147: addClassesToSchema(new Class[] {
148: CircularReferenceView1.class,
149: CircularReferenceView3.class,
150: CircularReferenceView2.class });
151: fail("Creating a view with a circular dependency should have thrown exception.");
152: } catch (JDOFatalUserException e) { /* Ignore */
153: }
154:
155: try {
156: addClassesToSchema(new Class[] {
157: CircularReferenceView2.class,
158: CircularReferenceView1.class,
159: CircularReferenceView3.class });
160: fail("Creating a view with a circular dependency should have thrown exception.");
161: } catch (JDOFatalUserException e) { /* Ignore */
162: }
163:
164: try {
165: addClassesToSchema(new Class[] {
166: CircularReferenceView2.class,
167: CircularReferenceView3.class,
168: CircularReferenceView1.class });
169: fail("Creating a view with a circular dependency should have thrown exception.");
170: } catch (JDOFatalUserException e) { /* Ignore */
171: }
172:
173: try {
174: addClassesToSchema(new Class[] {
175: CircularReferenceView3.class,
176: CircularReferenceView1.class,
177: CircularReferenceView2.class });
178: fail("Creating a view with a circular dependency should have thrown exception.");
179: } catch (JDOFatalUserException e) { /* Ignore */
180: }
181:
182: try {
183: addClassesToSchema(new Class[] {
184: CircularReferenceView3.class,
185: CircularReferenceView2.class,
186: CircularReferenceView1.class });
187: fail("Creating a view with a circular dependency should have thrown exception.");
188: } catch (JDOFatalUserException e) { /* Ignore */
189: }
190: }
191: }
|