[jbosstools-commits] JBoss Tools SVN: r41297 - in trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test: dialog/preferences and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed May 23 10:22:13 EDT 2012


Author: ljelinko
Date: 2012-05-23 10:22:12 -0400 (Wed, 23 May 2012)
New Revision: 41297

Added:
   trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/RuntimeDetectionTestCase.java
Modified:
   trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/RuntimeDuplications.java
   trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/ServerWithSeam.java
   trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/PreferencesDialog.java
   trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java
   trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/CheckSeamRuntimeTemplate.java
   trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/DetectRuntimeTemplate.java
Log:
Refactoring.

Modified: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/RuntimeDuplications.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/RuntimeDuplications.java	2012-05-23 13:47:41 UTC (rev 41296)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/RuntimeDuplications.java	2012-05-23 14:22:12 UTC (rev 41297)
@@ -10,12 +10,9 @@
 import org.apache.commons.io.FileUtils;
 import org.jboss.tools.runtime.as.ui.bot.test.RuntimeProperties;
 import org.jboss.tools.runtime.as.ui.bot.test.detector.server.eap5.DetectEAP5;
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.RuntimeDetectionPreferencesDialog;
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SeamPreferencesDialog;
 import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SearchingForRuntimesDialog;
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.ServerRuntimesPreferencesDialog;
 import org.jboss.tools.runtime.as.ui.bot.test.entity.Runtime;
-import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.runtime.as.ui.bot.test.template.RuntimeDetectionTestCase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -26,7 +23,7 @@
  * @author Lucia Jelinkova
  *
  */
-public class RuntimeDuplications extends SWTTestExt {
+public class RuntimeDuplications extends RuntimeDetectionTestCase {
 
 	private File tmpServerPath;
 	
@@ -34,14 +31,8 @@
 	
 	private File tmpServerBPath;
 	
-	private RuntimeDetectionPreferencesDialog runtimeDetectionPreferences;
-
 	private SearchingForRuntimesDialog searchingForRuntimesDialog;
 	
-	private SeamPreferencesDialog seamPreferences = new SeamPreferencesDialog();
-	
-	private ServerRuntimesPreferencesDialog serverRuntimesPreferences = new ServerRuntimesPreferencesDialog();
-	
 	@Before
 	public void prepareServers() throws IOException{
 		File tmpDir = FileUtils.getTempDirectory();
@@ -56,13 +47,13 @@
 	
 	@Test
 	public void duplicateRuntimes(){
-		searchRuntimePath();
+		searchingForRuntimesDialog = addPath(tmpServerPath.getAbsolutePath());
 		
 		assertFoundRuntimesNumber(4);
 		assertSeamRuntimesNumber(2);
 		assertServerRuntimesNumber(2);
 		
-		searchRuntimePath();
+		searchFirstPath();
 		assertFoundRuntimesNumber(0);
 	}
 
@@ -70,42 +61,15 @@
 	public void deleteServers() throws IOException{
 		FileUtils.deleteDirectory(tmpServerPath);
 		
-		runtimeDetectionPreferences.open();
-		runtimeDetectionPreferences.removePath(RuntimeProperties.getInstance().getRuntimePath(DetectEAP5.SERVER_ID));
-		runtimeDetectionPreferences.ok();
-		
-		seamPreferences.open();
-		seamPreferences.removeAllRuntimes();
-		seamPreferences.ok();
-		
-		serverRuntimesPreferences.open();
-		serverRuntimesPreferences.removeAllRuntimes();
-		serverRuntimesPreferences.ok();
+		removeAllPaths();
+		removeAllSeamRuntimes();
+		removeAllServerRuntimes();
 	}
 	
-	private void searchRuntimePath() {
-		runtimeDetectionPreferences = new RuntimeDetectionPreferencesDialog();
-		runtimeDetectionPreferences.open();
-		runtimeDetectionPreferences.addPath(tmpServerPath.getAbsolutePath());
-		searchingForRuntimesDialog = runtimeDetectionPreferences.search();
-	}
-	
 	private void assertFoundRuntimesNumber(int expected) {
 		List<Runtime> runtimes = searchingForRuntimesDialog.getRuntimes();
 		assertThat(runtimes.size(), is(expected));
 		searchingForRuntimesDialog.ok();
 		runtimeDetectionPreferences.ok();
 	}
-	
-	private void assertSeamRuntimesNumber(int expected) {
-		seamPreferences.open();
-		assertThat(seamPreferences.getRuntimes().size(), is(expected));
-		seamPreferences.ok();
-	}
-	
-	private void assertServerRuntimesNumber(int expected) {
-		serverRuntimesPreferences.open();
-		assertThat(serverRuntimesPreferences.getRuntimes().size(), is(expected));
-		serverRuntimesPreferences.ok();
-	}
 }

Modified: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/ServerWithSeam.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/ServerWithSeam.java	2012-05-23 13:47:41 UTC (rev 41296)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/detector/ServerWithSeam.java	2012-05-23 14:22:12 UTC (rev 41297)
@@ -1,15 +1,9 @@
 package org.jboss.tools.runtime.as.ui.bot.test.detector;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
 import org.jboss.tools.runtime.as.ui.bot.test.RuntimeProperties;
 import org.jboss.tools.runtime.as.ui.bot.test.detector.server.eap5.DetectEAP5;
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.RuntimeDetectionPreferencesDialog;
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SeamPreferencesDialog;
 import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SearchingForRuntimesDialog;
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.ServerRuntimesPreferencesDialog;
-import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.runtime.as.ui.bot.test.template.RuntimeDetectionTestCase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -21,22 +15,13 @@
  * @author Lucia Jelinkova
  *
  */
-public class ServerWithSeam extends SWTTestExt {
+public class ServerWithSeam extends RuntimeDetectionTestCase {
 
-	private RuntimeDetectionPreferencesDialog runtimeDetectionPreferences;
-
 	private SearchingForRuntimesDialog searchingForRuntimesDialog;
 	
-	private SeamPreferencesDialog seamPreferences = new SeamPreferencesDialog();
-	
-	private ServerRuntimesPreferencesDialog serverRuntimesPreferences = new ServerRuntimesPreferencesDialog();
-	
 	@Before
 	public void search(){
-		runtimeDetectionPreferences = new RuntimeDetectionPreferencesDialog();
-		runtimeDetectionPreferences.open();
-		runtimeDetectionPreferences.addPath(RuntimeProperties.getInstance().getRuntimePath(DetectEAP5.SERVER_ID));
-		searchingForRuntimesDialog = runtimeDetectionPreferences.search();
+		searchingForRuntimesDialog = addPath(RuntimeProperties.getInstance().getRuntimePath(DetectEAP5.SERVER_ID));
 	}
 	
 	@Test
@@ -67,17 +52,9 @@
 	
 	@After
 	public void cleanup(){
-		runtimeDetectionPreferences.open();
-		runtimeDetectionPreferences.removePath(RuntimeProperties.getInstance().getRuntimePath(DetectEAP5.SERVER_ID));
-		runtimeDetectionPreferences.ok();
-		
-		seamPreferences.open();
-		seamPreferences.removeAllRuntimes();
-		seamPreferences.ok();
-		
-		serverRuntimesPreferences.open();
-		serverRuntimesPreferences.removeAllRuntimes();
-		serverRuntimesPreferences.ok();
+		removeAllPaths();
+		removeAllSeamRuntimes();
+		removeAllServerRuntimes();
 	}
 
 	private void deselectRuntime(String name) {
@@ -86,21 +63,8 @@
 		runtimeDetectionPreferences.ok();
 	}
 	
-	private void assertSeamRuntimesNumber(int expected) {
-		seamPreferences.open();
-		assertThat(seamPreferences.getRuntimes().size(), is(expected));
-		seamPreferences.ok();
-	}
-	
-	private void assertServerRuntimesNumber(int expected) {
-		serverRuntimesPreferences.open();
-		assertThat(serverRuntimesPreferences.getRuntimes().size(), is(expected));
-		serverRuntimesPreferences.ok();
-	}
-	
 	private void addAllDetectedRuntimes() {
-		runtimeDetectionPreferences.open();
-		searchingForRuntimesDialog = runtimeDetectionPreferences.search();
+		searchFirstPath();
 		searchingForRuntimesDialog.ok();
 		runtimeDetectionPreferences.ok();
 	}

Modified: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/PreferencesDialog.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/PreferencesDialog.java	2012-05-23 13:47:41 UTC (rev 41296)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/PreferencesDialog.java	2012-05-23 14:22:12 UTC (rev 41297)
@@ -1,5 +1,7 @@
 package org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences;
 
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
 import org.jboss.tools.ui.bot.ext.SWTBotFactory;
 import org.jboss.tools.ui.bot.ext.gen.ActionItem.Preference;
 import org.jboss.tools.ui.bot.ext.gen.IPreference;
@@ -7,6 +9,13 @@
 public class PreferencesDialog {
 
 	protected void open(String... path){
+		SWTBotExt bot = SWTBotFactory.getBot();
+		try {
+			bot.shell("Preferences");
+			ok();
+		} catch (WidgetNotFoundException e){
+			// ok
+		}
 		IPreference preference = Preference.create(path);
 		SWTBotFactory.getOpen().preferenceOpen(preference);
 	}

Modified: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java	2012-05-23 13:47:41 UTC (rev 41296)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/dialog/preferences/RuntimeDetectionPreferencesDialog.java	2012-05-23 14:22:12 UTC (rev 41297)
@@ -7,6 +7,7 @@
 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.results.VoidResult;
 import org.eclipse.swtbot.swt.finder.waits.ICondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
 import org.jboss.tools.runtime.core.model.RuntimePath;
 import org.jboss.tools.runtime.ui.RuntimeUIActivator;
 import org.jboss.tools.ui.bot.ext.SWTBotExt;
@@ -16,13 +17,6 @@
 public class RuntimeDetectionPreferencesDialog extends PreferencesDialog{
 
 	public void open(){
-		SWTBotExt bot = SWTBotFactory.getBot();
-		try {
-			bot.shell("Preferences");
-			ok();
-		} catch (WidgetNotFoundException e){
-			// ok
-		}
 		open("JBoss Tools", "JBoss Tools Runtime Detection");
 	}
 	
@@ -47,6 +41,16 @@
 		SWTBotFactory.getBot().button("Remove").click();
 	}
 	
+	public void removeAllPaths(){
+		SWTBot bot = SWTBotFactory.getBot();
+		SWTBotTable table = bot.table();
+		
+		for (int i = 0; i < table.rowCount(); i++){
+			table.click(0, 0);
+			bot.button("Remove").click();
+		}
+	}
+	
 	public SearchingForRuntimesDialog search(){
 		SWTBotFactory.getBot().button("Search...").click();
 		SWTBot bot = SWTBotFactory.getBot().shell("Searching for runtimes...").bot();

Modified: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/CheckSeamRuntimeTemplate.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/CheckSeamRuntimeTemplate.java	2012-05-23 13:47:41 UTC (rev 41296)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/CheckSeamRuntimeTemplate.java	2012-05-23 14:22:12 UTC (rev 41297)
@@ -3,17 +3,13 @@
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SeamPreferencesDialog;
 import org.jboss.tools.runtime.as.ui.bot.test.entity.Runtime;
 import org.jboss.tools.runtime.as.ui.bot.test.matcher.RuntimeMatcher;
-import org.jboss.tools.ui.bot.ext.SWTTestExt;
 import org.junit.After;
 import org.junit.Test;
 
-public abstract class CheckSeamRuntimeTemplate extends SWTTestExt {
+public abstract class CheckSeamRuntimeTemplate extends RuntimeDetectionTestCase {
 
-	private SeamPreferencesDialog seamPreferences = new SeamPreferencesDialog();
-	
 	protected abstract Runtime getExpectedRuntime();
 	
 	@Test
@@ -26,7 +22,6 @@
 	
 	@After
 	public void cleanup(){
-		seamPreferences.removeAllRuntimes();
-		seamPreferences.ok();
+		removeAllSeamRuntimes();
 	}
 }

Modified: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/DetectRuntimeTemplate.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/DetectRuntimeTemplate.java	2012-05-23 13:47:41 UTC (rev 41296)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/DetectRuntimeTemplate.java	2012-05-23 14:22:12 UTC (rev 41297)
@@ -7,11 +7,9 @@
 import java.util.List;
 
 import org.jboss.tools.runtime.as.ui.bot.test.RuntimeProperties;
-import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.RuntimeDetectionPreferencesDialog;
 import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SearchingForRuntimesDialog;
 import org.jboss.tools.runtime.as.ui.bot.test.entity.Runtime;
 import org.jboss.tools.runtime.as.ui.bot.test.matcher.RuntimeMatcher;
-import org.jboss.tools.ui.bot.ext.SWTTestExt;
 import org.junit.After;
 import org.junit.Test;
 
@@ -22,10 +20,8 @@
  * @author Lucia Jelinkova
  *
  */
-public abstract class DetectRuntimeTemplate extends SWTTestExt {
+public abstract class DetectRuntimeTemplate extends RuntimeDetectionTestCase {
 
-	private RuntimeDetectionPreferencesDialog preferences;
-
 	private SearchingForRuntimesDialog searchingForRuntimesDialog;
 
 	protected abstract String getPathID();
@@ -34,10 +30,7 @@
 
 	@Test
 	public void detectRuntime(){
-		preferences = new RuntimeDetectionPreferencesDialog();
-		preferences.open();
-		preferences.addPath(RuntimeProperties.getInstance().getRuntimePath(getPathID()));
-		searchingForRuntimesDialog = preferences.search();
+		searchingForRuntimesDialog = addPath(RuntimeProperties.getInstance().getRuntimePath(getPathID()));
 		
 		List<Runtime> runtimes = searchingForRuntimesDialog.getRuntimes(); 
 		
@@ -50,7 +43,7 @@
 	@After
 	public void closePreferences(){
 		searchingForRuntimesDialog.ok();
-		preferences.removePath(RuntimeProperties.getInstance().getRuntimePath(getPathID()));
-		preferences.ok();
+		runtimeDetectionPreferences.removeAllPaths();
+		runtimeDetectionPreferences.ok();
 	}
 }

Added: trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/RuntimeDetectionTestCase.java
===================================================================
--- trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/RuntimeDetectionTestCase.java	                        (rev 0)
+++ trunk/runtime/tests/org.jboss.tools.runtime.as.ui.bot.test/src/org/jboss/tools/runtime/as/ui/bot/test/template/RuntimeDetectionTestCase.java	2012-05-23 14:22:12 UTC (rev 41297)
@@ -0,0 +1,68 @@
+package org.jboss.tools.runtime.as.ui.bot.test.template;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.RuntimeDetectionPreferencesDialog;
+import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SeamPreferencesDialog;
+import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.SearchingForRuntimesDialog;
+import org.jboss.tools.runtime.as.ui.bot.test.dialog.preferences.ServerRuntimesPreferencesDialog;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+
+/**
+ * Provides useful methods that can be used by its descendants. 
+ * 
+ * @author Lucia Jelinkova
+ *
+ */
+public abstract class RuntimeDetectionTestCase extends SWTTestExt {
+
+	protected RuntimeDetectionPreferencesDialog runtimeDetectionPreferences = new RuntimeDetectionPreferencesDialog();
+
+	protected SeamPreferencesDialog seamPreferences = new SeamPreferencesDialog();
+	
+	protected ServerRuntimesPreferencesDialog serverRuntimesPreferences = new ServerRuntimesPreferencesDialog();
+	
+	protected SearchingForRuntimesDialog addPath(String path){
+		runtimeDetectionPreferences = new RuntimeDetectionPreferencesDialog();
+		runtimeDetectionPreferences.open();
+		runtimeDetectionPreferences.addPath(path);
+		return runtimeDetectionPreferences.search();
+	}
+	
+	protected SearchingForRuntimesDialog searchFirstPath(){
+		runtimeDetectionPreferences = new RuntimeDetectionPreferencesDialog();
+		runtimeDetectionPreferences.open();
+		return runtimeDetectionPreferences.search();
+	}
+	
+	protected void removeAllPaths(){
+		runtimeDetectionPreferences.open();
+		runtimeDetectionPreferences.removeAllPaths();
+		runtimeDetectionPreferences.ok();
+	}
+	
+	protected void removeAllSeamRuntimes(){
+		seamPreferences.open();
+		seamPreferences.removeAllRuntimes();
+		seamPreferences.ok();
+	}
+	
+	protected void removeAllServerRuntimes(){
+		serverRuntimesPreferences.open();
+		serverRuntimesPreferences.removeAllRuntimes();
+		serverRuntimesPreferences.ok();
+	}
+	
+	protected void assertSeamRuntimesNumber(int expected) {
+		seamPreferences.open();
+		assertThat(seamPreferences.getRuntimes().size(), is(expected));
+		seamPreferences.ok();
+	}
+	
+	protected void assertServerRuntimesNumber(int expected) {
+		serverRuntimesPreferences.open();
+		assertThat(serverRuntimesPreferences.getRuntimes().size(), is(expected));
+		serverRuntimesPreferences.ok();
+	}
+}



More information about the jbosstools-commits mailing list