Skip to content
Permalink
Browse files

Adding unit tests for some bundle Activators

  • Loading branch information...
atooni committed Mar 26, 2019
1 parent 0debd34 commit 464c3c45d5b7d736c3f0a0109f1254c76413a0cc
@@ -0,0 +1,37 @@
package blended.akka.http.jmsqueue

import java.io.File

import blended.activemq.brokerstarter.internal.BrokerActivator
import blended.akka.http.HttpContext
import blended.akka.http.internal.BlendedAkkaHttpActivator
import blended.akka.internal.BlendedAkkaActivator
import blended.testsupport.BlendedTestSupport
import blended.testsupport.pojosr.{PojoSrTestHelper, SimplePojoContainerSpec}
import blended.testsupport.scalatest.LoggingFreeSpecLike
import org.osgi.framework.BundleActivator

import scala.concurrent.duration._

class JmsQueueActivatorSpec extends SimplePojoContainerSpec
with LoggingFreeSpecLike
with PojoSrTestHelper {

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "container").getAbsolutePath()

override def bundles: Seq[(String, BundleActivator)] = Seq(
"blended.akka" -> new BlendedAkkaActivator(),
"blended.activemq.brokerstarter" -> new BrokerActivator(),
"blended.akka.http" -> new BlendedAkkaHttpActivator(),
"blended.akka.http.jmsqueue" -> new BlendedAkkaHttpJmsqueueActivator()
)

"The JmsQueueActivator" - {

"should register a webcontext for the configured destinations" in {

implicit val timeout : FiniteDuration = 3.seconds
mandatoryService[HttpContext](registry)(None)
}
}
}
@@ -0,0 +1,10 @@
blended.akka.http.proxy {

context: "sampleproxy"

paths {
heise {
uri : "http://heise.de"
}
}
}
@@ -1,5 +1,33 @@
package blended.akka.http.proxy

class ProxyActivatorSpec {
import java.io.File

import blended.akka.http.HttpContext
import blended.akka.internal.BlendedAkkaActivator
import blended.testsupport.BlendedTestSupport
import blended.testsupport.pojosr.{PojoSrTestHelper, SimplePojoContainerSpec}
import blended.testsupport.scalatest.LoggingFreeSpecLike
import org.osgi.framework.BundleActivator

import scala.concurrent.duration._

class ProxyActivatorSpec extends SimplePojoContainerSpec
with LoggingFreeSpecLike
with PojoSrTestHelper {

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "container").getAbsolutePath()

override def bundles: Seq[(String, BundleActivator)] = Seq(
"blended.akka" -> new BlendedAkkaActivator(),
"blended.akka.http.proxy" -> new BlendedAkkaHttpProxyActivator()
)

"The HTTP proxy activator" - {

"should register the proxy routes as Simple Http context services" in {

implicit val timeout : FiniteDuration = 3.seconds
mandatoryService[HttpContext](registry)(None)
}
}
}
@@ -35,7 +35,7 @@ class BlendedAkkaHttpActivator extends DominoActivator with ActorSystemWatching

val dynamicRoutes = new RouteProvider()

log.info(s"Starting HTTP server at ${httpHost}:${httpPort}")
log.info(s"Starting HTTP server at [$httpHost:$httpPort]")
val bindingFuture = Http().bindAndHandle(dynamicRoutes.dynamicRoute, httpHost, httpPort)

bindingFuture.onComplete {
@@ -47,14 +47,14 @@ class BlendedAkkaHttpActivator extends DominoActivator with ActorSystemWatching
}

onStop {
log.info(s"Stopping HTTP server at ${httpHost}:${httpPort}")
log.info(s"Stopping HTTP server at [$httpHost:$httpPort]")
bindingFuture.map(serverBinding => serverBinding.unbind())
}

log.debug("Listening for SSLContext registrations of type=server...")
whenAdvancedServicePresent[SSLContext]("(type=server)") { sslContext =>

log.info(s"Detected an server SSLContext. Starting HTTPS server at ${httpsHost}:${httpsPort}")
log.info(s"Detected an server SSLContext. Starting HTTPS server at [$httpsHost:$httpsPort]")

val https = ConnectionContext.https(sslContext)
val httpsBindingFuture = Http().bindAndHandle(
@@ -72,17 +72,13 @@ class BlendedAkkaHttpActivator extends DominoActivator with ActorSystemWatching
}

onStop {
log.info(s"Stopping HTTPS server at ${httpsHost}:${httpsPort}")
log.info(s"Stopping HTTPS server at [$httpsHost:$httpsPort]")
httpsBindingFuture.map(serverBinding => serverBinding.unbind())
}
}

// Consume routes from OSGi Service Registry (white-board pattern)
dynamicRoutes.dynamicAdapt(capsuleContext, bundleContext)

}
}

}


@@ -0,0 +1,30 @@
package blended.akka.http.internal

import java.io.File

import blended.akka.internal.BlendedAkkaActivator
import blended.testsupport.BlendedTestSupport
import blended.testsupport.pojosr.{PojoSrTestHelper, SimplePojoContainerSpec}
import blended.testsupport.scalatest.LoggingFreeSpecLike
import org.osgi.framework.BundleActivator
import org.scalatest.Matchers

class HttpActivatorSpec extends SimplePojoContainerSpec
with LoggingFreeSpecLike
with PojoSrTestHelper
with Matchers {

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "container").getAbsolutePath()

override def bundles: Seq[(String, BundleActivator)] = Seq(
("blended.akka" -> new BlendedAkkaActivator()),
("blended.akka.http" -> new BlendedAkkaHttpActivator())
)

"The Akka Http Activator should" - {

"start a HTTP server based on Akka HTTP" in {
pending
}
}
}

This file was deleted.

Oops, something went wrong.
No changes.
@@ -0,0 +1,36 @@
package blended.akka.internal

import java.io.File

import akka.actor.ActorSystem
import blended.testsupport.BlendedTestSupport
import blended.testsupport.pojosr.{PojoSrTestHelper, SimplePojoContainerSpec}
import blended.testsupport.scalatest.LoggingFreeSpecLike
import org.osgi.framework.BundleActivator
import org.scalatest.Matchers

import scala.concurrent.duration._

class AkkaActivatorSpec extends SimplePojoContainerSpec
with LoggingFreeSpecLike
with PojoSrTestHelper
with Matchers {


override def bundles: Seq[(String, BundleActivator)] = Seq(
("blended.akka" -> new BlendedAkkaActivator())
)

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "container").getAbsolutePath()

"The Akka activator" - {

"should register a container wide Actor system as a service" in {

implicit val timeout : FiniteDuration = 3.seconds
mandatoryService[ActorSystem](registry)(None)

}
}

}
@@ -0,0 +1,31 @@
package blended.jmx.internal

import java.io.File

import blended.testsupport.BlendedTestSupport
import blended.testsupport.pojosr.{PojoSrTestHelper, SimplePojoContainerSpec}
import blended.testsupport.scalatest.LoggingFreeSpecLike
import javax.management.MBeanServer
import org.osgi.framework.BundleActivator

import scala.concurrent.duration._

class JmxActivatorSpec extends SimplePojoContainerSpec
with LoggingFreeSpecLike
with PojoSrTestHelper {

override def bundles: Seq[(String, BundleActivator)] = Seq(
("blended.jmx" -> new BlendedJmxActivator())
)

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "container").getAbsolutePath()

"The JMX Activator" - {

"should expose the platform MBean Server as a service" in {

implicit val timeout : FiniteDuration = 3.seconds
mandatoryService[MBeanServer](registry)(None)
}
}
}
@@ -31,8 +31,8 @@ class CertificateActivatorSpec extends SimplePojoContainerSpec

"start up and provide a server and a client SSL Context" in {

val serverContext : SSLContext = mandatoryService[SSLContext](registry)(Some("(type=server)"))
val clientContext : SSLContext = mandatoryService[SSLContext](registry)(Some("(type=client)"))
mandatoryService[SSLContext](registry)(Some("(type=server)"))
mandatoryService[SSLContext](registry)(Some("(type=client)"))

val hasher = new PasswordHasher(pojoUuid)

@@ -49,9 +49,7 @@ class CertificateActivatorSpec extends SimplePojoContainerSpec
"Only support selected CypherSuites and protocols" in {

val sslInfo : blended.security.ssl.SslContextInfo = mandatoryService[blended.security.ssl.SslContextInfo](registry)(None)
val serverContext : SSLContext = mandatoryService[SSLContext](registry)(Some("(type=server)"))

val enabled : List[String] = sslInfo.getEnabledCypherSuites().toList
mandatoryService[SSLContext](registry)(Some("(type=server)"))

val invalid = sslInfo.getInvalidCypherSuites()
log.info(s"Invalid CypherSuites [${invalid.size}] : [\n${invalid.mkString("\n")}\n]")
@@ -37,6 +37,7 @@ object BlendedAkka extends ProjectFactory {
BlendedContainerContextApi.project,
BlendedDomino.project,

BlendedTestsupport.project % "test"
BlendedTestsupport.project % "test",
BlendedTestsupportPojosr.project % "test"
)
}
@@ -14,6 +14,8 @@ object BlendedAkkaHttpProxy extends ProjectFactory {
Dependencies.akkaSlf4j % "test",
Dependencies.akkaTestkit % "test",
Dependencies.scalatest % "test",
Dependencies.akkaTestkit % "test",
Dependencies.akkaStreamTestkit % "test",
Dependencies.akkaHttpTestkit % "test",
Dependencies.logbackCore % "test",
Dependencies.logbackClassic % "test"
@@ -27,6 +29,7 @@ object BlendedAkkaHttpProxy extends ProjectFactory {
BlendedAkkaHttp.project,
BlendedUtil.project,
BlendedUtilLogging.project,
BlendedTestsupport.project % "test",
BlendedTestsupportPojosr.project % "test"
)
}
@@ -1,3 +1,4 @@
import sbt._
import blended.sbt.Dependencies

object BlendedJmx extends ProjectFactory {
@@ -14,5 +15,8 @@ object BlendedJmx extends ProjectFactory {
)
)

override val project = helper.baseProject
override val project = helper.baseProject.dependsOn(
BlendedTestsupport.project % "test",
BlendedTestsupportPojosr.project % "test"
)
}

0 comments on commit 464c3c4

Please sign in to comment.
You can’t perform that action at this time.