@Nullable public ClientConfig loadConfigFromSettings() { ConfigPart parentPart = loadParentPartFromSettings(); if (!parentPart.hasError() && ServerConfig.isValidServerConfig(parentPart)) { try { ServerConfig serverConfig = ServerConfig.createFrom(parentPart); if (ClientConfig.isValidClientConfig(serverConfig, parentPart)) { return ClientConfig.createFrom(serverConfig, parentPart); } } catch (IllegalArgumentException e) { LOG.info("Should have not caused an error due to previous error check", e); } } return null; }
@Test void createFrom_error() { assertThrows(IllegalArgumentException.class, () -> ServerConfig.createFrom(new MockConfigPart())); }
public ClientConfigRoot addClientConfigRoot(TemporaryFolder tmp, String clientRootDir) { File base = tmp.newFile(clientRootDir); if (!base.mkdirs()) { throw new RuntimeException("Could not create directory " + base); } MockConfigPart cp1 = new MockConfigPart() .withClientname("cn") .withUsername("u") .withServerName("s:123"); ClientConfig cc = ClientConfig.createFrom(ServerConfig.createFrom(cp1), cp1); FilePath fp = VcsUtil.getFilePath(base); VirtualFile rootDir = Objects.requireNonNull(fp.getVirtualFile()); registry.addClientConfig(cc, rootDir); roots.add(rootDir); return Objects.requireNonNull(registry.getClientFor(rootDir)); }
private ClientConfig createClientConfig(String clientName) { MockConfigPart data = new MockConfigPart() .withServerName("1666") .withUsername("user") .withClientname(clientName); ServerConfig serverConfig = ServerConfig.createFrom(data); return ClientConfig.createFrom(serverConfig, data); } }
@Test void createFrom_invalid_noClientname() { MockConfigPart data = new MockConfigPart() .withUsername("u") .withServerName("blah"); assertThrows(IllegalArgumentException.class, () -> ClientConfig.createFrom( ServerConfig.createFrom(data), data )); }
private void updateRoot(@NotNull P4VcsRootSettings settings, @NotNull VcsDirectoryMapping directoryMapping) { VirtualFile root = DirectoryMappingUtil.getDirectory(getProject(), directoryMapping); List<ConfigPart> parts = settings.getConfigParts(); MultipleConfigPart parentPart = new MultipleConfigPart("Project Registry", parts); if (LOG.isDebugEnabled()) { LOG.debug("Add mapping for " + root + " -> " + parentPart + " (directory mapping dir [" + directoryMapping.getDirectory() + "])"); } try { if (ServerConfig.isValidServerConfig(parentPart)) { ServerConfig serverConfig = ServerConfig.createFrom(parentPart); if (ClientConfig.isValidClientConfig(serverConfig, parentPart)) { ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, parentPart); addClientConfig(clientConfig, root); return; } if (LOG.isDebugEnabled()) { LOG.debug(root + ": skipping invalid config " + parentPart); } } else if (LOG.isDebugEnabled()) { LOG.debug(root + ": skipping invalid config " + parentPart); } } catch (IllegalArgumentException e) { LOG.info("Problem with config under " + root + ": " + parentPart, e); } // Invalid config. removeClientConfigAt(root); }
@Test void createFrom_invalid_invalidServerConfigSettings() { MockConfigPart data = new MockConfigPart() .withUsername("u") .withServerName("blah") .withClientname("c"); ServerConfig sc = ServerConfig.createFrom(data); data.withUsername(null).withServerName(null); // Should not throw an error - it only needs client stuff. ClientConfig.createFrom(sc, data); }
@Test void getCachedOpenedChangelists_noCacheForClient() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertEmpty(changes); }
private ClientConfig createClientConfig() { MockConfigPart part = new MockConfigPart() // By using the RSH port, it means that the connection will be kept open // (NTS connection). By keeping the connection open until explicitly // disconnected, this will indirectly be testing that the // SimpleConnectionManager closes the connection. .withServerName(p4.getPort()) .withUsername(p4.getUser()) .withClientname("client") .withNoPassword(); final ServerConfig serverConfig = ServerConfig.createFrom(part); return ClientConfig.createFrom(serverConfig, part); } }
@Test void createFrom_invalid_errors() { MockConfigPart data = new MockConfigPart() .withServerName("blah") .withUsername("u") .withClientname("c"); ServerConfig sc = ServerConfig.createFrom(data); data.withConfigProblems(createError()); assertThrows(IllegalArgumentException.class, () -> ClientConfig.createFrom( sc, data )); }
@Test void toProperties_ServerConfig_empty() { Map<String, String> props = ConfigPropertiesUtil.toProperties( ServerConfig.createFrom( new MockConfigPart() .withUsername("username") .withServerName("servername") ), "<unset>", "<stored>", "<ns>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", portName("servername")), new Pair<>("P4USER", "username"), new Pair<>("P4PASSWD", "<ns>"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>") )); }
@Test void toProperties_ServerConfig_emptyPassword() { Map<String, String> props = ConfigPropertiesUtil.toProperties( ServerConfig.createFrom( new MockConfigPart() .withUsername("username") .withServerName("servername") .withPassword("") ), "<unset>", "<stored>", "<ns>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", portName("servername")), new Pair<>("P4USER", "username"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>"), // The user supplied an empty password. This means that a password is stored. new Pair<>("P4PASSWD", "<stored>") )); }
@Test void getCachedOpenedChangelists_noActions() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); ClientQueryCacheStore clientStore = new ClientQueryCacheStore(clientConfig.getClientServerRef()); P4LocalChangelist cl1 = new P4LocalChangelistImpl.Builder() .withChangelistId(new P4ChangelistIdImpl(1, clientConfig.getClientServerRef())) .withComment("comment 1") .withClientname(clientConfig.getClientname()) .withUsername(serverConfig.getUsername()) .build(); clientStore.setChangelists(cl1); projectStore.addCache(clientStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertSize(1, changes); assertEqualChangelists(cl1, changes.iterator().next()); }
@Test void toProperties_ClientConfig_empty() { MockConfigPart part = new MockConfigPart() .withUsername("username") .withServerName("servername") .withClientname("client"); Map<String, String> props = ConfigPropertiesUtil.toProperties( ClientConfig.createFrom(ServerConfig.createFrom(part), part), "<unset>", "<stored>", "<ns>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", portName("servername")), new Pair<>("P4CLIENT", "client"), new Pair<>("P4USER", "username"), new Pair<>("P4PASSWD", "<ns>"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4CHARSET", "<unset>"), new Pair<>("P4IGNORE", "<unset>"), new Pair<>("P4HOST", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>") )); }
.withNoPassword() .withClientname("client1"); final ServerConfig serverConfig = ServerConfig.createFrom(part); final ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, part); final File clientRoot = tmpDir.newFile("clientRoot");
.withNoPassword() .withClientname("client1"); final ServerConfig serverConfig = ServerConfig.createFrom(part); final ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, part); final File clientRoot = tmpDir.newFile("clientRoot");
.withClientname("lclient") ServerConfig sc = ServerConfig.createFrom(data); ClientConfig cc = ClientConfig.createFrom(sc, data);
@Test void createFrom_empty() { ServerConfig sc = ServerConfig.createFrom( new MockConfigPart() .withUsername("username") .withServerName("servername") ); assertEquals(P4ServerName.forPort("servername"), sc.getServerName()); assertEquals("username", sc.getUsername()); assertNull(sc.getServerFingerprint()); assertNull(sc.getAuthTicket()); assertNull(sc.getTrustTicket()); assertNull(sc.getLoginSso()); assertThat(sc.getConfigVersion(), greaterThan(0)); assertFalse(sc.hasServerFingerprint()); assertFalse(sc.hasAuthTicket()); assertFalse(sc.hasTrustTicket()); assertFalse(sc.hasLoginSso()); assertFalse(sc.usesStoredPassword()); assertEquals("localhost:servername" + SEP + "username" + SEP + "null" + SEP + "null" + SEP + "null", sc.getServerId()); }
@Test void getCachedOpenedChangelists_deleteAction() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); ClientQueryCacheStore clientStore = new ClientQueryCacheStore(clientConfig.getClientServerRef()); P4LocalChangelist cl1 = new P4LocalChangelistImpl.Builder() .withChangelistId(new P4ChangelistIdImpl(1, clientConfig.getClientServerRef())) .withComment("comment 1") .withClientname(clientConfig.getClientname()) .withUsername(serverConfig.getUsername()) .build(); projectStore.addPendingAction(ActionStore.createPendingAction( clientConfig.getClientServerRef(), new DeleteChangelistAction(cl1.getChangelistId()))); clientStore.setChangelists(cl1); projectStore.addCache(clientStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertSize(0, changes); }
@Test void isSameServer_empty() { MockConfigPart part1 = new MockConfigPart() .withUsername("u1") .withServerName("n1:1"); ServerConfig sc = ServerConfig.createFrom(part1); assertTrue(sc.isSameServerConnection(part1)); // Change it in the client ways, and it's still the same server. part1.withClientHostname("h1").withClientname("cc") .withDefaultCharset("a1").withIgnoreFileName("i") .withReloadValue(false); assertTrue(sc.isSameServerConnection(part1)); // Change the user MockConfigPart part2 = part1.copy() .withUsername("u2"); assertFalse(sc.isSameServerConnection(part2)); // change the server name MockConfigPart part3 = part1.copy() .withServerName("n2:1"); assertFalse(sc.isSameServerConnection(part3)); // change the password MockConfigPart part4 = part1.copy() .withPassword("a"); assertFalse(sc.isSameServerConnection(part4)); part4.withNoPassword().withRequiresUserEnteredPassword(true); assertFalse(sc.isSameServerConnection(part4)); }