+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.impact.analysis.integrationtests;
+
+import java.util.List;
+
+import org.drools.impact.analysis.graph.Graph;
+import org.drools.impact.analysis.graph.ModelToGraphConverter;
+import org.drools.impact.analysis.graph.ReactivityType;
+import org.drools.impact.analysis.integrationtests.domain.Address;
+import org.drools.impact.analysis.integrationtests.domain.Person;
+import org.drools.impact.analysis.model.AnalysisModel;
+import org.drools.impact.analysis.model.right.ConsequenceAction;
+import org.drools.impact.analysis.model.right.DeleteSpecificFactAction;
+import org.drools.impact.analysis.model.right.SpecificProperty;
+import org.drools.impact.analysis.parser.ModelBuilder;
+import org.junit.Test;
+
+/**
+ * This test is to verify that DeleteSpecificFactAction can be handled correctly.
+ * DeleteSpecificFactAction cannot be created by ModelBuilder from DRL, so we programmatically add it to the model.
+ */
+public class DeleteSpecificFactActionTest extends AbstractGraphTest {
+
+ @Test
+ public void insertDeleteSpecific() {
+ String str =
+ "package mypkg;\n" +
+ "import " + Person.class.getCanonicalName() + ";" +
+ "import " + Address.class.getCanonicalName() + ";" +
+ "rule R1 when\n" +
+ " $p : Person(name == \"John\")\n" +
+ "then\n" +
+ " Address address = new Address();" +
+ " address.setStreet(\"ABC\");" +
+ " insert(address);" +
+ "end\n" +
+ "rule R2 when\n" +
+ " $p : Person(name == \"Paul\")\n" +
+ "then\n" +
+ // Here, delete a fact with street == "ABC" (ansible-rulebook can do it)
+ "end\n" +
+ "rule R3 when\n" +
+ " $a : Address(street == \"ABC\")\n" +
+ "then\n" +
+ "end\n";
+
+ AnalysisModel analysisModel = new ModelBuilder().build(str);
+
+ // Tweak analysisModel because DeleteSpecificFactAction cannot be created by ModelBuilder
+ List
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.impact.analysis.model.right;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class represents a delete action for a specific fact.
+ * Use this action when you know the fact's properties to be deleted, assuming other facts of the same class still
+ * exist in the working memory. (Usually, you don't know the fact's properties)
+ * This action is introduced to support retract_fact action in drools-ansible-rulebook-integration-visualization.
+ */
+public class DeleteSpecificFactAction extends ConsequenceAction {
+
+ private final List
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.impact.analysis.model.right;
+
+public class SpecificProperty extends ModifiedProperty {
+
+ public SpecificProperty(String property) {
+ this(property, null);
+ }
+
+ public SpecificProperty(String property, Object value) {
+ super(property, value);
+ }
+
+ @Override
+ public String toString() {
+ return "SpecificProperty{" +
+ "property='" + property + '\'' +
+ ", value=" + value +
+ '}';
+ }
+}