|
1 | 1 | (ns cmr.ingest.api.subscriptions-test |
2 | 2 | (:require |
3 | | - [clojure.string :as string] |
4 | | - [clojure.test :refer :all] |
5 | | - [cmr.common.util :as util] |
6 | | - [cmr.ingest.api.subscriptions :as subscriptions] |
7 | | - [cmr.ingest.config :as ingest-config])) |
| 3 | + [clojure.string :as string] |
| 4 | + [clojure.test :refer :all] |
| 5 | + [cmr.common.util :as util] |
| 6 | + [cmr.ingest.api.subscriptions :as subscriptions])) |
8 | 7 |
|
9 | 8 | (deftest generate-native-id-test |
10 | 9 | (let [parsed {:Name "the_beginning" |
|
29 | 28 | "given method is search and endpoint not given -- endpoint ignored" |
30 | 29 | {:EndPoint "", :Method "search"} |
31 | 30 |
|
32 | | - "given method is ingest, env is local, and endpoint is sqs arn" |
| 31 | + "given method is ingest and sqs arn is valid" |
33 | 32 | {:EndPoint "arn:aws:sqs:us-east-1:000000000:Test-Queue", :Method "ingest"} |
34 | 33 |
|
35 | | - "given method is ingest, env is local, and url is non-local" |
36 | | - {:EndPoint "https://testwebsite.com", :Method "ingest"} |
37 | | - |
38 | | - "given method is ingest, env is local, url is local" |
39 | | - {:EndPoint "http://localhost:8080/localllllll", :Method "ingest"})) |
| 34 | + "given method is ingest and url is valid" |
| 35 | + {:EndPoint "https://testwebsite.com", :Method "ingest"})) |
40 | 36 |
|
41 | 37 | (testing "validate subscription endpoint str -- expected invalid" |
42 | | - (with-redefs [ingest-config/app-environment (fn [] "non-local")] |
43 | | - (let [fun #'cmr.ingest.api.subscriptions/validate-subscription-endpoint] |
44 | | - ;; given method is ingest, env is non-local and sqs arn -- throws error |
45 | | - (is (thrown? Exception (fun {:EndPoint "iaminvalidendpoint", :Method "ingest"}))) |
46 | | - |
47 | | - ;; given method is ingest, env is non-local and endpoint is empty -- throws error |
48 | | - (is (thrown? Exception (fun {:EndPoint "", :Method "ingest"}))) |
49 | | - |
50 | | - ;; ;; given method is ingest, env is non-local and endpoint is local endpoint -- throws error |
51 | | - (is (thrown? Exception (fun {:EndPoint "http://localhost:8080", :Method "ingest"}))))))) |
52 | | - |
53 | | -(deftest check-subscription-for-collection-not-already-exist-test |
54 | | - (let [fun #'cmr.ingest.api.subscriptions/check-endpoint-queue-for-collection-not-already-exist |
55 | | - context nil] |
56 | 38 | (util/are3 [subscription-concept] |
57 | | - (is (= nil (fun context subscription-concept))) |
58 | | - |
59 | | - "subscription concept not ingest type -- does nothing" |
60 | | - {:EndPoint "", :Method "search"} |
61 | | - |
62 | | - "subscription concept not sqs arn nor local queue arn -- does nothing" |
63 | | - {:EndPoint "http://www.something.com", :Method "ingest"}) |
64 | | - |
65 | | - (let [subscription-concept {:EndPoint "arn:aws:sqs:blahblah" :Method "ingest" :CollectionConceptId "C123-PROV1"} |
66 | | - returned-cache-content {:Mode {:Delete ["sqs1" "sqs2"], :New ["url1"], :Update ["url1"]}} |
67 | | - returned-cache-content-with-duplicates {:Mode {:Delete ["sqs1" "sqs2"], :New ["url1" "arn:aws:sqs:blahblah"], :Update ["url1"]}}] |
68 | | - |
69 | | - ;; method for getting cache-content returns error -- this method should bubble up that error |
70 | | - (with-redefs [cmr.transmit.metadata-db2/get-subscription-cache-content (fn [context collection-concept-id] (throw (Exception. "Exception was thrown from cache-content func")))] |
71 | | - (is (thrown? Exception (fun context subscription-concept)))) |
72 | | - |
73 | | - ;; returns nil cache-content -- does nothing |
74 | | - (with-redefs [cmr.transmit.metadata-db2/get-subscription-cache-content (fn [context collection-concept-id] nil)] |
75 | | - (is (nil? (fun context subscription-concept)))) |
| 39 | + (let [fun #'cmr.ingest.api.subscriptions/validate-subscription-endpoint] |
| 40 | + (is (thrown? Exception (fun subscription-concept)))) |
76 | 41 |
|
77 | | - ;; duplication collection to sqs queue not found -- does nothing |
78 | | - (with-redefs [cmr.transmit.metadata-db2/get-subscription-cache-content (fn [context collection-concept-id] returned-cache-content)] |
79 | | - (is (nil? (fun context subscription-concept)))) |
| 42 | + "given method is ingest and sqs arn is invalid" |
| 43 | + {:EndPoint "iaminvalidendpoint", :Method "ingest"} |
80 | 44 |
|
81 | | - ;; duplicate collection to sqs queue found -- throws error |
82 | | - (with-redefs [cmr.transmit.metadata-db2/get-subscription-cache-content (fn [context collection-concept-id] returned-cache-content-with-duplicates)] |
83 | | - (is (thrown? Exception (fun context subscription-concept))))))) |
| 45 | + "given method is ingest and endpoint is empty is invalid" |
| 46 | + {:Endpoint "", :Method "ingest"}))) |
0 commit comments