Last active
August 29, 2015 13:59
-
-
Save skuro/10755103 to your computer and use it in GitHub Desktop.
Testing clara rules and queries over POJOs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package tk.skuro; | |
| public class Bean { | |
| private final String _value; | |
| public Bean(String value) { | |
| _value = value; | |
| } | |
| public String getValue() { | |
| return _value; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (import tk.skuro.Bean) | |
| (deftest a-test | |
| (testing "Clara rule and query over POJOs" | |
| (let [;; to be used as a starting fact | |
| bean1 (Bean. "Initial") | |
| ;; to be inserted into the working memory by a matching rule | |
| bean2 (Bean. "Derived") | |
| rule ;; matches a Bean and inserts a new one | |
| (dsl/parse-rule [[Bean [b] (= "Initial" (.getValue b)) | |
| (insert! (Bean. "Derived"))) | |
| result ;; should find the Bean inserted by the rule | |
| (dsl/parse-query [] | |
| [[Bean [c] (= "Derived" (.getValue b))]]) | |
| session ;; creates a fresh session, inserts the initial Bean then fires the rules | |
| (-> (mk-session [rule result]) | |
| (insert bean1) | |
| (fire-rules))] | |
| (is (= #{bean2} (set (query session result))))))) ;; (not (= #{#<Bean tk.skuro.Bean@1b0e0936>} #{{}})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment