@Test void createFrom_error() { assertThrows(IllegalArgumentException.class, () -> ServerConfig.createFrom(new MockConfigPart())); }
@Test void getServerIdForDataPart_empty() { MockConfigPart data = new MockConfigPart() .withNoPassword(); assertEquals("null" + SEP + "null" + SEP + "null" + SEP + "null" + SEP + "null", ServerConfig.getServerIdForDataPart(data)); }
@Test void getServerIdForDataPart_nullPassword() { MockConfigPart data = new MockConfigPart() .withPassword(null); assertEquals("null" + SEP + "null" + SEP + "null" + SEP + "null" + SEP + "null", ServerConfig.getServerIdForDataPart(data)); }
private static MockConfigPart createConfigPart() { return 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("1234") .withUsername("u") .withNoPassword() .withClientname("client1"); }
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 compareTo_err2() { MockConfigPart part = new MockConfigPart(); ConfigProblem cpF1 = new ConfigProblem(part, "Abc", false); ConfigProblem cpF2 = new ConfigProblem(part, "Def", false); ConfigProblem cpT1 = new ConfigProblem(part, "Abc", true); ConfigProblem cpT2 = new ConfigProblem(part, "Def", true); assertThat(cpF1.compareTo(cpF2), lessThan(0)); assertThat(cpF2.compareTo(cpF1), greaterThan(0)); assertThat(cpT1.compareTo(cpT2), lessThan(0)); assertThat(cpT2.compareTo(cpT1), greaterThan(0)); } }
@Test void getServerIdForDataPart_full() { MockConfigPart data = new MockConfigPart() .withServerName("1234") .withUsername("luser") .withPassword("my password") .withAuthTicketFile(new File("auth-ticket-file")) .withTrustTicketFile(new File("trust-ticket-file")) .withServerFingerprint("1234asdf1234asdf"); assertEquals("localhost:1234" + SEP + "luser" + SEP + "auth-ticket-file" + SEP + "trust-ticket-file" + SEP + "1234asdf1234asdf", ServerConfig.getServerIdForDataPart(data)); }
@Test void createFrom_invalid_noClientname() { MockConfigPart data = new MockConfigPart() .withUsername("u") .withServerName("blah"); assertThrows(IllegalArgumentException.class, () -> ClientConfig.createFrom( ServerConfig.createFrom(data), data )); }
@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); }
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 getters_1() { MockConfigPart part = new MockConfigPart(); ConfigProblem cp = new ConfigProblem(part, "Foo bar", true); assertEquals("Foo bar", cp.getMessage()); assertEquals(part, cp.getSource()); assertTrue(cp.isError()); assertEquals( "problem(" + part + ": Foo bar)", cp.toString()); }
@Test void toProperties_configPartEmpty() { Map<String, String> props = ConfigPropertiesUtil.toProperties( new MockConfigPart(), "<unset>", "<ep>", "<set>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", "<unset>"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4USER", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4PASSWD", "<unset>"), new Pair<>("P4CHARSET", "<unset>"), new Pair<>("P4IGNORE", "<unset>"), new Pair<>("P4CLIENT", "<unset>"), new Pair<>("P4HOST", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>") )); }
@SuppressWarnings("unchecked") @Test void toProperties_configPartEmptyPassword() { Map<String, String> props = ConfigPropertiesUtil.toProperties( new MockConfigPart() .withPassword(""), "<unset>", "<ep>", "<set>" ); assertThat(props, mapContainsAll( new Pair<>("P4PORT", "<unset>"), new Pair<>("P4TRUST", "<unset>"), new Pair<>("P4USER", "<unset>"), new Pair<>("P4TICKETS", "<unset>"), new Pair<>("P4FINGERPRINT", "<unset>"), new Pair<>("P4PASSWD", "<ep>"), new Pair<>("P4CHARSET", "<unset>"), new Pair<>("P4IGNORE", "<unset>"), new Pair<>("P4CLIENT", "<unset>"), new Pair<>("P4HOST", "<unset>"), new Pair<>("P4LOGINSSO", "<unset>") )); }
@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 isValid() { assertFalse(ServerConfig.isValidServerConfig(null)); MockConfigPart part = new MockConfigPart(); part.withConfigProblems(createError()); assertFalse(ServerConfig.isValidServerConfig(part)); part.withConfigProblems(); assertFalse(ServerConfig.isValidServerConfig(part)); P4ServerName mockName = mock(P4ServerName.class); when(mockName.getFullPort()).thenReturn(""); part.withP4ServerName(mockName); assertFalse(ServerConfig.isValidServerConfig(part)); part.withConfigProblems(createWarning()) .withServerName("my-server"); assertFalse(ServerConfig.isValidServerConfig(part)); part.withUsername(""); assertFalse(ServerConfig.isValidServerConfig(part)); part.withUsername("abc"); assertTrue(ServerConfig.isValidServerConfig(part)); }
@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 getters_2() { MockConfigPart part = new MockConfigPart(); ConfigProblem cp = new ConfigProblem(part, "Too bad", false); assertFalse(cp.isError()); assertEquals("Too bad", cp.getMessage()); assertEquals(part, cp.getSource()); assertEquals( "problem(" + part + ": Too bad)", cp.toString()); part.withUsername("u"); assertEquals(part, cp.getSource()); assertEquals( "problem(" + part + ": Too bad)", cp.toString()); }
public MockConfigPart copy() { MockConfigPart ret = new MockConfigPart() .withSourceName(sourceName) .withP4ServerName(serverName) .withClientname(clientname) .withUsername(username) .withAuthTicketFile(authTicketFile) .withTrustTicketFile(trustTicketFile) .withServerFingerprint(serverFingerprint) .withClientHostname(clientHostname) .withIgnoreFileName(ignoreFileName) .withDefaultCharset(defaultCharset) .withLoginSso(loginSso) .withReloadValue(reloadValue) .withRequiresUserEnteredPassword(requiresUserEnteredPassword); if (hasPasswordSet) { ret.withPassword(password); } else { ret.withNoPassword(); } return ret; }