diff --git a/test/weller/core_test.clj b/test/weller/core_test.clj index 44ab104..0b79934 100644 --- a/test/weller/core_test.clj +++ b/test/weller/core_test.clj @@ -16,16 +16,18 @@ (ns weller.core-test (:require [clojure.test :refer :all] - [cral.model.alfresco.cm :as cm] - [taoensso.telemere :as t] [weller.components.component :as component] [weller.core :refer :all] [weller.event-handler :as handler] + [weller.events :as events] [weller.filters :as filters] - [weller.events :as events])) + [weller.test-utils :as tu]) + (:import (java.util UUID))) (deftest node-created-test - (def res (promise)) - (def handler (handler/make-handler (filters/event? events/node-created) #(deliver res %))) - (println @res) + (def resource (promise)) + (def handler (handler/make-handler (filters/event? events/node-created) #(deliver resource %))) + (let [name (.toString (UUID/randomUUID))] + (tu/create-then-delete-node name) + (is (= (:name @resource)) name)) (component/stop handler)) \ No newline at end of file diff --git a/test/weller/test_utils.clj b/test/weller/test_utils.clj new file mode 100644 index 0000000..dce93cd --- /dev/null +++ b/test/weller/test_utils.clj @@ -0,0 +1,37 @@ +; weller - Alfresco out-of-process extensions in 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.test-utils + (:require [clojure.test :refer :all] + [cral.api.auth :as auth] + [cral.api.core.nodes :as nodes] + [cral.model.alfresco.cm :as cm] + [cral.model.core :as model] + [weller.config :as config])) + +(defn get-guest-home + [ticket] + (get-in (nodes/get-node ticket "-root-" (model/map->GetNodeQueryParams {:relative-path "/Guest Home"})) [:body :entry :id])) + +(defn create-then-delete-node + [name] + (let [ticket (get-in (auth/create-ticket (get-in @config/config [:alfresco :user]) (get-in @config/config [:alfresco :password])) [:body :entry]) + ;; create a node + create-node-response (->> (model/map->CreateNodeBody {:name name :node-type cm/type-content}) + (nodes/create-node ticket (get-guest-home ticket)))] + (is (= (:status create-node-response) 201)) + ;; delete node + (is (= (:status (nodes/delete-node ticket (get-in create-node-response [:body :entry :id]) {:permanent true})) 204))))