Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ingest-app/src/cmr/ingest/api/collections.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
(def VALIDATE_KEYWORDS_HEADER "cmr-validate-keywords")
(def ENABLE_UMM_C_VALIDATION_HEADER "cmr-validate-umm-c")
(def TESTING_EXISTING_ERRORS_HEADER "cmr-test-existing-errors")
(def SEND_KMS_METADATA_FIXER_HEADER "cmr-send-kms-metadata-fixer")
(def COLLECTION_WARNING_CONTEXT "After translating item to UMM-C the metadata had the following issue(s): ")
(def COLLECTION_EXISTING_ERROR_CONTEXT "After translating item to UMM-C the metadata had the following existing error(s): ")

Expand All @@ -28,7 +29,8 @@
(= "true" (get headers VALIDATE_KEYWORDS_HEADER)))]
{:validate-keywords? validate-keywords-value
:validate-umm? (= "true" (get headers ENABLE_UMM_C_VALIDATION_HEADER))
:test-existing-errors? (= "true" (get headers TESTING_EXISTING_ERRORS_HEADER))}))
:test-existing-errors? (= "true" (get headers TESTING_EXISTING_ERRORS_HEADER))
:send-metadata-fixer? (not= "false" (get headers SEND_KMS_METADATA_FIXER_HEADER))}))

(defn validate-collection
[provider-id native-id request]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
(common-context/context->user-id context)
"unknown user"))))
;; When a keyword error is detected but, ingest is alllowed send to kms fixer to resolve keyword
(when (should-notify-kms? has-keyword-error? existing-errors warnings)
(when (and (should-notify-kms? has-keyword-error? existing-errors warnings)
(:send-metadata-fixer? validation-options))
(transmit-kms/notify-kms context concept-id))
{:entry-title entry-title
:concept-id concept-id
Expand Down
143 changes: 143 additions & 0 deletions ingest-app/test/cmr/ingest/api/collections_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
(ns cmr.ingest.api.collections-test
"Unit tests for cmr.ingest.api.collections, starting with
get-validation-options. More tests for other functions in this
namespace can be added here over time."
(:require [clojure.test :refer [deftest testing is]]
[cmr.ingest.api.collections :as v :refer [get-validation-options
VALIDATE_KEYWORDS_HEADER
ENABLE_UMM_C_VALIDATION_HEADER
TESTING_EXISTING_ERRORS_HEADER
SEND_KMS_METADATA_FIXER_HEADER]]))

;; ---------------------------------------------------------------------
;; :validate-keywords? — default-true-enabled? = true
;; (only an explicit "false" header value turns validation off)
;; ---------------------------------------------------------------------
(deftest validate-keywords-default-true-enabled-true
(with-redefs [v/validate-keywords-default-true-enabled? true]
(testing "header explicitly \"false\" -> false"
(is (= false (:validate-keywords?
(get-validation-options {VALIDATE_KEYWORDS_HEADER "false"})))))

(testing "header explicitly \"true\" -> true"
(is (= true (:validate-keywords?
(get-validation-options {VALIDATE_KEYWORDS_HEADER "true"})))))

(testing "header missing -> true (defaults on)"
(is (= true (:validate-keywords?
(get-validation-options {})))))

(testing "header present but garbage value -> true (defaults on)"
(is (= true (:validate-keywords?
(get-validation-options {VALIDATE_KEYWORDS_HEADER "nope"})))))))

;; ---------------------------------------------------------------------
;; :validate-keywords? — default-true-enabled? = false
;; (must explicitly opt in with "true")
;; ---------------------------------------------------------------------
(deftest validate-keywords-default-true-enabled-false
(with-redefs [v/validate-keywords-default-true-enabled? false]
(testing "header explicitly \"true\" -> true"
(is (= true (:validate-keywords?
(get-validation-options {VALIDATE_KEYWORDS_HEADER "true"})))))

(testing "header explicitly \"false\" -> false"
(is (= false (:validate-keywords?
(get-validation-options {VALIDATE_KEYWORDS_HEADER "false"})))))

(testing "header missing -> false (defaults off)"
(is (= false (:validate-keywords?
(get-validation-options {})))))

(testing "header present but garbage value -> false (defaults off)"
(is (= false (:validate-keywords?
(get-validation-options {VALIDATE_KEYWORDS_HEADER "nope"})))))))

;; ---------------------------------------------------------------------
;; :validate-umm? — defaults to false, only "true" turns it on
;; ---------------------------------------------------------------------
(deftest validate-umm-test
(testing "header \"true\" -> true"
(is (= true (:validate-umm?
(get-validation-options {ENABLE_UMM_C_VALIDATION_HEADER "true"})))))

(testing "header missing -> false"
(is (= false (:validate-umm? (get-validation-options {})))))

(testing "header \"false\" -> false"
(is (= false (:validate-umm?
(get-validation-options {ENABLE_UMM_C_VALIDATION_HEADER "false"})))))

(testing "header garbage value -> false"
(is (= false (:validate-umm?
(get-validation-options {ENABLE_UMM_C_VALIDATION_HEADER "yes"}))))))

;; ---------------------------------------------------------------------
;; :test-existing-errors? — defaults to false, only "true" turns it on
;; ---------------------------------------------------------------------
(deftest test-existing-errors-test
(testing "header \"true\" -> true"
(is (= true (:test-existing-errors?
(get-validation-options {TESTING_EXISTING_ERRORS_HEADER "true"})))))

(testing "header missing -> false"
(is (= false (:test-existing-errors? (get-validation-options {})))))

(testing "header \"false\" -> false"
(is (= false (:test-existing-errors?
(get-validation-options {TESTING_EXISTING_ERRORS_HEADER "false"})))))

(testing "header garbage value -> false"
(is (= false (:test-existing-errors?
(get-validation-options {TESTING_EXISTING_ERRORS_HEADER "yes"}))))))

;; ---------------------------------------------------------------------
;; :send-metadata-fixer? — defaults to true, only explicit "false" turns it off
;; ---------------------------------------------------------------------
(deftest send-metadata-fixer-test
(testing "header missing -> true (defaults on)"
(is (= true (:send-metadata-fixer? (get-validation-options {})))))

(testing "header \"true\" -> true"
(is (= true (:send-metadata-fixer?
(get-validation-options {SEND_KMS_METADATA_FIXER_HEADER "true"})))))

(testing "header \"false\" -> false"
(is (= false (:send-metadata-fixer?
(get-validation-options {SEND_KMS_METADATA_FIXER_HEADER "false"})))))

(testing "header garbage value -> true (anything other than \"false\" is on)"
(is (= true (:send-metadata-fixer?
(get-validation-options {SEND_KMS_METADATA_FIXER_HEADER "nope"}))))))

;; ---------------------------------------------------------------------
;; Combination / full-map tests
;; ---------------------------------------------------------------------
(deftest get-validation-options-combined-test
(testing "empty headers map, default-true-enabled? true -> keywords on, rest off/on defaults"
(with-redefs [v/validate-keywords-default-true-enabled? true]
(is (= {:validate-keywords? true
:validate-umm? false
:test-existing-errors? false
:send-metadata-fixer? true}
(get-validation-options {})))))

(testing "empty headers map, default-true-enabled? false -> keywords off, rest off/on defaults"
(with-redefs [v/validate-keywords-default-true-enabled? false]
(is (= {:validate-keywords? false
:validate-umm? false
:test-existing-errors? false
:send-metadata-fixer? true}
(get-validation-options {})))))

(testing "all headers explicitly set"
(with-redefs [v/validate-keywords-default-true-enabled? true]
(is (= {:validate-keywords? false
:validate-umm? true
:test-existing-errors? true
:send-metadata-fixer? false}
(get-validation-options
{VALIDATE_KEYWORDS_HEADER "false"
ENABLE_UMM_C_VALIDATION_HEADER "true"
TESTING_EXISTING_ERRORS_HEADER "true"
SEND_KMS_METADATA_FIXER_HEADER "false"}))))))
Loading