KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > entity > TestEntityManager00


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id:$
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.entity;
26
27 import static org.testng.Assert.assertNotNull;
28 import static org.testng.Assert.assertNull;
29
30 import org.objectweb.easybeans.tests.common.ejbs.entity.ebstore.EBStore;
31 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.entitymanager.ItfEntityManagerTester00;
32 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.entitymanager.SLSBEntityManagerTester00;
33 import org.objectweb.easybeans.tests.common.helper.EJBHelper;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
36
37 /**
38  * Verifies if the methods remove and persist from EntityManager are working
39  * properly. The items 3.2.1 e 3.2.2 (Persistence doc)
40  * @reference JSR 220-PROPOSED FINAL
41  * @requirement Application Server must be running; the bean
42  * SLSBEntityManagerTester must be deployed.
43  * @setup gets the reference of SLSBEntityManagerTester
44  * @author Gisele Pinheiro Souza
45  * @author Eduardo Studzinski Estima de Castro
46  */

47 public class TestEntityManager00 {
48
49     /**
50      * The entity bean primary key that is used during the tests.
51      */

52     private static final int PRIMARY_KEY = 1;
53
54     /**
55      * The entity bean name that is used during the tests.
56      */

57     private static final String JavaDoc ENTITY_NAME = "test";
58
59     /**
60      * The statelles bean used to verify the EntityManager.
61      */

62     private ItfEntityManagerTester00 slsbEntityManagerTester;
63
64     /**
65      * Creates the stateless bean used during the tests.
66      * @throws Exception if an error occurs during the lookup.
67      */

68     @BeforeMethod
69     public void setup() throws Exception JavaDoc {
70         slsbEntityManagerTester = EJBHelper.getBeanRemoteInstance(SLSBEntityManagerTester00.class,
71                 ItfEntityManagerTester00.class);
72         slsbEntityManagerTester.removeEBStore(PRIMARY_KEY);
73     }
74
75     /**
76      * Tests if the EntityManager can persist a new entity.
77      * @input PRIMARY_KEY and ENTITY_NAME.
78      * @output the method execution without error.
79      */

80     @Test
81     public void createNewEntity() {
82         slsbEntityManagerTester.createEBStoreNew(PRIMARY_KEY, ENTITY_NAME);
83         EBStore ebstore = slsbEntityManagerTester.findEBStore(PRIMARY_KEY);
84         assertNotNull(ebstore, "The entity was not inserted in the database");
85     }
86
87     /**
88      * Tests if the EntityManager can persist a removed entity. The
89      * specification says that the bean must become managed.
90      * @input PRIMARY_KEY and ENTITY_NAME.
91      * @output the method execution without error.
92      */

93     @Test
94     public void createRemoved() {
95         slsbEntityManagerTester.createEBStoreRemoved(PRIMARY_KEY, ENTITY_NAME);
96         EBStore ebstore = slsbEntityManagerTester.findEBStore(PRIMARY_KEY);
97         assertNotNull(ebstore, "The entity was not re-inserted in the database");
98     }
99
100     /**
101      * Tests if the EntityManager can persist a managed entity. The
102      * specification says that the persist operation must be ignored.
103      * @input PRIMARY_KEY and ENTITY_NAME.
104      * @output the method execution without error.
105      */

106     @Test
107     public void createManaged() {
108         slsbEntityManagerTester.createEBStoreManaged(PRIMARY_KEY, ENTITY_NAME);
109         EBStore ebstore = slsbEntityManagerTester.findEBStore(PRIMARY_KEY);
110         assertNotNull(ebstore, "The persist operation was not ignored.");
111     }
112
113     /**
114      * Tests if the EntityManager can remove a new entity. The specification
115      * says that the remove operation must be ignored.
116      * @input PRIMARY_KEY and ENTITY_NAME.
117      * @output the method execution without error.
118      */

119     @Test
120     public void removeNew() {
121         slsbEntityManagerTester.removeEBStoreNew(PRIMARY_KEY, ENTITY_NAME);
122         EBStore ebstore = slsbEntityManagerTester.findEBStore(PRIMARY_KEY);
123         assertNull(ebstore, "The remove operation was not ignored.");
124     }
125
126     /**
127      * Tests if the EntityManager can remove a managed entity.
128      * @input PRIMARY_KEY and ENTITY_NAME.
129      * @output the method execution without error.
130      */

131     @Test
132     public void removeManaged() {
133         slsbEntityManagerTester.removeEBStoreManaged(PRIMARY_KEY, ENTITY_NAME);
134         EBStore ebstore = slsbEntityManagerTester.findEBStore(PRIMARY_KEY);
135         assertNull(ebstore, "The remove operation failed.");
136     }
137
138     /**
139      * Tests if the EntityManager can remove a removed entity. The specification
140      * says that the remove operation must be ignored.
141      * @input PRIMARY_KEY and ENTITY_NAME.
142      * @output the method execution without error.
143      */

144     @Test
145     public void removeRemoved() {
146         slsbEntityManagerTester.removeEBStoreManaged(PRIMARY_KEY, ENTITY_NAME);
147         EBStore ebstore = slsbEntityManagerTester.findEBStore(PRIMARY_KEY);
148         assertNull(ebstore, "The remove operation was not ignored.");
149     }
150 }
151
Popular Tags