|
| 1 | +(ns boot.pom-test |
| 2 | + (:require [boot.pom :as pom] |
| 3 | + [clojure.test :as test :refer [deftest is testing]] |
| 4 | + [clojure.zip :as zip] |
| 5 | + [clojure.data.xml :as dxml] |
| 6 | + [clojure.data.zip.xml :as dzxml])) |
| 7 | + |
| 8 | +(deftest pom-parent |
| 9 | + |
| 10 | + (testing "pom-xml-parse-string" |
| 11 | + (let [xml-str "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0\n https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n \n <parent>\n <groupId>org.codehaus.mojo</groupId>\n <artifactId>my-parent</artifactId>\n <version>2.0</version>\n <relativePath>../my-parent</relativePath>\n </parent>\n \n <artifactId>my-project</artifactId>\n</project>\n" |
| 12 | + {:keys [parent]} (pom/pom-xml-parse-string xml-str)] |
| 13 | + (is (= '[org.codehaus.mojo/my-parent "2.0"] (:dependency parent)) "The parent :dependency must exist and match the example") |
| 14 | + (is (= "../my-parent" (:relative-path parent)) "The parent :relative-path key must exist and match the example")) |
| 15 | + |
| 16 | + (let [xml-str "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0\n https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n \n <groupId>org.codehaus.mojo</groupId>\n <artifactId>my-parent</artifactId>\n <version>2.0</version>\n <packaging>pom</packaging>\n</project>" |
| 17 | + {:keys [parent]} (pom/pom-xml-parse-string xml-str)] |
| 18 | + (is (nil? parent) "The parent tag must not exist if missing in the pom")) |
| 19 | + |
| 20 | + (let [xml-str "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0\n https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n \n <parent>\n <artifactId>my-parent</artifactId>\n <version>2.0</version>\n </parent>\n \n <artifactId>my-project</artifactId>\n</project>\n" |
| 21 | + {:keys [parent]} (pom/pom-xml-parse-string xml-str)] |
| 22 | + (is (= '[my-parent "2.0"] (-> :dependency parent)) "The parent :dependency must exist and be just the artifactId of the example") |
| 23 | + (is (nil? (-> parent :dependency first namespace)) "The parent :dependency must exist but should not have the groupId as per example") |
| 24 | + (is (nil? (:relative-path parent)) "The parent :relative-path must be nil as it is not in the example")) |
| 25 | + |
| 26 | + ;; Edge case - parent tag is there but does not have artifactId |
| 27 | + (let [xml-str "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0\n https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n \n <parent>\n <groupId>org.codehaus.mojo</groupId>\n </parent>\n \n <artifactId>my-project</artifactId>\n</project>\n" |
| 28 | + {:keys [parent]} (pom/pom-xml-parse-string xml-str)] |
| 29 | + (is (nil? (-> :dependency parent)) "The parent :dependency should be nil if no artifactId is there"))) |
| 30 | + |
| 31 | + (testing "pom-xml :parent" |
| 32 | + (let [parent-loc (-> {:project 'group/my-plugin |
| 33 | + :version "1.2.0" |
| 34 | + :parent '[org.codehaus.mojo/my-parent "2.0"]} |
| 35 | + pom/pom-xml |
| 36 | + pr-str |
| 37 | + dxml/parse-str |
| 38 | + zip/xml-zip |
| 39 | + (dzxml/xml1-> :parent))] |
| 40 | + (is (not (nil? (dzxml/xml1-> parent-loc :groupId "org.codehaus.mojo"))) "I should contain a :groupId tag with correct content") |
| 41 | + (is (not (nil? (dzxml/xml1-> parent-loc :artifactId "my-parent"))) "It should contain a :artifactId tag with correct content") |
| 42 | + (is (not (nil? (dzxml/xml1-> parent-loc :version "2.0"))) "It should contain a :version tag with correct content")))) |
0 commit comments