Example #1
0
  @Test
  public void testEmptyDT() throws Exception {
    RulesRepository repo = getRulesRepository();
    PackageItem pkg = repo.loadDefaultPackage();
    AssetItem asset = pkg.addAsset("testEmptyDT", "");
    asset.updateFormat(AssetFormats.DECISION_TABLE_GUIDED);
    GuidedDecisionTable gt = new GuidedDecisionTable();
    asset.updateContent(GuidedDTXMLPersistence.getInstance().marshal(gt));
    asset.checkin("");

    GuidedDTContentHandler ch = new GuidedDTContentHandler();
    ch.compile(null, asset, null);
  }
  @Test
  public void testStore() throws Exception {
    FactModelContentHandler ch = new FactModelContentHandler();

    RulesRepository repo = rulesRepository;

    PackageItem pkg = repo.loadDefaultPackage();
    AssetItem asset = pkg.addAsset("testDeclaredTypeStore", "");
    asset.updateFormat("model.drl");
    asset.updateContent("declare Foo\n name: String\n end");
    asset.checkin("");

    RuleAsset ass = new RuleAsset();
    ch.retrieveAssetContent(ass, asset);
    assertTrue(ass.getContent() instanceof FactModels);
    FactModels fm = (FactModels) ass.getContent();

    assertEquals(1, fm.models.size());
    FactMetaModel mm = (FactMetaModel) fm.models.get(0);
    assertEquals(1, mm.getFields().size());
    assertEquals("Foo", mm.getName());

    FieldMetaModel fmm = (FieldMetaModel) mm.getFields().get(0);
    assertEquals("name", fmm.name);

    mm.getFields().add(new FieldMetaModel("age", "int"));

    ch.storeAssetContent(ass, asset);

    assertTrue(asset.getContent().indexOf("age: int") > -1);

    asset.updateContent("rubbish here");
    asset.checkin("");

    ch.retrieveAssetContent(ass, asset);
    assertTrue(ass.getContent() instanceof RuleContentText);

    ch.storeAssetContent(ass, asset);

    assertEquals("rubbish here", asset.getContent());
  }
Example #3
0
  @Test
  public void testValidating() throws Exception {
    RulesRepository repo = getRulesRepository();
    PackageItem pkg = repo.loadDefaultPackage();
    AssetItem asset = pkg.addAsset("testValidatingEnum", "");
    asset.updateFormat(AssetFormats.ENUMERATION);
    asset.updateContent("'Person.age' : [1, 2, 3]");

    EnumerationContentHandler ch = new EnumerationContentHandler();
    BuilderResult result = ch.validateAsset(asset);
    assertNotNull(result);
    assertEquals(0, result.getLines().size());

    asset.updateContent("goober boy");
    result = ch.validateAsset(asset);
    assertFalse(result.getLines().size() == 0);
    assertEquals(asset.getName(), result.getLines().get(0).getAssetName());
    assertEquals(asset.getFormat(), result.getLines().get(0).getAssetFormat());
    assertNotNull(result.getLines().get(0).getMessage());
    assertEquals(asset.getUUID(), result.getLines().get(0).getUuid());
  }
Example #4
0
  public void testUpdateFiles() throws Exception {
    RulesRepository repo = RepositorySessionUtil.getRepository();
    PackageItem pkg = repo.loadDefaultPackage();
    AssetItem asset = pkg.addAsset("testUpdateFilesSVN", "something");

    asset.updateContent("lala");
    asset.checkin("yeah");
    long oldVersion = asset.getVersionNumber();

    JcrActionFactory fact = new JcrActionFactory(repo);
    ScmAction action =
        fact.updateFile(
            RulesRepository.DEFAULT_PACKAGE,
            "testUpdateFilesSVN.drl",
            "lala".getBytes(),
            "lala2".getBytes());

    fact.execute(action, "goo");

    AssetItem asset2 = pkg.loadAsset("testUpdateFilesSVN");
    assertFalse(oldVersion == asset2.getVersionNumber());
    assertEquals("lala2", asset2.getContent());
    assertEquals("goo", asset2.getCheckinComment());
  }