test-driven development on marklogic

53

Upload: jake-trent

Post on 20-Jan-2015

477 views

Category:

Technology


3 download

DESCRIPTION

Unit testing is a required part of a healthy software development lifecycle and a balanced breakfast. Test-driven development is a rockin' part of an *awesome* development lifecycle. If you don't test-drive the dev of your MarkLogic XQuery, you may never come back to test again. Test-driven XQuery development will ease your headaches, put you into the plush seat of a developer with confidence, and rocket you down the road to making all your wildest dreams come true. Kachow!

TRANSCRIPT

Page 1: Test-driven Development on MarkLogic
Page 2: Test-driven Development on MarkLogic
Page 3: Test-driven Development on MarkLogic
Page 4: Test-driven Development on MarkLogic
Page 5: Test-driven Development on MarkLogic
Page 6: Test-driven Development on MarkLogic
Page 7: Test-driven Development on MarkLogic
Page 8: Test-driven Development on MarkLogic
Page 9: Test-driven Development on MarkLogic
Page 10: Test-driven Development on MarkLogic
Page 11: Test-driven Development on MarkLogic
Page 12: Test-driven Development on MarkLogic
Page 13: Test-driven Development on MarkLogic
Page 14: Test-driven Development on MarkLogic
Page 15: Test-driven Development on MarkLogic
Page 16: Test-driven Development on MarkLogic
Page 17: Test-driven Development on MarkLogic

declare function testFeature() {

let $actual := feature:doFeature()

(: assert feature condition :)

};

declare function doFeature() {

() (: todo: impl :)

};

Page 18: Test-driven Development on MarkLogic

declare function doFeature() {

let $output := lotsOfLogic()

return $output

};

Page 19: Test-driven Development on MarkLogic
Page 20: Test-driven Development on MarkLogic
Page 21: Test-driven Development on MarkLogic
Page 22: Test-driven Development on MarkLogic
Page 23: Test-driven Development on MarkLogic

import module namespace build = “b” at “/build.xqy”;

declare function testBuildXml() {

let $actual := b:buildXml()

(: assert only xml is well-built :)

};

import module namespace translate = “t” at “/transl8.xqy”;

declare function testAddTranslateFlags() {

let $actual := t:addTranslateFlags()

(: assert only that translation flags added correctly :)

};

Page 24: Test-driven Development on MarkLogic
Page 25: Test-driven Development on MarkLogic

import module namespace build = “b” at “/build.xqy”;

declare function buildXml_condition1() {

(: ... :)

};

declare function buildXml_condition2() {

(: ... :)

};

(: etc. :)

Page 26: Test-driven Development on MarkLogic
Page 27: Test-driven Development on MarkLogic

declare function bizLogic($input as element()*) {

(: ... :)

};

import module namespace logic = “logic” at “/logic.xqy”;

declare function bizLogic_emptyInput() {

(: ... :)

};

declare function bizLogic_oneInput() {

(: ... :)

};

declare function bizLogic_manyInput() {

(: ... :)

};

Page 28: Test-driven Development on MarkLogic
Page 29: Test-driven Development on MarkLogic

declare function bizLogic($input as element()*) {

(: ... :)

};

import module namespace logic = “logic” at “/logic.xqy”;

declare function bizLogic_insufficientInput() {

(: ... :)

};

declare function bizLogic_malformedInput() {

(: ... :)

};

Page 30: Test-driven Development on MarkLogic
Page 31: Test-driven Development on MarkLogic

declare function businessLogic($input) {

let $moreInput := /more-input[@attr eq $input]

let $returnVal :=

for $item in $moreInput

let $details := /detail[@id eq $item/id]

return if ($details/thing eq

xdmp:get-request-field(“thing-id”)) then

$details

else ()

return if (fn:exists($returnVal)) then

let $audit :=

xdmp:document-insert(“/latest.xml”, element ok {})

return $returnVal

else

xdmp:redirect-response(“/empty.xqy”);

};

Page 32: Test-driven Development on MarkLogic

declare function businessLogic($input) {

let $moreInput := /more-input[@attr eq $input]

let $returnVal :=

for $item in $moreInput

let $details := /detail[@id eq $item/id]

return if ($details/thing eq

xdmp:get-request-field(“thing-id”)) then

$details

else ()

return if (fn:exists($returnVal)) then

let $audit :=

xdmp:document-insert(“/latest.xml”, element ok {})

return $returnVal

else

xdmp:redirect-response(“/empty.xqy”);

};

Page 33: Test-driven Development on MarkLogic
Page 34: Test-driven Development on MarkLogic
Page 35: Test-driven Development on MarkLogic
Page 36: Test-driven Development on MarkLogic

xdmp:get-request-field(“var”)

xdmp:redirect-response(“/page.xqy”)

Page 37: Test-driven Development on MarkLogic

xdmp:document-insert(“/trades.xml”, element beads {})

fn:collection()/dances/rain

Page 38: Test-driven Development on MarkLogic
Page 39: Test-driven Development on MarkLogic
Page 40: Test-driven Development on MarkLogic
Page 41: Test-driven Development on MarkLogic
Page 42: Test-driven Development on MarkLogic
Page 43: Test-driven Development on MarkLogic
Page 44: Test-driven Development on MarkLogic

declare function feature() {

let $filter := xdmp:get-request-field(“filter”)

let $input := fn:collection()/data[@attr eq $filter]

let $result := businessLogic($input)

let $persist := xdmp:document-insert(“/doc.xml”, $result)

return xdmp:redirect-response(“complete.xqy”)

};

Page 45: Test-driven Development on MarkLogic
Page 46: Test-driven Development on MarkLogic
Page 47: Test-driven Development on MarkLogic
Page 48: Test-driven Development on MarkLogic

declare function feature() {

let $filter := xdmp:get-request-field(“filter”)

let $input := fn:collection()/data[@attr eq $filter]

let $result := businessLogic($input)

let $persist := xdmp:document-insert(“/doc.xml”, $result)

return xdmp:redirect-response(“complete.xqy”)

};

Page 49: Test-driven Development on MarkLogic
Page 50: Test-driven Development on MarkLogic
Page 51: Test-driven Development on MarkLogic
Page 52: Test-driven Development on MarkLogic

Green Ferrari Front (modified) http://www.flickr.com/photos/zouny/5054032055/ Design By Zouny's photostream Green Ferrari Side (modified) http://www.flickr.com/photos/zouny/5054024045/ Design By Zouny's photostream Belay http://www.flickr.com/photos/picsbycam/5173647461/ Cameron Cassan's photostream Thinker http://www.flickr.com/photos/garysoup/2705102139/ Gary Soup's photostream Clean Up http://www.flickr.com/photos/emilyrides/5188289325/lightbox/ emilydickinsonridesabmx's photostream Elephant http://www.flickr.com/photos/greenboots76/2924276160/ Henry Brett's photostream Chihuahua http://www.flickr.com/photos/62337512@N00/3727104807/ apdk's photostream Angry Dog http://www.flickr.com/photos/javiercito/2083111412/lightbox/ Javiercit0's photostream Clean up Pet http://www.flickr.com/photos/pointshoot/1144799868/ Eddie~S' photostream Hugging Fingers http://www.flickr.com/photos/ganesha_isis/4439563089/ ganesha.isis' photostream Fail Whale http://www.flickr.com/photos/coletivomambembe/3882172324/ Coletivo Mambembe's photostream Road Runner http://www.flickr.com/photos/snowpeak/4815685925/ snowpeak's photostream Keyboard Sleep http://www.flickr.com/photos/ytruly/1718468702/ YTruly's photostream Winding Road http://www.flickr.com/photos/dominicspics/422146490/ Dominic's pics' photostream

Neon Pipes http://www.flickr.com/photos/krossbow/3619931451/ krossbow's photostream - CC Attribution license Calculator http://www.flickr.com/photos/scoobay/2463236523/ Scoobay's photostream Water Droplet http://www.flickr.com/photos/shannonkringen/4680455907/ shannonkringen's photostream Decoupled http://www.flickr.com/photos/daquellamanera/2213902727/ Daquella manera's photostream Pointing Caterpillar http://www.flickr.com/photos/pinkstockphotos/5266977224/ PinkStock Photos!'s photostream Multiplication http://www.flickr.com/photos/somegeekintn/4048155967/ somegeekintn's photostream Cliff http://www.flickr.com/photos/elsie/144702426/ Elsie esq.'s photostream Pig Egg http://www.flickr.com/photos/katerha/5423107783/ katerha's photostream Spaghetti Noodle http://www.flickr.com/photos/pinksherbet/2201247567/ Pink Sherbet Photography's photostream Girl Eating Spaghetti http://www.flickr.com/photos/pinksherbet/5008273559/ Pink Sherbet Photography's photostream Camoflauge Lizard http://www.flickr.com/photos/lofink/4453281926/ dlofink's photostream Salute Flag http://www.flickr.com/photos/soldiersmediacenter/3920702814/ The U.S. Army's photostream Call on Beach http://www.flickr.com/photos/zitona/2268296925/ » Zitona «'s photostream

All Creative Commons 2.0 Attribution License unless otherwise noted

Page 53: Test-driven Development on MarkLogic

Indian Chief http://www.flickr.com/photos/boston_public_library/4100786887/in/photostream/ Boston Public Library's photostream Ninja Turtle http://www.flickr.com/photos/86805724@N00/1581833575/ ianmalcm's photostream Phone Booth http://www.flickr.com/photos/bexwalton/4204409348/ Bex.Walton's photostream Picasso http://www.flickr.com/photos/oddsock/101164507/ oddsock's photostream Suit http://www.flickr.com/photos/pss/4830803189/ Paul Stevenson's photostream Underwater http://www.flickr.com/photos/andreweick/4000567498/in/photostream/ AndrewEick's photostream Spider Tunnel http://www.flickr.com/photos/b1gw1ght/900924265/ b1gw1ght's photostream Safety Net http://www.flickr.com/photos/iamchadhearmesnore/3629410556/ iamchad's photostream Black Box http://www.flickr.com/photos/amagill/34762677/ AMagill's photostream The Sweded By David Quinn, used with permission Red Ferrari Engine http://www.flickr.com/photos/49889874@N05/5027004240/ marc falardeau's photostream Kodak Roll http://www.flickr.com/photos/picsbycam/4550970565/in/photostream/ Cameron Cassan's photostream Gnuolane Free font http://typodermicfonts.com Free for personal and commercial use