From 308a8f90cc66b033535aa4c5c2098bb5bfcb26ee Mon Sep 17 00:00:00 2001 From: Michael Hwang Date: Thu, 22 Feb 2018 19:05:02 -0500 Subject: Fix monkeypatching issue, use clj-fakes Change-Id: I8ae31c1b3dfff3096e4bfef709a8f0581d2e9a7c Issue-ID: DCAEGEN2-260 Signed-off-by: Michael Hwang --- pom.xml | 6 ++++++ project.clj | 3 +++ test/sch/core_test.clj | 9 ++++++--- test/sch/handle_test.clj | 41 +++++++++++++++++++++----------------- test/sch/inventory_client_test.clj | 17 +++++++++------- 5 files changed, 48 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index e40e352..bbabc27 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,12 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. clj-yaml 0.4.0 + + clj-fakes + clj-fakes + 0.9.0 + test + diff --git a/project.clj b/project.clj index 45976e5..3953da1 100644 --- a/project.clj +++ b/project.clj @@ -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"]] } } ) diff --git a/test/sch/core_test.clj b/test/sch/core_test.clj index e441343..958a0e6 100644 --- a/test/sch/core_test.clj +++ b/test/sch/core_test.clj @@ -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)) ) @@ -38,9 +39,11 @@ }]}] 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)))) ))) diff --git a/test/sch/handle_test.clj b/test/sch/handle_test.clj index 3ff0618..e986563 100644 --- a/test/sch/handle_test.clj +++ b/test/sch/handle_test.clj @@ -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]) ) @@ -45,10 +46,12 @@ 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 @@ -56,11 +59,12 @@ (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))))) ))) @@ -74,11 +78,11 @@ [{ :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))))) ))) @@ -87,9 +91,10 @@ 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))))) ))) diff --git a/test/sch/inventory_client_test.clj b/test/sch/inventory_client_test.clj index 86f369c..493a186 100644 --- a/test/sch/inventory_client_test.clj +++ b/test/sch/inventory_client_test.clj @@ -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]) ) @@ -42,9 +43,10 @@ {: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 {})))) ))) -- cgit 1.2.3-korg