Skip to content

Commit

Permalink
finos#1434 adding test for type ahead request with start string. Maki…
Browse files Browse the repository at this point in the history
…ng rpc function names typed and in separate files to make it easier to find as public api
  • Loading branch information
naleeha committed Aug 19, 2024
1 parent e20955d commit ec676f0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package org.finos.vuu.core.module.typeahead

import com.typesafe.scalalogging.StrictLogging
import org.finos.vuu.core.table.{DataTable, TableContainer}
import org.finos.vuu.net.RequestContext
import org.finos.vuu.net.rpc.{DefaultRpcHandler, RpcMethodCallResult, RpcMethodSuccess, RpcParams}
import org.finos.vuu.net.{RequestContext, RpcNames}

class ViewPortTypeAheadRpcHandler(tableContainer: TableContainer) extends DefaultRpcHandler with StrictLogging {

this.registerRpc("getUniqueFieldValues", params => processGetUniqueFieldValuesRequest(params))
this.registerRpc("getUniqueFieldValuesStartingWith", params => processGetUniqueFieldValuesStartWithRequest(params))
this.registerRpc(RpcNames.UniqueFieldValuesRpc, params => processGetUniqueFieldValuesRequest(params))
this.registerRpc(RpcNames.UniqueFieldValuesStartWithRpc, params => processGetUniqueFieldValuesStartWithRequest(params))

def processGetUniqueFieldValuesRequest(params: RpcParams): RpcMethodCallResult = {
val values = getUniqueFieldValues(
Expand Down
8 changes: 8 additions & 0 deletions vuu/src/main/scala/org/finos/vuu/net/RpcNames.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.finos.vuu.net

import org.finos.vuu.net.rpc.Rpc

object RpcNames {
val UniqueFieldValuesRpc: Rpc.FunctionName = "getUniqueFieldValues"
val UniqueFieldValuesStartWithRpc: Rpc.FunctionName = "getUniqueFieldValuesStartingWith"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import java.util.concurrent.ConcurrentHashMap

class DefaultRpcHandler extends RpcHandler with StrictLogging {

type RpcFunction = RpcParams => RpcMethodCallResult

private val rpcHandlerMap = new ConcurrentHashMap[String, RpcFunction]()
private val rpcHandlerMap = new ConcurrentHashMap[Rpc.FunctionName, Rpc.Function]()

/**
* Register a handler for a given rpc function
Expand All @@ -19,7 +17,7 @@ class DefaultRpcHandler extends RpcHandler with StrictLogging {
* @param handlerFunc handler function that takes RpcParams and return RpcMethodCallResult
*/

def registerRpc(functionName: String, handlerFunc: RpcFunction): Unit = {
def registerRpc(functionName: Rpc.FunctionName, handlerFunc: Rpc.Function): Unit = {

if (rpcHandlerMap.containsKey(functionName)) {
throw new IllegalArgumentException(s"Function $functionName already registered")
Expand Down
6 changes: 6 additions & 0 deletions vuu/src/main/scala/org/finos/vuu/net/rpc/Rpc.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.finos.vuu.net.rpc

object Rpc {
type Function = RpcParams => RpcMethodCallResult
type FunctionName = String
}
39 changes: 37 additions & 2 deletions vuu/src/test/scala/org/finos/vuu/net/WebSocketApiTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW
"row1" -> Map("Id" -> "row1", "Name" -> "Becky Thatcher", "Account" -> 1235),
"row2" -> Map("Id" -> "row2", "Name" -> "Tom Sawyer", "Account" -> 45321),
"row3" -> Map("Id" -> "row3", "Name" -> "Huckleberry Finn", "Account" -> 89564),
"row4" -> Map("Id" -> "row4", "Name" -> "Tom Thatcher", "Account" -> 1235),
))

val providerFactory = (table: DataTable, vuuServer: IVuuServer) => new TestProvider(table, dataSource)
Expand Down Expand Up @@ -179,7 +180,7 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW
response.get.msg shouldEqual "No such table found with name null in module TEST. Table name and module should not be null"
}

Scenario("Type ahead rcp request for a column") {
Scenario("Type ahead request for a column") {

Then("create viewport")
val createViewPortRequest = CreateViewPortRequest(ViewPortTable("TableMetaTest", "TEST"), ViewPortRange(1,100),columns = Array("Id", "Name", "Account"))
Expand All @@ -194,7 +195,7 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW

val getTypeAheadRequest = ViewPortRpcCall(
viewPortId,
"getUniqueFieldValues",
RpcNames.UniqueFieldValuesRpc,
params = Array(),
namedParams = Map(
"table" -> "TableMetaTest",
Expand All @@ -216,5 +217,39 @@ class WebSocketApiTest extends AnyFeatureSpec with BeforeAndAfterAll with GivenW

}
}

Scenario("Type ahead request that start with a string for a column") {

Then("create viewport")
val createViewPortRequest = CreateViewPortRequest(ViewPortTable("TableMetaTest", "TEST"), ViewPortRange(1,100),columns = Array("Id", "Name", "Account"))
vuuClient.send(sessionId, tokenId, createViewPortRequest)
val viewPortCreateResponse = vuuClient.awaitForMsgWithBody[CreateViewPortSuccess]
val viewPortId = viewPortCreateResponse.get.viewPortId

val getTypeAheadRequest = ViewPortRpcCall(
viewPortId,
RpcNames.UniqueFieldValuesStartWithRpc,
params = Array(),
namedParams = Map(
"table" -> "TableMetaTest",
"module" -> "TEST",
"column" -> "Name",
"starts" -> "Tom"
))
vuuClient.send(sessionId, tokenId, getTypeAheadRequest)

Then("return top 10 values in that column")
val response = vuuClient.awaitForMsgWithBody[ViewPortRpcResponse]
assert(response.isDefined)

response.get.method shouldEqual "getUniqueFieldValuesStartingWith"

val action = response.get.action
action shouldBe a [DisplayResultAction]
val displayResultAction = action.asInstanceOf[DisplayResultAction]
displayResultAction.result shouldEqual List("Tom Sawyer", "Tom Thatcher")

}

}

0 comments on commit ec676f0

Please sign in to comment.