Skip to content

Commit

Permalink
Added activator test for blended.updater to test status quo
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Jun 19, 2020
1 parent d9aa132 commit 1d42d83
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 6 deletions.
Expand Up @@ -18,16 +18,17 @@ class MgmtAgentActivatorSpec extends SimplePojoContainerSpec
with PojoSrTestHelper
with Matchers {

val akkaBundleName = classOf[BlendedAkkaActivator].getPackage().getName().replaceAll("[.]internal", "")
val bundleName = classOf[MgmtAgentActivator].getPackage().getName().replaceAll("[.]internal", "")

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

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

val bundleName = classOf[MgmtAgentActivator].getPackage().getName().replaceAll("[.]internal", "")

s"The ${bundleName}" - {
s"The bundle ${bundleName}" - {

"should register a MgmtReporter actor into the Akka system" in {
val actorSystem = mandatoryService[ActorSystem](registry, None)
Expand Down
Empty file.
@@ -0,0 +1,12 @@
package blended.launcher
import java.util.Properties

object TestBrandingPropsMutator {

def setBrandingProperties(properties: Map[String, String]) = {
val props = new Properties()
properties.foreach { case (k, v) => props.put(k, v) }
BrandingProperties.setLastBrandingProperties(props)
}

}
@@ -0,0 +1,65 @@
package blended.updater.internal

import java.io.File

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.Try

import akka.actor.{ActorSelection, ActorSystem}
import blended.akka.internal.BlendedAkkaActivator
import blended.launcher.TestBrandingPropsMutator
import blended.testsupport.BlendedTestSupport
import blended.testsupport.pojosr.{PojoSrTestHelper, SimplePojoContainerSpec}
import blended.testsupport.scalatest.LoggingFreeSpecLike
import blended.updater.config.Profile
import org.osgi.framework.BundleActivator

class BlendedUpdaterActivatorSpec extends SimplePojoContainerSpec with LoggingFreeSpecLike with PojoSrTestHelper {

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

val akkaBundleName = classOf[BlendedAkkaActivator].getPackage().getName().replaceAll("[.]internal", "")
val bundleName = classOf[BlendedUpdaterActivator].getPackage().getName().replaceAll("[.]internal", "")

override def bundles: Seq[(String, BundleActivator)] = Seq(
akkaBundleName -> new BlendedAkkaActivator()
// bundleName -> new BlendedUpdaterActivator()
)

s"The bundle ${bundleName}" - {
"in an non-updateable environment" - {
"should fail a bundle start" in {
val fail = withStartedBundle(registry)(bundleName, new BlendedUpdaterActivator()) { _ =>
Try { () }
}
assert(fail.isFailure)
}
}
"in an updateable environment" - {

"should register a bundle actor into the Akka system" in {
val actorSystem = mandatoryService[ActorSystem](registry, None)

val sel: ActorSelection = actorSystem.actorSelection(s"/user/${bundleName}")
val shouldFail = Await.ready(sel.resolveOne(1.second), 2.seconds)
assert(shouldFail.isCompleted && shouldFail.value.get.isFailure)

TestBrandingPropsMutator.setBrandingProperties(
Map(
Profile.Properties.PROFILE_NAME -> "test",
Profile.Properties.PROFILE_VERSION -> "1.0",
Profile.Properties.PROFILES_BASE_DIR -> (baseDir + "/profile")
))
val result = withStartedBundle(registry)(bundleName, new BlendedUpdaterActivator()) { _ =>
Try {
val sel: ActorSelection = actorSystem.actorSelection(s"/user/${bundleName}")
Await.result(sel.resolveOne(1.second), 2.seconds)
}
}
assert(result.isSuccess, s"But was: ${result}")
}
}
}

}
4 changes: 3 additions & 1 deletion build.sc
Expand Up @@ -1777,7 +1777,9 @@ class BlendedCross(crossScalaVersion: String) extends GenIdeaModule { blended =>
deps.mockitoAll
)}
override def moduleDeps: Seq[JavaModule] = super.moduleDeps ++ Seq(
blended.testsupport
blended.testsupport,
blended.testsupport.pojosr,
blended.akka
)
}

Expand Down

0 comments on commit 1d42d83

Please sign in to comment.