             [cmr.umm.core :as umm]
             [cmr.umm.spatial :as umm-s]))
 
-(use-fixtures :each (ingest/reset-fixture {"provguid1" "PROV1"}))
+(use-fixtures :each (ingest/reset-fixture {"provguid1" "PROV1" "provguid2" "PROV2"}))
 
 (comment
 

    (testing "reference XML"
      (let [refs (search/find-refs :granule {:granule-ur "g1"})
            location (:location (first (:refs refs)))]
        (is (d/refs-match? [gran1] refs))

        (testing "Location allows granule native format retrieval"
          (let [response (client/get location
                                     {:accept :application/echo10+xml
                                      :connection-manager (url/conn-mgr)})]
            (is (= (umm/umm->xml gran1 :echo10) (:body response))))))

      (testing "as extension"
        (is (d/refs-match? [gran1] (search/find-refs :granule
                                                     {:granule-ur "g1"}
                                                     {:format-as-ext? true})))))))


(deftest search-granule-csv

  )

(deftest search-granules-in-xml-metadata
  (let [c1-echo (d/ingest "PROV1" (dc/collection) :echo10)
        c2-smap (d/ingest "PROV2" (dc/collection) :iso-smap)
        g1-echo (d/ingest "PROV1" (dg/granule c1-echo {:granule-ur "g1"
                                                       :producer-gran-id "p1"}) :echo10)
        g2-echo (d/ingest "PROV1" (dg/granule c1-echo {:granule-ur "g2"
                                                       :producer-gran-id "p2"}) :echo10)
        g1-smap (d/ingest "PROV2" (dg/granule c2-smap {:granule-ur "g3"
                                                       :producer-gran-id "p3"}) :iso-smap)
        g2-smap (d/ingest "PROV2" (dg/granule c2-smap {:granule-ur "g4"
                                                       :producer-gran-id "p2"}) :iso-smap)
        all-granules [g1-echo g2-echo g1-smap g2-smap]]
    (index/refresh-elastic-index)

    (testing "Finding refs ingested in different formats"
      (are [search expected]
           (d/refs-match? expected (search/find-refs :granule search))
           {} all-granules
           {:granule-ur "g1"} [g1-echo]
           {:granule-ur "g3"} [g1-smap]
           {:producer-granule-id "p1"} [g1-echo]
           {:producer-granule-id "p3"} [g1-smap]
           {:producer-granule-id "p2"} [g2-echo g2-smap]
           {:granule-ur ["g1" "g4"]} [g1-echo g2-smap]
           {:producer-granule-id ["p1" "p3"]} [g1-echo g1-smap]))

    (testing "Retrieving results in echo10"
      (d/assert-metadata-results-match
        :echo10 all-granules
        (search/find-metadata :granule :echo10 {}))
      (d/assert-metadata-results-match
        :echo10 [g1-echo]
        (search/find-metadata :granule :echo10 {:granule-ur "g1"}))
      (testing "as extension"
        (d/assert-metadata-results-match
          :echo10 [g1-echo]
          (search/find-metadata :granule :echo10
                                {:granule-ur "g1"}
                                {:format-as-ext? true}))))

    (testing "Retrieving results in SMAP ISO"
      (d/assert-metadata-results-match
        :iso-smap all-granules
        (search/find-metadata :granule :iso-smap {}))
      (d/assert-metadata-results-match
        :iso-smap [g1-echo]
        (search/find-metadata :granule :iso-smap {:granule-ur "g1"}))
      (testing "as extension"
        (d/assert-metadata-results-match
          :iso-smap [g1-echo]
          (search/find-metadata :granule :iso-smap
                                {:granule-ur "g1"}
                                {:format-as-ext? true}))))

