@Test public void loadFormWithSSHTunneling() { ServerConfiguration configuration = ServerConfiguration.byDefault(); configuration.setSshTunnelingConfiguration( new SshTunnelingConfiguration("remotehost:22", "john.doe", AuthenticationMethod.PASSWORD, "", "mySecuredPassword")); configurationPanel.loadConfigurationData(configuration); frameFixture.tabbedPane("tabbedSettings") .selectTab("SSH"); frameFixture.textBox("sshProxyUrlField").requireText("remotehost:22"); frameFixture.textBox("sshProxyUsernameField").requireText("john.doe"); frameFixture.comboBox("sshAuthenticationMethodComboBox").requireSelection("Password"); frameFixture.textBox("sshProxyPasswordField").requireText("mySecuredPassword"); }
@NotNull private JTableFixture getResultTable() { JTableFixture tableFixture = frameFixture.table("resultTreeTable"); tableFixture.replaceCellReader(new JsonTableCellReader()); return tableFixture; } }
@Test public void loadFormWithEmptyConfiguration() { ServerConfiguration configuration = ServerConfiguration.byDefault(); configuration.setUsername("john"); configuration.setPassword("johnpassword"); configuration.setReadPreference(ReadPreference.nearest()); configurationPanel.loadConfigurationData(configuration); frameFixture.textBox("serverUrlsField").requireText("localhost:27017"); JComboBoxFixture readPreferenceComboBox = frameFixture.comboBox("readPreferenceComboBox"); readPreferenceComboBox.replaceCellReader(new ReadPreferenceComboBoxCellReader()); readPreferenceComboBox.requireSelection("nearest"); frameFixture.tabbedPane("tabbedSettings") .selectTab("Authentication"); frameFixture.textBox("usernameField").requireText("john"); frameFixture.textBox("passwordField").requireText("johnpassword"); frameFixture.tabbedPane("tabbedSettings") .selectTab("SSH"); frameFixture.textBox("sshProxyUrlField").requireEmpty(); frameFixture.comboBox("sshAuthenticationMethodComboBox").requireSelection("Private key"); frameFixture.textBox("sshPrivateKeyPathField").requireEmpty(); frameFixture.textBox("sshProxyUsernameField").requireEmpty(); frameFixture.textBox("sshProxyPasswordField").requireEmpty(); }
@Test public void validateFormWithOneServerUrl() { frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText("localhost:25"); frameFixture.checkBox("sslConnectionField").check(); JComboBoxFixture readPreferenceComboBox = frameFixture.comboBox("readPreferenceComboBox"); readPreferenceComboBox.replaceCellReader(new ReadPreferenceComboBoxCellReader()); readPreferenceComboBox.requireSelection("primary"); readPreferenceComboBox.selectItem("secondary"); frameFixture.textBox("userDatabaseField").setText("mydatabase"); frameFixture.tabbedPane("tabbedSettings") .selectTab("Authentication"); frameFixture.textBox("usernameField").setText("john"); frameFixture.textBox("passwordField").setText("johnpassword"); frameFixture.radioButton("scramSHA1AuthField").requireSelected(); frameFixture.radioButton("mongoCRAuthField").click(); ServerConfiguration configuration = new ServerConfiguration(); configurationPanel.applyConfigurationData(configuration); assertThat(configuration.getLabel()).isEqualTo("MyServer"); assertThat(configuration.getServerUrls()).containsExactly("localhost:25"); assertThat(configuration.isSslConnection()).isTrue(); assertThat(configuration.getReadPreference()).isEqualTo(ReadPreference.secondary()); assertThat(configuration.getUsername()).isEqualTo("john"); assertThat(configuration.getPassword()).isEqualTo("johnpassword"); assertThat(configuration.getUserDatabase()).isEqualTo("mydatabase"); assertThat(configuration.getAuthenticationMechanism()).isEqualTo(AuthenticationMechanism.MONGODB_CR); assertThat(configuration.getSshTunnelingConfiguration()).isEqualTo(SshTunnelingConfiguration.EMPTY); }
@Test public void validateFormWithSSHTunnelingAndPasswordAuthMethod() { frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText("localhost:25"); frameFixture.tabbedPane("tabbedSettings") .selectTab("SSH"); frameFixture.textBox("sshProxyUrlField").setText("remotehost:22"); frameFixture.comboBox("sshAuthenticationMethodComboBox").selectItem("Password"); frameFixture.label("passLabel").requireText("Password:"); frameFixture.panel(new TextFieldWithBrowseButtonGenericTypeMatcher("sshPrivateKeyPathComponent")).requireNotVisible(); frameFixture.textBox("sshProxyUsernameField").setText("john.doe"); frameFixture.textBox("sshProxyPasswordField").setText("myPassword"); ServerConfiguration configuration = new ServerConfiguration(); configurationPanel.applyConfigurationData(configuration); assertThat(configuration.getServerUrls()).containsExactly("localhost:25"); SshTunnelingConfiguration sshTunnelingConfiguration = configuration.getSshTunnelingConfiguration(); assertThat(sshTunnelingConfiguration).isNotNull(); assertThat(sshTunnelingConfiguration.getProxyUrl()).isEqualTo("remotehost:22"); assertThat(sshTunnelingConfiguration.getAuthenticationMethod()).isEqualTo(AuthenticationMethod.PASSWORD); assertThat(sshTunnelingConfiguration.getProxyUser()).isEqualTo("john.doe"); assertThat(sshTunnelingConfiguration.getPrivateKeyPath()).isNull(); assertThat(sshTunnelingConfiguration.getProxyPassword()).isEqualTo("myPassword"); }
@Test public void validateFormWithSSHTunnelingAndPassphraseAuthMethodToBeAsked() { frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText("localhost:25"); frameFixture.tabbedPane("tabbedSettings") .selectTab("SSH"); frameFixture.textBox("sshProxyUrlField").setText("remotehost:22"); frameFixture.comboBox("sshAuthenticationMethodComboBox").requireSelection("Private key"); frameFixture.label("passLabel").requireText("Passphrase:"); frameFixture.textBox("sshPrivateKeyPathField").setText("/Users/myself/.ssh/id_rsa"); frameFixture.textBox("sshProxyUsernameField").setText("john.doe"); ServerConfiguration configuration = new ServerConfiguration(); configurationPanel.applyConfigurationData(configuration); assertThat(configuration.getServerUrls()).containsExactly("localhost:25"); SshTunnelingConfiguration sshTunnelingConfiguration = configuration.getSshTunnelingConfiguration(); assertThat(sshTunnelingConfiguration).isNotNull(); assertThat(sshTunnelingConfiguration.getProxyUrl()).isEqualTo("remotehost:22"); assertThat(sshTunnelingConfiguration.getAuthenticationMethod()).isEqualTo(AuthenticationMethod.PRIVATE_KEY); assertThat(sshTunnelingConfiguration.getPrivateKeyPath()).isEqualTo("/Users/myself/.ssh/id_rsa"); assertThat(sshTunnelingConfiguration.getProxyUser()).isEqualTo("john.doe"); }
@Test public void validateFormWithReplicatSet() { frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText(" localhost:25, localhost:26 "); ServerConfiguration configuration = new ServerConfiguration(); configurationPanel.applyConfigurationData(configuration); assertThat(configuration.getServerUrls()).containsExactly("localhost:25", "localhost:26"); }
@Test public void displayMongoDocumentInTheTreeTable() { mongoEditionPanel.updateEditionTree( new Document("_id", new ObjectId("50b8d63414f85401b9268b99")) .append("label", "toto") .append("visible", false) .append("image", null)); frameFixture = Containers.showInFrame(mongoEditionPanel); JTableFixture tableFixture = frameFixture.table("editionTreeTable"); tableFixture.replaceCellReader(new JsonTableCellReader()); tableFixture.requireColumnCount(2) .requireContents(new String[][]{ {"_id", "50b8d63414f85401b9268b99"}, {"label", "toto"}, {"visible", "false"}, {"image", "null"} }); }
@Test public void loadFormWithReplicatSet() { ServerConfiguration configuration = new ServerConfiguration(); configuration.setServerUrls(Arrays.asList("localhost:25", "localhost:26")); configurationPanel.loadConfigurationData(configuration); frameFixture.textBox("serverUrlsField").requireText("localhost:25,localhost:26"); }
@Before public void setUp() { MockitoAnnotations.initMocks(MongoResultPanelTest.class); mongoResultPanel = GuiActionRunner.execute(new GuiQuery<MongoResultPanel>() { protected MongoResultPanel executeInEDT() { return new MongoResultPanel(DummyProject.getInstance(), mongoDocumentOperations, notifierMock); } }); frameFixture = Containers.showInFrame(mongoResultPanel); }
@After public void tearDown() { frameFixture.cleanUp(); }
@Test public void displayTreeWithASimpleDocument() throws Exception { mongoResultPanel.updateResultView(createCollectionResults("/testData/simpleDocument.json", "mycollec"), new Pagination()); getResultTable().requireColumnCount(2) .requireContents(new String[][]{ {"[0]", "{ \"_id\" : \"50b8d63414f85401b9268b99\", \"label\" : \"toto\", \"visible\" : false, \"image\" : null }"}, {"_id", "50b8d63414f85401b9268b99"}, {"label", "toto"}, {"visible", "false"}, {"image", "null"} }); }
@Test public void validateFormWithSSHTunnelingAndPassphraseAuthMethod() { frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText("localhost:25"); frameFixture.tabbedPane("tabbedSettings") .selectTab("SSH"); frameFixture.textBox("sshProxyUrlField").setText("remotehost:22"); frameFixture.comboBox("sshAuthenticationMethodComboBox").requireSelection("Private key"); frameFixture.label("passLabel").requireText("Passphrase:"); frameFixture.textBox("sshPrivateKeyPathField").setText("/Users/myself/.ssh/id_rsa"); frameFixture.textBox("sshProxyUsernameField").setText("john.doe"); frameFixture.textBox("sshProxyPasswordField").setText("mySecuredPassphrase"); ServerConfiguration configuration = new ServerConfiguration(); configurationPanel.applyConfigurationData(configuration); assertThat(configuration.getServerUrls()).containsExactly("localhost:25"); SshTunnelingConfiguration sshTunnelingConfiguration = configuration.getSshTunnelingConfiguration(); assertThat(sshTunnelingConfiguration).isNotNull(); assertThat(sshTunnelingConfiguration.getProxyUrl()).isEqualTo("remotehost:22"); assertThat(sshTunnelingConfiguration.getAuthenticationMethod()).isEqualTo(AuthenticationMethod.PRIVATE_KEY); assertThat(sshTunnelingConfiguration.getPrivateKeyPath()).isEqualTo("/Users/myself/.ssh/id_rsa"); assertThat(sshTunnelingConfiguration.getProxyUser()).isEqualTo("john.doe"); assertThat(sshTunnelingConfiguration.getProxyPassword()).isEqualTo("mySecuredPassphrase"); }
@Test public void validateFormWithMissingMongoUrlShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("URL(s) should be set"); frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText(null); configurationPanel.applyConfigurationData(new ServerConfiguration()); }
@Before public void setUp() { mongoManager = Mockito.spy(new MongoManager()); configurationPanel = GuiActionRunner.execute(new GuiQuery<ServerConfigurationPanel>() { protected ServerConfigurationPanel executeInEDT() { return new ServerConfigurationPanel(DummyProject.getInstance(), mongoManager); } }); frameFixture = Containers.showInFrame(configurationPanel); }
@After public void tearDown() { frameFixture.cleanUp(); }
@Test public void validateFormWithEmptyMongoUrlShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("URL(s) should be set"); frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText(""); configurationPanel.applyConfigurationData(new ServerConfiguration()); }
@After public void tearDown() { frameFixture.cleanUp(); }
@Test public void validateFormWithBadMongoPortShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("Port in the URL 'host:port' is incorrect. It should be a number"); frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText("host:port"); configurationPanel.applyConfigurationData(new ServerConfiguration()); }
@Test public void validateFormWithBadMongoUrlShouldThrowAConfigurationException() { thrown.expect(ConfigurationException.class); thrown.expectMessage("URL 'host' format is incorrect. It should be 'host:port'"); frameFixture.textBox("labelField").setText("MyServer"); frameFixture.textBox("serverUrlsField").setText("host"); configurationPanel.applyConfigurationData(new ServerConfiguration()); }