Merge branch 'master' into 11850-singlecontainer-max-requirements
[arvados.git] / sdk / R / tests / testthat / test-CollectionTree.R
1 context("CollectionTree")
2
3 test_that("constructor creates file tree from character array properly", {
4
5     collection <- "myCollection"
6     characterArray <- c("animal", 
7                         "animal/dog",
8                         "boat")
9
10     collectionTree <- CollectionTree$new(characterArray, collection)
11
12     root   <- collectionTree$getTree()
13     animal <- collectionTree$getElement("animal")
14     dog    <- collectionTree$getElement("animal/dog")
15     boat   <- collectionTree$getElement("boat")
16
17     rootHasNoParent             <- is.null(root$getParent())
18     rootIsOfTypeSubcollection   <- "Subcollection" %in% class(root)
19     animalIsOfTypeSubcollection <- "Subcollection" %in% class(animal)
20     dogIsOfTypeArvadosFile      <- "ArvadosFile" %in% class(dog)
21     boatIsOfTypeArvadosFile     <- "ArvadosFile" %in% class(boat)
22     animalsParentIsRoot         <- animal$getParent()$getName() == root$getName()
23     animalContainsDog           <- animal$getFirst()$getName() == dog$getName()
24     dogsParentIsAnimal          <- dog$getParent()$getName() == animal$getName()
25     boatsParentIsRoot           <- boat$getParent()$getName() == root$getName()
26
27     allElementsBelongToSameCollection <- root$getCollection()   == "myCollection" &&
28                                          animal$getCollection() == "myCollection" &&
29                                          dog$getCollection()    == "myCollection" &&
30                                          boat$getCollection()   == "myCollection"
31
32     expect_that(root$getName(), equals(""))
33     expect_that(rootIsOfTypeSubcollection, is_true())
34     expect_that(rootHasNoParent, is_true())
35     expect_that(animalIsOfTypeSubcollection, is_true())
36     expect_that(animalsParentIsRoot, is_true())
37     expect_that(animalContainsDog, is_true())
38     expect_that(dogIsOfTypeArvadosFile, is_true())
39     expect_that(dogsParentIsAnimal, is_true())
40     expect_that(boatIsOfTypeArvadosFile, is_true())
41     expect_that(boatsParentIsRoot, is_true())
42     expect_that(allElementsBelongToSameCollection, is_true())
43 }) 
44
45 test_that("getElement returns element from tree if element exists on specified path", {
46
47     collection <- "myCollection"
48     characterArray <- c("animal", 
49                         "animal/dog",
50                         "boat")
51
52     collectionTree <- CollectionTree$new(characterArray, collection)
53
54     dog <- collectionTree$getElement("animal/dog")
55
56     expect_that(dog$getName(), equals("dog"))
57 }) 
58
59 test_that("getElement returns NULL from tree if element doesn't exists on specified path", {
60
61     collection <- "myCollection"
62     characterArray <- c("animal", 
63                         "animal/dog",
64                         "boat")
65
66     collectionTree <- CollectionTree$new(characterArray, collection)
67
68     fish <- collectionTree$getElement("animal/fish")
69     fishIsNULL <- is.null(fish)
70
71     expect_that(fishIsNULL, is_true())
72 }) 
73
74 test_that("getElement trims ./ from start of relativePath", {
75
76     collection <- "myCollection"
77     characterArray <- c("animal", 
78                         "animal/dog",
79                         "boat")
80
81     collectionTree <- CollectionTree$new(characterArray, collection)
82
83     dog <- collectionTree$getElement("animal/dog")
84     dogWithDotSlash <- collectionTree$getElement("./animal/dog")
85
86     expect_that(dogWithDotSlash$getName(), equals(dog$getName()))
87 }) 
88
89 test_that("getElement trims / from end of relativePath", {
90
91     collection <- "myCollection"
92     characterArray <- c("animal", 
93                         "animal/dog",
94                         "boat")
95
96     collectionTree <- CollectionTree$new(characterArray, collection)
97
98     animal <- collectionTree$getElement("animal")
99     animalWithSlash <- collectionTree$getElement("animal/")
100
101     expect_that(animalWithSlash$getName(), equals(animal$getName()))
102 })