| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Cmis::Test::AtomFeed; | 
| 2 | 1 |  |  | 1 |  | 634 | use base qw(WebService::Cmis::Test); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 595 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | use strict; | 
| 5 |  |  |  |  |  |  | use warnings; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | use Test::More; | 
| 8 |  |  |  |  |  |  | use Error qw(:try); | 
| 9 |  |  |  |  |  |  | use WebService::Cmis qw(:collections :utils :relations :namespaces :contenttypes); | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub test_AtomFeed : Tests { | 
| 12 |  |  |  |  |  |  | my $this = shift; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | my $repo = $this->getRepository; | 
| 15 |  |  |  |  |  |  | my $productName = $repo->getRepositoryInfo->{productName}; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | my $resultSet = $repo->getCollection(ROOT_COLL); | 
| 18 |  |  |  |  |  |  | my $nrResults = $resultSet->getSize; | 
| 19 |  |  |  |  |  |  | ok($nrResults > 0) or diag("no objects in root collection"); | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | #print STDERR "found $nrResults results\n"; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | while (my $obj = $resultSet->getNext) { | 
| 24 |  |  |  |  |  |  | isa_ok($obj, "WebService::Cmis::Object"); | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | #print STDERR "name=".$obj->getName." type=".$obj->getTypeId." path=".($obj->getPath||'')."\n"; | 
| 27 |  |  |  |  |  |  | #print STDERR "toString=".$obj->toString."\n"; | 
| 28 |  |  |  |  |  |  | #print STDERR "xmlDoc=".$obj->{xmlDoc}->toString(1)."\n"; | 
| 29 |  |  |  |  |  |  | ok(defined $obj->getName); | 
| 30 |  |  |  |  |  |  | ok(defined $obj->getTypeId); | 
| 31 |  |  |  |  |  |  | ok(defined $obj->toString); | 
| 32 |  |  |  |  |  |  | if ($obj->isa("WebService::Cmis::Folder")) { | 
| 33 |  |  |  |  |  |  | ok(defined $obj->getPath); | 
| 34 |  |  |  |  |  |  | like($obj->getPath, qr"^/"); | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | SKIP: { | 
| 37 |  |  |  |  |  |  | skip "$productName does not maintain the object name as used in its path", 1 | 
| 38 |  |  |  |  |  |  | if $productName =~ /nuxeo/i;    # SMELL: make it configurable | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | my $regex = $obj->getName . '$'; | 
| 41 |  |  |  |  |  |  | note("path=" . $obj->getPath . ", regex=$regex"); | 
| 42 |  |  |  |  |  |  | like($obj->getPath, qr/$regex/); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  | ok(!ref($obj->toString)) or diag("illegal objectId"); | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub test_AtomFeed_rewind : Test { | 
| 51 |  |  |  |  |  |  | my $this = shift; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | my $repo = $this->getRepository; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | my $resultSet = $repo->getCollection(ROOT_COLL); | 
| 56 |  |  |  |  |  |  | my $size1 = $resultSet->getSize; | 
| 57 |  |  |  |  |  |  | #print STDERR "resultSet1=".$resultSet->{xmlDoc}->toString(1)."\n"; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | $resultSet->rewind; | 
| 60 |  |  |  |  |  |  | #print STDERR "resultSet2=".$resultSet->{xmlDoc}->toString(1)."\n"; | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | my $size2 = $resultSet->getSize; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | #print STDERR "size1=$size1, size2=$size2\n"; | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | is($size1, $size2); | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | sub test_AtomFeed_getSelfLinks_RootCollection : Tests { | 
| 70 |  |  |  |  |  |  | my $this = shift; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | my $repo = $this->getRepository; | 
| 73 |  |  |  |  |  |  | my $collection = $repo->getCollection(ROOT_COLL); | 
| 74 |  |  |  |  |  |  | my $nrEntries = $collection->getSize; | 
| 75 |  |  |  |  |  |  | note("found $nrEntries objects in root collection"); | 
| 76 |  |  |  |  |  |  | ok($nrEntries); | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | my $selfUrl = $collection->getLink(SELF_REL); | 
| 79 |  |  |  |  |  |  | note("self url of collection=$selfUrl"); | 
| 80 |  |  |  |  |  |  | ok($selfUrl); | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | my $index = 0; | 
| 83 |  |  |  |  |  |  | if ($collection->getSize > 0) { | 
| 84 |  |  |  |  |  |  | my $obj = $collection->getNext; | 
| 85 |  |  |  |  |  |  | ok(defined $obj) or diag("no object found in non-zero feed"); | 
| 86 |  |  |  |  |  |  | do { | 
| 87 |  |  |  |  |  |  | isa_ok($obj, "WebService::Cmis::Object"); | 
| 88 |  |  |  |  |  |  | my $id = $obj->getId; | 
| 89 |  |  |  |  |  |  | my $url = $obj->getSelfLink; | 
| 90 |  |  |  |  |  |  | my $title = $obj->getTitle; | 
| 91 |  |  |  |  |  |  | my $summary = $obj->getSummary; | 
| 92 |  |  |  |  |  |  | ok(defined $id); | 
| 93 |  |  |  |  |  |  | ok(defined $url); | 
| 94 |  |  |  |  |  |  | ok(defined $title); | 
| 95 |  |  |  |  |  |  | ok(defined $summary); | 
| 96 |  |  |  |  |  |  | note("title=$title, summary=$summary, url=$url"); | 
| 97 |  |  |  |  |  |  | $index++; | 
| 98 |  |  |  |  |  |  | } while ($obj = $collection->getNext); | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | is($index, $nrEntries); | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | sub test_AtomFeed_getSelfLinks_getDescendants : Tests { | 
| 105 |  |  |  |  |  |  | my $this = shift; | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | my $repo = $this->getRepository; | 
| 108 |  |  |  |  |  |  | my $root = $repo->getRootFolder; | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | my $resultSet = $root->getDescendants(depth=>2); | 
| 111 |  |  |  |  |  |  | my $nrEntries = $resultSet->getSize; | 
| 112 |  |  |  |  |  |  | note("found $nrEntries objects in result set"); | 
| 113 |  |  |  |  |  |  | #print STDERR "self url of result set=".$resultSet->getLink(SELF_REL)."\n"; | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | my $index = 0; | 
| 116 |  |  |  |  |  |  | while(my $obj = $resultSet->getNext) { | 
| 117 |  |  |  |  |  |  | isa_ok($obj, "WebService::Cmis::Object"); | 
| 118 |  |  |  |  |  |  | my $id = $obj->getId; | 
| 119 |  |  |  |  |  |  | my $url = $obj->getSelfLink; | 
| 120 |  |  |  |  |  |  | my $title = $obj->getTitle; | 
| 121 |  |  |  |  |  |  | note("title=$title, id=$id, url=$url"); | 
| 122 |  |  |  |  |  |  | $index++; | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | is($index, $nrEntries); | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | sub test_AtomFeed_reverse : Tests { | 
| 129 |  |  |  |  |  |  | my $this = shift; | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | my $repo = $this->getRepository; | 
| 132 |  |  |  |  |  |  | my $collection = $repo->getCollection(ROOT_COLL); | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | my $nrEntries = $collection->getSize; | 
| 135 |  |  |  |  |  |  | #print STDERR "found $nrEntries objects in root collection\n"; | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | my $index = 1; | 
| 138 |  |  |  |  |  |  | if ($nrEntries > 0) { | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | my $lastObj = $collection->getLast; | 
| 141 |  |  |  |  |  |  | my $lastObjId = $lastObj->getId; | 
| 142 |  |  |  |  |  |  | ok(defined $lastObj) or diag("no object found in non-zero feed"); | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | #print STDERR  "1 - index=$collection->{index} - lastObj=".$lastObjId.", ".$lastObj->getTitle."\n"; | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | while (my $obj = $collection->getPrev) { | 
| 147 |  |  |  |  |  |  | isa_ok($obj, "WebService::Cmis::Object"); | 
| 148 |  |  |  |  |  |  | $index++; | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | ok($collection->{index} >= 0) or diag("illegal index in AtomFeed"); | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | isnt($obj->getId, $lastObjId) or diag("can't travel backwards in atom feed"); | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | #print STDERR  "2 - index=$collection->{index} -     obj=".$obj->getId.", ".$obj->getTitle."\n"; | 
| 155 |  |  |  |  |  |  | }; | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | is($index, $nrEntries); | 
| 159 |  |  |  |  |  |  | } | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | sub test_AtomFeed_getAllowableActions : Tests { | 
| 162 |  |  |  |  |  |  | my $this = shift; | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | my $repo = $this->getRepository(); | 
| 165 |  |  |  |  |  |  | my $feed = $repo->query("select * from cmis:document", maxItems => 1); | 
| 166 |  |  |  |  |  |  | ok(defined $feed); | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | while (my $obj = $feed->getNext) { | 
| 169 |  |  |  |  |  |  | my $allowableActions = $obj->getAllowableActions; | 
| 170 |  |  |  |  |  |  | ok(defined $allowableActions) or diag("can't get allowable actions"); | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | foreach my $action (sort keys %$allowableActions) { | 
| 173 |  |  |  |  |  |  | note("$action=$allowableActions->{$action}"); | 
| 174 |  |  |  |  |  |  | like($action, qr'^can'); | 
| 175 |  |  |  |  |  |  | like($allowableActions->{$action}, qr'^(0|1)$'); | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  | last;    # only check the first one | 
| 178 |  |  |  |  |  |  | } | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | sub test_AtomFeed_getACL : Test(2) { | 
| 183 |  |  |  |  |  |  | my $this = shift; | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | my $repo = $this->getRepository(); | 
| 186 |  |  |  |  |  |  | my $obj = $this->getTestDocument; | 
| 187 |  |  |  |  |  |  | my $feed = $repo->query("select * from cmis:document", maxItems => 1); | 
| 188 |  |  |  |  |  |  | ok(defined $feed); | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | #print STDERR "feed=".$feed->{xmlDoc}->toString(1)."\n"; | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | my $canACL = $repo->getCapabilities()->{'ACL'}; | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | SKIP: { | 
| 195 |  |  |  |  |  |  | skip "not able to manage ACLs", 1 unless $canACL eq 'manage'; | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | while (my $obj = $feed->getNext) { | 
| 198 |  |  |  |  |  |  | my $acl = $obj->getACL; | 
| 199 |  |  |  |  |  |  | ok(defined $acl) or diag("can't get ACLs"); | 
| 200 |  |  |  |  |  |  | note($acl->toString); | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | last;    # only check the first one | 
| 203 |  |  |  |  |  |  | } | 
| 204 |  |  |  |  |  |  | } | 
| 205 |  |  |  |  |  |  | } | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | sub test_AtomFeed_getSelfLink : Tests { | 
| 208 |  |  |  |  |  |  | my $this = shift; | 
| 209 |  |  |  |  |  |  |  | 
| 210 |  |  |  |  |  |  | my $repo = $this->getRepository(); | 
| 211 |  |  |  |  |  |  | my $imageQuery; | 
| 212 |  |  |  |  |  |  | my $vendorName = $repo->getRepositoryInfo->{vendorName}; | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | # SMELL: argh ... more vendor differences to deal with | 
| 215 |  |  |  |  |  |  | $imageQuery = "select * from cmis:document where cmis:objectTypeId='Picture'" if $vendorName =~ /nuxeo/i; | 
| 216 |  |  |  |  |  |  | $imageQuery = "select * from cmis:document where cmis:contentStreamMimeType='image/jpeg'" unless defined $imageQuery; | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | my $feed = $repo->query($imageQuery, maxItems => 1); | 
| 219 |  |  |  |  |  |  | ok(defined $feed); | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | #print STDERR "feed=".$feed->{xmlDoc}->toString(1)."\n"; | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | while (my $obj = $feed->getNext) { | 
| 224 |  |  |  |  |  |  | my $link = $obj->getSelfLink; | 
| 225 |  |  |  |  |  |  | ok(defined $link) or diag("can't get self link"); | 
| 226 |  |  |  |  |  |  | note("self link=$link"); | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | last;    # only check the first one | 
| 229 |  |  |  |  |  |  | } | 
| 230 |  |  |  |  |  |  | } | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | sub test_AtomFeed_getEditLink : Tests { | 
| 233 |  |  |  |  |  |  | my $this = shift; | 
| 234 |  |  |  |  |  |  |  | 
| 235 |  |  |  |  |  |  | my $repo = $this->getRepository(); | 
| 236 |  |  |  |  |  |  | my $obj = $this->getTestDocument; | 
| 237 |  |  |  |  |  |  |  | 
| 238 |  |  |  |  |  |  | my $imageQuery; | 
| 239 |  |  |  |  |  |  | my $vendorName = $repo->getRepositoryInfo->{vendorName}; | 
| 240 |  |  |  |  |  |  |  | 
| 241 |  |  |  |  |  |  | # SMELL: argh ... more vendor differences to deal with | 
| 242 |  |  |  |  |  |  | $imageQuery = "select * from cmis:document where cmis:objectTypeId='Picture'" if $vendorName =~ /nuxeo/i; | 
| 243 |  |  |  |  |  |  | $imageQuery = "select * from cmis:document where cmis:contentStreamMimeType='image/jpeg'" unless defined $imageQuery; | 
| 244 |  |  |  |  |  |  |  | 
| 245 |  |  |  |  |  |  | my $feed = $repo->query($imageQuery, maxItems => 1); | 
| 246 |  |  |  |  |  |  | ok(defined $feed); | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  | #print STDERR "feed=".$feed->{xmlDoc}->toString(1)."\n"; | 
| 249 |  |  |  |  |  |  | my $size = $feed->getSize; | 
| 250 |  |  |  |  |  |  | note("found $size item(s)"); | 
| 251 |  |  |  |  |  |  | ok($size > 0) or diag("can't find image document anymore"); | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | while (my $obj = $feed->getNext) { | 
| 254 |  |  |  |  |  |  | my $link = $obj->getEditLink; | 
| 255 |  |  |  |  |  |  | ok(defined $link) or diag("can't get edit link"); | 
| 256 |  |  |  |  |  |  | note("link=$link"); | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  | last;    # only check the first one | 
| 259 |  |  |  |  |  |  | } | 
| 260 |  |  |  |  |  |  | } | 
| 261 |  |  |  |  |  |  |  | 
| 262 |  |  |  |  |  |  | 1; |