Skip to content

Commit

Permalink
Fixed marklogic-community#254: skipping cpf tests if no triggers db
Browse files Browse the repository at this point in the history
  • Loading branch information
grtjn committed Jan 28, 2016
1 parent 939c4c2 commit c14ab06
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 80 deletions.
8 changes: 5 additions & 3 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ def clean
def test
if @environment == "prod"
logger.error "There is no Test database on the Production server"
elsif ! @properties["ml.test-port"] || ! @properties["ml.test-content-db"]
logger.error "Testing is not properly configured"
else
if find_arg(['--skip-suite-teardown']).present?
suiteTearDown = "&runsuiteteardown=false"
Expand Down Expand Up @@ -1429,13 +1431,13 @@ def deploy_tests?(target_db)
@properties['ml.test-content-db'].present? &&
@properties['ml.test-port'].present? &&
!@properties['ml.do-not-deploy-tests'].split(",").include?(@environment) &&
@properties['ml.test-modules-db'] == target_db
conditional_prop('ml.test-modules-db', 'ml.app-modules-db') == target_db
end

def modules_databases
dbs = [@properties['ml.modules-db']]
dbs = [@properties['ml.app-modules-db']]
dbs << @properties['ml.test-modules-db'] if @properties['ml.test-modules-db'].present? &&
@properties['ml.test-modules-db'] != @properties['ml.modules-db']
@properties['ml.test-modules-db'] != @properties['ml.app-modules-db']
dbs
end

Expand Down
147 changes: 72 additions & 75 deletions src/test/suites/CPF/cpf.xqy
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
xquery version "1.0-ml";

import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";

if (xdmp:modules-database() eq 0) then
test:fail("You must run this test from a modules database.")
else ();

import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";

if (xdmp:triggers-database() eq 0) then
test:fail("You must configure a triggers database to run this test.")
else ();

import module namespace cpf = "http://marklogic.com/roxy/cpf" at "/roxy/lib/cpf.xqy";
cpf:clean-cpf()

if (xdmp:triggers-database() ne 0) then
cpf:clean-cpf()
else ()
;

import module namespace cpf = "http://marklogic.com/roxy/cpf" at "/roxy/lib/cpf.xqy";
Expand All @@ -32,79 +23,85 @@ declare function local:get-domain()
</options>)
};

test:assert-throws-error(xdmp:function(xs:QName("local:get-domain")), "CPF-DOMAINNOTFOUND")
if (xdmp:triggers-database() ne 0) then
test:assert-throws-error(xdmp:function(xs:QName("local:get-domain")), "CPF-DOMAINNOTFOUND")
else ()
;

import module namespace cpf = "http://marklogic.com/roxy/cpf" at "/roxy/lib/cpf.xqy";

import module namespace c = "http://marklogic.com/roxy/test-config" at "/test/test-config.xqy";

cpf:load-from-config(
<config xmlns="http://marklogic.com/roxy/cpf">
<domains>
<domain>
<name>My Test Domain</name>
<description>This domain is awesome!!!</description>
<pipelines>
<pipeline>{xdmp:modules-root()}test/suites/CPF/_test-pipeline1.xml</pipeline>
</pipelines>
<system-pipelines>
<system-pipeline>Status Change Handling</system-pipeline>
<system-pipeline>A fake name that doesn't exist</system-pipeline>
</system-pipelines>
<scope>
<type>document</type>
<uri>/stuff.xml</uri>
<depth/>
</scope>
<context>
<modules-database>{xdmp:database-name(xdmp:modules-database())}</modules-database>
<root>/</root>
</context>
<restart-user>{$c:USER}</restart-user>
<permissions>
<permission>
<capability>read</capability>
<role-name>admin</role-name>
</permission>
</permissions>
</domain>
</domains>
</config>)
if (xdmp:triggers-database() ne 0) then
cpf:load-from-config(
<config xmlns="http://marklogic.com/roxy/cpf">
<domains>
<domain>
<name>My Test Domain</name>
<description>This domain is awesome!!!</description>
<pipelines>
<pipeline>{xdmp:modules-root()}test/suites/CPF/_test-pipeline1.xml</pipeline>
</pipelines>
<system-pipelines>
<system-pipeline>Status Change Handling</system-pipeline>
<system-pipeline>A fake name that doesn't exist</system-pipeline>
</system-pipelines>
<scope>
<type>document</type>
<uri>/stuff.xml</uri>
<depth/>
</scope>
<context>
<modules-database>{xdmp:database-name(xdmp:modules-database())}</modules-database>
<root>/</root>
</context>
<restart-user>{$c:USER}</restart-user>
<permissions>
<permission>
<capability>read</capability>
<role-name>admin</role-name>
</permission>
</permissions>
</domain>
</domains>
</config>)
else ()
;
import module namespace cpf = "http://marklogic.com/roxy/cpf" at "/roxy/lib/cpf.xqy";
import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";
import module namespace p = "http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";
import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
let $dom :=
xdmp:eval('
xquery version "1.0-ml";
import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";
dom:get( "My Test Domain" )',(),
<options xmlns="xdmp:eval">
<database>{xdmp:triggers-database()}</database>
</options>)
let $pipelines :=
for $p in $dom/dom:pipeline
return
xdmp:eval(
fn:concat(
'import module namespace p = "http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";
p:get-by-id(', fn:string($p), ')'), (),
if (xdmp:triggers-database() ne 0) then
let $dom :=
xdmp:eval('
xquery version "1.0-ml";
import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";
dom:get( "My Test Domain" )',(),
<options xmlns="xdmp:eval">
<database>{xdmp:triggers-database()}</database>
</options>)
return
(
test:assert-equal("My Test Domain", fn:string($dom/dom:domain-name)),
test:assert-equal("This domain is awesome!!!", fn:string($dom/dom:domain-description)),
test:assert-equal("document", fn:string($dom/dom:domain-scope/dom:document-scope)),
test:assert-equal("/stuff.xml", fn:string($dom/dom:domain-scope/dom:uri)),
test:assert-equal(xdmp:database-name(xdmp:modules-database()), xdmp:database-name($dom/dom:evaluation-context/dom:database)),
test:assert-equal("/", fn:string($dom/dom:evaluation-context/dom:root)),
test:assert-equal(2, fn:count($pipelines)),
test:assert-equal(1, fn:count($pipelines/p:pipeline-name[. = "Test Pipeline 1"])),
test:assert-equal(1, fn:count($pipelines/p:pipeline-name[. = "Status Change Handling"]))
)
<database>{xdmp:triggers-database()}</database>
</options>)
let $pipelines :=
for $p in $dom/dom:pipeline
return
xdmp:eval(
fn:concat(
'import module namespace p = "http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";
p:get-by-id(', fn:string($p), ')'), (),
<options xmlns="xdmp:eval">
<database>{xdmp:triggers-database()}</database>
</options>)
return
(
test:assert-equal("My Test Domain", fn:string($dom/dom:domain-name)),
test:assert-equal("This domain is awesome!!!", fn:string($dom/dom:domain-description)),
test:assert-equal("document", fn:string($dom/dom:domain-scope/dom:document-scope)),
test:assert-equal("/stuff.xml", fn:string($dom/dom:domain-scope/dom:uri)),
test:assert-equal(xdmp:database-name(xdmp:modules-database()), xdmp:database-name($dom/dom:evaluation-context/dom:database)),
test:assert-equal("/", fn:string($dom/dom:evaluation-context/dom:root)),
test:assert-equal(2, fn:count($pipelines)),
test:assert-equal(1, fn:count($pipelines/p:pipeline-name[. = "Test Pipeline 1"])),
test:assert-equal(1, fn:count($pipelines/p:pipeline-name[. = "Status Change Handling"]))
)
else()
10 changes: 9 additions & 1 deletion src/test/suites/CPF/suite-setup.xqy
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
xquery version "1.0-ml";

import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";

if (xdmp:modules-database() eq 0) then
test:fail("You must run this test from a modules database.")
else ();

import module namespace cpf = "http://marklogic.com/roxy/cpf" at "/roxy/lib/cpf.xqy";

cpf:clean-cpf()
if (xdmp:triggers-database() ne 0) then
cpf:clean-cpf()
else ()
4 changes: 3 additions & 1 deletion src/test/suites/CPF/suite-teardown.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ xquery version "1.0-ml";

import module namespace cpf = "http://marklogic.com/roxy/cpf" at "/roxy/lib/cpf.xqy";

cpf:clean-cpf()
if (xdmp:triggers-database() ne 0) then
cpf:clean-cpf()
else ()

0 comments on commit c14ab06

Please sign in to comment.