- fix tests
This commit is contained in:
parent
1968756f73
commit
54bd2acf99
@ -25,6 +25,7 @@ case class GroupChats(chats: collection.immutable.Map[String, GroupChat]) {
|
||||
case class GroupChat(id: String, name: String, access: String, createdBy: GroupChatUser,
|
||||
users: Vector[GroupChatUser],
|
||||
msgs: Vector[GroupChatMessage]) {
|
||||
def findMsgWithId(id: String): Option[GroupChatMessage] = msgs.find(m => m.id == id)
|
||||
def add(user: GroupChatUser): GroupChat = copy(users = users :+ user)
|
||||
def remove(userId: String): GroupChat = copy(users = users.filterNot(u => u.id == userId))
|
||||
def add(msg: GroupChatMessage): GroupChat = copy(msgs = msgs :+ msg)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.bigbluebutton.core.models
|
||||
|
||||
import org.bigbluebutton.core.{ UnitSpec }
|
||||
import org.bigbluebutton.common2.msgs.{ GroupChatAccess, GroupChatUser }
|
||||
import org.bigbluebutton.core.UnitSpec
|
||||
import org.bigbluebutton.core.domain.BbbSystemConst
|
||||
|
||||
class GroupsChatTests extends UnitSpec {
|
||||
|
||||
@ -8,8 +10,8 @@ class GroupsChatTests extends UnitSpec {
|
||||
val gcId = "gc-id"
|
||||
val chatName = "Public"
|
||||
val userId = "uid-1"
|
||||
|
||||
val gc = GroupChatFactory.create(gcId, chatName, open = true, userId)
|
||||
val createBy = GroupChatUser(BbbSystemConst.SYSTEM_USER, BbbSystemConst.SYSTEM_USER)
|
||||
val gc = GroupChatFactory.create(gcId, chatName, GroupChatAccess.PUBLIC, createBy, Vector.empty, Vector.empty)
|
||||
val user = GroupChatUser(userId, "User 1")
|
||||
val gc2 = gc.add(user)
|
||||
assert(gc2.users.size == 1)
|
||||
@ -23,37 +25,43 @@ class GroupsChatTests extends UnitSpec {
|
||||
}
|
||||
|
||||
"A GroupChat" should "be able to add, update, and remove msg" in {
|
||||
val createBy = GroupChatUser(BbbSystemConst.SYSTEM_USER, BbbSystemConst.SYSTEM_USER)
|
||||
val gcId = "gc-id"
|
||||
val chatName = "Public"
|
||||
val userId = "uid-1"
|
||||
val gc = GroupChatFactory.create(gcId, chatName, open = true, userId)
|
||||
val gc = GroupChatFactory.create(gcId, chatName, GroupChatAccess.PUBLIC, createBy, Vector.empty, Vector.empty)
|
||||
val msgId1 = "msgid-1"
|
||||
val ts = System.currentTimeMillis()
|
||||
val hello = "Hello World!"
|
||||
val msg1 = GroupChatMessage(id = msgId1, createdOn = ts, updatedOn = ts, sender = userId,
|
||||
font = "arial", size = 14, color = "red", message = hello)
|
||||
|
||||
val msg1 = GroupChatMessage(id = msgId1, timestamp = ts, correlationId = "cordId1", createdOn = ts,
|
||||
updatedOn = ts, sender = createBy,
|
||||
font = "arial", size = 12, color = "red", message = hello)
|
||||
val gc2 = gc.add(msg1)
|
||||
|
||||
assert(gc2.msgs.size == 1)
|
||||
|
||||
val msgId2 = "msgid-2"
|
||||
val foo = "Foo bar"
|
||||
val now = System.currentTimeMillis()
|
||||
val msg2 = GroupChatMessage(id = msgId2, createdOn = now, updatedOn = now, sender = userId,
|
||||
font = "arial", size = 14, color = "red", message = foo)
|
||||
val ts2 = System.currentTimeMillis()
|
||||
val msg2 = GroupChatMessage(id = msgId2, timestamp = ts2, correlationId = "cordId2", createdOn = ts2,
|
||||
updatedOn = ts2, sender = createBy,
|
||||
font = "arial", size = 12, color = "red", message = foo)
|
||||
val gc3 = gc2.add(msg2)
|
||||
|
||||
assert(gc3.msgs.size == 2)
|
||||
|
||||
val baz = "Foo baz"
|
||||
val now2 = System.currentTimeMillis()
|
||||
val msg3 = GroupChatMessage(id = msgId2, createdOn = now2, updatedOn = now2, sender = userId,
|
||||
font = "arial", size = 14, color = "red", message = baz)
|
||||
val msgId3 = "msgid-3"
|
||||
val ts3 = System.currentTimeMillis()
|
||||
val msg3 = GroupChatMessage(id = msgId3, timestamp = ts3, correlationId = "cordId3", createdOn = ts3,
|
||||
updatedOn = ts3, sender = createBy,
|
||||
font = "arial", size = 12, color = "red", message = baz)
|
||||
val gc4 = gc3.update(msg3)
|
||||
|
||||
gc4.msgs.get(msgId2) match {
|
||||
gc4.findMsgWithId(msgId3) match {
|
||||
case Some(m) => assert(m.message == baz)
|
||||
case None => fail("Could not find message with id=" + msgId2)
|
||||
case None => fail("Could not find message with id=" + msgId3)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,186 +0,0 @@
|
||||
package org.bigbluebutton.core2.message.handlers
|
||||
|
||||
import akka.actor.{ ActorContext, ActorSystem, Props }
|
||||
import akka.testkit.{ DefaultTimeout, ImplicitSender, TestKit }
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.bigbluebutton.SystemConfiguration
|
||||
import org.bigbluebutton.common2.msgs._
|
||||
import org.bigbluebutton.core._
|
||||
import org.bigbluebutton.core.apps.users.UsersApp
|
||||
import org.bigbluebutton.core.bus._
|
||||
import org.bigbluebutton.core.models._
|
||||
import org.bigbluebutton.core.running.{ LiveMeeting, OutMsgRouter }
|
||||
import org.bigbluebutton.core2.testdata.TestDataGen
|
||||
import org.scalatest.{ Matchers, WordSpecLike }
|
||||
import akka.testkit.TestActorRef
|
||||
import org.bigbluebutton.core.domain.{ MeetingExpiryTracker, MeetingInactivityTracker, MeetingState2x }
|
||||
import org.bigbluebutton.core.util.TimeUtil
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class ValidateAuthTokenReqMsgHdlrTestsSpec extends TestKit(ActorSystem(
|
||||
"ValidateAuthTokenReqMsgHdlrTestsSpec",
|
||||
ConfigFactory.parseString(TestKitUsageSpec.config)
|
||||
))
|
||||
with DefaultTimeout with ImplicitSender with WordSpecLike
|
||||
with Matchers with StopSystemAfterAll with AppsTestFixtures with SystemConfiguration {
|
||||
|
||||
// See: http://doc.akka.io/docs/akka/current/scala/testing.html
|
||||
// Setup dependencies
|
||||
val outgoingEventBus = new OutgoingEventBus
|
||||
val outBus2 = new OutEventBus2
|
||||
val recordBus = new RecordingEventBus
|
||||
|
||||
val inactivityTracker = new MeetingInactivityTracker(
|
||||
12,
|
||||
2,
|
||||
lastActivityTimestampInMs = 10,
|
||||
warningSent = false,
|
||||
warningSentOnTimestampInMs = 0L
|
||||
)
|
||||
|
||||
val expiryTracker = new MeetingExpiryTracker(
|
||||
startedOnInMs = TimeUtil.timeNowInSeconds(),
|
||||
userHasJoined = false,
|
||||
lastUserLeftOnInMs = None,
|
||||
durationInMs = 120,
|
||||
meetingExpireIfNoUserJoinedInMs = 5,
|
||||
meetingExpireWhenLastUserLeftInMs = 2
|
||||
)
|
||||
|
||||
"A MeetingActor" should {
|
||||
"Reject an invalid authToken because there is no registered users in the meeting" in {
|
||||
within(500 millis) {
|
||||
|
||||
val live = newLiveMeeting()
|
||||
val msgGW = new OutMsgGWSeq()
|
||||
val outGW = new OutMsgRouter(false, msgGW)
|
||||
val eventBus = new InMsgBusGW(new IncomingEventBusImp())
|
||||
|
||||
var state = new MeetingState2x(new GroupChats(Map.empty), None, inactivityTracker, expiryTracker)
|
||||
|
||||
// Need to get an ActorContext
|
||||
val actorRef = TestActorRef[MockTestActor]
|
||||
val actor = actorRef.underlyingActor
|
||||
// Create actor under test Actor
|
||||
val meetingActorRef = new UsersApp(live, outGW, eventBus)(actor.context)
|
||||
|
||||
def build(meetingId: String, userId: String, authToken: String): ValidateAuthTokenReqMsg = {
|
||||
ValidateAuthTokenReqMsg(meetingId, userId, authToken)
|
||||
}
|
||||
|
||||
// Send our message
|
||||
val msg = build(live.props.meetingProp.intId, "unknown user", "fake auth token")
|
||||
meetingActorRef.handleValidateAuthTokenReqMsg(msg, state)
|
||||
|
||||
// Handle message expectations
|
||||
assert(msgGW.msgs.length == 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"A MeetingActor" should {
|
||||
"Reject an invalid authToken for a registered users in the meeting" in {
|
||||
within(500 millis) {
|
||||
|
||||
val live = newLiveMeeting()
|
||||
val msgGW = new OutMsgGWSeq()
|
||||
val outGW = new OutMsgRouter(false, msgGW)
|
||||
val eventBus = new InMsgBusGW(new IncomingEventBusImp())
|
||||
|
||||
var state = new MeetingState2x(new GroupChats(Map.empty), None, inactivityTracker, expiryTracker)
|
||||
|
||||
val richard = TestDataGen.createRegisteredUser(live.registeredUsers, "Richard", Roles.MODERATOR_ROLE,
|
||||
guest = false, authed = false, waitForApproval = false)
|
||||
|
||||
// Need to get an ActorContext
|
||||
val actorRef = TestActorRef[MockTestActor]
|
||||
val actor = actorRef.underlyingActor
|
||||
// Create actor under test Actor
|
||||
val meetingActorRef = new UsersApp(live, outGW, eventBus)(actor.context)
|
||||
|
||||
def build(meetingId: String, userId: String, authToken: String): ValidateAuthTokenReqMsg = {
|
||||
ValidateAuthTokenReqMsg(meetingId, userId, authToken)
|
||||
}
|
||||
|
||||
// Send our message
|
||||
val msg = build(live.props.meetingProp.intId, richard.id, "wrong token")
|
||||
meetingActorRef.handleValidateAuthTokenReqMsg(msg, state)
|
||||
|
||||
// Handle message expectations
|
||||
assert(msgGW.msgs.length == 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"A MeetingActor" should {
|
||||
"Accept a valid authToken for a registered users in the meeting and wait for approval for guests" in {
|
||||
within(500 millis) {
|
||||
|
||||
val registeredUsers = new RegisteredUsers
|
||||
val users2x = new Users2x
|
||||
val live = new LiveMeeting(defaultProps, meetingStatux2x, deskshareModel, chatModel, layouts,
|
||||
registeredUsers, polls2x, wbModel, presModel, captionModel,
|
||||
notesModel, webcams, voiceUsers, users2x, guestsWaiting)
|
||||
|
||||
// Set the guest policy to ask moderator
|
||||
GuestsWaiting.setGuestPolicy(live.guestsWaiting, GuestPolicy(GuestPolicyType.ASK_MODERATOR, "SYSTEM"))
|
||||
|
||||
// Register a user that is not a guest
|
||||
val richard = TestDataGen.createRegisteredUser(live.registeredUsers, "Richard", Roles.MODERATOR_ROLE,
|
||||
guest = false, authed = false, waitForApproval = false)
|
||||
val fred = TestDataGen.createRegisteredUser(live.registeredUsers, "Fred", Roles.MODERATOR_ROLE,
|
||||
guest = false, authed = false, waitForApproval = false)
|
||||
val anton = TestDataGen.createRegisteredUser(live.registeredUsers, "Anton", Roles.VIEWER_ROLE,
|
||||
guest = false, authed = false, waitForApproval = false)
|
||||
|
||||
val richardUser = TestDataGen.createUserFor(live, richard, presenter = false)
|
||||
val fredUser = TestDataGen.createUserFor(live, fred, presenter = false)
|
||||
val antonUser = TestDataGen.createUserFor(live, anton, presenter = false)
|
||||
|
||||
val chad = TestDataGen.createRegisteredUser(live.registeredUsers, "Chad", Roles.VIEWER_ROLE,
|
||||
guest = true, authed = false, waitForApproval = true)
|
||||
|
||||
val msgGW = new OutMsgGWSeq()
|
||||
val outGW = new OutMsgRouter(false, msgGW)
|
||||
val eventBus = new InMsgBusGW(new IncomingEventBusImp())
|
||||
|
||||
var state = new MeetingState2x(new GroupChats(Map.empty), None, inactivityTracker, expiryTracker)
|
||||
|
||||
// Need to get an ActorContext
|
||||
val actorRef = TestActorRef[MockTestActor]
|
||||
val actor = actorRef.underlyingActor
|
||||
// Create actor under test Actor
|
||||
val meetingActorRef = new UsersApp(live, outGW, eventBus)(actor.context)
|
||||
|
||||
def build(meetingId: String, userId: String, authToken: String): ValidateAuthTokenReqMsg = {
|
||||
ValidateAuthTokenReqMsg(meetingId, userId, authToken)
|
||||
}
|
||||
|
||||
println("****** Sending validate msg test")
|
||||
|
||||
val msg = build(live.props.meetingProp.intId, chad.id, chad.authToken)
|
||||
meetingActorRef.handleValidateAuthTokenReqMsg(msg, state)
|
||||
|
||||
println("******* Asserting message length ")
|
||||
assert(msgGW.msgs.length == 3)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def setupState(liveMeeting: LiveMeeting): LiveMeeting = {
|
||||
val richard = TestDataGen.createRegisteredUser(liveMeeting.registeredUsers, "Richard", Roles.MODERATOR_ROLE,
|
||||
guest = false, authed = false, waitForApproval = false)
|
||||
val fred = TestDataGen.createRegisteredUser(liveMeeting.registeredUsers, "Fred", Roles.MODERATOR_ROLE,
|
||||
guest = false, authed = false, waitForApproval = false)
|
||||
val anton = TestDataGen.createRegisteredUser(liveMeeting.registeredUsers, "Anton", Roles.VIEWER_ROLE,
|
||||
guest = false, authed = false, waitForApproval = false)
|
||||
|
||||
val chad = TestDataGen.createRegisteredUser(liveMeeting.registeredUsers, "Chad", Roles.VIEWER_ROLE,
|
||||
guest = true, authed = false, waitForApproval = true)
|
||||
|
||||
liveMeeting
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ object TestDataGen {
|
||||
RandomStringGenerator.randomAlphanumericString(10) + ".png"
|
||||
|
||||
val ru = RegisteredUsers.create(userId = id, extId, name, role,
|
||||
authToken, avatarURL, guest, authed, waitForApproval)
|
||||
authToken, avatarURL, guest, authed, GuestStatus.ALLOW)
|
||||
|
||||
RegisteredUsers.add(users, ru)
|
||||
ru
|
||||
@ -45,7 +45,7 @@ object TestDataGen {
|
||||
|
||||
def createUserFor(liveMeeting: LiveMeeting, regUser: RegisteredUser, presenter: Boolean): UserState = {
|
||||
val u = UserState(intId = regUser.id, extId = regUser.externId, name = regUser.name, role = regUser.role,
|
||||
guest = regUser.guest, authed = regUser.authed, waitingForAcceptance = regUser.waitingForAcceptance,
|
||||
guest = regUser.guest, authed = regUser.authed, guestStatus = regUser.guestStatus,
|
||||
emoji = "none", locked = false, presenter, avatar = regUser.avatarURL)
|
||||
Users2x.add(liveMeeting.users2x, u)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user