diff --git a/api/routes.xqm b/api/routes.xqm
index 1237286..525cee9 100644
--- a/api/routes.xqm
+++ b/api/routes.xqm
@@ -95,12 +95,16 @@ declare
%rest:query-param("end", "{$end}", "")
%rest:query-param("down", "{$down}", 0)
function routes:navigation($id as xs:string, $ref as xs:string, $start as xs:string, $end as xs:string, $down as xs:integer) {
- let $dbName := normalize-space(db:get($G:dots)//dots:member/node()[@dtsResourceId = $id]/@dbName)
- return
- if ($dbName != "")
- then utils:navigation($id, $ref, $start, $end, $down)
- else
- routes:badIdResource(xs:string($id))
+ if ($id != "")
+ then
+ let $dbName := normalize-space(db:get($G:dots)//dots:member/node()[@dtsResourceId = $id]/@dbName)
+ return
+ if ($dbName != "")
+ then utils:navigation($id, $ref, $start, $end, $down)
+ else
+ routes:badIdResource(xs:string($id))
+ else
+ routes:badIdResource(xs:string($id))
};
(:~
@@ -124,47 +128,51 @@ declare
%rest:query-param("end", "{$end}", "")
%rest:query-param("format", "{$format}", "")
function routes:document($id as xs:string, $ref as xs:string, $start as xs:string, $end as xs:string, $format as xs:string) {
- let $dbName := normalize-space(db:get($G:dots)//dots:member/node()[@dtsResourceId = $id]/@dbName)
- return
- if ($dbName != "")
- then
- let $ref := if ($ref) then $ref else ""
- let $start := if ($start) then $start else ""
- let $end := if ($end) then $end else ""
- let $result := utils:document($id, $ref, $start, $end)
- return
- if ($format)
- then
- let $f :=
- switch ($format)
- case ($format[. = "html"]) return "text/html;"
- case ($format[. = "txt"]) return "text/plain"
- default return "application/xml"
- let $style := concat($G:webapp, $G:xsl)
- let $project := db:get($G:dots)//node()[@dtsResourceId = $id]/@dbName
- let $doc :=
- if (db:get($project)/tei:TEI[@xml:id = $id])
- then db:get($project)/tei:TEI[@xml:id = $id]
- else
- db:get($project, $id)/tei:TEI
- let $trans :=
- if ($format = "html")
- then
- xslt:transform($result, $style)
- else $result
- return
- (
-
-
-
-
- ,
- $trans
- )
- else
- $result
- else
- routes:badIdResource(xs:string($id))
+ if ($id != "")
+ then
+ let $dbName := db:get($G:dots)//dots:member/node()[@dtsResourceId = $id]/@dbName
+ return
+ if ($dbName)
+ then
+ let $ref := if ($ref) then $ref else ""
+ let $start := if ($start) then $start else ""
+ let $end := if ($end) then $end else ""
+ let $result := utils:document($id, $ref, $start, $end)
+ return
+ if ($format)
+ then
+ let $f :=
+ switch ($format)
+ case ($format[. = "html"]) return "text/html;"
+ case ($format[. = "txt"]) return "text/plain"
+ default return "application/xml"
+ let $style := concat($G:webapp, $G:xsl)
+ let $project := db:get($G:dots)//node()[@dtsResourceId = $id]/@dbName
+ let $doc :=
+ if (db:get($project)/tei:TEI[@xml:id = $id])
+ then db:get($project)/tei:TEI[@xml:id = $id]
+ else
+ db:get($project, $id)/tei:TEI
+ let $trans :=
+ if ($format = "html")
+ then
+ xslt:transform($result, $style)
+ else $result
+ return
+ (
+
+
+
+
+ ,
+ $trans
+ )
+ else
+ $result
+ else
+ routes:badIdResource(xs:string($id))
+ else
+ routes:badIdResource(xs:string($id))
};
declare
@@ -177,4 +185,5 @@ function routes:badIdResource($id) {
else "Error 400 : no resource ID specified"
return
web:error(400, $message)
-};
\ No newline at end of file
+};
+
diff --git a/tests/data_model/dots_db_switcher.xml b/tests/data_model/dots_db_switcher.xml
new file mode 100644
index 0000000..3c56461
--- /dev/null
+++ b/tests/data_model/dots_db_switcher.xml
@@ -0,0 +1,9 @@
+
+
+
+ 2024-03-12T11:53:37.836+01:00
+ 2024-03-12T11:53:37.836+01:00
+ 0
+
+
+
diff --git a/tests/data_model/dots_default_metadata_mapping.xml b/tests/data_model/dots_default_metadata_mapping.xml
new file mode 100644
index 0000000..30128da
--- /dev/null
+++ b/tests/data_model/dots_default_metadata_mapping.xml
@@ -0,0 +1,8 @@
+
+
+
+ 2024-03-12T11:53:37.836+01:00
+ 2024-03-12T11:53:37.836+01:00
+
+
+
diff --git a/tests/deploimentTests.xqm b/tests/deploimentTests.xqm
new file mode 100644
index 0000000..80c8c07
--- /dev/null
+++ b/tests/deploimentTests.xqm
@@ -0,0 +1,40 @@
+xquery version '3.0' ;
+
+module namespace deployTest = "https://github.com/chartes/dots/deploimentTests";
+
+import module namespace G = "https://github.com/chartes/dots/globals" at "../globals.xqm";
+import module namespace functx = 'http://www.functx.com';
+
+declare default element namespace "https://github.com/chartes/dots/";
+
+declare variable $deployTest:dbSwitchModel := doc(concat($G:webapp, "dots/tests/data_model/dots_db_switcher.xml"));
+
+declare variable $deployTest:mappingModel := doc(concat($G:webapp, "dots/tests/data_model/dots_default_metadata_mapping.xml"));
+
+declare function deployTest:testDbSwitch() {
+ let $dots := db:get($G:dots)/dbSwitch
+ let $totalProjects := $dots/metadata/totalProjects
+ let $member := $dots/member
+ return
+ (
+ deep-equal($totalProjects, $deployTest:dbSwitchModel/dbSwitch/metadata/totalProjects),
+ deep-equal($member, $deployTest:dbSwitchModel/dbSwitch/member)
+ )
+};
+
+declare function deployTest:testMetadataMapping() {
+ let $dots := db:get($G:dots)
+ let $mapping := $dots/metadataMap/mapping
+ let $mappingModel := $deployTest:mappingModel/metadataMap/mapping
+ return
+ (
+ deep-equal($mapping, $mappingModel)
+ )
+};
+
+declare %unit:test function deployTest:check-boolean-response($returned) {
+ let $expected := true()
+ for $r in $returned
+ return
+ unit:assert-equals($r, $expected)
+};
\ No newline at end of file
diff --git a/tests/initTestsEndpoint.xqm b/tests/initTestsEndpoint.xqm
index a07aea8..cf04dad 100644
--- a/tests/initTestsEndpoint.xqm
+++ b/tests/initTestsEndpoint.xqm
@@ -2,6 +2,8 @@ xquery version '3.0' ;
module namespace initTests = "https://github.com/chartes/dots/initTests";
+declare default element namespace "https://github.com/chartes/dots/";
+
declare function initTests:endpoint($url) {
let $statutCode := http:send-request(, $url)
return
diff --git a/tests/launcher.xq b/tests/launcher.xq
index 045933f..4670de9 100644
--- a/tests/launcher.xq
+++ b/tests/launcher.xq
@@ -1,16 +1,28 @@
xquery version '3.0' ;
+import module namespace G = "https://github.com/chartes/dots/globals" at "../globals.xqm";
import module namespace test = "https://github.com/chartes/dots/tests" at "utilsTest.xqm";
import module namespace initTests = "https://github.com/chartes/dots/initTests" at "initTestsEndpoint.xqm";
+import module namespace deployTest = "https://github.com/chartes/dots/deploimentTests" at "deploimentTests.xqm";
(: Deploiment Tests :)
"> Starting deploiment tests in progress...",
"test init dots db...",
(: create a specific function "checkDotsExists" in deploimentTests.xqm :)
-if (db:exists("dots"))
+(: if (db:exists("dots"))
then "* ✅ DoTS Db created with success"
-else "* ❌ DoTS Db creation failed",
+else "* ❌ DoTS Db creation failed", :)
+
+(: Check if db dots exists :)
+(deployTest:check-boolean-response(db:exists($G:dots)), "* ✅ DoTS Db created with success"),
+(: Compare new switcher dots with switcher dots model :)
+(deployTest:check-boolean-response(deployTest:testDbSwitch()), "* ✅ DoTS Db switcher created with success"),
+(: Compare new default mapping dots with deult mapping dots model :)
+(deployTest:check-boolean-response(deployTest:testMetadataMapping()), "* ✅ DoTS Db default metadata mapping created with success"),
+
+(: deployTest:check-boolean-response(deployTest:testDbSwitch()),
+deployTest:check-boolean-response(deployTest:testMetadataMapping()), :)
(:
Check data in database