diff --git a/vuu/src/main/scala/org/finos/vuu/core/VuuServerOptions.scala b/vuu/src/main/scala/org/finos/vuu/core/VuuServerOptions.scala index 3b3986338..e6938eac9 100644 --- a/vuu/src/main/scala/org/finos/vuu/core/VuuServerOptions.scala +++ b/vuu/src/main/scala/org/finos/vuu/core/VuuServerOptions.scala @@ -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 diff --git a/vuu/src/test/scala/org/finos/vuu/net/TestModuleBuilder.scala b/vuu/src/test/scala/org/finos/vuu/net/TestModuleBuilder.scala new file mode 100644 index 000000000..cc120a9fe --- /dev/null +++ b/vuu/src/test/scala/org/finos/vuu/net/TestModuleBuilder.scala @@ -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() + + +} diff --git a/vuu/src/test/scala/org/finos/vuu/net/TestModuleFactory.scala b/vuu/src/test/scala/org/finos/vuu/net/TestModuleFactory.scala deleted file mode 100644 index 518a4ddb6..000000000 --- a/vuu/src/test/scala/org/finos/vuu/net/TestModuleFactory.scala +++ /dev/null @@ -1,18 +0,0 @@ -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, TableDefContainer, ViewServerModule} -import org.finos.vuu.provider.MockProvider - -object TestModuleFactory { - def build(moduleName: String, tableDef: TableDef, viewPortDef: ViewPortDef)(implicit time: Clock, lifecycle: LifecycleContainer, tableDefContainer: TableDefContainer): ViewServerModule = - ModuleFactory.withNamespace(moduleName) - .addTable( - tableDef, - (table, _) => new MockProvider(table), - (_, _, _, _) => viewPortDef - ) - .asModule() -} diff --git a/vuu/src/test/scala/org/finos/vuu/net/WebSocketApiTest.scala b/vuu/src/test/scala/org/finos/vuu/net/WebSocketApiTest.scala index d87272524..5062ec15c 100644 --- a/vuu/src/test/scala/org/finos/vuu/net/WebSocketApiTest.scala +++ b/vuu/src/test/scala/org/finos/vuu/net/WebSocketApiTest.scala @@ -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 @@ -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() @@ -86,7 +68,8 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW VuuThreadingOptions(), VuuClientConnectionOptions() .withHeartbeatDisabled() - ).withModule(module) + ) + .withModule(module) val viewServer = new VuuServer(config) @@ -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") { @@ -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")))