            tmpdir (fs/temp-dir "test-export-to-kramerius-request-")]
       (h/save-request [[:no-metadata payload] tmpdir])
       (h/prepare-marcxml2mods-request tmpdir)
-      (let [ metadata (-> (slurp "resources/marcxml2mods-response-metadata.clj")
+      (let [ metadata (-> (slurp "resources/communication-with-marcxml2mods/response/metadata.clj")
                           read-string
                           (update-in [:headers] assoc "UUID" (.toString tmpdir)))
-            payload (slurp "resources/marcxml2mods-response-payload.json")
+            payload (slurp "resources/communication-with-marcxml2mods/response/payload.json")
             [mods mods-tmpdir] (-> [metadata payload]
                                     h/save-marcxml2mods-response
                                     h/parse-mods-files

          ]
      (is (.exists tmpdir))
      (is (= tmpdir result))
      (is (.exists (io/file tmpdir "payload.bin")))
      (is (.exists (io/file tmpdir "metadata.clj")))

      (is (.exists (io/file tmpdir "payload")))
      (is (.exists (io/file tmpdir "payload" "uuid")))
      (is (.exists (io/file tmpdir "payload" "aleph_id")))
      (is (.exists (io/file tmpdir "payload" "isbn")))
      (is (.exists (io/file tmpdir "payload" "urnnbn")))
      (is (.exists (io/file tmpdir "payload" "edeposit-url.txt")))
      (is (.exists (io/file tmpdir "payload" "location-at-kramerius")))
      (is (.exists (io/file tmpdir "payload" "is-private")))
      (is (.exists (io/file tmpdir "payload" "oai_marc.xml")))
      (is (.exists (io/file tmpdir "payload" "oai_marc.xml.b64")))

      (is (.exists (io/file tmpdir "payload" "first-page")))
      (is (.exists (io/file tmpdir "payload" "first-page" "robotandbaby_001.jp2")))
      (is (.exists (io/file tmpdir "payload" "first-page" "mimetype")))
      (is (.exists (io/file tmpdir "payload" "first-page" "filename")))

      (is (.exists (io/file tmpdir "payload" "original")))
      (is (.exists (io/file tmpdir "payload" "original" "storage_path")))
      (is (.exists (io/file tmpdir "payload" "original" "mimetype")))
      (is (.exists (io/file tmpdir "payload" "original" "filename")))

      (is (= (fs/size (io/file tmpdir "payload" "oai_marc.xml"))
             (fs/size (io/file "resources" "oai_marc.xml"))))

      (is (= "e65d9072-2c9b-11e5-99fd-b8763f0a3d61" 
             (slurp (io/file tmpdir "payload" "uuid"))))

      (is (= "urn:nbn:cz:mzk-0005ol" 
             (slurp (io/file tmpdir "payload" "urnnbn"))))

      (is (= "80-251-0225-4"
             (slurp (io/file tmpdir "payload" "isbn"))))

      (is (= "cnb001492461" 
             (slurp (io/file tmpdir "payload" "aleph_id"))))

      (is (= "/monografie/2001/John McCarthy/Robot and Baby" 
             (slurp (io/file tmpdir "payload" "location-at-kramerius"))))
       
      (is (= "robotandbaby_001.jp2" 
             (slurp (io/file tmpdir "payload" "first-page" "filename"))))

      (is (= "image/jp2" 
             (slurp (io/file tmpdir "payload" "first-page" "mimetype"))))
      (fs/delete-dir tmpdir)       
      )
    )

      )
    )
  )

(deftest save-response-from-storage-test
  (testing "save response from storage test"
    (let [workdir (fs/temp-dir "test-export-to-kramerius-storage-response-")
          payload (.getBytes (slurp "resources/communication-with-storage/response/payload.bin"))
          metadata (-> (slurp "resources/communication-with-storage/response/metadata.clj")
                       read-string
                       (update-in [:headers] assoc "UUID" (.toString workdir)))]
      (let [ [msg response-workdir] (h/save-response-from-export-to-storage metadata payload)]
        (is (= workdir response-workdir))
        (is (.exists (io/file response-workdir)))
        (is (.exists (io/file response-workdir "export-to-storage")))
        (is (.exists (io/file response-workdir "export-to-storage" "response")))
        (is (.exists (io/file response-workdir "export-to-storage" "response" "payload")))

        (is (= "/monografie/01/02/aa-ofsdfasfs" (-> msg :dir_pointer)))
        (is (= "e65d9072-2c9b-11e5-99fd-b8763f0a3d61" (-> msg :uuid)))
        (is (= "cnb001492461" (-> msg :aleph_id)))
        (is (= "80-251-0225-4" (-> msg :isbn)))
        (is (= "" (-> msg :b64_data)))
        )
      (fs/delete-dir workdir)
      )
    )
  )

(deftest prepare-scp-to-kramerius-test
  (testing "prepare scp to kramerius test"
    (let     [payload (slurp "resources/export-request.json")
              workdir (fs/temp-dir "test-export-to-kramerius-request-")]
      (h/save-request [[:no-metadata payload] workdir])
      (h/prepare-marcxml2mods-request workdir)
      (let [ metadata (-> (slurp "resources/communication-with-marcxml2mods/response/metadata.clj")
                          read-string
                          (update-in [:headers] assoc "UUID" (.toString workdir)))
            payload (slurp "resources/communication-with-marcxml2mods/response/payload.json")
            [mods mods-tmpdir] (-> [metadata payload]
                                   h/save-marcxml2mods-response
                                   h/parse-mods-files
                                   h/add-urnnbn-to-mods)
            [oai_dcs oai-tmpdir] (-> [mods mods-tmpdir] h/mods->oai_dcs)
            [_ _ request-workdir] (-> (h/make-package-with-foxml   [mods mods-tmpdir] 
                                                                   [oai_dcs oai-tmpdir] 
                                                                   workdir)
                                      h/make-zip-package
                                      h/prepare-request-for-export-to-storage)]
        (let [payload (.getBytes (slurp "resources/communication-with-storage/response/payload.bin"))
              metadata (-> (slurp "resources/communication-with-storage/response/metadata.clj")
                           read-string
                           (update-in [:headers] assoc "UUID" (.toString workdir)))]
          (let [ [scp-workdir] (-> (h/save-response-from-export-to-storage metadata payload)
                                   (h/prepare-scp-to-kramerius
                                    :import-mount "/var/edeposit_import"
                                    :archive-mount "/var/edeposit_archive"
                                    :originals-mount "/var/edeposit_originals"))
                 uuid (slurp (io/file workdir "request" "payload" "uuid"))]
            (is (.exists (io/file scp-workdir)))
            (is (.exists (io/file scp-workdir "scp-to-kramerius")))
            (is (.exists (io/file scp-workdir "scp-to-kramerius" "dir_pointer")))
            (is (.exists (io/file scp-workdir "scp-to-kramerius" "request")))
            (is (.exists (io/file scp-workdir "scp-to-kramerius" "request" (str uuid ".xml"))))
            (is (.exists (io/file scp-workdir "scp-to-kramerius" "request" "from")))
            (is (= (.toString (io/file scp-workdir "scp-to-kramerius" "request" (str uuid ".xml")))
                   (slurp  (io/file scp-workdir "scp-to-kramerius" "request" "from"))))

            (is (.exists (io/file scp-workdir "scp-to-kramerius" "request" "to")))
            (is (= (str "/var/edeposit_import/" uuid ".xml")
                   (slurp (io/file scp-workdir "scp-to-kramerius" "request" "to"))))

            (let [dir_pointer (slurp (io/file scp-workdir "scp-to-kramerius" "dir_pointer"))
                  loc (-> (io/file scp-workdir "scp-to-kramerius" "request" (str uuid ".xml"))
                          io/input-stream
                          x/parse
                          zip/xml-zip)]
              (is (= "/monografie/01/02/aa-ofsdfasfs" dir_pointer))
              (is (= (str "file:///var/edeposit_originals/monografie/01/01-robotandbaby.pdf")
                     (zx/xml1-> loc :foxml:datastream [(zx/attr= :ID "IMG_FULL")] 
                                :foxml:datastreamVersion
                                :foxml:contentLocation (zx/attr :REF))))
              (is (= (str "file:///var/edeposit_archive" dir_pointer "/first-page/robotandbaby_001.jp2")
                     (zx/xml1-> loc :foxml:datastream [(zx/attr= :ID "IMG_PREVIEW")]
                                :foxml:datastreamVersion
                                :foxml:contentLocation (zx/attr :REF))))
              )
            )
          )
        )
      (fs/delete-dir workdir)
      )
    )
  )

(deftest scp-to-kramerius-test
  (testing "scp to kramerius test"
    (let     [local-now (lt/local-now)
              payload (slurp "resources/export-request.json")
              workdir (fs/temp-dir "test-export-to-kramerius-request-")]
      (h/save-request [[:no-metadata payload] workdir])
      (h/prepare-marcxml2mods-request workdir)
      (let [ metadata (-> (slurp "resources/communication-with-marcxml2mods/response/metadata.clj")
                          read-string
                          (update-in [:headers] assoc "UUID" (.toString workdir)))
            payload (slurp "resources/communication-with-marcxml2mods/response/payload.json")
            [mods mods-tmpdir] (-> [metadata payload]
                                   h/save-marcxml2mods-response
                                   h/parse-mods-files
                                   h/add-urnnbn-to-mods)
            [oai_dcs oai-tmpdir] (-> [mods mods-tmpdir] h/mods->oai_dcs)
            [_ _ request-workdir] (-> (h/make-package-with-foxml   [mods mods-tmpdir] 
                                                                   [oai_dcs oai-tmpdir] 
                                                                   workdir)
                                      h/make-zip-package
                                      h/prepare-request-for-export-to-storage)]
        (let [payload (.getBytes (slurp "resources/communication-with-storage/response/payload.bin"))
              metadata (-> (slurp "resources/communication-with-storage/response/metadata.clj")
                           read-string
                           (update-in [:headers] assoc "UUID" (.toString workdir)))]
          (let [ [scp-workdir] (-> (h/save-response-from-export-to-storage metadata payload)
                                   (h/prepare-scp-to-kramerius  :import-mount "/var/edeposit_import"
                                                                :archive-mount "/var/edeposit_archive"
                                                                :originals-mount "/var/edeposit_originals")
                                   (h/scp-to-kramerius {:scp (fn [from-path to-path] (str from-path
                                                                                         "->"
                                                                                         to-path))})
                                   )
                 uuid (slurp (io/file workdir "request" "payload" "uuid"))]
            (is (.exists (io/file scp-workdir)))
            (let [response-dir (io/file scp-workdir "scp-to-kramerius" "response")]
              (is (.exists response-dir))
              (is (.exists (io/file response-dir "result")))
              (is (.exists (io/file response-dir "sent")))
              (let [result (slurp (io/file response-dir "result"))]
                (is (re-find #"/var/edeposit_import" result ))
                (is (re-find #"->" result))
                (is (re-find #"scp-to-kramerius/request" result)))
              (let [sent (tc/from-string (slurp (io/file response-dir "sent")))]
                (is sent)
                (is (t/before? local-now sent))
                )
              )
            )
          )
        )
      (fs/delete-dir workdir)
      )
    )
  )


