BrokerConnection implements Connection { public SystemInfo fetchSystemInfo() throws RpcException { RpcResponse r = send(new RpcRequest(XUS_SIGNON_SETUP)); VistaSystemInfo info = new VistaSystemInfoResponseExtractor().extractData(r); r = send(new RpcRequest(XUS_INTRO_MSG)); info.setIntroText(r.toString()); r = send(new RpcRequest(XWB_GET_BROKER_INFO)); if (r.length() > 0) { int timeoutInSeconds = Integer.parseInt(r.toLines()[0].trim()); info.setActivityTimeoutSeconds(timeoutInSeconds); } return info; } BrokerConnection(RpcHost host, Socket socket, RpcProtocol protocol); RpcHost getHost(); SystemInfo getSystemInfo(); ConnectionUserDetails getUserDetails(); boolean isAuthenticated(); synchronized void stop(); RpcResponse send(RpcRequest request); synchronized RpcResponse sendInternal(RpcRequest request); synchronized void close(); boolean isClosed(); boolean isStale(); @Override ConnectionMetrics getMetrics(); @Override long getElapsedMillis(); void setElapsedMillis(long millis); SystemInfo fetchSystemInfo(); void pulse(); void authenticate(AccessVerifyConnectionSpec av); void authenticate(AppHandleConnectionSpec appHandleConnectionSpec); String getCurrentRpcContext();  }
@Test public void fetchSystemInfo() throws RpcException { RpcRequest request1 = new RpcRequest("XUS SIGNON SETUP"); RpcRequest request2 = new RpcRequest("XUS INTRO MSG"); RpcRequest request3 = new RpcRequest("XWB GET BROKER INFO"); when(mockReader.readResponse()) .thenReturn(buildMockSignOnSetupResponse().toRpcResponse()) .thenReturn(buildMockIntroMessageResponse().toRpcResponse()) .thenReturn(buildMockBrokerInfoResponse().toRpcResponse()); SystemInfo info = c.fetchSystemInfo(); assertThat(info.getServer(), is("foobar.vha.domain.ext")); assertThat(info.getDevice(), is("/dev/null:25522")); assertThat(info.getUCI(), is("FOO")); assertThat(info.getVolume(), is("FOO")); assertThat(info.getDomainName(), is("FOOBAR.server.DOMAIN.EXT")); assertThat(info.getIntroText(), is((char) 13 + "Hello world" + LINE_DELIMITER)); ArgumentCaptor<RpcRequest> requestsWritten = ArgumentCaptor.forClass(RpcRequest.class); verify(mockWriter, times(3)).write(requestsWritten.capture()); assertThat(requestsWritten.getAllValues().get(0), is(request1)); assertThat(requestsWritten.getAllValues().get(1), is(request2)); assertThat(requestsWritten.getAllValues().get(2), is(request3)); verify(mockWriter, times(3)).flush(); verify(mockReader, times(3)).readResponse(); }