Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed tests for core.rest namespace

  • Loading branch information...
commit de86a52e53767bf5e65a6a1de8907a2b20a6134c 1 parent 7e0fbd4
@antoniogarrote authored
View
17 src/plaza/examples/webapp.clj
@@ -12,7 +12,8 @@
[plaza.triple-spaces.core]
[plaza.triple-spaces.distributed-server]
[plaza.rest core])
- (:require [compojure.route :as route]))
+ (:require [compojure.route :as route]
+ [clojure.contrib.str-utils2 :as str2]))
;; We will use jena
@@ -33,6 +34,7 @@
:wikipedia_entry {:uri foaf:holdsAccount :range rdfs:Resource}))
(tbox-register-schema :celebrity ComputationCelebrity-schema)
+(tbox-register-schema :foaf-agent foaf:Agent-schema)
;; We create a Triple Space for the resources
@@ -53,6 +55,19 @@
(GET "/" [] "<h1>Testing plaza...</h1>")
(spawn-rest-resource! :celebrity "/Celebrity/:id" :celebrities)
(spawn-rest-collection-resource! :celebrity "/Celebrity" :celebrities)
+ (spawn-rest-resource! :foaf-agent "/CustomIds/:name" :resource
+ :id-property-alias :name
+ :id-property-uri foaf:name
+ :allowed-methods [:get]
+ :id-match-fn (fn [req env]
+ (let [pattern (str (:resource-qname-prefix env) (:resource-qname-local env))]
+ (str2/replace pattern ":name" (get (:params req) "name")))))
+ (spawn-rest-collection-resource! :foaf-agent "/CustomIds" :resource
+ :allowed-methods [:post]
+ :id-gen-fn (fn [req env]
+ (let [prefix (:resource-qname-prefix env)
+ local (:resource-qname-local env)]
+ {:id (get (:params req) "name") :uri (str prefix local "/" (get (:params req) "name"))})))
(route/not-found "Page not found"))
;; Running the application
View
23 src/plaza/rest/core.clj
@@ -339,13 +339,14 @@
(defn random-resource-id [ns]
(random-uuid))
-(defn build-triples-from-resource-map [uri mapping]
- (let [resource-uri (if (seq? uri) (apply rdf-resource uri) (rdf-resource uri))]
- (reduce (fn [acum [p o]]
- (if (keyword? o)
- acum
- (conj acum [resource-uri p o])))
- [] mapping)))
+(defn build-triples-from-resource-map
+ ([uri mapping]
+ (let [resource-uri (if (seq? uri) (apply rdf-resource uri) (rdf-resource uri))]
+ (reduce (fn [acum [p o]]
+ (if (keyword? o)
+ acum
+ (conj acum [resource-uri p o])))
+ [] mapping))))
(defn build-query-from-resource-map [mapping resource-type]
(concat [[?s rdf:type resource-type]]
@@ -593,7 +594,7 @@
(let [prefix (:resource-qname-prefix environment)
local (:resource-qname-local environment)
port (if (= (:server-port request) 80) "" (str ":" (:server-port request)))
- id (random-resource-id)]
+ id (random-uuid)]
{:id id :uri (str (str prefix port local) "/" id)}))
(defmacro wrap-request [kind prefix local request & body]
@@ -1062,9 +1063,9 @@
(defn handle-post-collection [request environment]
(let [params (dissoc (:params request) (name (:id-property-alias environment)))
mapping (apply-resource-argument-map params (:resource-map environment))
- {id :id resource-id :uri} ((:id-gen-function environment) request environment)
- triples-pre (conj (build-triples-from-resource-map id resource-id mapping) [resource-id rdf:type (:resource-type environment)])
- triples (if (nil? id) triples-pre (conj triples-pre [resource-id (:id-property-alias environment) (d id)]))]
+ {id :id resource-uri :uri} ((:id-gen-function environment) request environment)
+ triples-pre (conj (build-triples-from-resource-map resource-uri mapping) [resource-uri rdf:type (:resource-type environment)])
+ triples (if (nil? id) triples-pre (conj triples-pre [resource-uri (:id-property-alias environment) (d id)]))]
(out (ts (:resource-ts environment)) triples)
{:body (render-triples triples :xml (:resource environment) request)
:headers {"Content-Type" "application/xml"}
View
10 test/plaza/rest/core_test.clj
@@ -91,11 +91,11 @@
(str2/replace pattern ":name" (get (:params req) "name")))))
(spawn-rest-collection-resource! :foaf-agent "/CustomIds" :resource
- :allowed-methods [:post]
- :id-gen-fn (fn [req env]
- (let [prefix (:resource-qname-prefix env)
- local (:resource-qname-local env)]
- (str prefix local "/" (get (:params req) "name"))))))
+ :allowed-methods [:post]
+ :id-gen-fn (fn [req env]
+ (let [prefix (:resource-qname-prefix env)
+ local (:resource-qname-local env)]
+ {:id (get (:params req) "name") :uri (str prefix local "/" (get (:params req) "name"))}))))
;; Runnin the application
(future (run-jetty (var example) {:port 8082}))
Please sign in to comment.
Something went wrong with that request. Please try again.