Skip to content

Commit 50f7154

Browse files
author
Fabrizio Di Giuseppe
committed
Merge branch 'projects/v0.0.2'
2 parents 373bd43 + 2717855 commit 50f7154

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

src/test/scala/sbtBom/BomBuilderSpec.scala

+37-34
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ import scala.xml.{Node, NodeSeq, PrettyPrinter}
1212
todo customize xml matching in the right way
1313
*/
1414
class BomBuilderSpec extends AnyWordSpec with Matchers {
15+
import BomBuilderSpec._
16+
1517
"bom" should {
1618
"have a root with all required properties" in {
1719
val rootWithoutContent = root.copy(child = Seq())
1820
rootWithoutContent shouldBeSameXml
1921
<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">
2426
</bom>
2527
}
2628

2729
"contains all library components" in {
28-
allComponents.foreach(
30+
allLibraryComponents.foreach(
2931
_.attribute("type").get.text shouldBe "library"
3032
)
31-
allComponents.size shouldBe 3
33+
allLibraryComponents.size shouldBe 3
3234
}
3335
}
3436

@@ -50,10 +52,9 @@ class BomBuilderSpec extends AnyWordSpec with Matchers {
5052
(jacksonComponent \ "modified").text shouldBe "false"
5153
}
5254

53-
// todo: produced hashes unexpectedly change
55+
// todo: review hash generation to avoid unpredictable values
5456
"have hashes properties" ignore {
5557
println(jacksonComponent \ "hashes")
56-
5758
jacksonComponent \ "hashes" shouldBeSameXml
5859
<hashes>
5960
<hash alg="MD5">7cb6cc60cda9078bcbe999e8cdf14205</hash>
@@ -78,7 +79,6 @@ class BomBuilderSpec extends AnyWordSpec with Matchers {
7879
</licenses>
7980
}
8081

81-
8282
"have two licenses with name" in {
8383
esapiComponent \ "licenses" shouldBeSameXml
8484
<licenses>
@@ -92,44 +92,47 @@ class BomBuilderSpec extends AnyWordSpec with Matchers {
9292
}
9393
}
9494

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"))
96112

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"))
98114

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+
))
103119

104120
private val printer = new PrettyPrinter(80, 2)
105121

106122
private val dependencies = model.Dependencies() :+ jackson :+ pivotal :+ esapi
107123
private val builder = new BomBuilder(dependencies)
108124
private val root = builder.build
109125

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)
114131

115132
private def getResourceFile(resourcePath: String) = {
116133
getClass.getResource(resourcePath) match {
117134
case null => None
118135
case url => Some(new File(url.getPath))
119136
}
120137
}
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

Comments
 (0)