Fix monkeypatching issue, use clj-fakes 49/32649/1
authorMichael Hwang <mhwang@research.att.com>
Fri, 23 Feb 2018 00:05:02 +0000 (19:05 -0500)
committerMichael Hwang <mhwang@research.att.com>
Fri, 23 Feb 2018 00:08:28 +0000 (19:08 -0500)
Change-Id: I8ae31c1b3dfff3096e4bfef709a8f0581d2e9a7c
Issue-ID: DCAEGEN2-260
Signed-off-by: Michael Hwang <mhwang@research.att.com>
pom.xml
project.clj
test/sch/core_test.clj
test/sch/handle_test.clj
test/sch/inventory_client_test.clj

diff --git a/pom.xml b/pom.xml
index e40e352..bbabc27 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -95,6 +95,12 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
             <artifactId>clj-yaml</artifactId>
             <version>0.4.0</version>
         </dependency>
+        <dependency>
+            <groupId>clj-fakes</groupId>
+            <artifactId>clj-fakes</artifactId>
+            <version>0.9.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
index 45976e5..3953da1 100644 (file)
@@ -37,5 +37,8 @@
   :repositories [["onap nexus" "https://nexus.onap.org/content/repositories/snapshots/"]]
 
   :plugins [[lein-cloverage "1.0.9"]]
+  :profiles { :test { :dependencies [[clj-fakes "0.9.0"]] }
+              ; Added this for cloverage
+              :dev { :dependencies [[clj-fakes "0.9.0"]] } }
 
   )
index e441343..958a0e6 100644 (file)
@@ -20,7 +20,8 @@
 
 (ns sch.core-test
   (:use (clojure test))
-  (:require [sch.core :refer [create-distribution-client-config deploy-artifacts-ex!]])
+  (:require [sch.core :refer [create-distribution-client-config deploy-artifacts-ex!]]
+            [clj-fakes.core :as f])
   (:import (org.openecomp.sdc.utils DistributionStatusEnum))
   )
 
                                           }]}]
           requests [{:asdcResourceId "123" :typeName "type-foo"}]
           deploy-artifacts (partial deploy-artifacts-echo requests [] [] [])
-          nada (intern 'sch.handle 'deploy-artifacts! deploy-artifacts)
           ]
-      (is (= nil (deploy-artifacts-ex! "http://inventory" service-metadata requests send-dist-status-only-ok)))
+      (f/with-fakes
+        (f/patch! #'sch.handle/deploy-artifacts! deploy-artifacts)
+        (is (= nil (deploy-artifacts-ex! "http://inventory" service-metadata requests
+                                         send-dist-status-only-ok))))
       )))
 
 
index 3ff0618..e986563 100644 (file)
@@ -21,7 +21,8 @@
 (ns sch.handle-test
   (:use (clojure test))
   (:require [cheshire.core :refer [parse-stream]]
-            [sch.handle :refer :all])
+            [sch.handle :refer :all]
+            [clj-fakes.core :as f])
   )
 
 
           service-type-requests [{:typeName "some-type" :asdcServiceId "abc"
                                   :asdcResourceId "123" :typeVersion 3}]
           fake-get-service-types-insert (partial fake-get-service-types {})
-          nada (intern 'sch.inventory-client 'get-service-types! fake-get-service-types-insert)]
-      (is (= service-type-requests (find-service-types-to-post "http://inventory"
-                                                               service-type-requests)))
-      )))
+          ]
+      (f/with-fakes
+        (f/patch! #'sch.inventory-client/get-service-types! fake-get-service-types-insert)
+        (is (= service-type-requests (find-service-types-to-post "http://inventory"
+                                                                 service-type-requests)))
+      ))))
 
 
 (deftest test-post-service-types
             (assoc request :typeId "123"))]
     (let [service-type-requests [{:typeName "some-type" :asdcServiceId "abc"
                                   :asdcResourceId "123" :typeVersion 3}]
-          post-service-types #'sch.handle/post-service-types!
-          nada (intern 'sch.inventory-client 'post-service-type! fake-post-service-type)]
-      (is (= {:typeId "123" :typeName "some-type" :asdcServiceId "abc"
-              :asdcResourceId "123" :typeVersion 3}
-             (first (post-service-types "http://inventory" service-type-requests))))
+          post-service-types #'sch.handle/post-service-types!]
+      (f/with-fakes
+        (f/patch! #'sch.inventory-client/post-service-type! fake-post-service-type)
+        (is (= {:typeId "123" :typeName "some-type" :asdcServiceId "abc"
+                :asdcResourceId "123" :typeVersion 3}
+               (first (post-service-types "http://inventory" service-type-requests)))))
       )))
 
 
                                                  [{ :typeName "some-type"
                                                    :asdcServiceId "abc"
                                                    :asdcResourceId "456"
-                                                   :typeVersion 3 }])
-          nada (intern 'sch.inventory-client 'get-service-types!
-                       fake-get-service-types-delete)]
-      (is (= 1 (count (find-service-types-to-delete "http://inventory" "abc"
-                                                    service-type-requests))))
+                                                   :typeVersion 3 }])]
+      (f/with-fakes
+        (f/patch! #'sch.inventory-client/get-service-types! fake-get-service-types-delete)
+        (is (= 1 (count (find-service-types-to-delete "http://inventory" "abc"
+                                                      service-type-requests)))))
       )))
 
 
             type-id)]
     (let [service-type-requests [{:typeId "def" :typeName "some-type"
                                   :asdcServiceId "abc" :asdcResourceId "123" :typeVersion 3}]
-          delete-service-types #'sch.handle/delete-service-types!
-          nada (intern 'sch.inventory-client 'delete-service-type! fake-delete-service-type)]
-      (is (= "def" (first (delete-service-types "http://inventory" service-type-requests))))
+          delete-service-types #'sch.handle/delete-service-types!]
+      (f/with-fakes
+        (f/patch! #'sch.inventory-client/delete-service-type! fake-delete-service-type)
+        (is (= "def" (first (delete-service-types "http://inventory" service-type-requests)))))
       )))
 
 
index 86f369c..493a186 100644 (file)
@@ -21,7 +21,8 @@
 (ns sch.inventory-client-test
   (:use (clojure test))
   (:require [sch.inventory-client :as ic]
-            [cheshire.core :refer [generate-string]])
+            [cheshire.core :refer [generate-string]]
+            [clj-fakes.core :as f])
   )
 
 
             {:status 200 :body result})]
     (let [results {:items [{:typeId "123"}]}
           conn (ic/create-inventory-conn "http://inventory")
-          fake-get-success (partial fake-get (generate-string results))
-          nada (intern 'clj-http.client 'get fake-get-success)]
-      (is (= (:items results) (ic/get-service-types! conn [])))
+          fake-get-success (partial fake-get (generate-string results))]
+      (f/with-fakes
+        (f/patch! #'clj-http.client/get fake-get-success)
+        (is (= (:items results) (ic/get-service-types! conn []))))
       )))
 
 
@@ -53,7 +55,8 @@
             {:status 200 :body result})]
     (let [result {:typeId "123"}
           conn (ic/create-inventory-conn "http://inventory")
-          fake-post-success (partial fake-post (generate-string result))
-          nada (intern 'clj-http.client 'post fake-post-success)]
-      (is (= result (ic/post-service-type! conn {})))
+          fake-post-success (partial fake-post (generate-string result))]
+      (f/with-fakes
+        (f/patch! #'clj-http.client/post fake-post-success)
+        (is (= result (ic/post-service-type! conn {}))))
       )))