KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > xquarebc > listeners > XQuareBCJBIProcessorTest


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

22 package org.objectweb.petals.binding.xquarebc.listeners;
23
24 import java.io.FileInputStream JavaDoc;
25
26 /**
27  *
28  * Tests the XQuareBCJBIProcessor
29  *
30  * @version $Rev: 250 $Date: {date}
31  * @since Petals 1.0
32  * @author Marc Dutoo - Open Wide
33  *
34  */

35 public class XQuareBCJBIProcessorTest extends XQuareBCTestTemplate {
36
37
38     @Override JavaDoc
39     public void setUp() throws Exception JavaDoc {
40         super.setUp();
41     }
42
43
44     @Override JavaDoc
45     protected void tearDown() throws Exception JavaDoc {
46         super.tearDown();
47     }
48     
49     
50
51     /**
52      * NB. The default XQuare sample doesn't work for this example,
53      * its schema (auction.xsd) needs to be told no elements is allowed
54      * (add minOccurs="0" to the USERS, ITEMS and BIDS elements)
55      * @throws Exception
56      */

57     public void testInsertOneUser() throws Exception JavaDoc {
58         cleanDatabase();
59         String JavaDoc testContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_insert_one_user-message.xml"));
60         testOperation("insert", testContent, "<success/>", this.testXquareAuctionProperties);
61         int userNb = getSelectRowNb("select * from users");
62         assertEquals(1, userNb);
63     }
64
65     public void testInsertSmall() throws Exception JavaDoc {
66         cleanDatabase();
67         String JavaDoc testContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_insert_small-message.xml"));
68         testOperation("insert", testContent, "<success/>", this.testXquareAuctionProperties);
69         int bidNb = getSelectRowNb("select * from bids");
70         assertEquals(1, bidNb);
71     }
72
73     public void testInsertBig() throws Exception JavaDoc {
74         cleanDatabase();
75         String JavaDoc testContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_insert_big-message.xml"));
76         testOperation("insert", testContent, "<success/>", this.testXquareAuctionProperties);
77         int userNb = getSelectRowNb("select * from users");
78         assertEquals(6, userNb);
79         int bidNb = getSelectRowNb("select * from items");
80         assertEquals(8, bidNb);
81         int itemNb = getSelectRowNb("select * from bids");
82         assertEquals(16, itemNb);
83     }
84
85     
86     public void testQuery() throws Exception JavaDoc {
87         cleanDatabase();
88         String JavaDoc bigDataContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_insert_big-message.xml"));
89         testOperation("insert", bigDataContent, "<success/>", this.testXquareAuctionProperties);
90         
91         String JavaDoc testContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_query-message.xml"));
92         String JavaDoc testResults = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_query-results.xml"));
93         testOperation("query", testContent, testResults, this.testXquareAuctionProperties);
94         int userNb = getSelectRowNb("select * from users");
95         assertEquals(6, userNb);
96     }
97     
98     public void testStoredQuery() throws Exception JavaDoc {
99         testXquareAuctionProperties.put(XQuareBCJBIProcessor.STORED_QUERY_PROP_PREFIX + 0,
100             XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_stored_query_with_mod.xml")));
101         
102         cleanDatabase();
103         String JavaDoc bigDataContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_insert_big-message.xml"));
104         testOperation("insert", bigDataContent, "<success/>", this.testXquareAuctionProperties);
105         
106         String JavaDoc testContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_stored_query_with_mod-message.xml"));
107         String JavaDoc testResults = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_stored_query_with_mod-results.xml"));
108         testOperation("storedQuery", testContent, testResults, this.testXquareAuctionProperties);
109         int userNb = getSelectRowNb("select * from users");
110         assertEquals(6, userNb);
111     }
112     
113
114     public void testUpdateOneUser() throws Exception JavaDoc {
115         // first inserting one user :
116
testInsertOneUser();
117         // then updating it :
118
String JavaDoc testContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_update_one_user-message.xml"));
119         testOperation("insert", testContent, "<success/>", this.testXquareAuctionProperties);
120
121         int userNb = getSelectRowNb("select * from users");
122         assertEquals(1, userNb);
123         int fRatingUserNb = getSelectRowNb("select * from users where rating='f'");
124         assertEquals(1, fRatingUserNb);
125     }
126     
127
128     public void testNewDataListener() throws Exception JavaDoc {
129         // first inserting one user :
130
testInsertOneUser();
131         
132         //TODO
133

134         // then updating it :
135
String JavaDoc testContent = XQuareBCTestTemplate.getStringFromInputStream(new FileInputStream JavaDoc(auctionDir + "auction_test_update_one_user-message.xml"));
136         testOperation("insert", testContent, "<success/>", this.testXquareAuctionProperties);
137
138         int userNb = getSelectRowNb("select * from users");
139         assertEquals(1, userNb);
140         int fRatingUserNb = getSelectRowNb("select * from users where rating='f'");
141         assertEquals(1, fRatingUserNb);
142     }
143
144
145     
146 }
147
Popular Tags