Created
April 13, 2021 10:19
-
-
Save atooni/c308a6a274388a29403f80d7aa2b68d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ExploreSpec extends DefaultRunnableSpec { | |
val shopCfg = ShopConfig("cc", "09999", "A") | |
val solAdminUser = "admin" | |
val solAdminPwd = "admin123" | |
// Define all required docker containers in terms of ZLayer | |
val dockerLayer = | |
Blocking.live >>> ( | |
ApacheDS().layer ++ | |
SolaceJMS(solAdminUser, solAdminPwd).layer ++ | |
SagUM().layer ++ | |
Splunk().layer ++ | |
Shop().layer | |
) | |
val logLayer = Slf4jLogger.make((_, msg) => msg) | |
// Just get everything we need to talk to JMS | |
val jmsEnv = JmsApi.defaultJmsEnv(logLayer) | |
// Our final test environment | |
val testEnv = zio.test.environment.testEnvironment ++ logLayer ++ dockerLayer ++ jmsEnv | |
// make sure all containers are set up correctly before starting the real tests | |
override def spec = (suite("The Explorer Spec should")( | |
doSucceed @@ timeout(10.seconds) | |
) @@ timeout(3.minutes) @@ beforeAll(prepare())).provideCustomLayer(testEnv) | |
// The container under test must send a JMS message on startup identifying itself | |
private val doSucceed = testM("should work") { | |
for { | |
conMgr <- ZIO.service[JmsConnectionManager.Service] | |
cf <- Shop.shopAmq | |
env <- JmsEndpoint.make(cf, "ExploreSpec", JmsDestination.JmsQueue("startup")).use { ep => | |
for { | |
msg <- ep.nextEnvelope | |
} yield msg | |
} | |
// Get the apps log file from the docker filesystem for further inspection | |
_ <- getLogFile() | |
} yield { | |
val a1 = assert(env)(isSome) | |
val a2 = assert(env.get)(hasHeader("CountryId", shopCfg.country)) | |
val a3 = assert(env.get)(hasHeader("LocationId", shopCfg.location.takeRight(4))) | |
a1 && a2 && a3 | |
} | |
} | |
private def timeWarp = for { | |
_ <- | |
Live | |
.withLive(environment.TestClock.adjust(java.time.Duration.ofMillis(100)))( | |
_.repeat(Schedule.spaced(100.millis)) | |
) | |
} yield () | |
private def getLogFile() = for { | |
// Docker containers are accessible as services | |
ctShop <- ZIO.service[Shop] | |
_ = ctShop.copyFileFromContainer("/opt/sib.blended.shop_2.13/log/blended.log", "target/blended.log") | |
} yield () | |
private def prepare() = for { | |
_ <- log.info("Preparing test environment") | |
_ <- checkApacheDS() | |
_ <- prepareSolace() | |
_ <- prepareSagum() | |
_ <- log.info("Test environment prepared") | |
} yield () | |
private def checkApacheDS() = for { | |
conn <- ApacheDS.ldapConnection | |
_ <- LDAPAvailableCondition.checkLDAP(conn) | |
} yield () | |
private def prepareSolace() = | |
for { | |
_ <- timeWarp.fork | |
solMgmtConn <- | |
SolaceJMS.solaceAdminUrl.map(s => SolaceManagement.SolaceMgmtConnection(s, solAdminUser, solAdminPwd)) | |
solMgmt = new SolaceManagement(solMgmtConn) | |
_ <- SolaceConfigurator.configure("default", solMgmt, shopCfg) | |
} yield () | |
private def prepareSagum() = | |
for { | |
sagumCon <- SagUM.sagumUrl.map(s => SagumManagement.SagumConnection(s, "sib", Some("sib"))) | |
sagumMgmt = new SagumManagement(sagumCon) | |
_ <- SagConfigurator.configure(sagumMgmt, shopCfg, "nsp://sagum:29000") | |
} yield () | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment