/**
   * verifies that rule exports are the same regardless of whether the rule is ready for render, or
   * for persistance.
   */
  protected void assertRuleBaseValuesStateIndependence() throws Exception {
    for (Object o : KEWServiceLocator.getRuleService().fetchAllRules(true)) {
      RuleBaseValues rule = (RuleBaseValues) o;
      KewExportDataSet dataSet = new KewExportDataSet();
      dataSet.getRules().add(rule);

      // first, do a conversion in the just-loaded state:
      byte[] saveXmlBytes =
          CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
      String saveStr = new String(saveXmlBytes);

      // now, convert for render:
      WebRuleUtils.populateRuleMaintenanceFields(rule);

      // do another conversion in the ready-for-render state:
      byte[] loadXmlBytes =
          CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
      String loadStr = new String(loadXmlBytes);

      // check that the results are identical:
      assertTrue(
          "The load/render state of the RuleBaseValues shouldn't effect the export: \n"
              + saveStr
              + "\n\n != \n\n"
              + loadStr,
          StringUtils.equals(saveStr, loadStr));
    }
  }
  /**
   * Note that the assertion here will fail if you have multiple rules with the same description.
   */
  protected void assertExport() throws Exception {
    // export all existing rules and their dependencies (document types, rule templates, rule
    // attributes)
    List oldRules = KEWServiceLocator.getRuleService().fetchAllRules(true);
    assertAllRulesHaveUniqueNames(oldRules);
    List oldRuleDelegations =
        KEWServiceLocator.getRuleDelegationService().findAllCurrentRuleDelegations();
    assertAllRuleDelegationsHaveUniqueNames(oldRuleDelegations);

    KewExportDataSet dataSet = new KewExportDataSet();
    dataSet.getRules().addAll(oldRules);
    dataSet.getRuleDelegations().addAll(oldRuleDelegations);
    dataSet.getDocumentTypes().addAll(KEWServiceLocator.getDocumentTypeService().findAllCurrent());
    dataSet.getRuleTemplates().addAll(KEWServiceLocator.getRuleTemplateService().findAll());
    dataSet.getRuleAttributes().addAll(KEWServiceLocator.getRuleAttributeService().findAll());
    byte[] xmlBytes =
        CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
    assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);

    // now clear the tables
    ClearDatabaseLifecycle clearLifeCycle = new ClearDatabaseLifecycle();
    clearLifeCycle.getTablesToClear().add("KREW_RULE_T");
    clearLifeCycle.getTablesToClear().add("KREW_RULE_RSP_T");
    clearLifeCycle.getTablesToClear().add("KREW_DLGN_RSP_T");
    clearLifeCycle.getTablesToClear().add("KREW_RULE_ATTR_T");
    clearLifeCycle.getTablesToClear().add("KREW_RULE_TMPL_T");
    clearLifeCycle.getTablesToClear().add("KREW_DOC_TYP_T");
    clearLifeCycle.start();
    new ClearCacheLifecycle().stop();

    // import the exported xml
    loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));

    List newRules = KEWServiceLocator.getRuleService().fetchAllRules(true);
    assertEquals("Should have same number of old and new Rules.", oldRules.size(), newRules.size());
    for (Iterator iterator = oldRules.iterator(); iterator.hasNext(); ) {
      RuleBaseValues oldRule = (RuleBaseValues) iterator.next();
      boolean foundRule = false;
      for (Iterator iterator2 = newRules.iterator(); iterator2.hasNext(); ) {
        RuleBaseValues newRule = (RuleBaseValues) iterator2.next();
        if (oldRule.getDescription().equals(newRule.getDescription())) {
          assertRuleExport(oldRule, newRule);
          foundRule = true;
        }
      }
      assertTrue(
          "Could not locate the new rule for description " + oldRule.getDescription(), foundRule);
    }

    List newRuleDelegations =
        KEWServiceLocator.getRuleDelegationService().findAllCurrentRuleDelegations();
    assertDelegations(oldRuleDelegations, newRuleDelegations);
  }
Exemple #3
0
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   ExportDataSet dataSet = (ExportDataSet) request.getSession().getAttribute(EXPORT_DATA_SET_KEY);
   request.getSession().removeAttribute(EXPORT_DATA_SET_KEY);
   if (dataSet == null) {
     throw new ServletException("No data set was specified.");
   }
   String contentType = "application/xml";
   XmlExporterService exporter = CoreApiServiceLocator.getXmlExporterService();
   byte[] data = exporter.export(dataSet);
   response.setContentType(contentType);
   response.setContentLength(data.length);
   response.setHeader("Content-disposition", "attachment; filename=" + extractFileName(request));
   response.getOutputStream().write(data);
   response.getOutputStream().close();
 }
  protected void assertExport() throws Exception {
    // export all existing rule templates and their dependencies (rule attributes)
    List oldRuleTemplates = KEWServiceLocator.getRuleTemplateService().findAll();
    KewExportDataSet dataSet = new KewExportDataSet();
    dataSet.getRuleTemplates().addAll(oldRuleTemplates);
    dataSet.getRuleAttributes().addAll(KEWServiceLocator.getRuleAttributeService().findAll());
    byte[] xmlBytes =
        CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
    assertTrue("XML should be non empty.", xmlBytes != null && xmlBytes.length > 0);

    // now clear the tables
    new ClearDatabaseLifecycle(getPerTestTablesToClear(), getPerTestTablesNotToClear()).start();

    // import the exported xml
    loadXmlStream(new BufferedInputStream(new ByteArrayInputStream(xmlBytes)));

    List newRuleTemplates = KEWServiceLocator.getRuleTemplateService().findAll();
    assertEquals(
        "Should have same number of old and new RuleTemplates.",
        oldRuleTemplates.size(),
        newRuleTemplates.size());
    for (Iterator iterator = oldRuleTemplates.iterator(); iterator.hasNext(); ) {
      RuleTemplateBo oldRuleTemplate = (RuleTemplateBo) iterator.next();
      boolean foundTemplate = false;
      for (Iterator iterator2 = newRuleTemplates.iterator(); iterator2.hasNext(); ) {
        RuleTemplateBo newRuleTemplate = (RuleTemplateBo) iterator2.next();
        if (oldRuleTemplate.getName().equals(newRuleTemplate.getName())) {
          assertRuleTemplateExport(oldRuleTemplate, newRuleTemplate);
          foundTemplate = true;
        }
      }
      assertTrue(
          "Could not locate the new rule template for name " + oldRuleTemplate.getName(),
          foundTemplate);
    }
  }