diff --git a/README.md b/README.md index 2663e9d..0e24c6f 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,18 @@ Weller is like Alfresco out-of-process extensions but 100% Clojure. - 100% test coverage ## Usage - -COMING SOON +### Create and compose filters +Filters can be composed of a single predicate: +```clojure +(filters/event? events/node-updated) +``` +or a composition of predicates with `every-pred` (logical AND) or `some-fn` (logical OR): +```clojure +(every-pred (filters/event? events/node-updated) (filters/is-file?)) +(some-fn (filters/node-aspect? cm/asp-titled) (filters/node-aspect? cm/asp-dublincore)) +(some-fn (filters/node-aspect? cm/asp-titled) (filters/node-aspect? cm/asp-dublincore)) +(every-pred (filters/event? events/node-updated) (some-fn (filters/node-aspect? cm/asp-titled) (filters/node-aspect? cm/asp-dublincore))) +``` ## License Copyright (c) 2024 Saidone diff --git a/project.clj b/project.clj index 3c6d850..1f76b10 100644 --- a/project.clj +++ b/project.clj @@ -23,7 +23,7 @@ [com.stuartsierra/component "1.1.0"] [org.apache.activemq/activemq-broker "6.1.1"] [org.clojure/data.json "2.5.0"] - [org.saidone/cral "0.3.0"] + [org.saidone/cral "0.3.1"] [com.taoensso/telemere "1.0.0-beta9"] [russellwhitaker/immuconf "0.3.0"] [org.clojure/core.async "1.6.681"]] diff --git a/test/weller/filters_test.clj b/test/weller/filters_test.clj index 6d8094f..ab7f936 100644 --- a/test/weller/filters_test.clj +++ b/test/weller/filters_test.clj @@ -19,6 +19,7 @@ [cral.model.alfresco.cm :as cm] [weller.components.component :as component] [weller.event-handler :as handler] + [weller.events :as events] [weller.filters :as filters] [weller.fixtures :as fixtures] [weller.test-utils :as tu]) @@ -28,7 +29,7 @@ (deftest aspect-added-test (let [resource (promise) - handler (handler/make-handler (filters/aspect-added? cm/asp-versionable) #(deliver resource %))] + handler (handler/make-handler (every-pred (filters/event? events/node-updated) (filters/aspect-added? cm/asp-versionable)) #(deliver resource %))] (tu/add-aspect cm/asp-versionable) (is (.contains ^PersistentVector (:aspect-names @resource) (name cm/asp-versionable))) (component/stop handler))) \ No newline at end of file diff --git a/test/weller/handler_test.clj b/test/weller/handler_test.clj new file mode 100644 index 0000000..a07477a --- /dev/null +++ b/test/weller/handler_test.clj @@ -0,0 +1,52 @@ +; Weller is like Alfresco out-of-process extensions but 100% Clojure +; Copyright (C) 2024 Saidone +; +; This program is free software: you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation, either version 3 of the License, or +; (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . + +(ns weller.handler-test + (:require [clojure.test :refer :all] + [cral.api.core.nodes :as nodes] + [taoensso.telemere :as t] + [weller.components.component :as component] + [weller.config :as c] + [weller.event-handler :as handler] + [weller.events :as events] + [weller.filters :as filters] + [weller.fixtures :as fixtures] + [weller.test-utils :as tu])) + +(use-fixtures :once fixtures/ticket) + +(def node-name "test node name") + +(defn- get-node-name + [resource] + (get-in (nodes/get-node (:ticket @c/config) (:id resource)) [:body :entry :name])) + +(deftest make-handler-test + (let [result (promise) + handler (handler/make-handler) + handler (handler/add-filtered-tap handler (filters/event? events/node-created) #(deliver result (get-node-name %)))] + (component/start handler) + (tu/create-then-update-then-delete-node node-name) + (t/log! @result) + (component/stop handler))) + +(deftest simple-make-handler-test + (let [result (promise) + ;; note that handler is started automatically with this constructor + handler (handler/make-handler (filters/event? events/node-created) #(deliver result (get-node-name %)))] + (tu/create-then-update-then-delete-node node-name) + (t/log! @result) + (component/stop handler))) \ No newline at end of file diff --git a/test/weller/test_utils.clj b/test/weller/test_utils.clj index fd867f2..6a16e00 100644 --- a/test/weller/test_utils.clj +++ b/test/weller/test_utils.clj @@ -53,10 +53,12 @@ (nodes/delete-node (:ticket @c/config) node-id {:permanent true})) (defn create-then-update-then-delete-node - [name] - (->> (create-node name) - (update-node) - (delete-node))) + ([] + (create-then-update-then-delete-node (.toString (UUID/randomUUID)))) + ([name] + (->> (create-node name) + (update-node) + (delete-node)))) (defn create-then-delete-child-assoc []