1 21 22 package com.jaspersoft.jasperserver.ws.xmla; 23 24 import java.net.URL ; 25 import java.util.List ; 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 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 56 public XmlaTest(String method) { 57 super(method); 58 } 59 60 63 public void setUp() throws Exception { 64 if (!ENABLED) return; 65 XMLA_CLIENT = new XMLA_SOAP( JasperServerConstants.XMLA_URL, 67 JasperServerConstants.USERNAME, 68 JasperServerConstants.PASSWORD ); 69 } 70 71 74 public void tearDown() { 75 } 77 78 82 public static void main(String [] args) { 83 try { 84 junit.textui.TestRunner.run(suite()); 85 } catch (Exception _ex) { 86 _ex.printStackTrace(); 87 } 88 } 89 90 95 public static Test suite() throws Exception { 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 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(test5); 111 suite.addTest(test6); 112 113 return suite; 114 } 115 116 119 public void testNoCredentials() throws Exception { 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 ); success = false; 127 } catch (Throwable t) { 128 System.out.println("we should have just seen an exception printed but not thrown"); 133 } 134 if (!success) { 135 throw new SecurityException ("should have thrown a Bad credentials exception"); 136 } 137 } 138 139 142 public void testInvalidCredentials() throws Exception { 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 ("should have thrown a Bad credentials exception"); 150 } catch (Throwable t) { 151 if (!t.getMessage().endsWith("Bad credentials")) { 155 throw new SecurityException ("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 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 171 public void SKIP_testXmlaQuery() throws Exception { 172 if (!ENABLED) return; 173 174 URL configUrl = XMLA_OlapModelTag.class.getResource("config.xml"); 175 176 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 205 xmlaModel.initialize(); 206 xmlaModel.getResult(); 207 } 208 209 212 public void testDiscoverCatalogs() throws Exception { 213 if (!ENABLED) return; 214 System.out.println("testDiscoverCatalogs"); 215 List 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 226 public void testDiscoverSugarCRMCubes() throws Exception { 227 System.out.println("testDiscoverSugarCRMCubes"); 228 } 229 230 233 public void testDiscoverDSProperties() throws Exception { 234 if (!ENABLED) return; 235 System.out.println("testDiscoverDSProperties"); 236 List 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 |