        [(dc/psa {:name "bool" :data-type :boolean :value true})
         (dc/psa {:name "bool" :data-type :boolean :value true})]}
       ["AdditionalAttributes"]
-      ["Additional Attributes must be unique. This contains duplicates named [bool]."]))
+      ["Additional Attributes must be unique. This contains duplicates named [bool]."])) 
   (testing "Nested Path Validation"
     (assert-invalid
       {:platforms [(dc/platform {:instruments [(dc/instrument {:short-name "I1"})

    (assert-valid {:product-specific-attributes [(dc/psa {:name "bool1" :data-type :boolean :value true})
                                                 (dc/psa {:name "bool2" :data-type :boolean :value true})]}))

  (testing "Enabling UMM-C JSON-Schema validation through Cmr-Validate-Umm-C header being true"
    ;; create collection valid against echo10 but invalid against schema
    (let [response (d/ingest "PROV1" (dc/collection {:product-specific-attributes
                                                     [(dc/psa {:name "bool1" :data-type :boolean :value true})
                                                      (dc/psa {:name "bool2" :data-type :boolean :value true})]})
                             {:allow-failure? true :validate-umm-c true})]
      (is (= {:status 422
              :errors ["object has missing required properties ([\"ProcessingLevel\",\"RelatedUrls\",\"ScienceKeywords\",\"SpatialExtent\"])"]}
             (select-keys response [:status :errors]))))
    (assert-valid {:product-specific-attributes [(dc/psa {:name "bool1" :data-type :boolean :value true})
                                                 (dc/psa {:name "bool2" :data-type :boolean :value true})]}))
  (testing "Enabling UMM-C JSON-Schema validation through Cmr-Validate-Umm-C header being false"
    ;; create collection valid against echo10 but invalid against schema
    (let [response (d/ingest "PROV1" (dc/collection {:product-specific-attributes
                                                     [(dc/psa {:name "bool1" :data-type :boolean :value true})
                                                      (dc/psa {:name "bool2" :data-type :boolean :value true})]})
                             {:allow-failure? true :validate-umm-c false})]
      (is (= {:status 200}
             (select-keys response [:status :errors]))))
    (assert-valid {:product-specific-attributes [(dc/psa {:name "bool1" :data-type :boolean :value true})
                                                 (dc/psa {:name "bool2" :data-type :boolean :value true})]}))
  (testing "Enabling UMM-C JSON-Schema validation through Cmr-Validate-Umm-C header being absent"
    ;; create collection valid against echo10 but invalid against schema
    (let [response (d/ingest "PROV1" (dc/collection {:product-specific-attributes
                                                     [(dc/psa {:name "bool1" :data-type :boolean :value true})
                                                      (dc/psa {:name "bool2" :data-type :boolean :value true})]})
                             {:allow-failure? true})]
      (is (= {:status 200} 
             (select-keys response [:status :errors]))))
    (assert-valid {:product-specific-attributes [(dc/psa {:name "bool1" :data-type :boolean :value true})
                                                 (dc/psa {:name "bool2" :data-type :boolean :value true})]})) 
  
  (testing "Enabling UMM-Spec validation through Cmr-Validate-Umm-C header being true"
    ;; create a collection that's  valid against schema validation, but invalid against umm-spec validation
    (assert-invalid
      {:processing-level-id "1"
       :science-keywords [(dc/science-keyword {:category "upcase"
                                               :topic "Cool"
                                               :term "Mild"})]
       :spatial-coverage (dc/spatial {:gsr :cartesian})
       :related-urls [(dc/related-url {:type "type" :url "http://www.foo.com"})]
       :product-specific-attributes
       [(dc/psa {:name "bool" :data-type :boolean :value true})
        (dc/psa {:name "bool" :data-type :boolean :value true})]}
      ["AdditionalAttributes"]
      ["Additional Attributes must be unique. This contains duplicates named [bool]."]
      {:validate-umm-c true}))
  (testing "Enabling UMM-Spec validation through Cmr-Validate-Umm-C header being false"
    ;; create a collection that's  valid against schema validation, but invalid against umm-spec validation
    (assert-invalid
      {:processing-level-id "1"
       :science-keywords [(dc/science-keyword {:category "upcase"
                                               :topic "Cool"
                                               :term "Mild"})]
       :spatial-coverage (dc/spatial {:gsr :cartesian})
       :related-urls [(dc/related-url {:type "type" :url "http://www.foo.com"})]
       :product-specific-attributes
       [(dc/psa {:name "bool" :data-type :boolean :value true})
        (dc/psa {:name "bool" :data-type :boolean :value true})]}
      ["ProductSpecificAttributes"]
      ["Product Specific Attributes must be unique. This contains duplicates named [bool]."]
      {:validate-umm-c false}))
  (testing "Enabling UMM-Spec validation through Cmr-Validate-Umm-C header being absent"
    ;; create a collection that's  valid against schema validation, but invalid against umm-spec validation
    (assert-invalid
      {:processing-level-id "1"
       :science-keywords [(dc/science-keyword {:category "upcase"
                                               :topic "Cool"
                                               :term "Mild"})]
       :spatial-coverage (dc/spatial {:gsr :cartesian})
       :related-urls [(dc/related-url {:type "type" :url "http://www.foo.com"})]
       :product-specific-attributes
       [(dc/psa {:name "bool" :data-type :boolean :value true})
        (dc/psa {:name "bool" :data-type :boolean :value true})]}
      ["ProductSpecificAttributes"]
      ["Product Specific Attributes must be unique. This contains duplicates named [bool]."]))

  (side/eval-form `(icfg/set-return-umm-spec-validation-errors! true))


(ns cmr.system-int-test.ingest.collection-validation-test
  "CMR Ingest 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.system-int-test.data2.granule :as dg]
    [cmr.system-int-test.data2.core :as d]
    [cmr.common.mime-types :as mt]
    [cmr.umm.umm-collection :as c]
    [cmr.umm.umm-spatial :as umm-s]
    [cmr.common.util :refer [are2]]
    [cmr.common.util :as u :refer [are3]]
    [cmr.common-app.test.side-api :as side]
    [cmr.spatial.polygon :as poly]
    [cmr.spatial.point :as p]
    [cmr.spatial.line-string :as l]
    [cmr.spatial.mbr :as m]
    [cmr.ingest.config :as icfg]
    [cmr.ingest.services.messages :as msg]
    [cmr.common.mime-types :as mime-types]
    [cmr.system-int-test.utils.index-util :as index]
    [cmr.system-int-test.utils.search-util :as search]
    [clojure.java.io :as io]))

(use-fixtures :each (ingest/reset-fixture {"provguid1" "PROV1" "provguid2" "PROV2"}))

