Author: Grid.Qian
Date: 2008-06-20 02:34:33 -0400 (Fri, 20 Jun 2008)
New Revision: 8858
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java
trunk/ws/tests/org.jboss.tools.ws.ui.test/META-INF/MANIFEST.MF
trunk/ws/tests/org.jboss.tools.ws.ui.test/src/org/jboss/tools/ws/ui/test/preferences/JbossWSRuntimePreferencePageTest.java
Log:
JBIDE-2323: add test for preference page
Modified:
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java 2008-06-20
04:36:13 UTC (rev 8857)
+++
trunk/ws/plugins/org.jboss.tools.ws.core/src/org/jboss/tools/ws/core/classpath/JbossWSRuntimeManager.java 2008-06-20
06:34:33 UTC (rev 8858)
@@ -43,13 +43,7 @@
* Private constructor
*/
private JbossWSRuntimeManager() {
- IPreferenceStore ps = JbossWSCorePlugin.getDefault()
- .getPreferenceStore();
-
- String runtimeListString = ps
- .getString(JbossWSCoreMessages.WS_Location);
-
- runtimes = converter.getMap(runtimeListString);
+ load();
}
/**
@@ -111,7 +105,8 @@
* @param defaultRt
* boolean - default flag
*/
- public void addRuntime(String name, String path, String version, boolean defaultRt) {
+ public void addRuntime(String name, String path, String version,
+ boolean defaultRt) {
JbossWSRuntime jbossWSRt = new JbossWSRuntime();
jbossWSRt.setHomeDir(path);
jbossWSRt.setName(name);
@@ -277,7 +272,8 @@
for (IFacetedProject facetedProject : facetedProjects) {
QualifiedName qRuntimeName =
IJBossWSFacetDataModelProperties.PERSISTENCE_PROPERTY_QNAME_RUNTIME_NAME;
try {
- if(name.equals(facetedProject.getProject().getPersistentProperty(qRuntimeName))){
+ if (name.equals(facetedProject.getProject()
+ .getPersistentProperty(qRuntimeName))) {
return true;
}
} catch (CoreException e) {
@@ -287,4 +283,14 @@
return false;
}
+ public void load() {
+ IPreferenceStore ps = JbossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+
+ String runtimeListString = ps
+ .getString(JbossWSCoreMessages.WS_Location);
+
+ runtimes = converter.getMap(runtimeListString);
+ }
+
}
\ No newline at end of file
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java 2008-06-20
04:36:13 UTC (rev 8857)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/preferences/JbossRuntimeListFieldEditor.java 2008-06-20
06:34:33 UTC (rev 8858)
@@ -200,10 +200,11 @@
TableColumn tc2 = new TableColumn(tableView.getTable(), SWT.LEFT);
tc2.setWidth(TC_NAME_WIDTH);
tc2.setText(JbossWSUIMessages.JBossWS_Runtime_List_Field_Editor_Name);
-
+
TableColumn tc3 = new TableColumn(tableView.getTable(), SWT.LEFT);
tc3.setWidth(TC_VERSION_WIDTH);
- tc3.setText(JbossWSUIMessages.JBossWS_Runtime_List_Field_Editor_Version);
+ tc3
+ .setText(JbossWSUIMessages.JBossWS_Runtime_List_Field_Editor_Version);
TableColumn tc4 = new TableColumn(tableView.getTable(), SWT.LEFT);
tc4.setWidth(TC_PATH_WIDTH);
@@ -345,7 +346,7 @@
break;
}
}
- if (!checked) {
+ if (!checked && runtimes.size() > 0) {
if (tableView.getCheckedElements() == null
|| tableView.getCheckedElements().length == 0) {
tableView.setChecked(runtimes.get(0), true);
@@ -409,7 +410,7 @@
private static final String SRT_NAME = "name";
private static final String SRT_VERSION = "version";
private static final String SRT_HOMEDIR = "homeDir";
-
+
private static final int GL_PARENT_COLUMNS = 1;
private static final int GL_CONTENT_COLUMNS = 3;
@@ -421,14 +422,13 @@
IFieldEditor version = createTextEditor(SRT_VERSION,
JbossWSUIMessages.JBossWS_Runtime_List_Field_Editor_Version, "");
//$NON-NLS-1$
-
IFieldEditor homeDir = createBrowseFolderEditor(
SRT_HOMEDIR,
JbossWSUIMessages.JBossWS_Runtime_List_Field_Editor_Home_Folder,
""); //$NON-NLS-1$
JbossWSRuntime current = null;
-
+
IFieldEditor jars = null;
public JbossWSRuntimeWizardPage(List<JbossWSRuntime> editedList) {
@@ -461,15 +461,13 @@
version.addPropertyChangeListener(this);
homeDir.doFillIntoGrid(root);
homeDir.addPropertyChangeListener(this);
-
- jars = new JbwsLibraryListFieldEditor("", "",
- current);
+
+ jars = new JbwsLibraryListFieldEditor("", "", current);
jars.doFillIntoGrid(root);
jars.addPropertyChangeListener(this);
setPageComplete(false);
setControl(root);
}
-
/**
* Process evt: setup default values based on JbossWS Home folder and
@@ -518,22 +516,23 @@
}
}
- JbossWSRuntime jarJbws = (JbossWSRuntime)jars.getValue();
+ JbossWSRuntime jarJbws = (JbossWSRuntime) jars.getValue();
if (current != null
&& current.getName().equals(name.getValueAsString())
&& current.getHomeDir().equals(homeDir.getValueAsString())
&& current.getVersion().equals(version.getValueAsString())
- && current.isUserConfigClasspath() == jarJbws.isUserConfigClasspath()
- && (!jarJbws.isUserConfigClasspath()
- || hasSameLibraies(current.getLibraries(), jarJbws.getLibraries()))) {
-
+ && current.isUserConfigClasspath() == jarJbws
+ .isUserConfigClasspath()
+ && (!jarJbws.isUserConfigClasspath() || hasSameLibraies(
+ current.getLibraries(), jarJbws.getLibraries()))) {
+
setErrorMessage(null);
setPageComplete(false);
return;
}
-
- if(jarJbws.isUserConfigClasspath()
- && jarJbws.getLibraries().size() == 0){
+
+ if (jarJbws.isUserConfigClasspath()
+ && jarJbws.getLibraries().size() == 0) {
setErrorMessage("The library must contian at least one jar.");
setPageComplete(false);
return;
@@ -556,14 +555,17 @@
setPageComplete(true);
}
- private boolean hasSameLibraies(List<String> lib1, List<String> lib2){
- if(lib1.size() != lib2.size()) return false;
- for(String jar: lib1){
- if(!lib2.contains(jar)) return false;
+ private boolean hasSameLibraies(List<String> lib1, List<String> lib2) {
+ if (lib1.size() != lib2.size())
+ return false;
+ for (String jar : lib1) {
+ if (!lib2.contains(jar))
+ return false;
}
-
+
return true;
}
+
/**
* Return JbossWS Runtime instance initialized by user input
*
@@ -574,7 +576,7 @@
newRt.setName(name.getValueAsString());
newRt.setVersion(version.getValueAsString());
newRt.setHomeDir(homeDir.getValueAsString());
- JbossWSRuntime rt = (JbossWSRuntime)jars.getValue();
+ JbossWSRuntime rt = (JbossWSRuntime) jars.getValue();
newRt.setLibraries(rt.getLibraries());
newRt.setUserConfigClasspath(rt.isUserConfigClasspath());
return newRt;
@@ -605,8 +607,6 @@
return editor;
}
-
-
public ButtonFieldEditor.ButtonPressedAction createSelectFolderAction(
String buttonName) {
return new ButtonFieldEditor.ButtonPressedAction(buttonName) {
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.test/META-INF/MANIFEST.MF 2008-06-20 04:36:13 UTC
(rev 8857)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.test/META-INF/MANIFEST.MF 2008-06-20 06:34:33 UTC
(rev 8858)
@@ -8,5 +8,6 @@
org.eclipse.core.runtime,
org.junit,
org.jboss.tools.tests,
- org.jboss.tools.ws.ui
+ org.jboss.tools.ws.ui,
+ org.jboss.tools.ws.core
Eclipse-LazyStart: true
Modified:
trunk/ws/tests/org.jboss.tools.ws.ui.test/src/org/jboss/tools/ws/ui/test/preferences/JbossWSRuntimePreferencePageTest.java
===================================================================
---
trunk/ws/tests/org.jboss.tools.ws.ui.test/src/org/jboss/tools/ws/ui/test/preferences/JbossWSRuntimePreferencePageTest.java 2008-06-20
04:36:13 UTC (rev 8857)
+++
trunk/ws/tests/org.jboss.tools.ws.ui.test/src/org/jboss/tools/ws/ui/test/preferences/JbossWSRuntimePreferencePageTest.java 2008-06-20
06:34:33 UTC (rev 8858)
@@ -7,12 +7,24 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.ws.ui.test.preferences;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceDialog;
import org.jboss.tools.test.util.WorkbenchUtils;
+import org.jboss.tools.ws.core.JbossWSCorePlugin;
+import org.jboss.tools.ws.core.classpath.JbossWSRuntime;
+import org.jboss.tools.ws.core.classpath.JbossWSRuntimeListConverter;
+import org.jboss.tools.ws.core.classpath.JbossWSRuntimeManager;
+import org.jboss.tools.ws.core.messages.JbossWSCoreMessages;
+import org.jboss.tools.ws.ui.preferences.JbossRuntimeListFieldEditor;
import org.jboss.tools.ws.ui.preferences.JbossWSRuntimePreferencePage;
import junit.framework.TestCase;
@@ -21,23 +33,121 @@
* @author Grid Qian
*/
public class JbossWSRuntimePreferencePageTest extends TestCase {
-
+
/**
* Test that preference page is showed up without errors
*/
- public void testShowSeamPreferencePage() {
-
- PreferenceDialog prefDialog =
- WorkbenchUtils.createPreferenceDialog("org.jboss.tools.ws.ui.preferences.JbossWSRuntimePreferencePage");
+ public void testShowJbossWSRuntimePreferencePage() {
+ PreferenceDialog prefDialog = WorkbenchUtils
+ .createPreferenceDialog("org.jboss.tools.ws.ui.preferences.JbossWSRuntimePreferencePage");
try {
- prefDialog.setBlockOnOpen(false);
- prefDialog.open();
-
- Object selectedPage = prefDialog.getSelectedPage();
- assertTrue("Selected page is not an instance of
JbossWSRuntimePreferencePage", selectedPage instanceof
JbossWSRuntimePreferencePage);
+ Object object = openPreferencepage(prefDialog);
+ assertTrue(
+ "Selected page is not an instance of JbossWSRuntimePreferencePage",
+ object instanceof JbossWSRuntimePreferencePage);
} finally {
prefDialog.close();
}
}
+
+ private Object openPreferencepage(PreferenceDialog prefDialog) {
+ prefDialog.setBlockOnOpen(false);
+ prefDialog.open();
+ return prefDialog.getSelectedPage();
+ }
+
+ /**
+ * Test correct contents in that preference page
+ */
+ @SuppressWarnings("unchecked")
+ public void testDisplayJbossWSRuntimePreferencePage() {
+ PreferenceDialog prefDialog = WorkbenchUtils
+ .createPreferenceDialog("org.jboss.tools.ws.ui.preferences.JbossWSRuntimePreferencePage");
+ JbossWSRuntimePreferencePage selectedPage = null;
+ try {
+ Object object = openPreferencepage(prefDialog);
+ String runtime = getRuntimeList();
+ selectedPage = (JbossWSRuntimePreferencePage) object;
+ JbossRuntimeListFieldEditor jbossWSRuntimes = selectedPage
+ .getJbossWSRuntimes();
+ if (runtime.equals("")) {
+ assertTrue(
+ "The JBoss Ws Runtime locations are not displayed",
+ ((ArrayList<JbossWSRuntime>) jbossWSRuntimes.getValue())
+ .size() == 0);
+ } else {
+ JbossWSRuntimeListConverter converter = new JbossWSRuntimeListConverter();
+ Map<String, JbossWSRuntime> runtimes = converter
+ .getMap(runtime);
+ assertTrue(
+ "The JBoss Ws Runtime locations are not displayed",
+ runtimes.values().size() == ((ArrayList<JbossWSRuntime>) jbossWSRuntimes
+ .getValue()).size());
+ }
+ } finally {
+ prefDialog.close();
+ }
+
+ }
+
+ /**
+ * Set and Test correct contents in that preference page
+ */
+ @SuppressWarnings("unchecked")
+ public void testSetAndDisplayJbossWSRuntimePreferencePage() {
+ setRuntimeList();
+ PreferenceDialog prefDialog = WorkbenchUtils
+ .createPreferenceDialog("org.jboss.tools.ws.ui.preferences.JbossWSRuntimePreferencePage");
+ JbossWSRuntimePreferencePage selectedPage = null;
+ try {
+ Object object = openPreferencepage(prefDialog);
+ String runtime = getRuntimeList();
+ selectedPage = (JbossWSRuntimePreferencePage) object;
+ JbossRuntimeListFieldEditor jbossWSRuntimes = selectedPage
+ .getJbossWSRuntimes();
+ assertTrue("The preference store for jboss ws runtime is wrong",
+ !runtime.equals(""));
+ JbossWSRuntimeListConverter converter = new JbossWSRuntimeListConverter();
+ Map<String, JbossWSRuntime> runtimes = converter.getMap(runtime);
+ assertTrue(
+ "The JBoss Ws Runtime locations are not displayed correctly",
+ runtimes.values().size() == ((ArrayList<JbossWSRuntime>) jbossWSRuntimes
+ .getValue()).size());
+ } finally {
+ prefDialog.close();
+ }
+
+ }
+
+ private void setRuntimeList() {
+ String jbosshome = System.getProperty("jbosstools.test.jboss.home.4.2",
+ "/home/grid/Software/jboss-4.2.2.GA");
+ String runtime = "name|jboss-4.2.2.GA|version|2.0|homeDir|" + jbosshome
+ + "|default|false|userConfig|true|libraries|" + jbosshome
+ + "/lib/commons-codec.jar,name|jboss|version|2.0|homeDir|"
+ + jbosshome + "|default|true|userConfig|false|libraries|";
+ JbossWSCorePlugin.getDefault().getPreferenceStore().setValue(
+ JbossWSCoreMessages.WS_Location, runtime);
+ IPreferenceStore store = JbossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+ if (store instanceof IPersistentPreferenceStore) {
+ try {
+ ((IPersistentPreferenceStore) store).save();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ JbossWSRuntimeManager.getInstance().load();
+
+ }
+
+ private String getRuntimeList() {
+ IPreferenceStore ps = JbossWSCorePlugin.getDefault()
+ .getPreferenceStore();
+ String runtimeListString = ps
+ .getString(JbossWSCoreMessages.WS_Location);
+ return runtimeListString;
+ }
+
}