Author: dgolovin
Date: 2008-10-17 16:13:31 -0400 (Fri, 17 Oct 2008)
New Revision: 10944
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/OpenSeamComponentDialog.java
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/AbstractSeamNewOperationTest.java
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/OpenSeamComponentDialogTest.java
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/SeamProjectNewWizardTest.java
Log:
Example how coverage report should be used to achieve maximum coverage for JUnitTests
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/OpenSeamComponentDialog.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/OpenSeamComponentDialog.java 2008-10-17
18:09:05 UTC (rev 10943)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/wizard/OpenSeamComponentDialog.java 2008-10-17
20:13:31 UTC (rev 10944)
@@ -15,8 +15,10 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -24,6 +26,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogSettings;
@@ -50,6 +53,7 @@
*
*/
public class OpenSeamComponentDialog extends FilteredItemsSelectionDialog {
+
private static final String FILE_NAME = "OpenSeamComponentHistory.xml";
//$NON-NLS-1$
private static final String ROOT_NODE = "historyRootNode"; //$NON-NLS-1$
private static final String INFO_NODE = "infoNode"; //$NON-NLS-1$
@@ -73,14 +77,21 @@
getSelectionHistory().load(memento);
}
- public void beginTest() {
- create();
+ public void startSearch() {
applyFilter();
}
- public void endTest() {
+ @Override
+ public void okPressed() {
+ // TODO Auto-generated method stub
+ super.okPressed();
+ }
+
+ public void stopSearchAndShowResults() {
refresh();
- setResult(getSelectedItems().toList());
+ List list = getSelectedItems().toList();
+ Collections.sort(list,getItemsComparator());
+ setResult(list);
}
protected Control createExtendedContentArea(Composite parent) {
@@ -198,7 +209,7 @@
}
protected IStatus validateItem(Object item) {
- return new SeamComponentStatus();
+ return new Status(getSelectedItems().size() >=
0?IStatus.OK:IStatus.ERROR,SeamGuiPlugin.PLUGIN_ID,null);
}
public class SeamComponentComparator implements
@@ -239,48 +250,6 @@
}
}
- public class SeamComponentStatus implements IStatus {
- public IStatus[] getChildren() {
- return null;
- }
-
- public int getCode() {
- return 0;
- }
-
- public Throwable getException() {
- return null;
- }
-
- public String getMessage() {
- return ""; //$NON-NLS-1$
- }
-
- public String getPlugin() {
- return ""; //$NON-NLS-1$
- }
-
- public int getSeverity() {
- return 0;
- }
-
- public boolean isMultiStatus() {
- return false;
- }
-
- public boolean isOK() {
- if (getSelectedItems().size() < 0)
- return false;
-
- return true;
- }
-
- public boolean matches(int severityMask) {
- return false;
- }
-
- }
-
public class SeamComponentSelectionHistory extends SelectionHistory {
public SeamComponentSelectionHistory() {
@@ -368,18 +337,10 @@
return componentName;
}
- public void setComponentName(String componentName) {
- this.componentName = componentName;
- }
-
public String getProjectName() {
return projectName;
}
- public void setProjectName(String projectName) {
- this.projectName = projectName;
- }
-
public ISeamComponent getComponent() {
if (component == null) {
IProject project = ResourcesPlugin.getWorkspace().getRoot()
@@ -398,10 +359,6 @@
return component;
}
- public void setComponent(ISeamComponent component) {
- this.component = component;
- }
-
}
public static void validateHistory(ISeamProject seamProject) {
Modified:
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/AbstractSeamNewOperationTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/AbstractSeamNewOperationTest.java 2008-10-17
18:09:05 UTC (rev 10943)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/AbstractSeamNewOperationTest.java 2008-10-17
20:13:31 UTC (rev 10944)
@@ -84,13 +84,12 @@
}
protected void setUp() throws Exception {
- super.setUp();
- try {
+
JobUtils.waitForIdle();
- } catch (Exception e) {
- JUnitUtils.fail(e.getMessage(), e);
- }
- JobUtils.delay(3000);
+
+
+
+
}
abstract protected IProject getProject();
Modified:
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/OpenSeamComponentDialogTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/OpenSeamComponentDialogTest.java 2008-10-17
18:09:05 UTC (rev 10943)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/OpenSeamComponentDialogTest.java 2008-10-17
20:13:31 UTC (rev 10944)
@@ -43,10 +43,8 @@
"projects/TestComponentView",
"TestComponentView");
project = setup.importProject();
- this.project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
this.project = project.getProject();
- this.project.build(IncrementalProjectBuilder.FULL_BUILD, null);
JobUtils.waitForIdle();
}
@@ -69,45 +67,44 @@
}
public void testOpenSeamComponentDialogSearch() {
-
find("m", "mockSecureEntity", true);
find("o", "org.jboss.seam.captcha.captcha", false);
find("p", "org.jboss.seam.core.pageContext", false);
-
}
-
//JBIDE-1879
public void testFindShortHand() {
find("o*jbpm", "org.jboss.seam.core.jbpm", true);
find("jbpm", "org.jboss.seam.core.jbpm", false);
-
-
}
private void find(String pattern, String componentName, boolean wait){
OpenSeamComponentDialog dialog = new OpenSeamComponentDialog(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ dialog.setBlockOnOpen(false);
dialog.setInitialPattern(pattern);
- dialog.beginTest();
- if(wait){
- try {
- JobUtils.waitForIdle();
- }catch(Exception ex){
- ex.printStackTrace();
+ dialog.open();
+ try {
+ dialog.startSearch();
+ if(wait){
+ JobUtils.waitForIdle();
+ JobUtils.delay(2000);
}
- }
- dialog.endTest();
- Object[] objects = dialog.getResult();
+ dialog.stopSearchAndShowResults();
+ Object[] objects = dialog.getResult();
+
+ assertNotNull("Search dialog returned null when searching for " + pattern,
objects);
+
+ assertTrue("Component "+componentName+" not found", objects.length
!= 0);
- assertNotNull("Search dialog returned null when searching for " + pattern,
objects);
+ SeamComponentWrapper wrapper = (SeamComponentWrapper)objects[0];
+ assertNotNull(wrapper.getComponent());
- assertTrue("Component "+componentName+" not found", objects.length
!= 0);
-
- SeamComponentWrapper wrapper = (SeamComponentWrapper)objects[0];
-
- assertEquals("Component "+componentName+" not found with " +
pattern, wrapper.getComponentName(), componentName);
+ assertEquals("Component "+componentName+" not found with " +
pattern, componentName, wrapper.getComponentName());
+ } finally {
+ dialog.okPressed();
+ }
}
}
Modified:
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/SeamProjectNewWizardTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/SeamProjectNewWizardTest.java 2008-10-17
18:09:05 UTC (rev 10943)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/wizard/SeamProjectNewWizardTest.java 2008-10-17
20:13:31 UTC (rev 10944)
@@ -26,6 +26,7 @@
import org.eclipse.ui.PlatformUI;
import
org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import
org.eclipse.wst.common.frameworks.internal.operations.IProjectCreationPropertiesNew;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.web.ui.internal.wizards.NewProjectDataModelFacetWizard;
import org.jboss.tools.common.util.WorkbenchUtils;
@@ -70,6 +71,7 @@
wizard);
dialog.create();
startSeamPrjWzPg = wizard.getStartingPage();
+ wizard.getDataModel().setStringProperty("IProjectCreationPropertiesNew.PROJECT_NAME","testName");
assertNotNull("Cannot create seam start wizard page", startSeamPrjWzPg);
}