Changeset 459 for trunk/src/unit_tests


Ignore:
Timestamp:
05/09/11 09:28:16 (14 years ago)
Author:
lgiessmann
Message:

JTM: added unit-tests for the function merge-topic-from-jtm-list => fixed a bug when referencing the topic that has to be merged

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/unit_tests/jtm_test.lisp

    r458 r459  
    4242           :test-import-names
    4343           :test-make-instance-of-association
    44            :test-import-topics))
     44           :test-import-topics
     45           :test-merge-topics))
    4546
    4647
     
    16371638
    16381639
    1639 
    16401640(test test-make-instance-of-association
    16411641  "Tests the function make-instance-of-association."
     
    17051705                                   (eql (player role :revision 0) top-2)))
    17061706                          (roles assoc :revision 0))))
    1707       (signals exceptions:JTM-error
     1707      (signals exceptions:missing-reference-error
    17081708        (jtm::make-instance-of-association top-1 top-3 nil :revision 100))
    17091709      (delete-psi
     
    18471847
    18481848
    1849 ;TODO:
    1850 ; *merge-topics-from-jtm-lists
    1851 ; *merge-topic-from-jtm-list
     1849
     1850(test test-merge-topics
     1851  "Tests the functions import-topic-stub-from-jtm-list,
     1852   and import-topic-stubs-from-jtm-lists."
     1853  (with-fixture with-empty-db ("data_base")
     1854    (let* ((prefixes (list (list :pref "xsd" :value *xsd-ns*)
     1855                           (list :pref "pref_1" :value *xsd-ns*)
     1856                           (list :pref "pref_2" :value "http://some.where/")))
     1857           (j-top-1 "{\"version\":\"1.1\",\"prefixes\":{\"pref_1\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\"xsd\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#\",\"pref_2\":\"http:\\/\\/some.where\\/\"},\"subject_identifiers\":[\"[pref_2:psi-1]\",\"[pref_2:psi-2]\"],\"subject_locators\":[\"[pref_2:sl-2]\"],\"item_identifiers\":[\"[pref_2:ii-4]\"],\"instance_of\":[\"ii:[pref_2:ii-1]\"],\"item_type\":\"topic\",\"names\":[{\"item_identifiers\":null,\"value\":\"name-1\",\"type\":null,\"scope\":null,\"variants\":null,\"reifier\":null},{\"item_identifiers\":null,\"value\":\"name-2\",\"type\":null,\"scope\":[\"sl:[pref_2:sl-1]\"],\"variants\":[{\"item_identifiers\":null,\"datatype\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"value\":\"var-1\",\"scope\":[\"ii:[pref_2:ii-1]\"],\"reifier\":null}],\"reifier\":null}],\"occurrences\":[{\"item_identifiers\":[\"[pref_2:ii-2]\"],\"datatype\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"type\":\"sl:[pref_2:sl-1]\",\"value\":\"occ-1\",\"scope\":[\"si:[pref_2:psi-1]\"],\"reifier\":\"ii:[pref_2:ii-1]\"},{\"item_identifiers\":null,\"datatype\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#anyURI\",\"type\":\"si:[pref_2:psi-1]\",\"value\":\"http:\\/\\/any.uri\",\"scope\":null,\"reifier\":null}]}")
     1858           (j-top-2 "{\"version\":\"1.0\",\"subject_identifiers\":[\"http:\\/\\/some.where\\/psi-1\",\"http:\\/\\/some.where\\/psi-2\"],\"subject_locators\":[\"http:\\/\\/some.where\\/sl-2\"],\"item_identifiers\":[\"http:\\/\\/some.where\\/ii-4\"],\"item_type\":\"topic\",\"parent\":[\"ii:http:\\/\\/some.where\\/ii-3\"],\"names\":[{\"item_identifiers\":null,\"value\":\"name-1\",\"type\":null,\"scope\":null,\"variants\":null,\"reifier\":null},{\"item_identifiers\":null,\"value\":\"name-2\",\"type\":null,\"scope\":[\"sl:http:\\/\\/some.where\\/sl-1\"],\"variants\":[{\"item_identifiers\":null,\"datatype\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"value\":\"var-1\",\"scope\":[\"ii:http:\\/\\/some.where\\/ii-1\"],\"reifier\":null}],\"reifier\":null}],\"occurrences\":[{\"item_identifiers\":[\"http:\\/\\/some.where\\/ii-2\"],\"datatype\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#string\",\"type\":\"sl:http:\\/\\/some.where\\/sl-1\",\"value\":\"occ-1\",\"scope\":[\"si:http:\\/\\/some.where\\/psi-1\"],\"reifier\":\"ii:http:\\/\\/some.where\\/ii-1\"},{\"item_identifiers\":null,\"datatype\":\"http:\\/\\/www.w3.org\\/2001\\/XMLSchema#anyURI\",\"type\":\"si:http:\\/\\/some.where\\/psi-1\",\"value\":\"http:\\/\\/any.uri\",\"scope\":null,\"reifier\":null}]}")
     1859           (j-top-3 "{\"subject_identifiers\":[\"http:\\/\\/some.where\\/tmsparql\\/author\"],\"subject_locators\":null,\"item_identifiers\":null,\"names\":null,\"occurrences\":null}")
     1860           (j-top-4 "{\"subject_identifiers\":null,\"subject_locators\":[\"http:\\/\\/some.where\\/sl-1\"],\"item_identifiers\":null,\"names\":null,\"occurrences\":null}")
     1861           (j-top-5 "{\"subject_identifiers\":null,\"subject_locators\":null,\"item_identifiers\":[\"http:\\/\\/some.where\\/ii-1\"],\"names\":null,\"occurrences\":null}")
     1862           (tm-1 (make-construct
     1863                  'TopicMapC :start-revision 100
     1864                  :item-identifiers
     1865                  (list (make-construct 'ItemIdentifierC
     1866                                        :uri "http://some.where/tm-1"))))
     1867           (tm-2 (make-construct
     1868                  'TopicMapC :start-revision 100
     1869                  :item-identifiers
     1870                  (list (make-construct 'ItemIdentifierC
     1871                                        :uri "http://some.where/tm-2"))))
     1872           (tops (jtm::import-topic-stubs-from-jtm-lists
     1873                  (list (json:decode-json-from-string j-top-1)
     1874                        (json:decode-json-from-string j-top-2)
     1875                        (json:decode-json-from-string j-top-3)
     1876                        (json:decode-json-from-string j-top-4)
     1877                        (json:decode-json-from-string j-top-5))
     1878                  (list tm-1 tm-2) :revision 100 :prefixes prefixes)))
     1879      (is (= (length tops) 5))
     1880      (is (= (length (remove-duplicates tops)) 4))
     1881      (is (= (length (elephant:get-instances-by-class 'TopicC)) 4))
     1882      (is (= (length (elephant:get-instances-by-class 'PersistentIdC)) 3))
     1883      (is (= (length (elephant:get-instances-by-class 'ItemIdentifierC)) 4))
     1884      (is (= (length (elephant:get-instances-by-class 'SubjectLocatorC)) 2))
     1885      (is-false (elephant:get-instances-by-class 'NameC))
     1886      (is-false (elephant:get-instances-by-class 'VariantC))
     1887      (is-false (elephant:get-instances-by-class 'RoleC))
     1888      (is-false (elephant:get-instances-by-class 'AssociationC))
     1889      (is-false (elephant:get-instances-by-class 'OccurrenceC))
     1890      (signals exceptions:missing-reference-error  ;missing topics for
     1891        (jtm::merge-topic-from-jtm-list            ;type-instance-associations
     1892         (json:decode-json-from-string j-top-1)
     1893         (list tm-1 tm-2) :revision 100 :prefixes prefixes))
     1894      (make-construct 'TopicC :start-revision 100
     1895                      :psis
     1896                      (list (make-construct 'PersistentIdC
     1897                                            :uri *type-psi*)))
     1898      (make-construct 'TopicC :start-revision 100
     1899                      :psis
     1900                      (list (make-construct 'PersistentIdC
     1901                                            :uri *instance-psi*)))
     1902      (make-construct 'TopicC :start-revision 100
     1903                      :psis
     1904                      (list (make-construct 'PersistentIdC
     1905                                            :uri *type-instance-psi*)))
     1906      (let ((top-1 (jtm::merge-topic-from-jtm-list
     1907                    (json:decode-json-from-string j-top-1)
     1908                    (list tm-1 tm-2) :revision 100 :prefixes prefixes))
     1909            (top-2 (jtm::merge-topic-from-jtm-list
     1910                    (json:decode-json-from-string j-top-2)
     1911                    (list tm-1 tm-2) :revision 100 :prefixes prefixes)))
     1912        (is (= (length (elephant:get-instances-by-class 'TopicC)) 7))
     1913        (is (= (length (elephant:get-instances-by-class 'PersistentIdC)) 6))
     1914        (is (= (length (elephant:get-instances-by-class 'ItemIdentifierC)) 5))
     1915        (is (= (length (elephant:get-instances-by-class 'SubjectLocatorC)) 2))
     1916        (is (= (length (elephant:get-instances-by-class 'NameC)) 2))
     1917        (is (= (length (elephant:get-instances-by-class 'VariantC)) 1))
     1918        (is (= (length (elephant:get-instances-by-class 'RoleC)) 2))
     1919        (is (= (length (elephant:get-instances-by-class 'AssociationC)) 1))
     1920        (is (= (length (elephant:get-instances-by-class 'OccurrenceC)) 2))
     1921        (is (eql top-1 top-2))
     1922        (is (= (length (names top-1 :revision 0)) 2))
     1923        (is-true (find-if #'(lambda(name)
     1924                              (and (string= (charvalue name) "name-1")
     1925                                   (not (instance-of name :revision 0))
     1926                                   (not (themes name :revision 0))
     1927                                   (not (variants name :revision 0))
     1928                                   (not (reifier name :revision 0))
     1929                                   (not (item-identifiers name :revision 0))))
     1930                          (names top-1 :revision 0)))
     1931        (is-true
     1932         (find-if #'(lambda(name)
     1933                      (and (string= (charvalue name) "name-2")
     1934                           (not (instance-of name :revision 0))
     1935                           (= (length (themes name :revision 0)) 1)
     1936                           (= (length (locators (first (themes name :revision 0))
     1937                                                :revision 0)) 1)
     1938                           (string=
     1939                            (uri (first (locators (first (themes name :revision 0))
     1940                                                  :revision 0)))
     1941                            "http://some.where/sl-1")
     1942                           (= (length (variants name :revision 0)) 1)
     1943                           (not (reifier name :revision 0))
     1944                           (not (item-identifiers name :revision 0))))
     1945                  (names top-1 :revision 0)))
     1946        (is-true
     1947         (find-if #'(lambda(occ)
     1948                      (and (string= (charvalue occ) "occ-1")
     1949                           (string= (datatype occ) *xml-string*)
     1950                           (instance-of occ :revision 0)
     1951                           (= (length (locators (instance-of occ :revision 0)
     1952                                                :revision 0)) 1)
     1953                           (string=
     1954                            (uri (first (locators (instance-of occ :revision 0)
     1955                                                  :revision 0)))
     1956                            "http://some.where/sl-1")
     1957                           (= (length (themes occ :revision 0)) 1)
     1958                           (= (length (psis (first (themes occ :revision 0))
     1959                                            :revision 0)) 2)
     1960                           (or (string=
     1961                                (uri (first (psis (first (themes occ :revision 0))
     1962                                                  :revision 0)))
     1963                                "http://some.where/psi-1")
     1964                               (string=
     1965                                (uri (second (psis (first (themes occ :revision 0))
     1966                                                   :revision 0)))
     1967                                "http://some.where/psi-1"))
     1968                           (reifier occ :revision 0)
     1969                           (= (length (item-identifiers occ :revision 0)) 1)
     1970                           (string= (uri (first (item-identifiers occ :revision 0)))
     1971                                    "http://some.where/ii-2")))
     1972                  (occurrences top-1 :revision 0)))
     1973        (is-true
     1974         (find-if #'(lambda(occ)
     1975                      (and (string= (charvalue occ) "http://any.uri")
     1976                           (string= (datatype occ) *xml-uri*)
     1977                           (instance-of occ :revision 0)
     1978                           (or (string=
     1979                                (uri (first (psis (instance-of occ :revision 0)
     1980                                                  :revision 0)))
     1981                                "http://some.where/psi-1")
     1982                               (string=
     1983                                (uri (second (psis (instance-of occ :revision 0)
     1984                                                   :revision 0)))
     1985                                "http://some.where/psi-1"))
     1986                           (not (themes occ :revision 0))
     1987                           (not (reifier occ :revision 0))
     1988                           (not (item-identifiers occ :revision 0))))
     1989                  (occurrences top-1 :revision 0))))
     1990      (let ((tops (jtm::merge-topics-from-jtm-lists
     1991                   (list (json:decode-json-from-string j-top-1)
     1992                         (json:decode-json-from-string j-top-2)
     1993                         (json:decode-json-from-string j-top-3)
     1994                         (json:decode-json-from-string j-top-4)
     1995                         (json:decode-json-from-string j-top-5))
     1996                   (list tm-1 tm-2) :revision 200 :prefixes prefixes)))
     1997        (is (= (length (remove-duplicates tops)) 4))
     1998        (is (= (length (elephant:get-instances-by-class 'TopicC)) 7))
     1999        (is (= (length (elephant:get-instances-by-class 'PersistentIdC)) 6))
     2000        (is (= (length (elephant:get-instances-by-class 'ItemIdentifierC)) 5))
     2001        (is (= (length (elephant:get-instances-by-class 'SubjectLocatorC)) 2))
     2002        (is (= (length (elephant:get-instances-by-class 'NameC)) 2))
     2003        (is (= (length (elephant:get-instances-by-class 'VariantC)) 1))
     2004        (is (= (length (elephant:get-instances-by-class 'RoleC)) 2))
     2005        (is (= (length (elephant:get-instances-by-class 'AssociationC)) 1))
     2006        (is (= (length (elephant:get-instances-by-class 'OccurrenceC)) 2)))
     2007      (signals exceptions:jtm-error
     2008        (jtm::merge-topic-from-jtm-list
     2009         (json:decode-json-from-string j-top-1)
     2010         (list tm-1 tm-2) :revision 200))
     2011      (signals exceptions:jtm-error
     2012        (jtm::merge-topic-from-jtm-list
     2013         (json:decode-json-from-string j-top-1)
     2014         (list tm-1 tm-2) :revision 200 :prefixes prefixes :instance-of-p nil))
     2015      (signals exceptions:missing-reference-error
     2016        (jtm::merge-topic-from-jtm-list
     2017         (json:decode-json-from-string j-top-1)
     2018         nil :revision 200 :prefixes prefixes))
     2019     (signals exceptions:jtm-error
     2020        (jtm::merge-topics-from-jtm-lists
     2021         (list (json:decode-json-from-string j-top-1))
     2022         (list tm-1 tm-2) :revision 200))
     2023      (signals exceptions:jtm-error
     2024        (jtm::merge-topics-from-jtm-lists
     2025         (list (json:decode-json-from-string j-top-1))
     2026         (list tm-1 tm-2) :revision 200 :prefixes prefixes :instance-of-p nil))
     2027      (signals exceptions:missing-reference-error
     2028        (jtm::merge-topics-from-jtm-lists
     2029         (list (json:decode-json-from-string j-top-1))
     2030         nil :revision 200 :prefixes prefixes)))))
    18522031
    18532032
Note: See TracChangeset for help on using the changeset viewer.