All Downloads are FREE. Search and download functionalities are using the official Maven repository.

blended.itestsupport.ldap.LDAPAvailableCondition.scala Maven / Gradle / Ivy

Go to download

Define an integration test API for collaborating blended container(s) using docker as a runtime for the container(s) under test and an Akka based Camel framework to perform the integration tests as pure blackbox tests. Container(s) may be prestarted and discovered (for execution speed) or started by the integration test (for reproducability).

The newest version!
package blended.itestsupport.ldap

import java.util
import java.util.concurrent.atomic.AtomicBoolean

import akka.actor.{ActorSystem, OneForOneStrategy, Props, SupervisorStrategy}
import blended.itestsupport.condition.{AsyncChecker, AsyncCondition}
import javax.naming.directory.InitialDirContext

import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration

object LDAPAvailableCondition {
  def apply(env: Map[String, String], t: Option[FiniteDuration])(implicit system: ActorSystem) =
    AsyncCondition(Props(LDAPChecker(env)), "LDAPAvailableCondition", t)
}

private[ldap] object LDAPChecker {
  def apply(env: Map[String,String]) = new LDAPChecker(env)
}

private[ldap] class LDAPChecker(env: Map[String, String]) extends AsyncChecker {

  var connected : AtomicBoolean = new AtomicBoolean(false)
  var connecting : AtomicBoolean = new AtomicBoolean(false)

  override def supervisorStrategy = OneForOneStrategy() {
    case _ => SupervisorStrategy.Stop
  }

  override def performCheck(condition: AsyncCondition): Future[Boolean] = {

    if (!connected.get() && !(connecting.get())) {
      connecting.set(true)

      val ldapEnv = new util.Hashtable[String, String]
      env.foreach{ case (k,v) => ldapEnv.put(k,v) }

      try {
        val ctxt = new InitialDirContext(ldapEnv)
        connected.set(true)
        ctxt.close()
      } catch {
        case _ : Throwable => connected.set(false)
      }

      connecting.set(false)
    }

    Future(connected.get())
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy