예제 #1
0
  @Test
  public void testSaveModelSettings() throws ConfigurationException, IOException {
    PivotModel model = getPivotModel();
    model.setMdx(getTestQuery());
    model.initialize();

    model.setSorting(true);
    model.setTopBottomCount(3);
    model.setSortCriteria(SortCriteria.BOTTOMCOUNT);

    CellSet cellSet = model.getCellSet();
    CellSetAxis axis = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal());

    model.sort(axis, axis.getPositions().get(0));

    String mdx = model.getCurrentMdx();

    XMLConfiguration configuration = new XMLConfiguration();
    configuration.setDelimiterParsingDisabled(true);

    model.saveSettings(configuration);

    Logger logger = LoggerFactory.getLogger(getClass());
    if (logger.isDebugEnabled()) {
      StringWriter writer = new StringWriter();
      configuration.save(writer);
      writer.flush();
      writer.close();

      logger.debug("Loading report content :" + System.getProperty("line.separator"));
      logger.debug(writer.getBuffer().toString());
    }

    PivotModel newModel = new PivotModelImpl(getDataSource());
    newModel.restoreSettings(configuration);

    newModel.getCellSet();

    String newMdx = newModel.getCurrentMdx();
    if (newMdx != null) {
      // Currently the parser treats every number as double value.
      // It's inevitable now and does not impact the result.
      newMdx = newMdx.replaceAll("3\\.0", "3");
    }

    assertEquals("MDX has been changed after the state restoration", mdx, newMdx);
    assertTrue(
        "Property 'sorting' has been changed after the state restoration", newModel.isSorting());
    assertEquals(
        "Property 'topBottomCount' has been changed after the state restoration",
        3,
        newModel.getTopBottomCount());
    assertEquals(
        "Property 'sortMode' has been changed after the state restoration",
        SortCriteria.BOTTOMCOUNT,
        newModel.getSortCriteria());
  }
예제 #2
0
  @Test
  public void testBookmarkModelState() {
    PivotModel model = getPivotModel();
    model.setMdx(getTestQuery());
    model.initialize();

    model.setSorting(true);
    model.setTopBottomCount(3);
    model.setSortCriteria(SortCriteria.BOTTOMCOUNT);

    CellSet cellSet = model.getCellSet();
    CellSetAxis axis = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal());

    model.sort(axis, axis.getPositions().get(0));

    String mdx = model.getCurrentMdx();

    Serializable bookmark = model.saveState();

    assertNotNull("Bookmarked state should not be null", bookmark);

    PivotModel newModel = new PivotModelImpl(getDataSource());
    newModel.restoreState(bookmark);

    newModel.getCellSet();

    String newMdx = newModel.getCurrentMdx();
    if (newMdx != null) {
      // Currently the parser treats every number as double value.
      // It's inevitable now and does not impact the result.
      newMdx = newMdx.replaceAll("3\\.0", "3");
    }

    assertEquals("MDX has been changed after the state restoration", mdx, newMdx);
    assertTrue(
        "Property 'sorting' has been changed after the state restoration", newModel.isSorting());
    assertEquals(
        "Property 'topBottomCount' has been changed after the state restoration",
        3,
        newModel.getTopBottomCount());
    assertEquals(
        "Property 'sortMode' has been changed after the state restoration",
        SortCriteria.BOTTOMCOUNT,
        newModel.getSortCriteria());
  }