KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > proxycompiler > test > BeanProxyUnitTestCase


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.proxycompiler.test; // Generated package name
23

24 import junit.framework.*;
25
26 import org.jboss.test.JBossTestCase;
27
28 import org.jboss.test.proxycompiler.Util;
29 import org.jboss.test.proxycompiler.beans.interfaces.ProxyCompilerTest;
30 import org.jboss.test.proxycompiler.beans.interfaces.ProxyCompilerTestHome;
31
32 import java.util.Iterator JavaDoc;
33 import java.util.Collection JavaDoc;
34
35 /**
36  * Tests the proxy generation for beans.
37  *
38  * <p>Currently only tests CMP2 beans.
39  *
40  * Created: Wed Jan 30 00:16:57 2002
41  *
42  * @version <tt>$Revision: 37406 $</tt>
43  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
44  */

45 public class BeanProxyUnitTestCase
46    extends JBossTestCase
47 {
48    private ProxyCompilerTestHome home;
49    
50    public BeanProxyUnitTestCase(final String JavaDoc name)
51    {
52       super(name);
53    }
54
55    public static Test suite() throws Exception JavaDoc
56    {
57       return getDeploySetup(ProxyCompilerUnitTestCase.class, "proxycompiler-test.jar");
58    }
59
60    public void testProxyCompilerTest() throws Exception JavaDoc
61    {
62       
63       Integer JavaDoc pk = new Integer JavaDoc(1);
64       ProxyCompilerTest bean = home.create(pk);
65       
66       assertEquals("Object argument error", pk, bean.getPk());
67       
68       bean.setBool(true);
69       assertTrue("boolean argument error", bean.getBool());
70       
71       byte byteArg = (byte)123;
72       bean.setByte(byteArg);
73       assertEquals("byte argument error", byteArg, bean.getByte());
74       
75       char charArg = 'N';
76       bean.setChar(charArg);
77       assertEquals("char argument error", charArg, bean.getChar());
78       
79       double doubleArg = 1.5;
80       bean.setDouble(doubleArg);
81       assertEquals("double argument error", doubleArg, bean.getDouble(), 0.01);
82
83       float floatArg = 1.5f;
84       bean.setFloat(floatArg);
85       assertEquals("float argument error", floatArg, bean.getFloat(), 0.01f);
86       
87       int intArg = 234;
88       bean.setInt(intArg);
89       assertEquals("int argument error", intArg, bean.getInt());
90       
91       long longArg = 23456L;
92       bean.setLong(longArg);
93       assertEquals("long argument error", longArg, bean.getLong());
94       
95       short shortArg = (short)7;
96       bean.setShort(shortArg);
97       assertEquals("short argument error", shortArg, bean.getShort());
98       
99       Object JavaDoc[] objectArrayArg = new Object JavaDoc[]{new Integer JavaDoc(4), "Hello Mum", new Float JavaDoc(123.0)};
100       bean.setObjectArray(objectArrayArg);
101       Object JavaDoc[] objectReturnArg = bean.getObjectArray();
102       for ( int i = 0; i < objectArrayArg.length; i++ ) {
103          assertEquals("Object[] argument error", objectArrayArg[i], objectReturnArg[i]);
104       }
105       
106       int[] intArrayArg = new int[]{2, 4, 6, 8};
107       bean.setIntArray(intArrayArg);
108       int[] intReturnArg = bean.getIntArray();
109       for ( int i = 0; i < intArrayArg.length; i++ ) {
110          assertEquals("int[] argument error", intArrayArg[i], intReturnArg[i]);
111       }
112
113       assertTrue("noArgs argument error", bean.noArgsMethod());
114       
115       String JavaDoc stringRep = Util.getStringRepresentation(intArg, pk, intArrayArg, objectArrayArg);
116
117       String JavaDoc returnArg = bean.complexSignatureMethod(intArg, pk, intArrayArg, objectArrayArg);
118
119       assertEquals("complex argument error", stringRep, returnArg);
120
121    }
122
123    protected void setUp()
124       throws Exception JavaDoc
125    {
126       home = (ProxyCompilerTestHome)getInitialContext().lookup("ProxyCompilerTest");
127       getLog().debug("Remove ProxyCompilerTest bean instances");
128
129       Collection JavaDoc beansColl = home.findAll();
130       
131       for(Iterator JavaDoc beans = beansColl.iterator(); beans.hasNext();) {
132          ProxyCompilerTest bean = (ProxyCompilerTest)beans.next();
133          getLog().debug("Removing " + bean.getPrimaryKey());
134          bean.remove();
135       }
136    }
137
138 }// ProxyCompilerTestUnitTestCase
139
Popular Tags