KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > ws > xmla > XmlaTest


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21
22 package com.jaspersoft.jasperserver.ws.xmla;
23
24 import java.net.URL JavaDoc;
25 import java.util.List JavaDoc;
26
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30
31 import com.tonbeller.jpivot.core.Model;
32 import com.tonbeller.jpivot.core.ModelFactory;
33
34 import com.tonbeller.jpivot.xmla.XMLA_SOAP;
35 import com.tonbeller.jpivot.xmla.XMLA_Model;
36 import com.tonbeller.jpivot.xmla.XMLA_Result;
37 import com.tonbeller.jpivot.xmla.XMLA_OlapModelTag;
38
39 import com.jaspersoft.jasperserver.war.JasperServerConstants;
40
41
42 /**
43  * @author sbirney
44  */

45
46
47 public class XmlaTest extends TestCase {
48
49     private static boolean ENABLED = true;
50
51     private static XMLA_SOAP XMLA_CLIENT = null;
52
53     /**
54      * default constructor
55      */

56     public XmlaTest(String JavaDoc method) {
57     super(method);
58     }
59
60     /*
61      * setUp method
62      */

63     public void setUp() throws Exception JavaDoc {
64     if (!ENABLED) return;
65     XMLA_CLIENT = new XMLA_SOAP( //"http://localhost:8080/mondrian-embedded/xmla",
66
JasperServerConstants.XMLA_URL,
67                      JasperServerConstants.USERNAME,
68                      JasperServerConstants.PASSWORD );
69     }
70
71     /*
72      * tearDown method
73      */

74     public void tearDown() {
75     //no tearDown
76
}
77
78     /**
79      * main method defined here
80      * @param args
81      */

82     public static void main(String JavaDoc[] args) {
83     try {
84         junit.textui.TestRunner.run(suite());
85     } catch (Exception JavaDoc _ex) {
86         _ex.printStackTrace();
87     }
88     }
89
90     /**
91      * this method is for adding which all test case/s method/s need to be
92      * @return Test
93      * @throws Exception if fails
94      */

95     public static Test suite() throws Exception JavaDoc {
96     TestSuite suite = new TestSuite();
97
98     TestCase test1 = new XmlaTest("testDiscoverCatalogs");
99     TestCase test2 = new XmlaTest("testDiscoverDSProperties");
100     TestCase test3 = new XmlaTest("testDiscoverSugarCRMCubes");
101     // disabled - failing 07-19-06
102
//TestCase test4 = new XmlaTest("testXmlaQuery");
103
TestCase test5 = new XmlaTest("testInvalidCredentials");
104     TestCase test6 = new XmlaTest("testNoCredentials");
105
106     suite.addTest(test1);
107     suite.addTest(test2);
108     suite.addTest(test3);
109     //suite.addTest(test4); // disabled 07-19-06
110
suite.addTest(test5);
111     suite.addTest(test6);
112
113     return suite;
114     }
115
116     /*
117      * test no credentials
118      */

119     public void testNoCredentials() throws Exception JavaDoc {
120     if (!ENABLED) return;
121     System.out.println("testNoCredentials");
122     boolean success = true;
123     try {
124         XMLA_SOAP noCredClient = new XMLA_SOAP( JasperServerConstants.XMLA_URL,
125                             null, null ); // null or "" is empty
126
success = false;
127     } catch (Throwable JavaDoc t) {
128         // for some reason this seems to be throwing up some text/html about:
129
//org.acegisecurity.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
130
//org.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:414)
131
//org.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:308)
132
System.out.println("we should have just seen an exception printed but not thrown");
133     }
134     if (!success) {
135         throw new SecurityException JavaDoc("should have thrown a Bad credentials exception");
136     }
137     }
138
139     /*
140      * test invalid credentials
141      */

142     public void testInvalidCredentials() throws Exception JavaDoc {
143     if (!ENABLED) return;
144     System.out.println("testInvalidCredentials");
145     try {
146         XMLA_SOAP badCredClient = new XMLA_SOAP( JasperServerConstants.XMLA_URL,
147                              "wrong",
148                              "bad" );
149         throw new SecurityException JavaDoc("should have thrown a Bad credentials exception");
150     } catch (Throwable JavaDoc t) {
151         // message should look like this:
152
// javax.xml.soap.SOAPException: java.security.PrivilegedActionException:
153
// javax.xml.soap.SOAPException: Bad response: (401Bad credentials"
154
if (!t.getMessage().endsWith("Bad credentials")) {
155         //something other than we expected went wrong
156
throw new SecurityException JavaDoc("Unexpected error while testing credentials", t);
157         }
158         System.out.println("we should have just seen an exception printed but not thrown");
159     }
160     }
161
162     private String JavaDoc SAMPLE_SUGAR_CRM_MDX_QUERY =
163     "select {[Measures].[Total Sale Amount], [Measures].[Number of Sales], [Measures].[Avg Sale Amount], [Measures].[Avg Time To Close (Days)], [Measures].[Avg Close Probablility]} ON COLUMNS, " +
164     " NON EMPTY {([Account Categorization].[All Accounts], [Close Period].[All Periods])} ON ROWS " +
165     " from [SalesAnalysis] " +
166     " where [Sale State].[All Types].[Closed Won]";
167
168     /*
169      * test xmla query
170      */

171     public void SKIP_testXmlaQuery() throws Exception JavaDoc {
172     if (!ENABLED) return;
173
174     URL JavaDoc configUrl = XMLA_OlapModelTag.class.getResource("config.xml");
175
176     // let Digester create a model from config input
177
// the config input stream MUST refer to the XMLA_Model class
178
// <model class="com.tonbeller.bii.xmla.XMLA_Model"> is required
179
Model model;
180     model = ModelFactory.instance(configUrl);
181
182     XMLA_Model xmlaModel = (XMLA_Model) model;
183
184     xmlaModel.setCatalog("SugarCRM");
185     xmlaModel.setDataSource("Provider=Mondrian;DataSource=SugarCRM;");
186     xmlaModel.setMdxQuery(SAMPLE_SUGAR_CRM_MDX_QUERY);
187     xmlaModel.setID("SugarCRM-1");
188     xmlaModel.setUri(JasperServerConstants.XMLA_URL);
189     xmlaModel.setUser(JasperServerConstants.USERNAME);
190     xmlaModel.setPassword(JasperServerConstants.PASSWORD);
191
192     /*
193     XMLA_SOAP xmlaClient = new XMLA_SOAP( JasperServerConstants.XMLA_URL,
194                           JasperServerConstants.USERNAME,
195                           JasperServerConstants.PASSWORD,
196                           xmlaModel.getDataSource() );
197
198     // this is how jpivot executes the remote query
199     XMLA_Result result = new XMLA_Result(xmlaModel,
200                          xmlaClient,
201                          "SugarCRM",
202                          SAMPLE_SUGAR_CRM_MDX_QUERY,
203                          false);
204     */

205     xmlaModel.initialize();
206     xmlaModel.getResult();
207     }
208
209     /*
210      * test discover method
211      */

212     public void testDiscoverCatalogs() throws Exception JavaDoc {
213     if (!ENABLED) return;
214     System.out.println("testDiscoverCatalogs");
215     List JavaDoc cats = XMLA_CLIENT.discoverCat();
216     if (cats == null) {
217         fail("no catalogs available");
218         return;
219     }
220     System.out.println("number of catalogs: " + cats.size());
221     }
222
223     /*
224      * test discover method
225      */

226     public void testDiscoverSugarCRMCubes() throws Exception JavaDoc {
227     System.out.println("testDiscoverSugarCRMCubes");
228     }
229
230     /*
231      * test discover method
232      */

233     public void testDiscoverDSProperties() throws Exception JavaDoc {
234     if (!ENABLED) return;
235     System.out.println("testDiscoverDSProperties");
236     List JavaDoc props = XMLA_CLIENT.discoverDSProps();
237     if (props == null) {
238         fail("no DSProperties available");
239         return;
240     }
241     System.out.println("XmlaTest::discoverDSProps props length " + props.size());
242     }
243
244 }
245
Popular Tags