KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > enums > test > EnumUnitTestCase


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.enums.test;
23
24 import java.util.List JavaDoc;
25 import net.sourceforge.junitejb.EJBTestCase;
26 import junit.framework.Test;
27 import org.jboss.test.JBossTestCase;
28 import org.jboss.test.cmp2.enums.ejb.Facade;
29 import org.jboss.test.cmp2.enums.ejb.FacadeUtil;
30 import org.jboss.test.cmp2.enums.ejb.ColorEnum;
31 import org.jboss.test.cmp2.enums.ejb.AnimalEnum;
32 import org.jboss.test.cmp2.enums.ejb.IDClass;
33
34 /**
35  *
36  * @author <a HREF="mailto:alex@jboss.org">Alex Loubyansky</a>
37  * @author <a HREF="mailto:gturner@unzane.com">Gerald Turner</a>
38  */

39 public class EnumUnitTestCase
40    extends EJBTestCase
41 {
42    public static Test suite() throws Exception JavaDoc
43    {
44       return JBossTestCase.getDeploySetup(EnumUnitTestCase.class, "cmp2-enum.jar");
45    }
46
47    public EnumUnitTestCase(String JavaDoc s)
48    {
49       super(s);
50    }
51
52    // Tests
53

54    public void testColorEnum()
55       throws Exception JavaDoc
56    {
57       Facade facade = FacadeUtil.getHome().create();
58       IDClass childId = new IDClass(1);
59       facade.createChild(childId);
60       assertTrue(ColorEnum.RED == facade.getColorForId(childId));
61       facade.setColor(childId, ColorEnum.GREEN);
62       assertTrue(ColorEnum.GREEN == facade.getColorForId(childId));
63       facade.setColor(childId, ColorEnum.BLUE);
64       assertTrue(ColorEnum.BLUE == facade.getColorForId(childId));
65       facade.removeChild(childId);
66    }
67
68    public void testAnimalEnum()
69       throws Exception JavaDoc
70    {
71       Facade facade = FacadeUtil.getHome().create();
72       IDClass childId = new IDClass(2);
73       facade.createChild(childId);
74       assertTrue(AnimalEnum.PENGUIN == facade.getAnimalForId(childId));
75       facade.setAnimal(childId, AnimalEnum.DOG);
76       assertTrue(AnimalEnum.DOG == facade.getAnimalForId(childId));
77       facade.setAnimal(childId, AnimalEnum.CAT);
78       assertTrue(AnimalEnum.CAT == facade.getAnimalForId(childId));
79       facade.removeChild(childId);
80    }
81
82    public void testFindByColor()
83       throws Exception JavaDoc
84    {
85       Facade facade = FacadeUtil.getHome().create();
86       IDClass childId = new IDClass(3);
87       facade.createChild(childId);
88       try
89       {
90          facade.setColor(childId, ColorEnum.BLUE);
91          IDClass id = facade.findByColor(ColorEnum.BLUE);
92          assertEquals(childId, id);
93       }
94       finally
95       {
96          facade.removeChild(childId);
97       }
98    }
99
100    public void testFindAndOrderByColor()
101       throws Exception JavaDoc
102    {
103       Facade facade = FacadeUtil.getHome().create();
104       IDClass childId = new IDClass(3);
105       facade.createChild(childId);
106       try
107       {
108          facade.setColor(childId, ColorEnum.BLUE);
109          IDClass id = facade.findAndOrderByColor(ColorEnum.BLUE);
110          assertEquals(childId, id);
111       }
112       finally
113       {
114          facade.removeChild(childId);
115       }
116    }
117
118    public void testFindByColorDeclaredSql()
119       throws Exception JavaDoc
120    {
121       Facade facade = FacadeUtil.getHome().create();
122       IDClass childId = new IDClass(4);
123       facade.createChild(childId);
124       try
125       {
126          facade.setColor(childId, ColorEnum.BLUE);
127          IDClass id = facade.findByColorDeclaredSql(ColorEnum.BLUE);
128          assertEquals(childId, id);
129       }
130       finally
131       {
132          facade.removeChild(childId);
133       }
134    }
135
136    public void testLowColor()
137       throws Exception JavaDoc
138    {
139       Facade facade = FacadeUtil.getHome().create();
140       IDClass childId = new IDClass(3);
141       facade.createChild(childId);
142       try
143       {
144          facade.setColor(childId, ColorEnum.RED);
145          List JavaDoc ids = facade.findLowColor(ColorEnum.BLUE);
146          assertEquals(1, ids.size());
147          assertEquals(childId, ids.get(0));
148       }
149       finally
150       {
151          facade.removeChild(childId);
152       }
153    }
154 }
155
Popular Tags