-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1434 adding java web socket api level end to end test
- Loading branch information
1 parent
ce4ab99
commit 4117373
Showing
5 changed files
with
192 additions
and
72 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
example/main-java/src/test/java/org/finos/vuu/PersonRpcHandlerJavaWSApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.finos.vuu; | ||
|
||
import org.finos.toolbox.time.DefaultClock; | ||
import org.finos.vuu.core.module.TableDefContainer; | ||
import org.finos.vuu.core.module.ViewServerModule; | ||
import org.finos.vuu.module.JavaExampleModule; | ||
import org.finos.vuu.net.*; | ||
import org.finos.vuu.viewport.ViewPortRange; | ||
import org.finos.vuu.viewport.ViewPortTable; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import scala.jdk.javaapi.OptionConverters; | ||
|
||
import java.util.List; | ||
|
||
import static org.finos.vuu.util.ScalaCollectionConverter.toScala; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
//@RunWith(Enclosed.class) | ||
public class PersonRpcHandlerJavaWSApiTest extends WebSocketApiJavaTestBase { | ||
|
||
private final String tableName = "PersonManualMapped"; | ||
private final String moduleName = JavaExampleModule.NAME; | ||
|
||
@Test | ||
public void type_ahead_requested_for_a_column() { | ||
var createViewPortRequest = new CreateViewPortRequest( | ||
new ViewPortTable(tableName, moduleName), | ||
new ViewPortRange(1, 100), | ||
new String [] {"Id", "Name"}, | ||
new SortSpec(toScala(List.of())), | ||
new String[0], | ||
null, | ||
new Aggregations[0] | ||
); | ||
var requestId = vuuClient.send(sessionId, tokenId, createViewPortRequest); | ||
var viewPortCreateResponse = vuuClient.awaitForResponse(requestId); | ||
|
||
var viewPortCreateResponse2 = OptionConverters.toJava(viewPortCreateResponse); | ||
Assert.assertTrue("view port creation request returns response successfully", viewPortCreateResponse2.isPresent()); | ||
CreateViewPortSuccess responseBody = ((CreateViewPortSuccess) viewPortCreateResponse2.get().body()); | ||
//todo assert type before casting | ||
//CreateViewPortSuccess responseBody = assertBodyIsInstanceOf(viewPortCreateResponse); | ||
//RpcResponseNew responseBody = assertBodyIsInstanceOf(viewPortCreateResponse); | ||
var viewPortId = responseBody.viewPortId(); | ||
|
||
//todo type ahead request | ||
} | ||
|
||
@Override | ||
public ViewServerModule defineModuleWithTestTables() { | ||
return new JavaExampleModule().create(new TableDefContainer(), new DefaultClock()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
example/main-java/src/test/java/org/finos/vuu/WebSocketApiJavaTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.finos.vuu; | ||
|
||
import org.finos.toolbox.lifecycle.LifecycleContainer; | ||
import org.finos.toolbox.time.Clock; | ||
import org.finos.toolbox.time.DefaultClock; | ||
import org.finos.vuu.core.module.TableDefContainer; | ||
import org.finos.vuu.core.module.ViewServerModule; | ||
import org.finos.vuu.wsapi.helpers.TestStartUp; | ||
import org.finos.vuu.wsapi.helpers.TestVuuClient; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import scala.jdk.javaapi.OptionConverters; | ||
|
||
public abstract class WebSocketApiJavaTestBase { | ||
|
||
protected TestVuuClient vuuClient; | ||
protected String tokenId; | ||
protected String sessionId; | ||
|
||
protected Clock clock = new DefaultClock(); | ||
protected LifecycleContainer lifecycle = new LifecycleContainer(clock); | ||
protected TableDefContainer tableDefContainer = new TableDefContainer(); | ||
|
||
@Before | ||
public void setUp() { | ||
vuuClient = testStartUp(); | ||
tokenId = vuuClient.createAuthToken(); | ||
var sessionOption = OptionConverters.toJava(vuuClient.login(tokenId, "testUser")); | ||
Assert.assertTrue("login request returns response successfully", sessionOption.isPresent()); | ||
sessionId = sessionOption.get(); | ||
} | ||
|
||
public TestVuuClient testStartUp() { | ||
var startUp = new TestStartUp( | ||
this::defineModuleWithTestTables, | ||
clock, | ||
lifecycle, | ||
tableDefContainer); | ||
return startUp.startServerAndClient(); | ||
} | ||
|
||
public abstract ViewServerModule defineModuleWithTestTables(); | ||
|
||
@After | ||
public void after(){ | ||
lifecycle.stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
vuu/src/test/scala/org/finos/vuu/wsapi/helpers/TestStartUp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.finos.vuu.wsapi.helpers | ||
|
||
import org.finos.toolbox.jmx.{MetricsProvider, MetricsProviderImpl} | ||
import org.finos.toolbox.lifecycle.LifecycleContainer | ||
import org.finos.toolbox.time.Clock | ||
import org.finos.vuu.core.{VuuClientConnectionOptions, VuuSecurityOptions, VuuServer, VuuServerConfig, VuuThreadingOptions, VuuWebSocketOptions} | ||
import org.finos.vuu.core.module.{TableDefContainer, ViewServerModule} | ||
import org.finos.vuu.net.{AlwaysHappyLoginValidator, ViewServerClient, WebSocketViewServerClient} | ||
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator | ||
import org.finos.vuu.net.http.VuuHttp2ServerOptions | ||
import org.finos.vuu.net.json.JsonVsSerializer | ||
import org.finos.vuu.net.ws.WebSocketClient | ||
|
||
class TestStartUp(moduleFactoryFunc: () => ViewServerModule)( | ||
implicit val timeProvider: Clock, | ||
implicit val lifecycle: LifecycleContainer, | ||
implicit val tableDefContainer: TableDefContainer) { | ||
|
||
|
||
def startServerAndClient(): TestVuuClient = { | ||
|
||
implicit val metrics: MetricsProvider = new MetricsProviderImpl | ||
|
||
lifecycle.autoShutdownHook() | ||
|
||
val rand = new scala.util.Random | ||
val http = rand.between(10011, 10500) | ||
val ws = rand.between(10011, 10500) | ||
|
||
val module: ViewServerModule = moduleFactoryFunc() | ||
|
||
val config = VuuServerConfig( | ||
VuuHttp2ServerOptions() | ||
.withWebRoot("vuu/src/main/resources/www") | ||
.withSslDisabled() | ||
.withDirectoryListings(true) | ||
.withPort(http), | ||
VuuWebSocketOptions() | ||
.withBindAddress("0.0.0.0") | ||
.withUri("websocket") | ||
.withWsPort(ws) | ||
.withWssDisabled(), | ||
VuuSecurityOptions() | ||
.withAuthenticator(new AlwaysHappyAuthenticator) | ||
.withLoginValidator(new AlwaysHappyLoginValidator), | ||
VuuThreadingOptions(), | ||
VuuClientConnectionOptions() | ||
.withHeartbeatDisabled() | ||
) | ||
.withModule(module) | ||
|
||
val viewServer = new VuuServer(config) | ||
|
||
val client = new WebSocketClient(s"ws://localhost:$ws/websocket", ws) //todo review params - port specified twice | ||
val viewServerClient: ViewServerClient = new WebSocketViewServerClient(client, JsonVsSerializer) | ||
val vuuClient = new TestVuuClient(viewServerClient) | ||
|
||
//set up a dependency on ws server from ws client. | ||
lifecycle(client).dependsOn(viewServer) | ||
|
||
//lifecycle registration is done in constructor of service classes, so sequence of create is important | ||
lifecycle.start() | ||
|
||
vuuClient | ||
} | ||
|
||
} |