fix bug 8804, add unit tests
authortimkelly
Mon, 06 Apr 2009 14:24:14 -0500
changeset 54 ff58688cad6c
parent 51 da820b19f9da (diff)
parent 53 fc4ab2e45685 (current diff)
child 56 887bd61e1328
fix bug 8804, add unit tests
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.branch.txt	Mon Apr 06 14:24:14 2009 -0500
@@ -0,0 +1,1 @@
+default
--- a/.hgignore	Mon Apr 06 14:15:56 2009 -0500
+++ b/.hgignore	Mon Apr 06 14:24:14 2009 -0500
@@ -1,6 +1,5 @@
 # use glob syntax.
 syntax: glob
-*.class
 bin
 runtime
 .DS_Store
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnectedService.java	Mon Apr 06 14:15:56 2009 -0500
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/AbstractConnectedService.java	Mon Apr 06 14:24:14 2009 -0500
@@ -32,7 +32,7 @@
 
 public abstract class AbstractConnectedService implements IConnectedService {
 	
-	protected final static int TIMEOUT = 2000;
+	public final static int TIMEOUT = 2000;
 	
 	public static class ConnectionFailException extends Exception {
 		public ConnectionFailException(String string) {
@@ -122,6 +122,7 @@
 	protected IRunnableContext runnableContext;
 	protected Status currentStatus;
 	protected Tester tester;
+	protected boolean manualTesting;
 
 	public AbstractConnectedService(IService service, AbstractSynchronizedConnection connection) {
 		this.service = service;
@@ -173,7 +174,7 @@
 	}
 
 	public void testStatus() {
-		if (!isEnabled())
+		if (!(isEnabled() || manualTesting))
 			return;
 			
 		final TestResult result[] = { null };
@@ -196,12 +197,16 @@
 			result[0] = runTestStatus(new NullProgressMonitor());
 		}
 		
-		if (!isEnabled()) // could be waiting for response past when service testing was disabled
+		if (!(isEnabled() || manualTesting)) // could be waiting for response past when service testing was disabled
 			return;
 		if (result[0].shortDescription != null && result[0].longDescription != null) {
 			currentStatus.setEStatus(result[0].estatus, result[0].shortDescription, result[0].longDescription);
 		}
 	}
+	
+	public void setManualTesting() {
+		manualTesting = true;
+	}
 
 	public boolean isEnabled() {
 		return tester != null;
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionSettingsPage.java	Mon Apr 06 14:15:56 2009 -0500
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionSettingsPage.java	Mon Apr 06 14:24:14 2009 -0500
@@ -23,6 +23,7 @@
 import com.nokia.carbide.remoteconnections.interfaces.*;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory.IValidationErrorReporter;
 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller;
 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller.IPackageContents;
@@ -55,6 +56,23 @@
 import java.util.List;
 
 public class ConnectionSettingsPage extends WizardPage {
+	
+	public final class Tester extends Thread {
+		@Override
+		public void run() {
+			((AbstractConnectedService) connectedService).setManualTesting();
+			for (int i = 0; i < 3 && connectedService != null; i++) {
+				connectedService.testStatus();
+				try {
+					if (i < 2)
+						sleep(AbstractConnectedService.TIMEOUT);
+				} catch (InterruptedException e) {
+					break;
+				}
+			}
+			resetServiceTesting(false);
+		}
+	}
 
 	private final static TreeNode LOADING_CONTENT_TREENODE = 
 		new TreeNode(Messages.getString("ConnectionSettingsPage.GettingDataMessage")); //$NON-NLS-1$
@@ -78,8 +96,9 @@
 	private IConnectionFactory connectionFactory;
 	private IConnection connection;
 	private IService service;
-	private IConnectedService connectedService;
+	private volatile IConnectedService connectedService;
 	private IStatusChangedListener statusListener;
+	private Tester tester;
 	private SashForm installerSashForm;
 	private TreeViewer installerTreeViewer;
 	private Text installerInfoText;
@@ -201,7 +220,7 @@
 				IService curService = (IService) selection.getFirstElement();
 				if (!curService.equals(service)) {
 					service = curService;
-					resetServiceTesting();
+					resetServiceTesting(true);
 				}
 			}
 		});
@@ -230,7 +249,7 @@
 			public void widgetSelected(SelectionEvent e) {
 				if (isTesting) {
 					serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel")); //$NON-NLS-1$
-					resetServiceTesting();
+					resetServiceTesting(true);
 				}
 				else {
 					serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StopServiceTestButtonLabel")); //$NON-NLS-1$
@@ -443,7 +462,7 @@
 			}
 			servicesListViewer.getList().addFocusListener(new FocusAdapter() {
 				public void focusGained(FocusEvent e) {
-					resetServiceTesting();
+					resetServiceTesting(true);
 				}
 			});
 			
@@ -505,7 +524,7 @@
 				}
 				deviceOSComboViewer.getCombo().addFocusListener(new FocusAdapter() {
 					public void focusGained(FocusEvent e) {
-						resetServiceTesting();
+						resetServiceTesting(true);
 					}
 				});
 			}
@@ -568,13 +587,16 @@
 						public void run() {
 							if (!statusText.isDisposed())
 								statusText.setText(status.getLongDescription());
+							if (status.getEStatus().equals(EStatus.UP))
+								resetServiceTesting(false);
 						}
 					});
 				}
 			});
 			if (connectedService instanceof AbstractConnectedService)
 				((AbstractConnectedService) connectedService).setRunnableContext(getContainer());
-			connectedService.setEnabled(true);
+			tester = new Tester();
+			tester.start();
 			isTesting = true;
 		}
 	}
@@ -764,16 +786,23 @@
 		}
 	}
 	
-	private void resetServiceTesting() {
+	private void resetServiceTesting(final boolean resetAll) {
 		isTesting = false;
 		if (service == null)
 			return;
-		serviceTestInfo.setText(service.getAdditionalServiceInfo());
-		agentTestTabComposite.layout(true, true);
-		statusText.setText(STATUS_NOT_TESTED);
-		disposeConnectedService();
-		String buttonLabel = Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel"); //$NON-NLS-1$
-		serviceTestButton.setText(buttonLabel);
+		// may be called from a test thread
+		Display.getDefault().syncExec(new Runnable() {
+			public void run() {
+				if (resetAll) {
+					statusText.setText(STATUS_NOT_TESTED);
+					serviceTestInfo.setText(service.getAdditionalServiceInfo());
+					agentTestTabComposite.layout(true, true);
+				}
+				disposeConnectedService();
+				String buttonLabel = Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel"); //$NON-NLS-1$
+				serviceTestButton.setText(buttonLabel);
+			}
+		});
 	}
 
 }
--- a/core/com.nokia.carbide.cpp-feature/feature.xml	Mon Apr 06 14:15:56 2009 -0500
+++ b/core/com.nokia.carbide.cpp-feature/feature.xml	Mon Apr 06 14:24:14 2009 -0500
@@ -2,7 +2,7 @@
 <feature
       id="com.nokia.carbide.cpp"
       label="%featureName"
-      version="2.0.3.qualifier"
+      version="2.1.0.qualifier"
       provider-name="Nokia"
       plugin="com.nokia.carbide.cpp"
       image="Carbide_Image.png">
--- a/core/com.nokia.carbide.cpp/META-INF/MANIFEST.MF	Mon Apr 06 14:15:56 2009 -0500
+++ b/core/com.nokia.carbide.cpp/META-INF/MANIFEST.MF	Mon Apr 06 14:24:14 2009 -0500
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: Carbide.c++
 Bundle-SymbolicName: com.nokia.carbide.cpp; singleton:=true
-Bundle-Version: 2.0.3.qualifier
+Bundle-Version: 2.1.0.qualifier
 Bundle-Activator: com.nokia.carbide.cpp.ProductPlugin
 Bundle-Vendor: Nokia
 Bundle-Localization: plugin