   "CMR Ingest revision validation integration tests"
   (:require
     [clojure.test :refer :all]
-    [cmr.system-int-test.utils.ingest-util :as ingest]
-    [cmr.system-int-test.data2.collection :as dc]
-    [cmr.ingest.services.messages :as msg]))
+    [cmr.ingest.services.messages :as msg]
+    [cmr.system-int-test.data2.umm-spec-collection :as data-umm-c]
+    [cmr.system-int-test.utils.ingest-util :as ingest]))
 
 (defn- assert-revision-conflict
   [concept-id format-str response]

(deftest revision-conflict-tests
  (testing "Update with lower revision id should be rejected 
            if it comes after an concept with a higher revision id"
    (let [concept (dc/collection-concept {:revision-id 4})
          concept-id (:concept-id (ingest/ingest-concept concept))
          response (ingest/ingest-concept (assoc concept :revision-id 2))]
      (assert-revision-conflict concept-id "Expected revision-id of [5] got [2] for [%s]" response)))

  (testing "Delete with lower revision id than latest concept should be rejected"
    (let [concept (dc/collection-concept {:revision-id 4})
          concept-id (:concept-id (ingest/ingest-concept concept))
          response (ingest/delete-concept concept {:revision-id 2})]
      (assert-revision-conflict concept-id "Expected revision-id of [5] got [2] for [%s]" response)))

  (testing "Ingest with lower revision id than latest tombstone should be rejected"
    (let [concept (dc/collection-concept {})
          concept-id (:concept-id (ingest/ingest-concept concept))
          _ (ingest/delete-concept concept {:revision-id 5})
          response (ingest/ingest-concept (assoc concept :revision-id 3))]
      (assert-revision-conflict concept-id "Expected revision-id of [6] got [3] for [%s]" response)))

  (testing "Delete with lower revision id than latest tombstone results in a 404"
    (let [concept (dc/collection-concept {})
          concept-id (:concept-id (ingest/ingest-concept concept))
          _ (ingest/delete-concept concept {:revision-id 5})
          {:keys [status errors]} (ingest/delete-concept concept {:revision-id 3})]

             response))))
 
  (testing "attempting to ingest using an non-integer revision id returns an error"
    (let [response (ingest/ingest-concept (data-umm-c/collection-concept {:EntryTitle "E2" :ShortName "S2" :concept-id "C2-PROV1"
                                                                  :revision-id "NaN"}))]
      (is (= {:status 422
              :errors [(msg/invalid-revision-id "NaN")]}
             response))))
  
  (testing "attempting to ingest using a negative revision id returns an error"
    (let [response (ingest/ingest-concept (data-umm-c/collection-concept {:EntryTitle "E3" :ShortName "S3" :concept-id "C2-PROV1"
                                                                  :revision-id "-1"}))]
      (is (= {:status 422
              :errors [(msg/invalid-revision-id "-1")]}
             response))))
  
  (testing "ingesting a concept with just the revision-id succeeds"
    (let [response (ingest/ingest-concept (data-umm-c/collection-concept {:EntryTitle "E4" :ShortName "S4" :revision-id "2"}))]
      (is (and (= 200 (:status response)) (= 2 (:revision-id response))))))
  
  (testing "ingesting a concept while skipping revision-ids succeeds, 
            but fails if revision id is smaller than the maximum revision id"
    (let [concept-id "C3-PROV1"
          coll (data-umm-c/collection-concept {:EntryTitle "E5" :ShortName "S5" :concept-id concept-id})
          _ (ingest/ingest-concept (assoc coll :revision-id "2"))
          response1 (ingest/ingest-concept (assoc coll :revision-id "6"))
          response2 (ingest/ingest-concept (assoc coll :revision-id "4"))]
