public class RepositoyScenarioTest extends GuvnorTestBase {
@Test
public void testRunScenario() throws Exception {
ServiceImplementation impl = getServiceImplementation();
RulesRepository repo = impl.getRulesRepository();
RepositoryCategoryService repositoryCategoryService = getRepositoryCategoryService();
RepositoryPackageService repositoryPackageService = getRepositoryPackageService();
System.out.println( "create package" );
PackageItem pkg = repo.createPackage( "testScenarioRun",
"" );
DroolsHeader.updateDroolsHeader( "import org.drools.Person\n global org.drools.Cheese cheese\n",
pkg );
AssetItem rule1 = pkg.addAsset( "rule_1",
"" );
rule1.updateFormat( AssetFormats.DRL );
rule1.updateContent( "rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end" );
rule1.checkin( "" );
repo.save();
Scenario sc = new Scenario();
FactData person = new FactData();
person.setName( "p" );
person.setType( "Person" );
person.getFieldData().add( new FieldData( "age",
"40" ) );
person.getFieldData().add( new FieldData( "name",
"michael" ) );
sc.getFixtures().add( person );
sc.getFixtures().add( new ExecutionTrace() );
VerifyRuleFired vr = new VerifyRuleFired( "rule1",
1,
null );
sc.getFixtures().add( vr );
VerifyFact vf = new VerifyFact();
vf.setName( "p" );
vf.getFieldValues().add( new VerifyField( "name",
"michael",
"==" ) );
vf.getFieldValues().add( new VerifyField( "age",
"42",
"==" ) );
sc.getFixtures().add( vf );
FactData cheese = new FactData();
cheese.setName( "cheese" );
cheese.setType( "Cheese" );
cheese.getFieldData().add( new FieldData( "price",
"42" ) );
sc.getGlobals().add( cheese );
ScenarioRunResult res = repositoryPackageService.runScenario( pkg.getName(),
sc ).result;
assertNull( res.getErrors() );
assertNotNull( res.getScenario() );
assertTrue( vf.wasSuccessful() );
assertTrue( vr.wasSuccessful() );
res = repositoryPackageService.runScenario( pkg.getName(),
sc ).result;
assertNull( res.getErrors() );
assertNotNull( res.getScenario() );
assertTrue( vf.wasSuccessful() );
assertTrue( vr.wasSuccessful() );
RuleBaseCache.getInstance().clearCache();
res = repositoryPackageService.runScenario( pkg.getName(),
sc ).result;
assertNull( res.getErrors() );
assertNotNull( res.getScenario() );
assertTrue( vf.wasSuccessful() );
assertTrue( vr.wasSuccessful() );
//BuilderResult[] results = impl.buildPackage(pkg.getUUID(), null, true);
//assertNull(results);
rule1.updateContent( "Junk" );
rule1.checkin( "" );
RuleBaseCache.getInstance().clearCache();
pkg.updateBinaryUpToDate( false );
repo.save();
res = repositoryPackageService.runScenario( pkg.getName(),
sc ).result;
assertNotNull( res.getErrors() );
assertNull( res.getScenario() );