forked from coursier/coursier
/
IvyParserTests.scala
49 lines (41 loc) · 1.39 KB
/
IvyParserTests.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package coursier.ivy
import java.io.File
import coursier.core._
import utest._
import java.nio.file.Files
import scala.util.Using
import scala.io.Source
import scala.util._
object IvyParserTests extends TestSuite {
val ivyXmlPath = Option(getClass.getResource("/sample-jackson-databind-ivy.xml"))
.map(u => new File(u.toURI).getAbsolutePath)
.getOrElse {
throw new Exception("sample-jackson-databind-ivy.xml resource not found")
}
val ivyXmlFile = new File(ivyXmlPath)
val result = Using(Source.fromFile(ivyXmlFile)) { bufferedSource =>
val contents = bufferedSource.getLines()
.map(line => s"$line\n")
.mkString
compatibility.xmlParse(contents)
} match {
case Failure(exception) => throw exception
case Success(Left(parseError)) => throw new IllegalArgumentException(parseError)
case Success(Right(xmlNode)) => xmlNode
}
val tests: Tests = Tests {
test("project can be parsed") {
val success = IvyXml.project(result)
assert(success.isRight)
}
test("licenses are available") {
val success = IvyXml.project(result)
assert(success.isRight)
val project = success.toOption.get
assert(project.info.licenseInfo.exists(license =>
license.name == "The Apache Software License, Version 2.0" &&
license.url == Some("http://www.apache.org/licenses/LICENSE-2.0.txt")
))
}
}
}