KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > mondrian > MementoTest


1 /*
2  * Created on 12.08.2003
3  * by hh
4  */

5 package com.tonbeller.jpivot.mondrian;
6
7 import java.beans.XMLDecoder JavaDoc;
8 import java.beans.XMLEncoder JavaDoc;
9 import java.io.ByteArrayInputStream JavaDoc;
10 import java.io.ByteArrayOutputStream JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.util.List JavaDoc;
13
14 import junit.framework.TestCase;
15
16 import org.xml.sax.SAXException JavaDoc;
17
18 import com.tonbeller.jpivot.olap.model.Axis;
19 import com.tonbeller.jpivot.olap.model.Hierarchy;
20 import com.tonbeller.jpivot.olap.model.Member;
21 import com.tonbeller.jpivot.olap.model.OlapException;
22 import com.tonbeller.jpivot.olap.model.Position;
23 import com.tonbeller.jpivot.olap.model.Result;
24 import com.tonbeller.jpivot.olap.navi.ChangeSlicer;
25 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition;
26 import com.tonbeller.jpivot.olap.navi.DrillReplace;
27 import com.tonbeller.jpivot.olap.navi.ExpressionParser;
28 import com.tonbeller.jpivot.olap.navi.SortRank;
29 import com.tonbeller.jpivot.olap.query.DrillExpandPositionExt;
30 import com.tonbeller.jpivot.olap.query.DrillReplaceExt;
31 import com.tonbeller.jpivot.olap.query.ExpBean;
32 import com.tonbeller.jpivot.olap.query.PositionNodeBean;
33 import com.tonbeller.jpivot.olap.query.ResultBase;
34 import com.tonbeller.jpivot.tags.MondrianModelFactory;
35 import com.tonbeller.wcf.bookmarks.Bookmarkable;
36
37 /**
38  * Test Memento State Serialization.
39  */

40 public class MementoTest extends TestCase {
41
42   /**
43    */

44   public MementoTest() {
45     super();
46   }
47
48   /**
49    * @param arg0
50    */

51   public MementoTest(String JavaDoc arg0) {
52     super(arg0);
53   }
54
55   public void testMementoExpandExtensional() throws Exception JavaDoc {
56     MondrianMemento memento = createMementoExpand(Bookmarkable.EXTENSIONAL);
57     assertEquals(2, memento.getQuaxes().length);
58     PositionNodeBean nb = memento.getQuaxes()[1].getPosTreeRoot();
59     assertEquals(3, nb.getChildren().length);
60     assertEquals( "[Gender].[All Gender].[F]", nb.getChildren()[2].getReference().getName());
61     String JavaDoc xml = serializeMemento(memento);
62     setMementoExpand(xml);
63   }
64
65   public void testMementoExpandIntensional() throws Exception JavaDoc {
66     MondrianMemento memento = createMementoExpand(Bookmarkable.INTENSIONAL);
67     assertEquals(2, memento.getQuaxes().length);
68     // check measures on columns
69
PositionNodeBean nb = memento.getQuaxes()[0].getPosTreeRoot();
70     assertEquals(1, nb.getChildren().length);
71     assertNull(nb.getReference());
72     ExpBean eb = nb.getChildren()[0].getReference();
73     assertEquals(3, eb.getArgs().length);
74     // check rows
75
nb = memento.getQuaxes()[1].getPosTreeRoot();
76     assertEquals(1, nb.getChildren().length);
77     assertNull(nb.getReference());
78     String JavaDoc[] hiers = {"[Gender]", "[Marital Status]", "[Customers]", "[Product]"};
79     for (int i = 0; i < hiers.length; i++) {
80       assertEquals(1, nb.getChildren().length);
81       nb = nb.getChildren()[0];
82       eb = nb.getReference();
83       assertEquals(ExpBean.TYPE_TOPLEVEL_MEMBERS, eb.getType());
84       assertEquals(1, eb.getArgs().length);
85       ExpBean arg = eb.getArgs()[0];
86       assertEquals(ExpBean.TYPE_HIER, arg.getType());
87       assertEquals(hiers[i], arg.getName());
88     }
89     
90     // we use a different initial query to restore
91
MondrianModel model = createSimpleModel();
92     model.setBookmarkState(memento);
93     Result result = model.getResult();
94     Axis axis = result.getAxes()[1];
95     // nur die toplevel member = ALL
96
assertEquals(1, axis.getPositions().size());
97     MondrianHierarchy[] mh = (MondrianHierarchy[]) axis.getHierarchies();
98     for (int i = 0; i < hiers.length; i++) {
99       assertEquals(hiers[i], mh[i].getUniqueName());
100     }
101   }
102
103   public void testMementoDrillExtensional() throws Exception JavaDoc {
104     MondrianMemento memento = createMementoDrill(Bookmarkable.EXTENSIONAL);
105     assertEquals(2, memento.getQuaxes().length);
106     PositionNodeBean nb = memento.getQuaxes()[1].getPosTreeRoot();
107     assertEquals(1, nb.getChildren().length);
108     assertEquals("[Store].[All Stores]", nb.getChildren()[0].getReference().getArgs()[0].getName());
109     String JavaDoc xml = serializeMemento(memento);
110     setMementoDrill(xml);
111   }
112
113   public void testMementoDrillIntensional() throws Exception JavaDoc {
114     MondrianMemento memento = createMementoDrill(Bookmarkable.INTENSIONAL);
115     assertEquals(2, memento.getQuaxes().length);
116     PositionNodeBean nb = memento.getQuaxes()[1].getPosTreeRoot();
117     assertNull(nb.getReference());
118     assertEquals(1, nb.getChildren().length);
119     nb = nb.getChildren()[0];
120     ExpBean eb = nb.getReference();
121     assertEquals(ExpBean.TYPE_TOPLEVEL_MEMBERS, eb.getType());
122     assertEquals(1, eb.getArgs().length);
123     eb = eb.getArgs()[0];
124     assertEquals(ExpBean.TYPE_HIER, eb.getType());
125     assertEquals("[Store]", eb.getName());
126     
127     MondrianModel model = createSimpleModel();
128     model.setBookmarkState(memento);
129     Result result = model.getResult();
130     
131     // nur die toplevel member = ALL
132
Axis axis = result.getAxes()[1];
133     assertEquals(1, axis.getPositions().size());
134   }
135   
136   /**
137    * slicer is restored by bookmark
138    */

139   public void testSlicerExtensional() throws Exception JavaDoc {
140     MondrianMemento memento = createMementoSlicer(Bookmarkable.EXTENSIONAL);
141     MondrianModel model = createSimpleModel();
142     model.setBookmarkState(memento);
143     Result result = model.getResult();
144     Axis axis = result.getSlicer();
145     assertNotNull(axis);
146     Position pos = (Position) axis.getPositions().get(0);
147     MondrianMember[] m = (MondrianMember[]) pos.getMembers();
148     assertEquals(1, m.length);
149     assertEquals("[Time].[1997]", m[0].getUniqueName());
150   }
151   
152   /**
153    * slicer is NOT restored by bookmark - because the members
154    * may not be available anymore when the slicer is restored
155    */

156   public void testSlicerIntensional() throws Exception JavaDoc {
157     MondrianMemento memento = createMementoSlicer(Bookmarkable.INTENSIONAL);
158     MondrianModel model = createSimpleModel();
159     model.setBookmarkState(memento);
160     Result result = model.getResult();
161     Axis axis = result.getSlicer();
162     assertNotNull(axis);
163     Position pos = (Position) axis.getPositions().get(0);
164     MondrianMember[] m = (MondrianMember[]) pos.getMembers();
165     assertEquals(0, m.length);
166   }
167   
168   
169   public void testSortExtensional() throws Exception JavaDoc {
170     MondrianMemento memento = createMementoSort(createSimpleModel(), Bookmarkable.EXTENSIONAL);
171     assertEquals("[Measures].[Unit Sales]", memento.getSortPosMembers()[0]);
172     Result result = restoreMementoSort(createCalcMeasureModel(), memento);
173     assertEquals(3, result.getAxes()[1].getPositions().size());
174   }
175
176   public void testSortIntensional() throws Exception JavaDoc {
177     MondrianMemento memento = createMementoSort(createSimpleModel(), Bookmarkable.INTENSIONAL);
178     Result result = restoreMementoSort(createCalcMeasureModel(), memento);
179     assertEquals(1, result.getAxes()[1].getPositions().size());
180     assertEquals("[Measures].[Unit Sales]", memento.getSortPosMembers()[0]);
181     // ensure no ex is thrown when the sort position can not be restored
182
MondrianModel model = createSimpleModel();
183     SortRank sr = (SortRank) model.getExtension(SortRank.ID);
184     memento.setSortPosMembers(new String JavaDoc[]{"[Measures].[Invalid Measure]"});
185     model.setBookmarkState(memento);
186     assertFalse(sr.isSorting());
187     result = model.getResult();
188     assertEquals(1, result.getAxes()[1].getPositions().size());
189   }
190   
191   public void testSortCalcMeasureExtensional() throws Exception JavaDoc {
192     MondrianMemento memento = createMementoSort(createCalcMeasureModel(), Bookmarkable.EXTENSIONAL);
193     assertEquals("[Measures].[Calculated]", memento.getSortPosMembers()[0]);
194     Result result = restoreMementoSort(createSimpleModel(), memento);
195     assertEquals(3, result.getAxes()[1].getPositions().size());
196   }
197
198   public void testSortCalcMeasureIntensional() throws Exception JavaDoc {
199     MondrianMemento memento = createMementoSort(createCalcMeasureModel(), Bookmarkable.INTENSIONAL);
200     assertEquals("[Measures].[Calculated]", memento.getSortPosMembers()[0]);
201     Result result = restoreMementoSort(createSimpleModel(), memento);
202     assertEquals(1, result.getAxes()[1].getPositions().size());
203   }
204   
205   public MondrianMemento createMementoSlicer(int levelOfDetail) throws Exception JavaDoc {
206     MondrianModel model = createSimpleModel();
207     ChangeSlicer cs = (ChangeSlicer) model.getExtension(ChangeSlicer.ID);
208     ExpressionParser ep = (ExpressionParser)model.getExtension(ExpressionParser.ID);
209     Member m = ep.lookupMember("[Time].[1997]");
210     cs.setSlicer(new Member[]{m});
211     Result result = model.getResult();
212     // create and test memento
213
MondrianMemento memento = (MondrianMemento) model.getBookmarkState(levelOfDetail);
214     return memento;
215   }
216   
217   public MondrianMemento createMementoSort(MondrianModel model, int levelOfDetail) throws Exception JavaDoc {
218     SortRank sr = (SortRank) model.getExtension(SortRank.ID);
219     // first step
220
Result result = model.getResult();
221     sr.setSortMode(SortRank.ASC);
222     sr.setSorting(true);
223     Axis axis = result.getAxes()[0];
224     Position pos = (Position) axis.getPositions().get(0);
225     sr.sort(axis, pos);
226     // second step
227
result = model.getResult();
228     // create and test memento
229
MondrianMemento memento = (MondrianMemento) model.getBookmarkState(levelOfDetail);
230     assertTrue(memento.isSorting());
231     assertEquals(1, memento.getSortPosMembers().length);
232     return memento;
233   }
234   
235   public Result restoreMementoSort(MondrianModel model, MondrianMemento memento) throws Exception JavaDoc {
236     SortRank sr = (SortRank) model.getExtension(SortRank.ID);
237     model.setBookmarkState(memento);
238     assertTrue(sr.isSorting());
239     Result result = model.getResult();
240     assertEquals(2, result.getAxes().length);
241     return result;
242   }
243
244   private MondrianModel createSimpleModel() throws SAXException JavaDoc, IOException JavaDoc, OlapException {
245     String JavaDoc mdxQuery =
246       "select {[Measures].[Unit Sales]} on columns,"
247       + " [Product].[Product Family].Members ON rows\n"
248         + "from [Sales]";
249     MondrianModel model = MondrianModelFactory.instance();
250     model.setMdxQuery(mdxQuery);
251     TestConnection.initModel(model);
252     return model;
253   }
254
255   private MondrianModel createCalcMeasureModel() throws SAXException JavaDoc, IOException JavaDoc, OlapException {
256     String JavaDoc mdxQuery =
257       "with member [Measures].[Calculated] as '([Measures].[Store Sales] - [Measures].[Store Cost])', format_string = \"#,##0.00\"\n"
258         + "select {[Measures].[Calculated]} ON columns,\n"
259         + " [Product].[Product Family].Members ON rows\n"
260         + "from [Sales]\n";
261     MondrianModel model = MondrianModelFactory.instance();
262     model.setMdxQuery(mdxQuery);
263     TestConnection.initModel(model);
264     return model;
265   }
266
267   
268   public MondrianMemento createMementoExpand(int levelOfDetail) throws Exception JavaDoc {
269     String JavaDoc renderFile = null; // "d:\\x\\createMementoExpand";
270
int renderNum = 0;
271
272     String JavaDoc mdxQuery =
273       "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns,"
274         + "{([Gender].[All Gender], [Marital Status].[All Marital Status],"
275         + "[Customers].[All Customers],"
276         + "[Product].[All Products] ) } on rows "
277         + "from Sales where ([Time].[1997])";
278
279     Result result;
280     List JavaDoc positions;
281
282     MondrianModel model = MondrianModelFactory.instance();
283     model.setMdxQuery(mdxQuery);
284     TestConnection.initModel(model);
285
286     DrillExpandPositionExt mdep =
287       (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID);
288
289     // first step
290
result = model.getResult();
291     if (renderFile != null)
292        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
293     positions = result.getAxes()[1].getPositions();
294     // expand All Gender
295
Position pos = (Position) positions.get(0);
296     assertTrue(mdep.canExpand(pos, pos.getMembers()[0]));
297     mdep.expand(pos, pos.getMembers()[0]); // expand All Gender
298

299     result = model.getResult();
300     if (renderFile != null)
301        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
302     positions = result.getAxes()[1].getPositions();
303     assertPosition(
304       result,
305       1,
306       new String JavaDoc[] { "F", "All Marital Status", "All Customers", "All Products" });
307
308     // expand (F,,All Customers,)
309
pos = (Position) positions.get(1);
310     assertTrue(mdep.canExpand(pos, pos.getMembers()[2]));
311     mdep.expand(pos, pos.getMembers()[2]); // expand All Customers
312

313     result = model.getResult();
314     if (renderFile != null)
315        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
316     positions = result.getAxes()[1].getPositions();
317     assertPosition(result, 4, new String JavaDoc[] { "F", "All Marital Status", "USA", "All Products" });
318
319     // expand All Products
320
pos = (Position) positions.get(4);
321     assertTrue(mdep.canExpand(pos, pos.getMembers()[3]));
322     mdep.expand(pos, pos.getMembers()[3]); // expand All Products
323

324     result = model.getResult();
325     if (renderFile != null)
326        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
327     positions = result.getAxes()[1].getPositions();
328     assertPosition(result, 5, new String JavaDoc[] { "F", "All Marital Status", "USA", "Drink" });
329
330     // expand USA
331
pos = (Position) positions.get(5);
332     assertTrue(mdep.canExpand(pos, pos.getMembers()[2]));
333     mdep.expand(pos, pos.getMembers()[2]); // expand USA
334

335     result = model.getResult();
336     if (renderFile != null)
337        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
338     positions = result.getAxes()[1].getPositions();
339
340     assertPosition(result, 9, new String JavaDoc[] { "F", "All Marital Status", "CA", "Drink" });
341     assertPosition(result, 14, new String JavaDoc[] { "F", "All Marital Status", "OR", "Food" });
342
343     // expand All Marital status under F
344
pos = (Position) positions.get(1);
345     assertTrue(mdep.canExpand(pos, pos.getMembers()[1]));
346     mdep.expand(pos, pos.getMembers()[1]); // expand All Marital Status
347

348     result = model.getResult();
349     if (renderFile != null)
350        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
351     positions = result.getAxes()[1].getPositions();
352
353     assertPosition(result, positions.size() - 2, new String JavaDoc[] { "F", "S", "WA", "Non-Consumable" });
354     assertPosition(result, positions.size() - 5, new String JavaDoc[] { "F", "S", "WA", "All Products" });
355
356     return (MondrianMemento) model.getBookmarkState(levelOfDetail);
357
358   }
359
360
361   public void setMementoExpand(String JavaDoc xml) throws Exception JavaDoc {
362
363     Result result;
364     List JavaDoc positions;
365
366     String JavaDoc renderFile = null; // "d:\\x\\setMementoExpand";
367
int renderNum = 0;
368
369     MondrianModel model = MondrianModelFactory.instance();
370     //TestConnection.initModel(model);
371

372     DrillExpandPositionExt mdep =
373       (DrillExpandPositionExt) model.getExtension(DrillExpandPosition.ID);
374
375     // restore memento
376
XMLDecoder JavaDoc d = new XMLDecoder JavaDoc(new ByteArrayInputStream JavaDoc(xml.getBytes()));
377     Object JavaDoc mo = d.readObject();
378     d.close();
379     model.setBookmarkState(mo);
380
381     result = model.getResult();
382     if (renderFile != null)
383        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
384     positions = result.getAxes()[1].getPositions();
385
386     // Collapse all Products
387
Position pos = (Position) positions.get(positions.size() - 5);
388     assertTrue(mdep.canCollapse(pos, pos.getMembers()[3]));
389     mdep.collapse(pos, pos.getMembers()[3]); // All Products
390

391     result = model.getResult();
392     if (renderFile != null)
393        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
394     positions = result.getAxes()[1].getPositions();
395
396     assertPosition(result, positions.size() - 2, new String JavaDoc[] { "F", "S", "WA", "All Products" });
397
398     // collapse All Marital Status
399
pos = (Position) positions.get(1);
400     assertTrue(mdep.canCollapse(pos, pos.getMembers()[1]));
401     mdep.collapse(pos, pos.getMembers()[1]); // All Marital Status
402

403     result = model.getResult();
404     if (renderFile != null)
405        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
406     positions = result.getAxes()[1].getPositions();
407
408     assertPosition(result, 8, new String JavaDoc[] { "F", "All Marital Status", "CA", "All Products" });
409
410     // collapse All Gender
411
pos = (Position) positions.get(0);
412     assertTrue(mdep.canCollapse(pos, pos.getMembers()[0]));
413     mdep.collapse(pos, pos.getMembers()[0]); // All Gender
414

415     result = model.getResult();
416     if (renderFile != null)
417        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
418     positions = result.getAxes()[1].getPositions();
419     assertEquals(positions.size(), 1);
420   }
421
422   public MondrianMemento createMementoDrill(int levelOfDetail) throws Exception JavaDoc {
423
424     String JavaDoc renderFile = null; // "d:\\x\\createMementoDrill";
425
int renderNum = 0;
426
427     /*
428     select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns,
429     CrossJoin( [Store].[USA].children, [Product].[All Products].[Drink].children) on rows
430     from Sales where ([Time].[1997])
431     */

432     String JavaDoc mdxQuery =
433       "select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns, "
434         + "CrossJoin( [Store].[USA].children, [Product].[All Products].[Drink].children) on rows "
435         + "from Sales where ([Time].[1997])";
436
437     Result result;
438
439     MondrianModel model = MondrianModelFactory.instance();
440     model.setMdxQuery(mdxQuery);
441     TestConnection.initModel(model);
442
443     // first step
444
result = model.getResult();
445     if (renderFile != null)
446        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
447
448     assertPosition(result, 1, new String JavaDoc[] { "CA", "Beverages" });
449     assertPosition(result, 6, new String JavaDoc[] { "WA", "Alcoholic Beverages" });
450
451     DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID);
452
453     // Drill down CA
454
Axis[] axes = result.getAxes();
455     List JavaDoc positions = axes[1].getPositions();
456     Position pos1 = (Position) positions.get(1); // (CA,Beverages)
457

458     assertTrue(mdrep.canDrillDown(pos1.getMembers()[0]));
459     mdrep.drillDown(pos1.getMembers()[0]); // drilldown CA
460

461     result = model.getResult();
462     if (renderFile != null)
463        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
464     assertPosition(result, 6, new String JavaDoc[] { "Los Angeles", "Alcoholic Beverages" });
465     assertPosition(result, 10, new String JavaDoc[] { "San Diego", "Beverages" });
466     assertPosition(result, 14, new String JavaDoc[] { "San Francisco", "Dairy" });
467
468     // drill up the Store hierarchy
469
axes = result.getAxes();
470     positions = axes[1].getPositions();
471     Position pos0 = (Position) positions.get(0); // no matter what it is
472
Hierarchy hier = pos0.getMembers()[0].getLevel().getHierarchy();
473
474     assertTrue(mdrep.canDrillUp(hier));
475     mdrep.drillUp(hier); // drill up "Store"
476

477     result = model.getResult();
478     if (renderFile != null)
479        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
480
481     assertPosition(result, 2, new String JavaDoc[] { "CA", "Dairy" });
482     assertPosition(result, 7, new String JavaDoc[] { "WA", "Beverages" });
483
484     // another drill up of the Store hierarchy
485
axes = result.getAxes();
486     positions = axes[1].getPositions();
487     pos0 = (Position) positions.get(0); // no matter what it is
488
hier = pos0.getMembers()[0].getLevel().getHierarchy();
489
490     assertTrue(mdrep.canDrillUp(hier));
491     mdrep.drillUp(hier); // drill up "Store"
492

493     result = model.getResult();
494     if (renderFile != null)
495        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
496
497     assertPosition(result, 7, new String JavaDoc[] { "USA", "Beverages" });
498
499     // create Memento and write it to xml string
500
return (MondrianMemento) model.getBookmarkState(levelOfDetail);
501   }
502
503   public void setMementoDrill(String JavaDoc xml) throws Exception JavaDoc {
504
505     String JavaDoc renderFile = null; // "d:\\x\\setMementoDrill";
506
int renderNum = 0;
507     //String renderFile = null;
508

509     Result result;
510
511     MondrianModel model = MondrianModelFactory.instance();
512     DrillReplaceExt mdrep = (DrillReplaceExt) model.getExtension(DrillReplace.ID);
513
514     // restore memento
515
XMLDecoder JavaDoc d = new XMLDecoder JavaDoc(new ByteArrayInputStream JavaDoc(xml.getBytes()));
516     Object JavaDoc mo = d.readObject();
517     d.close();
518     model.setBookmarkState(mo);
519
520     result = model.getResult();
521     if (renderFile != null)
522        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
523
524     // last drill up of the Store hierarchy reaching "All Stores"
525
Axis[] axes = result.getAxes();
526     List JavaDoc positions = axes[1].getPositions();
527     Position pos0 = (Position) positions.get(0); // no matter what it is
528
Hierarchy hier = pos0.getMembers()[0].getLevel().getHierarchy();
529
530     assertTrue(mdrep.canDrillUp(hier));
531     mdrep.drillUp(hier); // drill up "Store"
532

533     result = model.getResult();
534     if (renderFile != null)
535        ResultBase.renderHtml(result, model.getCurrentMdx(), renderFile + renderNum++ +".html");
536
537     assertPosition(result, 2, new String JavaDoc[] { "All Stores", "Dairy" });
538
539     // now drill up is not possible any more
540
assertTrue(!mdrep.canDrillUp(hier));
541
542   }
543
544   /**
545    * assert position
546    */

547   private void assertPosition(Result result, int iPos, String JavaDoc[] posMembers) {
548     Position pos = (Position) result.getAxes()[1].getPositions().get(iPos);
549     for (int i = 0; i < posMembers.length; i++) {
550       String JavaDoc str = pos.getMembers()[i].getLabel();
551       assertEquals(str, posMembers[i]);
552     }
553   }
554
555   private String JavaDoc serializeMemento(MondrianMemento memento) {
556     ByteArrayOutputStream JavaDoc outs = new ByteArrayOutputStream JavaDoc();
557     XMLEncoder JavaDoc e = new XMLEncoder JavaDoc(outs);
558     e.writeObject(memento);
559     e.close();
560     return outs.toString();
561   }
562
563 } // End MementoExpandTest
564
Popular Tags