diff --git a/test/clj/metafacture_playground/process_test.clj b/test/clj/metafacture_playground/process_test.clj index fc8ba3e..505e422 100644 --- a/test/clj/metafacture_playground/process_test.clj +++ b/test/clj/metafacture_playground/process_test.clj @@ -1,49 +1,59 @@ (ns metafacture-playground.process-test - (:require [clojure.test :refer :all] - [metafacture-playground.process :refer [process]])) + (:require [clojure.test :refer [deftest testing is]] + [metafacture-playground.process :refer [process]] + [clojure.java.io :as io] + [lambdaisland.uri :refer [uri query-string->map]])) -; TODO: we should extract the samples here and in db.cljs to files -(def sample-data {:data "1{a: Faust, b {n: Goethe, v: JW}, c: Weimar}\n2{a: Räuber, b {n: Schiller, v: F}, c: Weimar}" - :flux-with-fix "inputFile|\nopen-file\n|as-lines\n|decode-formeta\n|fix(transformationFile)\n|encode-xml(rootTag=\"collection\")\n|print\n;" - :flux-with-morph "inputFile|\nopen-file\n|as-lines\n|decode-formeta\n|morph(transformationFile)\n|encode-xml(rootTag=\"collection\")\n|print\n;" - :fix "move_field(_id, id)\nmove_field(a, title)\npaste(author, b.v, b.n, '~aus', c)\nretain(id, title, author)" - :morph (str "\n" - "\n" - "\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\t\n" - "\t\t\n" - "\t\n" - "\n")}) +(deftest processing-correctly-test + (let [test-data {:data "1{a: Faust, b {n: Goethe, v: JW}, c: Weimar}\n2{a: Räuber, b {n: Schiller, v: F}, c: Weimar}" + :flux-with-fix "inputFile|\nopen-file\n|as-lines\n|decode-formeta\n|fix(transformationFile)\n|encode-xml(rootTag=\"collection\")\n|print\n;" + :flux-with-morph "inputFile|\nopen-file\n|as-lines\n|decode-formeta\n|morph(transformationFile)\n|encode-xml(rootTag=\"collection\")\n|print\n;" + :fix "move_field(_id, id)\nmove_field(a, title)\npaste(author, b.v, b.n, '~aus', c)\nretain(id, title, author)" + :morph (str "\n" + "\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\t\n" + "\t\t\n" + "\t\n" + "\n") + :result (str "" + "\n" + "\n" + "\n " + "\n 1" + "\n Faust" + "\n JW Goethe aus Weimar" + "\n " + "\n" + "\n " + "\n 2" + "\n Räuber" + "\n F Schiller aus Weimar" + "\n " + "\n" + "\n\n")}] + (testing "Process sample data (with fix) with correct result." + (let [result (process (:flux-with-fix test-data) (:data test-data) (:fix test-data))] + (is (= result (:result test-data))))) -(def test-data (merge sample-data - {:result (str "" - "\n" - "\n" - "\n " - "\n 1" - "\n Faust" - "\n JW Goethe aus Weimar" - "\n " - "\n" - "\n " - "\n 2" - "\n Räuber" - "\n F Schiller aus Weimar" - "\n " - "\n" - "\n\n")})) + (testing "Process sample data (with morph) with correct result." + (let [result (process (:flux-with-morph test-data) (:data test-data) (:morph test-data))] + (is (= result (:result test-data))))))) -(deftest processing-test - (testing "Process sample data (with fix) correctly." - (let [result (process (:flux-with-fix test-data) (:data test-data) (:fix test-data))] - (is (= result (:result test-data))))) - - (testing "Process sample data (with morph) correctly." - (let [result (process (:flux-with-morph test-data) (:data test-data) (:morph test-data))] - (is (= result (:result test-data)))))) +(deftest process-examples-test + (testing "Process all examples in resources/examples without exceptions." + (let [examples (->> (io/resource "examples") + io/file + .listFiles + ;(map io/file) + (keep #(when (.isFile %) + (slurp %))) + (map #(-> % uri :query query-string->map)))] + (doseq [example examples] + (is (process (:flux example) (:data example) (:transformation example)))))))