-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue446: Bean accessors don't account for IndexedPropertyDescriptors
- Loading branch information
ec027900
committed
Feb 1, 2020
1 parent
b7c002b
commit 4bd9490
Showing
4 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package clara.test.facts; | ||
|
||
/** | ||
* A Java Pojo for the express purpose of testing the behavior of compilation and execution of rules. | ||
* | ||
* This class should not be included in the released artifact, if it did make it into a released artifact it should be | ||
* ignored and not consumed as it may be moved/removed without warning to consumers. | ||
*/ | ||
public class BeanTestFact { | ||
private String[] locations; | ||
private String[] roadConditions; | ||
|
||
public BeanTestFact(String[] locations) { | ||
this.locations = locations; | ||
} | ||
|
||
// Standard and Indexed property accessors | ||
public void setLocations(String[] locations) { | ||
this.locations = locations; | ||
} | ||
public String[] getLocations() { | ||
return locations; | ||
} | ||
public void setLocations(int pos, String location) { | ||
locations[pos] = location; | ||
} | ||
public String getLocations(int pos){ | ||
return locations[pos]; | ||
} | ||
|
||
// Partial Indexed property accessor, ie. no standard accessor | ||
public void setRoadConditions(int pos, String condition) { | ||
roadConditions[pos] = condition; | ||
} | ||
public String getRoadConditions(int pos){ | ||
return roadConditions[pos]; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns clara.test-java-facts | ||
(:require [clara.tools.testing-utils :as tu] | ||
[clara.rules :as rules] | ||
[clojure.test :refer [is deftest run-tests testing use-fixtures]]) | ||
(:import [clara.test.facts | ||
BeanTestFact])) | ||
|
||
;; A test to demonstrate that a Pojo with indexed property accessors can be used as an alpha root in a session, | ||
;; see https://github.com/cerner/clara-rules/issues/446 | ||
(tu/def-rules-test test-basic-rule | ||
{:rules [kansas-rule [[[BeanTestFact | ||
(= ?locs locations) | ||
(some #(= "Kansas" %) ?locs)]] | ||
(rules/insert! "Kansas Exists")]] | ||
:queries [string-query [[] [[?s <- String]]]] | ||
|
||
:sessions [empty-session [kansas-rule string-query] {}]} | ||
|
||
(let [locs (make-array String 2)] | ||
(aset locs 0 "Florida") | ||
(aset locs 1 "Kansas") | ||
(let [session-strings (into #{} | ||
(map :?s) | ||
(-> empty-session | ||
(rules/insert (BeanTestFact. locs)) | ||
(rules/fire-rules) | ||
(rules/query string-query)))] | ||
(is (= 1 (count session-strings))) | ||
(is (contains? session-strings "Kansas Exists"))))) |