KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > cmr > test > CMRPostCreatesWrittenUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.cmr.test;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.SortedMap JavaDoc;
27 import java.util.TreeMap JavaDoc;
28
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import junit.framework.*;
32 import org.jboss.test.JBossTestCase;
33 import org.jboss.test.cmp2.cmr.interfaces.CMRBugManagerEJB;
34 import org.jboss.test.cmp2.cmr.interfaces.CMRBugManagerEJBHome;
35
36 /**
37  *
38  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
39  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
40  * @version 1.0
41  */

42 public class CMRPostCreatesWrittenUnitTestCase extends JBossTestCase
43 {
44
45    public CMRPostCreatesWrittenUnitTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    public static Test suite() throws Exception JavaDoc
51    {
52       return getDeploySetup(CMRPostCreatesWrittenUnitTestCase.class, "cmr-postcreateswritten.jar");
53    }
54
55    /**
56     * This tests directly for bug 523627 and is based on the test case supplied by
57     * Michael Newcomb. It tests whether changes made in ejbPostCreate are committed.
58     * It also tests indirectly for bug 523239, since it uses xdoclet. It reports the same
59     * error as seen in bug 523239, from GlobalTxEntityMap.
60     */

61    public void testCMRWrittenAfterPostCreate() throws Exception JavaDoc
62    {
63       getLog().debug("looking up CMRBugManager");
64       Object JavaDoc ref = getInitialContext().lookup("CMRBugManager");
65       getLog().debug("found CMRBugManager");
66
67       CMRBugManagerEJBHome home = (CMRBugManagerEJBHome)
68          PortableRemoteObject.narrow(ref, CMRBugManagerEJBHome.class);
69
70       getLog().debug("creating CMRBugManagerEJB");
71       CMRBugManagerEJB cmrBugManager = home.create();
72       getLog().debug("created CMRBugManagerEJB");
73
74       SortedMap JavaDoc cmrBugs = new TreeMap JavaDoc();
75       cmrBugs.put("1", "one");
76       cmrBugs.put("1.1", "one.one");
77       cmrBugs.put("1.2", "one.two");
78       cmrBugs.put("1.3", "one.three");
79
80       getLog().debug("creating " + cmrBugs.size() + " CMR bugs");
81       cmrBugManager.createCMRBugs(cmrBugs);
82       getLog().debug("created " + cmrBugs.size() + " CMR bugs");
83
84       Iterator JavaDoc i = cmrBugs.entrySet().iterator();
85       while(i.hasNext())
86       {
87          Map.Entry JavaDoc entry = (Map.Entry JavaDoc)i.next();
88
89          String JavaDoc[] parentIdAndDescription =
90             cmrBugManager.getParentFor((String JavaDoc)entry.getKey());
91          if(!entry.getKey().equals("1"))
92          {
93             assertTrue("Child has not Parent! cmr post create updates NOT WRITTEN! " + entry.getKey(),
94                parentIdAndDescription != null);
95          } // end of if ()
96

97          String JavaDoc parentMsg = parentIdAndDescription == null ? " has no parent" :
98             (" parent is " + parentIdAndDescription[0] + "-" +
99             parentIdAndDescription[1]);
100          getLog().debug(entry.getKey() + "-" + entry.getValue() + parentMsg);
101       }
102    }
103
104    /**
105     * Tests correct foreign key state initialization when the foreign key
106     * loaded is not a valid (stale) value, i.e. the relationship was already changed in the tx.
107     */

108    public void testLoadFKState() throws Exception JavaDoc
109    {
110       Object JavaDoc ref = getInitialContext().lookup("CMRBugManager");
111       CMRBugManagerEJBHome home = (CMRBugManagerEJBHome)PortableRemoteObject.narrow(ref, CMRBugManagerEJBHome.class);
112       CMRBugManagerEJB manager = home.create();
113
114       try
115       {
116          // create bugs
117
manager.setupLoadFKState();
118
119          // update
120
manager.moveLastNodeBack();
121
122          // check results
123
assertTrue("The last element is the last in the chain.", !manager.lastHasNextNode());
124       }
125       finally
126       {
127          manager.tearDownLoadFKState();
128       }
129    }
130 }
131
Popular Tags