From b975d1fcf8c17121f191f53cfaaf108bfffdd27a Mon Sep 17 00:00:00 2001 From: Stefan Seelmann Date: Tue, 25 May 2021 19:47:59 +0200 Subject: Fix flaky test --- .../test/integration/ui/PreferencesTest.java | 106 +++++++++++++++++++-- .../CertificateValidationPreferencePageBot.java | 21 +--- .../ModificationLogsViewPreferencePageBot.java | 56 +++++++++++ .../bots/PasswordsKeystorePreferencePageBot.java | 8 +- .../integration/ui/bots/PreferencePageBot.java | 43 +++++++++ .../test/integration/ui/bots/PreferencesBot.java | 17 ++++ .../ui/bots/SearchLogsViewPreferencePageBot.java | 65 +++++++++++++ 7 files changed, 283 insertions(+), 33 deletions(-) create mode 100644 tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ModificationLogsViewPreferencePageBot.java create mode 100644 tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencePageBot.java create mode 100644 tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchLogsViewPreferencePageBot.java diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java index 60c7bee37..046febaaa 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/PreferencesTest.java @@ -44,8 +44,10 @@ import org.apache.directory.studio.test.integration.junit5.TestLdapServer; import org.apache.directory.studio.test.integration.ui.bots.CertificateValidationPreferencePageBot; import org.apache.directory.studio.test.integration.ui.bots.CertificateViewerDialogBot; import org.apache.directory.studio.test.integration.ui.bots.KeepConnectionsPasswordsDialogBot; +import org.apache.directory.studio.test.integration.ui.bots.ModificationLogsViewPreferencePageBot; import org.apache.directory.studio.test.integration.ui.bots.PasswordsKeystorePreferencePageBot; import org.apache.directory.studio.test.integration.ui.bots.PreferencesBot; +import org.apache.directory.studio.test.integration.ui.bots.SearchLogsViewPreferencePageBot; import org.apache.directory.studio.test.integration.ui.bots.SetupMasterPasswordDialogBot; import org.apache.directory.studio.test.integration.ui.bots.VerifyMasterPasswordDialogBot; import org.eclipse.core.runtime.Platform; @@ -69,10 +71,7 @@ public class PreferencesTest extends AbstractTestBase @Test public void testCertificatValidationSettingsSaved() throws Exception { - URL url = Platform.getInstanceLocation().getURL(); - File file = new File( url.getFile() - + ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.apache.directory.studio.connection.core.prefs" ); - assertFalse( file.exists() ); + File file = getConnectionCorePreferencesFile(); // open preferences dialog PreferencesBot preferencesBot = studioBot.openPreferences(); @@ -101,9 +100,26 @@ public class PreferencesTest extends AbstractTestBase pageBot.clickRestoreDefaultsButton(); assertTrue( pageBot.isValidateCertificatesSelected() ); - // click OK, this should remove the property file as only defaults are set + // click OK, this should remove the property or the whole file preferencesBot.clickOkButton(); - assertFalse( file.exists() ); + if ( file.exists() ) + { + lines = FileUtils.readLines( file, StandardCharsets.UTF_8 ); + assertFalse( lines.contains( "validateCertificates=false" ) ); + } + else + { + assertFalse( file.exists() ); + } + } + + + private File getConnectionCorePreferencesFile() + { + URL url = Platform.getInstanceLocation().getURL(); + File file = new File( url.getFile() + + ".metadata/.plugins/org.eclipse.core.runtime/.settings/org.apache.directory.studio.connection.core.prefs" ); + return file; } @@ -255,4 +271,82 @@ public class PreferencesTest extends AbstractTestBase preferencesBot.clickCancelButton(); } + + @Test + public void testSearchLogsViewPreferencesPage() throws Exception + { + File file = getConnectionCorePreferencesFile(); + + // open preferences dialog + PreferencesBot preferencesBot = studioBot.openPreferences(); + SearchLogsViewPreferencePageBot page = preferencesBot.openSearchLogsViewPage(); + + page.setEnableSearchRequestLogs( false ); + page.setEnableSearchResultEntryLogs( true ); + page.setLogFileCount( 7 ); + page.setLogFileSize( 77 ); + page.clickApplyButton(); + + assertTrue( file.exists() ); + List lines = FileUtils.readLines( file, StandardCharsets.UTF_8 ); + assertTrue( lines.contains( "searchRequestLogsEnable=false" ) ); + assertTrue( lines.contains( "searchResultEntryLogsEnable=true" ) ); + assertTrue( lines.contains( "searchLogsFileCount=7" ) ); + assertTrue( lines.contains( "searchLogsFileSize=77" ) ); + + page.clickRestoreDefaultsButton(); + preferencesBot.clickOkButton(); + if ( file.exists() ) + { + lines = FileUtils.readLines( file, StandardCharsets.UTF_8 ); + assertFalse( lines.contains( "searchRequestLogsEnable=false" ) ); + assertFalse( lines.contains( "searchResultEntryLogsEnable=true" ) ); + assertFalse( lines.contains( "searchLogsFileCount=7" ) ); + assertFalse( lines.contains( "searchLogsFileSize=77" ) ); + } + else + { + assertFalse( file.exists() ); + } + } + + + @Test + public void testModificationLogsViewPreferencesPage() throws Exception + { + File file = getConnectionCorePreferencesFile(); + + // open preferences dialog + PreferencesBot preferencesBot = studioBot.openPreferences(); + ModificationLogsViewPreferencePageBot page = preferencesBot.openModificationLogsViewPage(); + + page.setEnableModificationLogs( false ); + page.setMaskedAttributes( "userPassword" ); + page.setLogFileCount( 2 ); + page.setLogFileSize( 22 ); + page.clickApplyButton(); + + assertTrue( file.exists() ); + List lines = FileUtils.readLines( file, StandardCharsets.UTF_8 ); + assertTrue( lines.contains( "modificationLogsEnable=false" ) ); + assertTrue( lines.contains( "modificationLogsMaskedAttributes=userPassword" ) ); + assertTrue( lines.contains( "modificationLogsFileCount=2" ) ); + assertTrue( lines.contains( "modificationLogsFileSize=22" ) ); + + page.clickRestoreDefaultsButton(); + preferencesBot.clickOkButton(); + if ( file.exists() ) + { + lines = FileUtils.readLines( file, StandardCharsets.UTF_8 ); + assertFalse( lines.contains( "modificationLogsEnable=false" ) ); + assertFalse( lines.contains( "modificationLogsMaskedAttributes=userPassword" ) ); + assertFalse( lines.contains( "modificationLogsFileCount=2" ) ); + assertFalse( lines.contains( "modificationLogsFileSize=22" ) ); + } + else + { + assertFalse( file.exists() ); + } + } + } diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/CertificateValidationPreferencePageBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/CertificateValidationPreferencePageBot.java index a9a8c51f2..7beeae47c 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/CertificateValidationPreferencePageBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/CertificateValidationPreferencePageBot.java @@ -20,30 +20,11 @@ package org.apache.directory.studio.test.integration.ui.bots; -public class CertificateValidationPreferencePageBot extends DialogBot +public class CertificateValidationPreferencePageBot extends PreferencePageBot { private static final String VALIDATE_CERTIFICATES_FOR_SECURE_LDAP_CONNECTIONS = "Validate certificates for secure LDAP connections"; - - public CertificateValidationPreferencePageBot() - { - super( "Preferences" ); - } - - - public void clickApplyButton() - { - super.clickButton( "Apply" ); - } - - - public void clickRestoreDefaultsButton() - { - super.clickButton( "Restore Defaults" ); - } - - public boolean isValidateCertificatesSelected() { return bot.checkBox( VALIDATE_CERTIFICATES_FOR_SECURE_LDAP_CONNECTIONS ).isChecked(); diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ModificationLogsViewPreferencePageBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ModificationLogsViewPreferencePageBot.java new file mode 100644 index 000000000..c5a8b687a --- /dev/null +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/ModificationLogsViewPreferencePageBot.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.test.integration.ui.bots; + + +public class ModificationLogsViewPreferencePageBot extends PreferencePageBot +{ + + public void setEnableModificationLogs( boolean b ) + { + activate(); + if ( b ) + { + bot.checkBox( 0 ).select(); + } + else + { + bot.checkBox( 0 ).deselect(); + } + } + + + public void setMaskedAttributes( String s ) + { + bot.text( 1 ).setText( s ); + } + + + public void setLogFileCount( int i ) + { + bot.text( 2 ).setText( "" + i ); + } + + + public void setLogFileSize( int i ) + { + bot.text( 3 ).setText( "" + i ); + } +} diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PasswordsKeystorePreferencePageBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PasswordsKeystorePreferencePageBot.java index 9d7fcd2fc..bd22e97ed 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PasswordsKeystorePreferencePageBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PasswordsKeystorePreferencePageBot.java @@ -20,15 +20,9 @@ package org.apache.directory.studio.test.integration.ui.bots; -public class PasswordsKeystorePreferencePageBot extends DialogBot +public class PasswordsKeystorePreferencePageBot extends PreferencePageBot { - public PasswordsKeystorePreferencePageBot() - { - super( "Preferences" ); - } - - public boolean isPasswordsKeystoreEnabled() { activate(); diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencePageBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencePageBot.java new file mode 100644 index 000000000..3438718cf --- /dev/null +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencePageBot.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.test.integration.ui.bots; + + +public class PreferencePageBot extends DialogBot +{ + + public PreferencePageBot() + { + super( "Preferences" ); + } + + + public void clickApplyButton() + { + super.clickButton( "Apply" ); + } + + + public void clickRestoreDefaultsButton() + { + super.clickButton( "Restore Defaults" ); + } + +} diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java index 35788cb43..e2f717d4a 100644 --- a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/PreferencesBot.java @@ -19,6 +19,7 @@ */ package org.apache.directory.studio.test.integration.ui.bots; + import org.apache.directory.studio.test.integration.ui.utils.TreeBot; @@ -67,4 +68,20 @@ public class PreferencesBot extends DialogBot .expand().getNode( "Syntax Coloring" ).select(); } + + public SearchLogsViewPreferencePageBot openSearchLogsViewPage() + { + bot.tree().getTreeItem( "Apache Directory Studio" ).select().expand().getNode( "LDAP Browser" ).select() + .expand().getNode( "Views" ).expand().getNode( "Search Logs View" ).select(); + return new SearchLogsViewPreferencePageBot(); + } + + + public ModificationLogsViewPreferencePageBot openModificationLogsViewPage() + { + bot.tree().getTreeItem( "Apache Directory Studio" ).select().expand().getNode( "LDAP Browser" ).select() + .expand().getNode( "Views" ).expand().getNode( "Modification Logs View" ).select(); + return new ModificationLogsViewPreferencePageBot(); + } + } diff --git a/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchLogsViewPreferencePageBot.java b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchLogsViewPreferencePageBot.java new file mode 100644 index 000000000..eba102a78 --- /dev/null +++ b/tests/test.integration.ui/src/main/java/org/apache/directory/studio/test/integration/ui/bots/SearchLogsViewPreferencePageBot.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.test.integration.ui.bots; + + +public class SearchLogsViewPreferencePageBot extends PreferencePageBot +{ + + public void setEnableSearchRequestLogs( boolean b ) + { + activate(); + if ( b ) + { + bot.checkBox( 0 ).select(); + } + else + { + bot.checkBox( 0 ).deselect(); + } + } + + + public void setEnableSearchResultEntryLogs( boolean b ) + { + activate(); + if ( b ) + { + bot.checkBox( 1 ).select(); + } + else + { + bot.checkBox( 1 ).deselect(); + } + } + + + public void setLogFileCount( int i ) + { + bot.text( 1 ).setText( "" + i ); + } + + + public void setLogFileSize( int i ) + { + bot.text( 2 ).setText( "" + i ); + } + +} -- cgit v1.2.3