use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.
the class TestScenarioFactory method makeTestScenarioWithoutVerifyFact.
public static Scenario makeTestScenarioWithoutVerifyFact(final String packageName, final Collection<Import> imports, final String name) {
final Scenario model = new Scenario();
model.getImports().getImports().addAll(imports);
model.setPackageName(packageName);
model.setName(name);
model.getFixtures().add(new FactData("Applicant", "$a", new ArrayList<Field>() {
{
add(new FieldData("age", "33"));
}
}, false));
return model;
}
use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.
the class TestScenarioFactory method makeTestScenarioWithVerifyRuleFired.
// See https://bugzilla.redhat.com/show_bug.cgi?id=1179158
public static Scenario makeTestScenarioWithVerifyRuleFired(final String packageName, final Collection<Import> imports, final String name) {
final Scenario model = new Scenario();
model.getImports().getImports().addAll(imports);
model.setPackageName(packageName);
model.setName(name);
model.getFixtures().add(new VerifyRuleFired("test", 1, true));
return model;
}
use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.
the class IndexTestScenarioTest method testIndexTestScenario.
@Test
public void testIndexTestScenario() throws IOException, InterruptedException {
// Add test files
final Path path1 = basePath.resolve("scenario1.scenario");
final Scenario model1 = TestScenarioFactory.makeTestScenarioWithVerifyFact("org.drools.workbench.screens.testscenario.backend.server.indexing", new ArrayList<Import>() {
{
add(new Import("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant"));
add(new Import("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage"));
}
}, "scenario1");
final String xml1 = ScenarioXMLPersistence.getInstance().marshal(model1);
ioService().write(path1, xml1);
final Path path2 = basePath.resolve("scenario2.scenario");
final Scenario model2 = TestScenarioFactory.makeTestScenarioWithoutVerifyFact("org.drools.workbench.screens.testscenario.backend.server.indexing", new ArrayList<Import>() {
{
add(new Import("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant"));
add(new Import("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage"));
}
}, "scenario2");
final String xml2 = ScenarioXMLPersistence.getInstance().marshal(model2);
ioService().write(path2, xml2);
final Path path3 = basePath.resolve("scenario3.scenario");
final Scenario model3 = TestScenarioFactory.makeTestScenarioWithVerifyRuleFired("org.drools.workbench.screens.testscenario.backend.server.indexing", new ArrayList<Import>() {
{
add(new Import("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant"));
add(new Import("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage"));
}
}, "scenario3");
final String xml3 = ScenarioXMLPersistence.getInstance().marshal(model3);
ioService().write(path3, xml3);
final Path path4 = basePath.resolve("scenario4.scenario");
final Scenario model4 = TestScenarioFactory.makeTestScenarioWithGlobalVerifyGlobal("org.drools.workbench.screens.testscenario.backend.server.indexing", new ArrayList<Import>() {
{
add(new Import("java.util.Date"));
}
}, "scenario1");
final String xml4 = ScenarioXMLPersistence.getInstance().marshal(model4);
ioService().write(path4, xml4);
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
// Test Scenarios using org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
searchFor(index, query, 2, path1, path2);
}
// Test Scenarios using org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
searchFor(index, query, 1, path1);
}
// Test Scenarios using org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage#amount
{
final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage", "amount", PartType.FIELD)).build();
searchFor(index, query, 1, path1);
}
// Test Scenarios using java.lang.Integer
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("java.lang.Integer", ResourceType.JAVA)).build();
searchFor(index, query, 3, path1, path2);
}
// Test Scenarios expecting rule "test" to fire
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("test", ResourceType.RULE)).build();
searchFor(index, query, 1, path3);
}
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("java.util.Date", ResourceType.JAVA)).build();
searchFor(index, query, 1, path4);
}
}
use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.
the class ScenarioRunnerService method getKSessions.
private Map<String, KieSession> getKSessions(Path path, List<Scenario> scenarios) {
Map<String, KieSession> ksessions = new HashMap<String, KieSession>();
for (Scenario scenario : scenarios) {
String ksessionName = getKSessionName(scenario.getKSessions());
ksessions.put(ksessionName, loadKSession(moduleService.resolveModule(path), ksessionName));
}
return ksessions;
}
use of org.drools.workbench.models.testscenarios.shared.Scenario in project drools-wb by kiegroup.
the class TestScenarioFileIndexer method fillIndexBuilder.
@Override
public DefaultIndexBuilder fillIndexBuilder(final Path path) throws Exception {
final String content = ioService.readAllString(path);
final Scenario model = ScenarioXMLPersistence.getInstance().unmarshal(content);
final ModuleDataModelOracle dmo = getModuleDataModelOracle(path);
final Module project = moduleService.resolveModule(Paths.convert(path));
final Package pkg = moduleService.resolvePackage(Paths.convert(path));
final DefaultIndexBuilder builder = new DefaultIndexBuilder(Paths.convert(path).getFileName(), project, pkg);
final TestScenarioIndexVisitor visitor = new TestScenarioIndexVisitor(dmo, builder, model);
visitor.visit();
addReferencedResourcesToIndexBuilder(builder, visitor);
return builder;
}
Aggregations