Skip to content

Commit

Permalink
spline #341 ArangoDatabaseFacade to set host and the default port pro…
Browse files Browse the repository at this point in the history
…perly
  • Loading branch information
wajda committed Sep 6, 2019
1 parent 10442ce commit d8a883c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import za.co.absa.spline.common.OptionImplicits.StringWrapper

import scala.util.matching.Regex

case class ArangoConnectionURL(user: Option[String], password: Option[String], host: String, port: Option[Int], dbName: String) {
case class ArangoConnectionURL(user: Option[String], password: Option[String], host: String, port: Int, dbName: String) {
require(user.isDefined || password.isEmpty, "user cannot be blank if password is specified")
}

object ArangoConnectionURL {

private val DefaultPort = 8529

private val arangoConnectionUrlRegex = {
val user = "([^@:]+)"
val password = "(.+)"
Expand All @@ -43,7 +45,7 @@ object ArangoConnectionURL {
user = user.nonBlankOption,
password = password.nonBlankOption,
host = host,
port = port.nonBlankOption.map(_.toInt),
port = port.nonBlankOption.map(_.toInt) getOrElse DefaultPort,
dbName = dbName
)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import za.co.absa.spline.common.OptionImplicits.AnyWrapper

class ArangoDatabaseFacade(connectionURL: ArangoConnectionURL) extends DisposableBean {

private val ArangoConnectionURL(maybeUser, maybePassword, host, maybePort, dbName) = connectionURL
private val ArangoConnectionURL(maybeUser, maybePassword, host, port, dbName) = connectionURL

private val arango: ArangoDBAsync = new ArangoDBAsync.Builder()
.registerModule(new VPackScalaModule)
.optionally(_.host(host, _: Int), maybePort)
.host(host, port)
.optionally(_.user(_: String), maybeUser)
.optionally(_.password(_: String), maybePassword)
.build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class ArangoConnectionURLSpec extends FlatSpec with Matchers {
it should "parse ArangoDB connection URL without port number" in {
val url = ArangoConnectionURL("arangodb://my.host.com/foo-bar_db")
url.host shouldEqual "my.host.com"
url.port shouldEqual 8529
url.dbName shouldEqual "foo-bar_db"
}

it should "parse ArangoDB connection URL with port number" in {
val url = ArangoConnectionURL("arangodb://my.host.com:1234/foo-bar_db")
url.host shouldEqual "my.host.com"
url.port shouldEqual Some(1234)
url.port shouldEqual 1234
url.dbName shouldEqual "foo-bar_db"
}

Expand Down

0 comments on commit d8a883c

Please sign in to comment.