Skip to content

Commit

Permalink
#1415 added extension methods to help add table to module for test us…
Browse files Browse the repository at this point in the history
…ecases
  • Loading branch information
naleeha authored and keikeicheung committed Jul 22, 2024
1 parent 717d0be commit 49f160f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.finos.vuu.core

import org.finos.vuu.core.module.ViewServerModule
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator
import org.finos.vuu.net.flowcontrol.{DefaultFlowController, FlowController, NoHeartbeatFlowController}
import org.finos.vuu.net.http.{VuuHttp2ServerOptions, VuuSecurityOptions}
import org.finos.vuu.net.{AlwaysHappyLoginValidator, Authenticator, LoginTokenValidator}
import org.finos.vuu.plugin.Plugin
Expand Down
62 changes: 62 additions & 0 deletions vuu/src/test/scala/org/finos/vuu/net/TestModuleBuilder.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.finos.vuu.net

import org.finos.toolbox.lifecycle.LifecycleContainer
import org.finos.toolbox.time.Clock
import org.finos.vuu.api.{TableDef, ViewPortDef}
import org.finos.vuu.core.module.{ModuleFactory, ModuleFactoryNode, TableDefContainer, ViewServerModule}
import org.finos.vuu.provider.MockProvider


object TestExtension {
implicit class ModuleFactoryExtension(val moduleFactoryNode: ModuleFactoryNode) {

def addTableForTest(tableDef: TableDef)(implicit clock: Clock, lifecycle: LifecycleContainer): ModuleFactoryNode = {
moduleFactoryNode.addTable(
tableDef,
(table, _) => new MockProvider(table)
)
}

def addTableForTest(tableDef: TableDef, viewPortDef: ViewPortDef)(implicit clock: Clock, lifecycle: LifecycleContainer): ModuleFactoryNode = {
moduleFactoryNode.addTable(
tableDef,
(table, _) => new MockProvider(table),
(_, _, _, _) => viewPortDef
)
}

}
}
class TestModuleBuilder(moduleName:String)(implicit clock: Clock, lifecycle: LifecycleContainer, tableDefContainer: TableDefContainer){


private var moduleFactory = ModuleFactory.withNamespace(moduleName)
def withTable(tableDef: TableDef, viewPortDef: ViewPortDef): TestModuleBuilder = {
moduleFactory = moduleFactory.addTable(
tableDef,
(table, _) => new MockProvider(table),
(_, _, _, _) => viewPortDef
)
this
}


def build(moduleName: String, tableDef: TableDef, viewPortDef: ViewPortDef)(implicit clock: Clock, lifecycle: LifecycleContainer, tableDefContainer: TableDefContainer): ViewServerModule =
ModuleFactory.withNamespace(moduleName)
.addTable(
tableDef,
(table, _) => new MockProvider(table),
(_, _, _, _) => viewPortDef
)
.asModule()

def build(moduleName: String, tableDef: TableDef)(implicit clock: Clock, lifecycle: LifecycleContainer, tableDefContainer: TableDefContainer): ViewServerModule =
ModuleFactory.withNamespace(moduleName)
.addTable(
tableDef,
(table, _) => new MockProvider(table)
)
.asModule()


}
18 changes: 0 additions & 18 deletions vuu/src/test/scala/org/finos/vuu/net/TestModuleFactory.scala

This file was deleted.

74 changes: 52 additions & 22 deletions vuu/src/test/scala/org/finos/vuu/net/WebSocketApiTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import org.finos.toolbox.lifecycle.LifecycleContainer
import org.finos.toolbox.time.{Clock, DefaultClock}
import org.finos.vuu.api.{ColumnBuilder, NoRpcHandler, TableDef, ViewPortDef}
import org.finos.vuu.core._
import org.finos.vuu.core.module.TableDefContainer
import org.finos.vuu.core.module.{ModuleFactory, TableDefContainer, ViewServerModule}
import org.finos.vuu.net.TestExtension.ModuleFactoryExtension
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator
import org.finos.vuu.net.http.VuuHttp2ServerOptions
import org.finos.vuu.net.json.JsonVsSerializer
Expand Down Expand Up @@ -48,26 +49,7 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW
val http = 10011
val ws = 10013

val tableDef = TableDef(
name = "TableMetaTest",
keyField = "Id",
columns =
new ColumnBuilder()
.addString("Id")
.addString("Name")
.addInt("Account")
.build()
)
val viewPortDef = ViewPortDef(
columns =
new ColumnBuilder()
.addString("Id")
.addInt("Account")
.build(),
service = NoRpcHandler
)

val module = TestModuleFactory.build("TEST", tableDef, viewPortDef)
val module: ViewServerModule = defineModuleWithTestTables()

val config = VuuServerConfig(
VuuHttp2ServerOptions()
Expand All @@ -86,7 +68,8 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW
VuuThreadingOptions(),
VuuClientConnectionOptions()
.withHeartbeatDisabled()
).withModule(module)
)
.withModule(module)

val viewServer = new VuuServer(config)

Expand All @@ -103,6 +86,41 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW
vuuClient
}

private def defineModuleWithTestTables(): ViewServerModule = {
val tableDef = TableDef(
name = "TableMetaTest",
keyField = "Id",
columns =
new ColumnBuilder()
.addString("Id")
.addString("Name")
.addInt("Account")
.build()
)
val viewPortDef = ViewPortDef(
columns =
new ColumnBuilder()
.addString("Id")
.addInt("Account")
.build(),
service = NoRpcHandler
)

val tableDef2 = TableDef(
name = "TableMetaDefaultVPTest",
keyField = "Id",
columns =
new ColumnBuilder()
.addString("Id")
.build()
)

ModuleFactory.withNamespace("TEST")
.addTableForTest(tableDef, viewPortDef)
.addTableForTest(tableDef2)
.asModule()
}

Feature("Server web socket api") {
Scenario("client requests to get table metadata for a table") {

Expand All @@ -117,6 +135,18 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW
responseMessage.columns shouldEqual Array("Id", "Account")
}

Scenario("client requests to get table metadata for a table with no view port def defined") {

vuuClient.send(sessionId, tokenId, GetTableMetaRequest(ViewPortTable("TableMetaDefaultVPTest", "TEST")))

Then("return view port columns in response")
val response = vuuClient.awaitForMsgWithBody[GetTableMetaResponse]
assert(response.isDefined)

val responseMessage = response.get
responseMessage.columns.length shouldEqual 0
}

Scenario("client requests to get table metadata for a non existent") {

vuuClient.send(sessionId, tokenId, GetTableMetaRequest(ViewPortTable("DoesNotExist", "TEST")))
Expand Down

0 comments on commit 49f160f

Please sign in to comment.