From 7c322c3f93ece4007146906e93d85b380b4255dd Mon Sep 17 00:00:00 2001 From: jmaeng72 <44305062+jmaeng72@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:12:11 -0500 Subject: [PATCH] clean up --- .../src/cmr/ingest/api/subscriptions.clj | 2 +- .../metadata_db/services/concept_service.clj | 2 - .../metadata_db/services/subscriptions.clj | 176 ++------------ .../test/services/concept_service.clj | 37 --- .../test/services/subscriptions_test.clj | 216 +----------------- 5 files changed, 23 insertions(+), 410 deletions(-) diff --git a/ingest-app/src/cmr/ingest/api/subscriptions.clj b/ingest-app/src/cmr/ingest/api/subscriptions.clj index 360fa437f6..496b7cf5b3 100644 --- a/ingest-app/src/cmr/ingest/api/subscriptions.clj +++ b/ingest-app/src/cmr/ingest/api/subscriptions.clj @@ -333,7 +333,7 @@ parsed)] (when-not (= CMR_PROVIDER provider-id) (api-core/verify-provider-exists context provider-id)) - (validate-user-id context subscriber-id) ;; TODO temp comment out to bypass user id check + (validate-user-id context subscriber-id) (validate-query context parsed) (validate-subscription-endpoint parsed) (let [parsed-metadata (assoc parsed :SubscriberId subscriber-id)] diff --git a/metadata-db-app/src/cmr/metadata_db/services/concept_service.clj b/metadata-db-app/src/cmr/metadata_db/services/concept_service.clj index 95468bc9d4..a359fae0d3 100644 --- a/metadata-db-app/src/cmr/metadata_db/services/concept_service.clj +++ b/metadata-db-app/src/cmr/metadata_db/services/concept_service.clj @@ -889,8 +889,6 @@ context (ingest-events/associations-update-event associations)))))) -;; TODO jyna main concepts func -;; TODO jyna saving subscription or granule or any other concept falls to this func ;; false implies creation of a non-tombstone revision (defmethod save-concept-revision false [context concept] diff --git a/metadata-db-app/src/cmr/metadata_db/services/subscriptions.clj b/metadata-db-app/src/cmr/metadata_db/services/subscriptions.clj index 343d9a21f4..a0f50543f6 100644 --- a/metadata-db-app/src/cmr/metadata_db/services/subscriptions.clj +++ b/metadata-db-app/src/cmr/metadata_db/services/subscriptions.clj @@ -44,11 +44,13 @@ :concept-type :subscription :collection-concept-id coll-concept-id}))) +;;TODO unit test (defn convert-concept-to-edn "Converts the passed in concept to edn" [subscription] (update subscription :metadata #(json/decode % true))) +;; TODO unit test (defn convert-and-filter-subscriptions "Convert the metadata of the subscriptions to edn and then filter out the non ingest subscriptions." @@ -58,33 +60,6 @@ (= false (:deleted %))) subs))) -(defn add-to-existing-mode - "Depending on the passed in new-mode [\"New\" \"Update\"] create a structure that merges - the new mode to the existing mode. The result looks like [\"New\" \"Update\"]" - [existing-modes new-modes] - (loop [ms new-modes - result existing-modes] - (let [mode (first ms)] - (if (nil? mode) - result - (if result - (if (some #(= mode %) result) - (recur (rest ms) result) - (recur (rest ms) (merge result mode))) - (recur (rest ms) [mode])))))) - -;(defn merge-modes -; "Go through the list of subscriptions and combine the :modes found into one array. -; Return the array of modes." -; [subscriptions] -; (loop [subs subscriptions -; result []] -; (let [sub (first subs)] -; (if (nil? sub) -; result -; (recur (rest subs) (add-to-existing-mode result (get-in sub [:metadata :Mode]))))))) - - (use 'clojure.set) (defn create-mode-to-endpoints-map "Creates a mode-to-endpoints map given a list of subscriptions all for the same one collection. @@ -113,18 +88,6 @@ ) @final-map)) -;(defn change-subscription -; "When a subscription is added or deleted, the collection-concept-id must be put into -; or deleted from the subscription cache. Get the subscriptions that match the collection-concept-id -; from the database and rebuild the modes list. Return 1 if successful 0 otherwise." -; [context concept-edn] -; (let [coll-concept-id (:CollectionConceptId (:metadata concept-edn)) -; subs (convert-and-filter-subscriptions (get-subscriptions-from-db context coll-concept-id))] -; (if (seq subs) -; (subscription-cache/set-value context coll-concept-id (merge-modes subs)) -; (subscription-cache/remove-value context coll-concept-id)))) - - (defn change-subscription-in-cache "When a subscription is added or deleted, the collection-concept-id must be added or deleted from the subscription cache. Get the subscriptions that match the collection-concept-id from the database and rebuild the info map for this collection. @@ -143,7 +106,7 @@ (subscription-cache/remove-value context coll-concept-id)))) ;; -;; The functions below are for subscribing and unsubscribing and endpoint to the topic. +;; The functions below are for subscribing and unsubscribing an endpoint to the topic. ;; (defn add-or-delete-ingest-subscription-in-cache @@ -180,6 +143,7 @@ (some? (re-matches #"http://localhost:9324.*" endpoint)) false)) +;;TODO unit test this (defn attach-subscription-to-topic "If valid ingest subscription, will attach the subscription concept's sqs arn to external SNS topic and will add the sqs arn used as an extra field to the concept" @@ -195,6 +159,8 @@ concept)) concept))) + +;;TODO unit test this (defn set-subscription-arn-if-applicable "If subscription has an endpoint that is an SQS ARN, then it will attach the SQS ARN to the CMR SNS external topic and save the SQS ARN to the subscription concept. @@ -210,6 +176,7 @@ ;; and we don't consider that an error concept)) +;:TODO unit test (defn delete-ingest-subscription "Remove the subscription from the cache and unsubscribe the subscription from the topic if applicable. @@ -231,73 +198,6 @@ ;; The functions below are for refreshing the subscription cache if needed. ;; -;;TODO update this with new structure -;(defn create-subscription-cache-contents-for-refresh -; "Go through all the subscriptions and find the ones that are -; ingest subscriptions. Create the mode values for each collection-concept-id -; and put those into a map. The end result looks like: -; {Collection concept id 1: [\"New\" \"Update\"] -; Collection concept id 2: [\"New\" \"Update\" \"Delete\"] -; ...}" -; [result sub] -; (let [concept-edn (convert-concept-to-edn sub) -; metadata-edn (:metadata concept-edn)] -; (if (ingest-subscription-concept? concept-edn) -; (let [coll-concept-id (:CollectionConceptId metadata-edn) -; concept-map (result coll-concept-id) -; mode (:Mode metadata-edn)] -; (if concept-map -; (update result coll-concept-id #(add-to-existing-mode % mode)) -; (assoc result coll-concept-id (add-to-existing-mode nil mode)))) -; result))) - -;(defn create-subscription-cache-contents-for-refresh -; "Go through all the subscriptions and find the ones that are -; ingest subscriptions. Create the mode values for each collection-concept-id -; and put those into a map. The end result looks like: -; {Collection concept id 1: [\"New\" \"Update\"] -; Collection concept id 2: [\"New\" \"Update\" \"Delete\"] -; ...}" -; [subscriptions] -; (let [cache-map (atom {})] -; (doseq [sub subscriptions] -; (let [final-sub-map (atom {}) -; concept-edn (convert-concept-to-edn sub) -; metadata-edn (:metadata concept-edn)] -; (if (ingest-subscription-concept? concept-edn) -; (let [coll-concept-id (:CollectionConceptId metadata-edn) -; modes (:Mode metadata-edn) -; endpoint (:EndPoint metadata-edn)] -; (doseq [curr-mode modes] -; ;(let [curr-coll-sub-map (get-in @cache-map coll-concept-id)] -; (if final-sub-map -; ;;add to the existing cache-map -; (let [endpoint-set (get-in @final-sub-map curr-mode)] -; (if endpoint-set -; ;; create your own mode-to-endpoints-map and combine with the existing one -; ;(swap! final-sub-map (fn [n] (merge-with union mode-set {modes #{endpoint}}))) -; ;(swap! cache-map assoc coll-concept-id {"Mode" final-sub-map}) -; -; ;; create current map -; (conj endpoint-set endpoint) -; -; ) -; -; ) -; ;; else create new cache-map -; (swap! final-sub-map assoc curr-mode #{endpoint}) -; ;) -; ) -; -; ) -; ) -; ) -; ) -; ) -; @cache-map -; ) -; ) - (defn create-subscription-cache-contents-for-refresh "Go through all the subscriptions and find the ones that are ingest subscriptions. Create the mode values for each collection-concept-id @@ -312,13 +212,13 @@ ;; order the subscriptions by collection and create a map collection to subscriptions (doseq [sub subscriptions] ;(println "curr sub = " sub) - (let [metadata-edn (:metadata sub)] - (let [coll-concept-id (:CollectionConceptId metadata-edn) - sub-list (get @coll-to-subscription-concept-map coll-concept-id)] + (let [metadata-edn (:metadata sub) + coll-concept-id (:CollectionConceptId metadata-edn) + sub-list (get @coll-to-subscription-concept-map coll-concept-id)] ;(println "sub-list = " sub-list) (swap! coll-to-subscription-concept-map conj {coll-concept-id (conj sub-list sub)}) ;(println "curr coll-to-subscription-concept-map = " @coll-to-subscription-concept-map) - ))) + )) ;(println "coll-to-subscription-concept-map = " @coll-to-subscription-concept-map) ;;for every subscription list by the collection create a mode-to-endpoints-map and add it to the final cache map (doseq [[coll-id subscription-list] @coll-to-subscription-concept-map] @@ -328,8 +228,6 @@ (swap! cache-map assoc coll-id {"Mode" mode-to-endpoints-map}))) @cache-map)) - -;;TODO fix this. Refreshing cache requires for it to be the new structure. (defn refresh-subscription-cache "Go through all the subscriptions and create a map of collection concept ids and their mode values. Get the old keys from the cache and if the keys exist in the new structure @@ -337,8 +235,8 @@ [context] (when ingest-subscriptions-enabled? (info "Starting refreshing the ingest subscription cache.") - (let [subs (convert-and-filter-subscriptions (get-subscriptions-from-db context)) - new-contents (create-subscription-cache-contents-for-refresh subs) + (let [subscriptions-from-db (convert-and-filter-subscriptions (get-subscriptions-from-db context)) + new-contents (create-subscription-cache-contents-for-refresh subscriptions-from-db) ;_ (println "new-contents = " new-contents) cache-content-keys (subscription-cache/get-keys context)] ;; update the cache with the new values contained in the new-contents map. @@ -397,54 +295,6 @@ [mode] (str mode " Notification")) -;(defn create-attributes-and-subject-map -; "Determine based on the passed in concept if the granule is new, is an update -; or delete. Use the passed in mode to determine if any subscription is interested -; in a notification. If they are then return the message attributes and subject, otherwise -; return nil." -; [concept mode coll-concept-id] -; (cond -; ;; Mode = Delete. -; (and (:deleted concept) -; (some #(= "Delete" %) mode)) -; {:attributes (create-message-attributes coll-concept-id "Delete") -; :subject (create-message-subject "Delete")} -; -; ;; Mode = New -; (and (not (:deleted concept)) -; (= 1 (:revision-id concept)) -; (some #(= "New" %) mode)) -; {:attributes (create-message-attributes coll-concept-id "New") -; :subject (create-message-subject "New")} -; -; ;; Mode = Update -; (and (not (:deleted concept)) -; (pos? (compare (:revision-id concept) 1)) -; (some #(= "Update" %) mode)) -; {:attributes (create-message-attributes coll-concept-id "Update") -; :subject (create-message-subject "Update")})) - -;(defn publish-subscription-notification-if-applicable -; "Publish a notification to the topic if the passed-in concept is a granule -; and a subscription is interested in being informed of the granule's actions." -; [context concept] -; (when (granule-concept? (:concept-type concept)) -; (let [start (System/currentTimeMillis) -; coll-concept-id (:parent-collection-id (:extra-fields concept)) -; sub-cache-map (subscription-cache/get-value context coll-concept-id)] -; ;; if this granule's collection is found in subscription cache that means it has a subscription attached to it -; (when sub-cache-map -; ;; Check the mode to see if the granule notification needs to be pushed. Mode examples are 'new', 'update', 'delete'. -; (let [topic (get-in context [:system :sns :internal]) -; message (create-notification-message-body concept) -; ;; TODO Jyna will need to update this attributes and subject map for URL endpoints -; {:keys [attributes subject]} (create-attributes-and-subject-map concept sub-cache-map coll-concept-id)] -; (when (and attributes subject) -; (let [result (topic-protocol/publish topic message attributes subject) -; duration (- (System/currentTimeMillis) start)] -; (debug (format "Work potential subscription publish took %d ms." duration)) -; result))))))) - (defn- get-gran-concept-mode "Gets the granule concept's ingestion mode (i.e. Update, Delete, New, etc)" [concept] diff --git a/metadata-db-app/test/cmr/metadata_db/test/services/concept_service.clj b/metadata-db-app/test/cmr/metadata_db/test/services/concept_service.clj index b0a559d4d7..01945f2e40 100644 --- a/metadata-db-app/test/cmr/metadata_db/test/services/concept_service.clj +++ b/metadata-db-app/test/cmr/metadata_db/test/services/concept_service.clj @@ -254,40 +254,3 @@ "sets a collection concept id." (dissoc example-concept :concept-id))))) - -;(deftest set-subscription-arn-test -; (testing "set-subscription-arn" -; (are3 [concept-type concept expected] -; (is (= expected (cs/set-subscription-arn nil concept-type concept))) -; -; "non-subscription concept type returns un-changed concept" -; :granule -; {:metadata {:EndPoint ""}} -; {:metadata {:EndPoint ""}} -; -; "empty endpoint returns un-changed concept" -; :subscription -; {:metadata {:EndPoint ""}} -; {:metadata {:EndPoint ""}} -; -; "url endpoint returns un-changed concept" -; :subscription -; {:metadata {:EndPoint "https://www.endpoint.com"}} -; {:metadata {:EndPoint "https://www.endpoint.com"}})) -; (with-redefs [cmr.metadata-db.services.subscriptions/attach-subscription-to-topic (fn [context concept] "sqs:arn")] -; (testing "local test queue url endpoint returns changed concept" -; (let [concept {:metadata {:EndPoint "http://localhost:9324/000000000/"}} -; expected-concept {:metadata {:EndPoint "http://localhost:9324/000000000/"} :extra-fields {:aws-arn "sqs:arn"}}] -; (is (= expected-concept (cs/set-subscription-arn nil :subscription concept))))) -; -; (testing "sqs arn endpoint returns changed concept" -; (let [concept {:metadata {:EndPoint "arn:aws:sqs:1234:Queue-Name"}} -; expected-concept {:metadata {:EndPoint "arn:aws:sqs:1234:Queue-Name"} :extra-fields {:aws-arn "sqs:arn"}}] -; (is (= expected-concept (cs/set-subscription-arn nil :subscription concept))))))) - - - - - - - diff --git a/metadata-db-app/test/cmr/metadata_db/test/services/subscriptions_test.clj b/metadata-db-app/test/cmr/metadata_db/test/services/subscriptions_test.clj index 6a7d90d077..56d82a7ece 100644 --- a/metadata-db-app/test/cmr/metadata_db/test/services/subscriptions_test.clj +++ b/metadata-db-app/test/cmr/metadata_db/test/services/subscriptions_test.clj @@ -57,9 +57,9 @@ (is (= 1 (subscriptions/change-subscription-in-cache test-context {:concept-type :subscription :deleted false :metadata {:CollectionConceptId "C12345-PROV1" - :EndPoint "some-endpoint" - :Mode ["New"] - :Method "ingest"} + :EndPoint "some-endpoint" + :Mode ["New"] + :Method "ingest"} :extra-fields {:collection-concept-id "C12345-PROV1"}}))))) (testing "Delete a subscription from the cache" (with-bindings {#'subscriptions/get-subscriptions-from-db (fn [_context _coll-concept-id] '({:concept-type :subscription @@ -72,74 +72,16 @@ (is (= 1 (subscriptions/change-subscription-in-cache test-context {:concept-type :subscription :deleted true :metadata {:CollectionConceptId "C12345-PROV1" - :EndPoint "some-endpoint" - :Mode ["New"] - :Method "ingest"} + :EndPoint "some-endpoint" + :Mode ["New"] + :Method "ingest"} :extra-fields {:collection-concept-id "C12345-PROV1"}}))))) - (testing "Add-to-existing-mode" - (are3 - [expected existing-modes new-modes] - (is (= (set expected) - (set (subscriptions/add-to-existing-mode existing-modes new-modes)))) - - "new subscription with no existing modes in cache." - ["New" "Update" "Delete"] - nil - ["New" "Update" "Delete"] - - "new subscription with empty existing modes in cache." - ["Delete"] - [] - ["Delete"] - - "Adding new subscription with existing mode in cache of a different value." - ["Delete" "New"] - ["New"] - ["Delete"] - - "Adding new subscription with existing modes." - ["New" "Delete"] - ["New"] - ["New" "Delete"] - - "Adding duplicate subscription with existing modes." - ["New" "Delete"] - ["New" "Delete"] - ["New" "Delete"])) - - ;(testing "Merge modes" - ; (are3 - ; [expected subscriptions] - ; (is (= (set expected) (set (subscriptions/merge-modes subscriptions)))) - ; - ; "merge 1 mode." - ; ["Update"] - ; '({:metadata {:Mode ["Update"]}}) - ; - ; "Merge several modes" - ; ["New" "Update" "Delete"] - ; '({:metadata {:Mode ["Update"]}} - ; {:metadata {:Mode ["New"]}} - ; {:metadata {:Mode ["Delete"]}}) - ; - ; "Merge several modes 2" - ; ["New" "Update" "Delete"] - ; '({:metadata {:Mode ["Update"]}} - ; {:metadata {:Mode ["New" "Delete"]}}) - ; - ; "Merge several modes 3 with duplicates." - ; ["New" "Update" "Delete"] - ; '({:metadata {:Mode ["Update"]}} - ; {:metadata {:Mode ["New" "Delete"]}} - ; {:metadata {:Mode ["New"]}} - ; {:metadata {:Mode ["New" "Update"]}}))) (testing "adding and removing subscriptions from the cache." (are3 [expected example-record db-contents] (with-bindings {#'subscriptions/get-subscriptions-from-db (fn [_context _coll-concept-id] db-contents)} (subscriptions/change-subscription-in-cache test-context example-record) - ;(is (= expected (create-value-set (hash-cache/get-map cache-client cache-key))))) (is (= expected (hash-cache/get-map cache-client cache-key)))) @@ -245,7 +187,7 @@ \"EndPoint\":\"ARN\", \"Mode\":[\"New\", \"Delete\"], \"Method\":\"ingest\"}" - :concept-type :subscription})))))))) + :concept-type :subscription})))))))) (def db-result-1 '({:revision-id 1 @@ -468,53 +410,6 @@ (is (= "Delete Notification" (subscriptions/create-message-subject mode)))))) -;(deftest get-attributes-and-subject-test -; (testing "Getting notificaiton attributes and subject." -; (are3 -; ;;concept mode coll-concept-id -; [expected concept mode coll-concept-id] -; (is (= expected -; (subscriptions/create-attributes-and-subject-map concept mode coll-concept-id))) -; -; "Deleted concept" -; {:attributes {"collection-concept-id" "C12345-PROV1" -; "mode" "Delete"} -; :subject "Delete Notification"} -; {:deleted true} -; ["New" "Delete"] -; "C12345-PROV1" -; -; "Deleted concept, but not looking for the mode." -; nil -; {:deleted true} -; ["New" "Update"] -; "C12345-PROV1" -; -; "Deleted concept, but not looking for the mode, making sure no other condition is met." -; nil -; {:deleted true -; :revision-id 2} -; ["New" "Update"] -; "C12345-PROV1" -; -; "New concept." -; {:attributes {"collection-concept-id" "C12345-PROV1" -; "mode" "New"} -; :subject "New Notification"} -; {:deleted false -; :revision-id 1} -; ["New" "Update"] -; "C12345-PROV1" -; -; "Update concept." -; {:attributes {"collection-concept-id" "C12345-PROV1" -; "mode" "Update"} -; :subject "Update Notification"} -; {:deleted false -; :revision-id 3} -; ["New" "Update"] -; "C12345-PROV1"))) - (defn set-db-result "Sets the mock db result with a real queue endpoint to test real subscriptions and publishing of a message." @@ -654,10 +549,7 @@ messages (queue/receive-messages sqs-client internal-queue-url)] (is (some? messages)) (when messages - (is (some? (queue/delete-messages sqs-client internal-queue-url messages))))) - ) - ) - ) + (is (some? (queue/delete-messages sqs-client internal-queue-url messages)))))))) (testing "Concept will be unsubscribed." (with-bindings {#'subscriptions/get-subscriptions-from-db (fn [_context _coll-concept-id] (conj '() (-> (first (set-db-result queue-url)) @@ -669,8 +561,7 @@ (is (= (:concept-id sub-concept) (subscriptions/delete-ingest-subscription test-context sub-concept))) ;; Also remove subscription from internal queue. (let [topic (get-in test-context [:system :sns :internal])] - (topic-protocol/unsubscribe topic sub-concept))))) - )) + (topic-protocol/unsubscribe topic sub-concept))))))) (defn work-potential-notification-with-real-aws "This function exists to manually test out the same code as @@ -732,37 +623,6 @@ (is (= '(:concept-id :granule-ur :producer-granule-id :location) (keys real-message))) (is (some? (queue/delete-messages sqs-client internal-queue-url messages)))))))))) -;(deftest set-subscription-arn-if-applicable-test -; (testing "set-subscription-arn returns un-changed concept" -; (are3 [concept-type concept expected] -; (is (= expected (subscriptions/set-subscription-arn-if-applicable nil concept-type concept))) -; -; "non-subscription concept type returns un-changed concept" -; :granule -; {:metadata {:EndPoint ""}} -; {:metadata {:EndPoint ""}} -; -; "empty endpoint returns un-changed concept" -; :subscription -; {:metadata (json/encode {:EndPoint ""})} -; {:metadata (json/encode {:EndPoint ""})})) -; (with-redefs [cmr.metadata-db.services.subscriptions/attach-subscription-to-topic (fn [context concept] {:metadata (json/encode {"EndPoint" "http://localhost:9324/000000000/"}) :extra-fields {:aws-arn "SUB1234"}})] -; (testing "local test queue url endpoint returns changed concept" -; (let [concept {:metadata (json/encode {"EndPoint" "http://localhost:9324/000000000/"})} -; expected-concept {:metadata (json/encode {"EndPoint" "http://localhost:9324/000000000/"}) :extra-fields {:aws-arn "SUB1234"}}] -; (is (= expected-concept (subscriptions/set-subscription-arn-if-applicable nil :subscription concept))))) -; -; (testing "http endpoint returns changed concept" -; (let [concept {:metadata (json/encode {"EndPoint" "http://www.endpoint.com"})} -; expected-concept {:metadata (json/encode {"EndPoint" "http://www.endpoint.com"}) :extra-fields {:aws-arn "http://www.endpoint.com"}}] -; (is (= expected-concept (subscriptions/set-subscription-arn-if-applicable nil :subscription concept)))))) -; -; (with-redefs [cmr.metadata-db.services.subscriptions/attach-subscription-to-topic (fn [context concept] {:metadata (json/encode {"EndPoint" "arn:aws:sqs:1234:Queue-Name"}) :extra-fields {:aws-arn "sqs:arn"}})] -; (testing "sqs arn endpoint returns changed concept" -; (let [concept {:metadata (json/encode {:EndPoint "arn:aws:sqs:1234:Queue-Name"})} -; expected-concept {:metadata (json/encode {"EndPoint" "arn:aws:sqs:1234:Queue-Name"}) :extra-fields {:aws-arn "sqs:arn"}}] -; (is (= expected-concept (subscriptions/set-subscription-arn-if-applicable nil :subscription concept))))))) - (deftest is-valid-sqs-arn-test (testing "sqs endpoint validation for subscription endpoint" (are3 [endpoint expected] @@ -864,64 +724,6 @@ false ))) -;(deftest attach-subscription-to-topic-test -; (with-redefs [cmr.message-queue.topic.topic-protocol/subscribe (fn [topic concept] "subscription-arn")] -; (testing "concept is not ingest subscription - returns un-changed concept" -; (let [concept {:metadata (json/encode {:Method "search"})}] -; (is (= concept (subscriptions/attach-subscription-to-topic {:system {:sns {:external "default-topic"}}} concept))))) -; (testing "subscribing to topic succeeded -- returns updated concept with new aws-arn field" -; (let [concept {:metadata (json/encode {:Method "ingest" :EndPoint "arn:aws:sqs:1234:Queue-Name"})} -; expected-concept {:metadata (json/encode {:Method "ingest" :EndPoint "arn:aws:sqs:1234:Queue-Name"}) -; :extra-fields {:aws-arn "subscription-arn"}}] -; (is (= expected-concept (subscriptions/attach-subscription-to-topic {:system {:sns {:external "default-topic"}}} concept)))))) -; (with-redefs [cmr.message-queue.topic.topic-protocol/subscribe (fn [topic concept] nil)] -; (testing "subscribing to topic returned nil - returns un-changed concept" -; (let [concept {:metadata (json/encode {:Method "ingest" :EndPoint "arn:aws:sqs:1234:Queue-Name"})}] -; (is (= concept (subscriptions/attach-subscription-to-topic {:system {:sns {:external "default-topic"}}} concept)))))) -; (with-redefs [cmr.message-queue.topic.topic-protocol/subscribe (fn [topic concept] (throw (Exception. "some exception")))] -; (testing "subscribing to topic failed and threw error - returns un-changed concept" -; (let [concept {:metadata (json/encode {:Method "ingest" :EndPoint "arn:aws:sqs:1234:Queue-Name"})}] -; (is (= concept (subscriptions/attach-subscription-to-topic {:system {:sns {:external "default-topic"}}} concept))))))) -; -;;;TODO fix this test -;(deftest delete-ingest-subscription-test -; (let [context {:system {:sns {:external "default-topic"}}} -; expected-subscription-arn "subscription-arn"] -; (with-redefs [cmr.message-queue.topic.topic-protocol/unsubscribe (fn [topic concept] expected-subscription-arn)] -; (testing "is valid sqs arn" -; (let [concept {:metadata (json/encode {:Method "ingest" :EndPoint "arn:aws:sqs:1234:Queue-Name"}) -; :extra-fields {:aws-arn "subscription-arn"}} -; concept-edn {:metadata {:Method "ingest" :EndPoint "arn:aws:sqs:1234:Queue-Name"} -; :extra-fields {:aws-arn "subscription-arn"}}] -; (with-redefs [cmr.metadata-db.services.subscriptions/add-or-delete-ingest-subscription-in-cache (fn [context concept] concept-edn)] -; (is (= expected-subscription-arn (subscriptions/delete-ingest-subscription context concept))) -; ))) -; (testing "is local test queue" -; (let [concept {:metadata (json/encode {:Method "ingest" :EndPoint "http://localhost:9324/000000000/test-queue"}) -; :extra-fields {:aws-arn "subscription-arn"}} -; concept-edn {:metadata {:Method "ingest" :EndPoint "http://localhost:9324/000000000/test-queue"} -; :extra-fields {:aws-arn "subscription-arn"}}] -; (with-redefs [cmr.metadata-db.services.subscriptions/add-or-delete-ingest-subscription-in-cache (fn [context concept] concept-edn)] -; (is (= expected-subscription-arn (subscriptions/delete-ingest-subscription context concept)))))) -; (testing "is valid http url" -; (let [concept {:metadata (json/encode {:Method "ingest" :EndPoint "http://www.endpoint.com"}) -; :extra-fields {:aws-arn "http://www.endpoint.com"}} -; concept-edn {:metadata {:Method "ingest" :EndPoint "http://www.endpoint.com"} -; :extra-fields {:aws-arn "http://www.endpoint.com"}}] -; (with-redefs [cmr.metadata-db.services.subscriptions/add-or-delete-ingest-subscription-in-cache (fn [context concept] concept-edn)] -; (is (= "http://www.endpoint.com" (subscriptions/delete-ingest-subscription context concept)))))) -; (testing "is invalid endpoint" -; (let [concept {:metadata (json/encode {:Method "ingest" :EndPoint "random"}) :extra-fields {:aws-arn "random"}} -; concept-edn {:metadata {:Method "ingest" :EndPoint "random"} :extra-fields {:aws-arn "random"}}] -; (with-redefs [cmr.metadata-db.services.subscriptions/add-or-delete-ingest-subscription-in-cache (fn [context concept] concept-edn)] -; (is (= "random" (subscriptions/delete-ingest-subscription context concept)))))) -; (testing "non-ingest subscription concept given" -; (let [concept {:metadata (json/encode {:Method "search"})} -; concept-edn {:metadata {:Method "search"}}] -; (with-redefs [cmr.metadata-db.services.subscriptions/add-or-delete-ingest-subscription-in-cache (fn [context concept] concept-edn)] -; (is (= nil (subscriptions/delete-ingest-subscription context concept)))))) -; ))) - (deftest create-mode-to-endpoints-map (testing "creating mode to endpoints map test" (are3 [subscriptions expected]