Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package admin.bank.manage
- import play.api.mvc._
- import main.init.Properties
- import Bank._
- import login._
- import main._
- import common._
- import play.api.inject.guice._
- import play.api.inject.bind
- import play.api.libs.json._
- import org.scalatest._
- import org.scalatestplus.play._
- import play.api.test._
- import play.api.test.Helpers._
- import java.time._
- import java.time.format._
- import scala.concurrent.Future
- import scala.concurrent.ExecutionContext.Implicits.global
- import org.scalatest.mock.MockitoSugar
- import org.mockito.Mockito._
- import org.mockito.ArgumentMatchers
- import com.google.inject.AbstractModule
- import tasks.etl.MainEtl
- import akka.actor._
- import com.google.inject._
- import com.google.inject.name.Names
- class ManageBanksTest extends PlaySpec with OneAppPerSuite with MockitoSugar {
- //implicit override lazy val app = new GuiceApplicationBuilder().build
- val modules = Option(new AbstractModule {
- override def configure() = {
- val mockMainETL: MainEtl = mock[MainEtl]
- bind(classOf[ActorRef])
- .annotatedWith(Names.named("mainEtl"))
- .toInstance(mockMainETL)
- }
- })
- implicit override lazy val app = new GuiceApplicationBuilder()
- .overrides(modules.map(GuiceableModule.guiceable).toSeq: _*)
- .build
- val permCode = 12
- val manyResponse = """
- {
- "bnks" : [ {
- "sk":1,
- "nm":"Bank 1",
- "dsc":"Bank 1 description",
- "als":"BK1"
- },
- {
- "sk":2,
- "nm":"Bank 2",
- "dsc":"Bank 2 description",
- "als":"BK2"
- },
- {
- "sk":3,
- "nm":"Bank 3",
- "dsc":"Bank 3 description",
- "als":"BK3"
- }]
- }
- """
- val bk1 = BankSeq(1,"Bank 1", Some("Bank 1 description"),"BK1")
- val bk2 = BankSeq(2,"Bank 2", Some("Bank 2 description"),"BK2")
- val bk3 = BankSeq(3,"Bank 3", Some("Bank 3 description"),"BK3")
- val seqMany = Seq(bk1, bk2, bk3)
- "Banks Management" should {
- "read many - user authorized (admin)" in {
- val mock1 = mock[ManageBanksDAO]
- when(mock1.readMany).thenReturn(Future{seqMany})
- val userMock = UserMock.getAdmin
- val props = new Properties
- val auth = UserMock.getAuth(userMock)
- val userRoleMock = UserMock.getManagePerm(permCode)
- val controller = new ManageBanks(auth,props,mock1,userRoleMock)
- val result: Future[Result] = controller.readMany().apply(FakeRequest(POST, "/"))
- val bodyText: String = contentAsString(result)
- val access = 2
- val admin = 1
- val jsonManyResponse: JsValue = Json.parse(manyResponse.format(access,admin))
- bodyText mustBe jsonManyResponse.toString
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement