Search in sources :

Example 31 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class BasicGraphTest method testNoConstraint.

@Test
public void testNoConstraint() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person()\n" + "then\n" + "  modify($p) { setAge( 18 ) };" + "end\n" + "rule R2 when\n" + "  $p : Person()\n" + "then\n" + "end\n";
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2");
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Person(org.drools.impact.analysis.integrationtests.domain.Person) Test(org.junit.Test)

Example 32 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class BasicGraphTest method testLoop.

@Test
public void testLoop() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "  modify($p) { setAge( 18 ) };" + "end\n" + "rule R2 when\n" + "  $p : Person(age > 10)\n" + "then\n" + "  modify($p) { setName( \"Toshiya\" ) };" + "end\n";
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
    assertLink(graph, "mypkg.R2", "mypkg.R1", ReactivityType.NEGATIVE);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 33 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class GraphCollapsionTest method testSpreadsheet.

@Test
public void testSpreadsheet() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.drools.impact.analysis.integrationtests", "spreadsheet-test", "1.0.0");
    KieFileSystem kfs = createKieFileSystemWithClassPathResourceNames(releaseId, getClass(), "collapsion01.xls", "collapsion02.xls", "collapsion03.xls");
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(ImpactAnalysisProject.class);
    ImpactAnalysisKieModule analysisKieModule = (ImpactAnalysisKieModule) kieBuilder.getKieModule();
    AnalysisModel analysisModel = analysisKieModule.getAnalysisModel();
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    Graph collapsedGraph = new GraphCollapsionHelper().collapseWithRuleNamePrefix(graph);
    assertEquals(3, collapsedGraph.getNodeMap().size());
    assertLink(collapsedGraph, "mypkg2.CustomerCheck", "mypkg2.PriceCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg2.PriceCheck", "mypkg2.StatusCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg2.StatusCheck", "mypkg2.PriceCheck", ReactivityType.NEGATIVE);
    // --- impact analysis
    // Assuming that "modify" action in PriceCheck_X is changed
    // modify action in PriceCheck_X
    Node changedNode = collapsedGraph.getNodeMap().get("mypkg2.PriceCheck");
    ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
    Graph impactedSubGraph = impactFilter.filterImpactedNodes(collapsedGraph, changedNode);
    assertNull(impactedSubGraph.getNodeMap().get("mypkg2.CustomerCheck"));
    assertEquals(Status.CHANGED, impactedSubGraph.getNodeMap().get("mypkg2.PriceCheck").getStatus());
    assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg2.StatusCheck").getStatus());
}
Also used : Graph(org.drools.impact.analysis.graph.Graph) KieFileSystem(org.kie.api.builder.KieFileSystem) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) Node(org.drools.impact.analysis.graph.Node) ImpactAnalysisKieModule(org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule) GraphCollapsionHelper(org.drools.impact.analysis.graph.GraphCollapsionHelper) KieServices(org.kie.api.KieServices) ImpactAnalysisHelper(org.drools.impact.analysis.graph.ImpactAnalysisHelper) ReleaseId(org.kie.api.builder.ReleaseId) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 34 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class RhsTest method testForEachDelete.

@Test
public void testForEachDelete() {
    String str = "package mypkg;\n" + "import " + List.class.getCanonicalName() + ";" + "rule R1\n" + "  when\n" + "    $objectList : List() from collect(Object())\n" + "  then\n" + "    for(Object $object : $objectList){\n" + "      delete($object);\n" + "    }\n" + "end";
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    // at the moment, R1's patternClass is parsed as `List`. It will be addressed in DROOLS-6616
    assertLink(graph, "mypkg.R1", "mypkg.R1");
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 35 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class RhsTest method testForEachInsert.

@Test
public void testForEachInsert() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "rule R1\n" + "  when\n" + "    $person : Person()\n" + "  then\n" + "    for(Address $address : $person.getAddresses()){\n" + "      insert($address);\n" + "    }\n" + "end\n" + "rule R2\n" + "  when\n" + "    Address()\n" + "  then\n" + "end\n";
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) Address(org.drools.impact.analysis.integrationtests.domain.Address) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Aggregations

Graph (org.drools.impact.analysis.graph.Graph)38 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)38 AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)38 ModelBuilder (org.drools.impact.analysis.parser.ModelBuilder)36 Test (org.junit.Test)36 Person (org.drools.impact.analysis.integrationtests.domain.Person)9 ImpactAnalysisHelper (org.drools.impact.analysis.graph.ImpactAnalysisHelper)6 Address (org.drools.impact.analysis.integrationtests.domain.Address)5 GraphCollapsionHelper (org.drools.impact.analysis.graph.GraphCollapsionHelper)4 ControlFact (org.drools.impact.analysis.integrationtests.domain.ControlFact)3 ArrayList (java.util.ArrayList)2 Node (org.drools.impact.analysis.graph.Node)2 PropHolder (org.drools.impact.analysis.integrationtests.domain.PropHolder)2 ImpactAnalysisKieModule (org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule)2 KieServices (org.kie.api.KieServices)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 ReleaseId (org.kie.api.builder.ReleaseId)2 BigDecimal (java.math.BigDecimal)1 Order (org.drools.impact.analysis.example.domain.Order)1