KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > entity > test > EntityUnitTestCase


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.entity.test;
23
24 import junit.framework.Test;
25
26 import org.jboss.test.JBossTestCase;
27
28 import org.jboss.test.entity.interfaces.TestEntity;
29 import org.jboss.test.entity.interfaces.TestEntityHome;
30 import org.jboss.test.entity.interfaces.TestEntityUtil;
31 import org.jboss.test.entity.interfaces.TestEntityValue;
32
33 /**
34  * Some entity bean tests.
35  *
36  * @author Adrian.Brock@HappeningTimes.com
37  * @version $Revision: 37406 $
38  */

39 public class EntityUnitTestCase
40    extends JBossTestCase
41 {
42    public EntityUnitTestCase(String JavaDoc name)
43    {
44       super(name);
45    }
46
47    public static Test suite()
48       throws Exception JavaDoc
49    {
50       return getDeploySetup(EntityUnitTestCase.class, "jboss-test-entity.jar");
51    }
52
53    public void testExternalRemoveAfterCreateThenRecreate()
54       throws Exception JavaDoc
55    {
56       getLog().debug("Retrieving home");
57       TestEntityHome home = TestEntityUtil.getHome();
58
59       getLog().debug("Creating entity");
60       TestEntityValue value = new TestEntityValue("key1", null);
61       home.create(value);
62
63       getLog().debug("Removing entity externally");
64       home.removeExternal("key1");
65
66       getLog().debug("Recreating the entity");
67       home.create(value);
68    }
69
70    public void testInternalHomeRemoveAfterCreateThenRecreate()
71       throws Exception JavaDoc
72    {
73       getLog().debug("Retrieving home");
74       TestEntityHome home = TestEntityUtil.getHome();
75
76       getLog().debug("Creating entity");
77       TestEntityValue value = new TestEntityValue("key2", null);
78       home.create(value);
79
80       getLog().debug("Removing entity internally");
81       home.remove("key2");
82
83       getLog().debug("Recreating the entity");
84       home.create(value);
85    }
86
87    public void testInternalBeanRemoveAfterCreateThenRecreate()
88       throws Exception JavaDoc
89    {
90       getLog().debug("Retrieving home");
91       TestEntityHome home = TestEntityUtil.getHome();
92
93       getLog().debug("Creating entity");
94       TestEntityValue value = new TestEntityValue("key3", null);
95       TestEntity bean = home.create(value);
96
97       getLog().debug("Removing entity internally");
98       bean.remove();
99
100       getLog().debug("Recreating the entity");
101       home.create(value);
102    }
103
104    public void testChangeReadOnlyField()
105       throws Exception JavaDoc
106    {
107       getLog().debug("Retrieving home");
108       TestEntityHome home = TestEntityUtil.getHome();
109
110       getLog().debug("Creating entity");
111       TestEntityValue value = new TestEntityValue("key4", "original");
112       TestEntity bean = home.create(value);
113
114       getLog().debug("Access the value");
115       assertEquals("original", bean.getValue1());
116
117       getLog().debug("Change the value");
118       home.changeValue1("key4", "changed");
119       assertEquals("changed", bean.getValue1());
120    }
121 }
122
Popular Tags