ConnectCommandRunner extends AbstractServerCommandRunner { @NotNull @Override public P4CommandRunner.QueryAnswer<ListClientsForUserResult> getClientsForUser( @NotNull OptionalClientServerConfig config, @NotNull ListClientsForUserQuery query) { return new QueryAnswerImpl<>(connectionManager.withConnection(config, (server) -> listClientsForUser(server, config, query.getUsername(), query.getMaxClients()))); } ConnectCommandRunner(
            @NotNull Project project,
            @NotNull ConnectionManager connectionManager); @Override void disconnect(@NotNull P4ServerName config); @NotNull @Override P4CommandRunner.QueryAnswer<AnnotateFileResult> getFileAnnotation(
            @NotNull ClientConfig config,
            @NotNull final AnnotateFileQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<DescribeChangelistResult> describeChangelist(
            @NotNull OptionalClientServerConfig config,
            @NotNull DescribeChangelistQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<GetJobSpecResult> getJobSpec(
            @NotNull OptionalClientServerConfig config); @NotNull @Override P4CommandRunner.QueryAnswer<ListOpenedFilesChangesResult> listOpenedFilesChanges(@NotNull ClientConfig config,
            @NotNull ListOpenedFilesChangesQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListClientsForUserResult> getClientsForUser(
            @NotNull OptionalClientServerConfig config,
            @NotNull ListClientsForUserQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListSubmittedChangelistsResult> listSubmittedChangelists(
            @NotNull final ClientConfig config, @NotNull final ListSubmittedChangelistsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<GetFileContentsResult> getFileContents(
            @NotNull ClientConfig config,
            @NotNull final GetFileContentsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListFileHistoryResult> listFilesHistory(
            @NotNull ClientConfig config,
            @NotNull final ListFileHistoryQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListFilesDetailsResult> listFilesDetails(
            @NotNull ClientConfig config,
            @NotNull final ListFilesDetailsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListJobsResult> listJobs(
            @NotNull OptionalClientServerConfig config,
            @NotNull final ListJobsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListLabelsResult> listLabels(
            @NotNull OptionalClientServerConfig config,
            @NotNull final ListLabelsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListUsersResult> listUsers(
            @NotNull OptionalClientServerConfig config,
            @NotNull final ListUsersQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<SwarmConfigResult> getSwarmConfig(
            @NotNull OptionalClientServerConfig config,
            @NotNull final SwarmConfigQuery query);  }
@ExtendWith(TemporaryFolderExtension.class) @Test void getClientsForUser_nonExistent(TemporaryFolder tmpDir) throws IOException { idea.useInlineThreading(null); MockConfigPart part = new MockConfigPart() .withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword() .withClientname("client1"); final ServerConfig serverConfig = ServerConfig.createFrom(part); final ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, part); final File clientRoot = tmpDir.newFile("clientRoot"); final TestableP4RequestErrorHandler errorHandler = new TestableP4RequestErrorHandler(idea.getMockProject()); setupClient(clientConfig, tmpDir, clientRoot, errorHandler) .map((cm) -> new ConnectCommandRunner(idea.getMockProject(), cm)) .futureMap((runner, sink) -> runner.getClientsForUser(new OptionalClientServerConfig(clientConfig), new ListClientsForUserQuery("not-a-user", 50)) .whenCompleted(sink::resolve) .whenServerError(sink::reject) ) .whenCompleted((r) -> { assertThat(r, instanceOf(ListClientsForUserResult.class)); ListClientsForUserResult res = (ListClientsForUserResult) r; assertSame(serverConfig, res.getServerConfig()); assertEquals("not-a-user", res.getRequestedUser()); assertEmpty(res.getClients()); }) .whenFailed(Assertions::fail); }
@ExtendWith(TemporaryFolderExtension.class) @Test void getClientsForUser_passwordNotGiven(TemporaryFolder tmpDir) throws IOException, InterruptedException { idea.useInlineThreading(null); final MockConfigPart setupPart = new MockConfigPart() .withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword(); final ServerConfig setupServerConfig = ServerConfig.createFrom(setupPart); final File clientRoot = tmpDir.newFile("clientRoot"); assertTrue(withConnection(setupServerConfig, tmpDir) .mapAsync((mgr) -> mgr.withConnection(new OptionalClientServerConfig(setupServerConfig, null), server -> { CoreFactory.createClient( server, "client1", "new client from CoreFactory", clientRoot.getAbsolutePath(), new String[]{" true); return mgr; })) .mapAsync((mgr) -> mgr.withConnection(new OptionalClientServerConfig(setupServerConfig, null), server -> { String res = server.changePassword(null, "x", server.getUserName()); System.err.println("Password change: [" + res + "]"); return null; })) .blockingWait(5, TimeUnit.SECONDS)); final MockConfigPart part = new MockConfigPart() .withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword() .withClientname("client1"); final ServerConfig serverConfig = ServerConfig.createFrom(part); final ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, part); final TestableP4RequestErrorHandler errorHandler = new TestableP4RequestErrorHandler(idea.getMockProject()); withConnection(clientConfig.getServerConfig(), tmpDir, errorHandler) .map((cm) -> new ConnectCommandRunner(idea.getMockProject(), cm)) .futureMap((runner, sink) -> runner.getClientsForUser(new OptionalClientServerConfig(clientConfig), new ListClientsForUserQuery(server.getUser(), 1)) .whenCompleted(sink::resolve) .whenServerError(sink::reject) ) .whenCompleted((r) -> fail("Did not fail with password error")) .whenFailed((e) -> { assertEquals(e.getResultError().getCategory(), P4CommandRunner.ErrorCategory.ACCESS_DENIED); assertEquals(e.getLocalizedMessage(), e.getLocalizedMessage()); assertThat(e.getResultError().getMessage().orElse(null), containsString(e.getLocalizedMessage())); }); }