Skip to content

Commit

Permalink
ajoute un set de tests pour le script dots_db_init.xq
Browse files Browse the repository at this point in the history
  • Loading branch information
philippepons committed Mar 12, 2024
1 parent eda9719 commit 23d845a
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 50 deletions.
105 changes: 57 additions & 48 deletions api/routes.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
};

(:~
Expand All @@ -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
(
<rest:response>
<http:response status="200">
<http:header name="Content-Type" value="{concat($f, ' charset=utf-8')}"/>
</http:response>
</rest:response>,
$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
(
<rest:response>
<http:response status="200">
<http:header name="Content-Type" value="{concat($f, ' charset=utf-8')}"/>
</http:response>
</rest:response>,
$trans
)
else
$result
else
routes:badIdResource(xs:string($id))
else
routes:badIdResource(xs:string($id))
};

declare
Expand All @@ -177,4 +185,5 @@ function routes:badIdResource($id) {
else "Error 400 : no resource ID specified"
return
web:error(400, $message)
};
};

9 changes: 9 additions & 0 deletions tests/data_model/dots_db_switcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<dbSwitch xmlns="https://github.com/chartes/dots/">
<metadata>
<dct:created xmlns:dct="http://purl.org/dc/terms/">2024-03-12T11:53:37.836+01:00</dct:created>
<dct:modified xmlns:dct="http://purl.org/dc/terms/">2024-03-12T11:53:37.836+01:00</dct:modified>
<totalProjects>0</totalProjects>
</metadata>
<member/>
</dbSwitch>
8 changes: 8 additions & 0 deletions tests/data_model/dots_default_metadata_mapping.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadataMap xmlns="https://github.com/chartes/dots/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
<metadata>
<dct:created>2024-03-12T11:53:37.836+01:00</dct:created>
<dct:modified>2024-03-12T11:53:37.836+01:00</dct:modified>
</metadata>
<mapping><dc:title xpath="//titleStmt/title[@type = 'main' or position() = 1]" scope="document"/><dc:creator xpath="//titleStmt/author" scope="document"/><dct:publisher xpath="//publicationStmt/publisher" scope="document"/></mapping>
</metadataMap>
40 changes: 40 additions & 0 deletions tests/deploimentTests.xqm
Original file line number Diff line number Diff line change
@@ -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)
};
2 changes: 2 additions & 0 deletions tests/initTestsEndpoint.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -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(<http:request method='get' status-only='true'/>, $url)
return
Expand Down
16 changes: 14 additions & 2 deletions tests/launcher.xq
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 23d845a

Please sign in to comment.