KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > ReplicatedByteTest


1 /*
2  * JBoss, Home of Professional Open Source.
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * as indicated by the @author tags. See the copyright.txt file in the
5  * distribution for a 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
23 package org.jboss.cache.pojo;
24
25 import junit.framework.TestCase;
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.jboss.cache.pojo.test.Resource;
31
32 /**
33  * Replicate POJO with byte array field.
34  *
35  * @author Ben Wang
36  */

37 public class ReplicatedByteTest extends TestCase
38 {
39    Log log = LogFactory.getLog(ReplicatedByteTest.class);
40    PojoCache cache, cache1;
41
42
43    public ReplicatedByteTest(String JavaDoc name)
44    {
45       super(name);
46    }
47
48    protected void setUp() throws Exception JavaDoc
49    {
50       super.setUp();
51       log.info("setUp() ....");
52       String JavaDoc configFile = "META-INF/replSync-service.xml";
53       boolean toStart = false;
54       cache = PojoCacheFactory.createCache(configFile, toStart);
55       cache.start();
56       cache1 = PojoCacheFactory.createCache(configFile, toStart);
57       cache1.start();
58    }
59
60    protected void tearDown() throws Exception JavaDoc
61    {
62       super.tearDown();
63       cache.stop();
64       cache1.stop();
65    }
66
67    public void testSimple() throws Exception JavaDoc
68    {
69       log.info("testSimple() ....");
70       Resource res = new Resource();
71       res.setName("mapping");
72       res.setConnection("wire");
73       String JavaDoc s = "This is a test";
74       byte by = 1;
75       byte[] b = new byte[1];
76       b[0] = by;
77       res.setByte(b);
78
79       cache.attach("resource", res);
80
81       Resource res1 = (Resource)cache1.find("resource");
82       assertEquals("Name ", res.getName(), res1.getName());
83
84       assertEquals("byte ", res.getByte()[0], res1.getByte()[0]);
85
86       // field modification
87
by = 2;
88       b[0] = by;
89       res1.setByte(b);
90       assertEquals("Name ", res.getName(), res1.getName());
91
92       assertEquals("byte ", res.getByte()[0], res1.getByte()[0]);
93
94    }
95
96    public static Test suite() throws Exception JavaDoc
97    {
98       return new TestSuite(ReplicatedByteTest.class);
99    }
100
101
102    public static void main(String JavaDoc[] args) throws Exception JavaDoc
103    {
104       junit.textui.TestRunner.run(suite());
105    }
106
107 }
108
Popular Tags