@@ -12,23 +12,25 @@ import scala.xml.{Node, NodeSeq, PrettyPrinter}
12
12
todo customize xml matching in the right way
13
13
*/
14
14
class BomBuilderSpec extends AnyWordSpec with Matchers {
15
+ import BomBuilderSpec ._
16
+
15
17
" bom" should {
16
18
" have a root with all required properties" in {
17
19
val rootWithoutContent = root.copy(child = Seq ())
18
20
rootWithoutContent shouldBeSameXml
19
21
< bom
20
- xmlns= " http://cyclonedx.org/schema/bom/1.0"
21
- xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance"
22
- version= " 1"
23
- xsi: schemaLocation= " http://cyclonedx.org/schema/bom/1.0 http://cyclonedx.org/schema/bom/1.0" >
22
+ xmlns= " http://cyclonedx.org/schema/bom/1.0"
23
+ xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance"
24
+ version= " 1"
25
+ xsi: schemaLocation= " http://cyclonedx.org/schema/bom/1.0 http://cyclonedx.org/schema/bom/1.0" >
24
26
</bom >
25
27
}
26
28
27
29
" contains all library components" in {
28
- allComponents .foreach(
30
+ allLibraryComponents .foreach(
29
31
_.attribute(" type" ).get.text shouldBe " library"
30
32
)
31
- allComponents .size shouldBe 3
33
+ allLibraryComponents .size shouldBe 3
32
34
}
33
35
}
34
36
@@ -50,10 +52,9 @@ class BomBuilderSpec extends AnyWordSpec with Matchers {
50
52
(jacksonComponent \ " modified" ).text shouldBe " false"
51
53
}
52
54
53
- // todo: produced hashes unexpectedly change
55
+ // todo: review hash generation to avoid unpredictable values
54
56
" have hashes properties" ignore {
55
57
println(jacksonComponent \ " hashes" )
56
-
57
58
jacksonComponent \ " hashes" shouldBeSameXml
58
59
<hashes >
59
60
<hash alg =" MD5" >7cb6cc60cda9078bcbe999e8cdf14205</hash >
@@ -78,7 +79,6 @@ class BomBuilderSpec extends AnyWordSpec with Matchers {
78
79
</licenses >
79
80
}
80
81
81
-
82
82
" have two licenses with name" in {
83
83
esapiComponent \ " licenses" shouldBeSameXml
84
84
<licenses >
@@ -92,44 +92,47 @@ class BomBuilderSpec extends AnyWordSpec with Matchers {
92
92
}
93
93
}
94
94
95
- val jackson = model.Dependency (group = " org.codehaus.jackson" , name = " jackson-jaxrs" , version = " 1.9.13" , modified = false , file = getResourceFile(" /jackson.txt" ))
95
+ import scala .xml .Utility .trim
96
+
97
+ implicit class ElemShouldWrapper (node : Node ) {
98
+ def shouldBeSameXml (that : Node ): Assertion =
99
+ printer.format(trim(node)) shouldBe printer.format(trim(that))
100
+ }
101
+
102
+ implicit class ElemSeqShouldWrapper (ns : NodeSeq ) {
103
+ def shouldBeSameXml (that : Node ): Assertion = {
104
+ ns.size shouldBe 1
105
+ printer.format(trim(ns.head)) shouldBe printer.format(trim(that))
106
+ }
107
+ }
108
+ }
109
+
110
+ object BomBuilderSpec {
111
+ private val jackson = model.Dependency (group = " org.codehaus.jackson" , name = " jackson-jaxrs" , version = " 1.9.13" , modified = false , file = getResourceFile(" /jackson.txt" ))
96
112
97
- val pivotal = model.Dependency (group = " org.springframework.boot" , name = " spring-boot-legacy" , version = " 1.0.1.RELEASE" , modified = true , licenses = Seq (License (id = Some (" Apache-2.0" ), name = Some (" Apache 2.0" ))), file = getResourceFile(" /pivotal.txt" ))
113
+ private val pivotal = model.Dependency (group = " org.springframework.boot" , name = " spring-boot-legacy" , version = " 1.0.1.RELEASE" , modified = true , licenses = Seq (License (id = Some (" Apache-2.0" ), name = Some (" Apache 2.0" ))), file = getResourceFile(" /pivotal.txt" ))
98
114
99
- val esapi = model.Dependency (group = " org.owasp.esapi" , name = " esapi" , version = " 2.0GA" , modified = false , licenses = Seq (
100
- License (name = Some (" BSD" )),
101
- License (name = Some (" Creative Commons 3.0 BY-SA" )),
102
- ))
115
+ private val esapi = model.Dependency (group = " org.owasp.esapi" , name = " esapi" , version = " 2.0GA" , modified = false , licenses = Seq (
116
+ License (name = Some (" BSD" )),
117
+ License (name = Some (" Creative Commons 3.0 BY-SA" )),
118
+ ))
103
119
104
120
private val printer = new PrettyPrinter (80 , 2 )
105
121
106
122
private val dependencies = model.Dependencies () :+ jackson :+ pivotal :+ esapi
107
123
private val builder = new BomBuilder (dependencies)
108
124
private val root = builder.build
109
125
110
- private val allComponents = root \ " components" \ " component"
111
- private val jacksonComponent = allComponents.head
112
- private val pivotalComponent = allComponents(1 )
113
- private val esapiComponent = allComponents(2 )
126
+ private val allLibraryComponents = root \ " components" \ " component"
127
+
128
+ private val jacksonComponent = allLibraryComponents.head
129
+ private val pivotalComponent = allLibraryComponents(1 )
130
+ private val esapiComponent = allLibraryComponents(2 )
114
131
115
132
private def getResourceFile (resourcePath : String ) = {
116
133
getClass.getResource(resourcePath) match {
117
134
case null => None
118
135
case url => Some (new File (url.getPath))
119
136
}
120
137
}
121
-
122
- import scala .xml .Utility .trim
123
-
124
- implicit class ElemShouldWrapper (node : Node ) {
125
- def shouldBeSameXml (that : Node ): Assertion =
126
- printer.format(trim(node)) shouldBe printer.format(trim(that))
127
- }
128
-
129
- implicit class ElemSeqShouldWrapper (ns : NodeSeq ) {
130
- def shouldBeSameXml (that : Node ): Assertion = {
131
- ns.size shouldBe 1
132
- printer.format(trim(ns.head)) shouldBe printer.format(trim(that))
133
- }
134
- }
135
- }
138
+ }
0 commit comments